14#include "llvm/ADT/STLExtras.h"
15#include "llvm/TargetParser/Triple.h"
1312 const llvm::Triple::ArchType arch_type = arch.
GetTriple().getArch();
1313 const llvm::Triple::VendorType vendor_type = arch.
GetTriple().getVendor();
1315 if (vendor_type != llvm::Triple::Apple) {
1316 if ((arch_type == llvm::Triple::arm) ||
1317 (arch_type == llvm::Triple::thumb)) {
1328 llvm::ArrayRef<addr_t> args)
const {
1342 const uint8_t reg_names[] = {
1346 llvm::ArrayRef<addr_t>::iterator ai = args.begin(), ae = args.end();
1348 for (
size_t i = 0; i < std::size(reg_names); ++i) {
1363 size_t num_stack_regs = ae - ai;
1365 sp -= (num_stack_regs * 4);
1367 sp &= ~(8ull - 1ull);
1375 for (; ai != ae; ++ai) {
1378 ->WriteRegisterValueToMemory(reg_info, arg_pos,
1413 uint32_t new_cpsr = curr_cpsr & ~MASK_CPSR_IT_MASK;
1415 if (function_addr & 1ull)
1418 new_cpsr &= ~MASK_CPSR_T;
1420 if (new_cpsr != curr_cpsr) {
1433 uint32_t num_values = values.
GetSize();
1448 for (uint32_t value_idx = 0; value_idx < num_values; ++value_idx) {
1457 if (compiler_type) {
1458 bool is_signed =
false;
1459 size_t bit_width = 0;
1462 if (std::optional<uint64_t> size = compiler_type.
GetBitSize(&thread))
1470 if (value_idx < 4) {
1496 const uint32_t arg_byte_size = (bit_width + (8 - 1)) / 8;
1502 sp += arg_byte_size;
1512 size_t byte_size,
Value &value) {
1533 const ArchSpec &arch(process_sp->GetTarget().GetArchitecture());
1547 return return_valobj_sp;
1555 return return_valobj_sp;
1559 uint32_t float_count;
1560 bool is_vfp_candidate =
false;
1561 uint8_t vfp_count = 0;
1562 uint8_t vfp_byte_size = 0;
1569 std::optional<uint64_t> bit_width = compiler_type.
GetBitSize(&thread);
1570 std::optional<uint64_t> byte_size = compiler_type.
GetByteSize(&thread);
1571 if (!bit_width || !byte_size)
1572 return return_valobj_sp;
1575 switch (*bit_width) {
1577 return return_valobj_sp;
1589 value.
GetScalar() = (uint64_t)raw_value;
1622 if (
IsArmHardFloat(thread) && (*byte_size == 8 || *byte_size == 16)) {
1623 is_vfp_candidate =
true;
1625 vfp_count = (*byte_size == 8 ? 1 : 2);
1626 }
else if (*byte_size <= 16) {
1628 uint32_t *buffer_ptr = (uint32_t *)buffer.
GetBytes();
1630 for (uint32_t i = 0; 4 * i < *byte_size; ++i) {
1639 return return_valobj_sp;
1642 if (float_count == 1 && !is_complex) {
1643 switch (*bit_width) {
1645 return return_valobj_sp;
1647 static_assert(
sizeof(double) ==
sizeof(uint64_t));
1665 value.
GetScalar() = *
reinterpret_cast<double *
>(&raw_value);
1671 static_assert(
sizeof(float) ==
sizeof(uint32_t));
1683 value.
GetScalar() = *
reinterpret_cast<float *
>(&raw_value);
1688 }
else if (is_complex && float_count == 2) {
1690 is_vfp_candidate =
true;
1691 vfp_byte_size = *byte_size / 2;
1695 return return_valobj_sp;
1698 return return_valobj_sp;
1702 const uint32_t homogeneous_count =
1705 if (homogeneous_count > 0 && homogeneous_count <= 4) {
1706 std::optional<uint64_t> base_byte_size = base_type.
GetByteSize(&thread);
1708 if (base_byte_size &&
1709 (*base_byte_size == 8 || *base_byte_size == 16)) {
1710 is_vfp_candidate =
true;
1712 vfp_count = (*base_byte_size == 8 ? homogeneous_count
1713 : homogeneous_count * 2);
1716 if (float_count == 1 && !is_complex) {
1717 is_vfp_candidate =
true;
1719 vfp_byte_size = *base_byte_size;
1720 vfp_count = homogeneous_count;
1723 }
else if (homogeneous_count == 0) {
1724 const uint32_t num_children = compiler_type.
GetNumFields();
1726 if (num_children > 0 && num_children <= 2) {
1728 for (index = 0; index < num_children; index++) {
1734 std::optional<uint64_t> base_byte_size =
1736 if (float_count == 2 && is_complex) {
1737 if (index != 0 && base_byte_size &&
1738 vfp_byte_size != *base_byte_size)
1740 else if (base_byte_size)
1741 vfp_byte_size = *base_byte_size;
1748 if (index == num_children) {
1749 is_vfp_candidate =
true;
1750 vfp_byte_size = (vfp_byte_size >> 1);
1751 vfp_count = (num_children << 1);
1757 if (*byte_size <= 4) {
1759 uint32_t raw_value =
1761 value.
SetBytes(&raw_value, *byte_size);
1762 }
else if (!is_vfp_candidate) {
1764 return return_valobj_sp;
1768 return return_valobj_sp;
1771 if (is_vfp_candidate) {
1773 ByteOrder byte_order = process_sp->GetByteOrder();
1776 uint32_t data_offset = 0;
1778 for (uint32_t reg_index = 0; reg_index < vfp_count; reg_index++) {
1779 uint32_t regnum = 0;
1781 if (vfp_byte_size == 4)
1783 else if (vfp_byte_size == 8)
1790 if (reg_info ==
nullptr)
1798 if ((data_offset + vfp_byte_size) <= data_sp->GetByteSize()) {
1801 *reg_info, data_sp->GetBytes() + data_offset, vfp_byte_size,
1803 if (bytes_copied != vfp_byte_size)
1806 data_offset += bytes_copied;
1810 if (data_offset == *byte_size) {
1819 return return_valobj_sp;
1827 return return_valobj_sp;
1833 if (!new_value_sp) {
1834 error.SetErrorString(
"Empty value object for return value.");
1838 CompilerType compiler_type = new_value_sp->GetCompilerType();
1839 if (!compiler_type) {
1840 error.SetErrorString(
"Null clang type for return value.");
1844 Thread *thread = frame_sp->GetThread().get();
1852 bool set_it_simple =
false;
1857 size_t num_bytes = new_value_sp->GetData(data, data_error);
1858 if (data_error.
Fail()) {
1859 error.SetErrorStringWithFormat(
1860 "Couldn't convert return value to raw data: %s",
1865 if (num_bytes <= 8) {
1868 if (num_bytes <= 4) {
1869 uint32_t raw_value = data.
GetMaxU32(&offset, num_bytes);
1872 set_it_simple =
true;
1874 uint32_t raw_value = data.
GetMaxU32(&offset, 4);
1879 uint32_t raw_value = data.
GetMaxU32(&offset, num_bytes - offset);
1882 set_it_simple =
true;
1886 error.SetErrorString(
"We don't support returning longer than 64 bit "
1887 "integer values at present.");
1891 error.SetErrorString(
1892 "We don't support returning complex values at present");
1894 error.SetErrorString(
1895 "We don't support returning float values at present");
1899 error.SetErrorString(
1900 "We only support setting simple integer return types at present.");
1906 unwind_plan.
Clear();
1916 row->GetCFAValue().SetIsRegisterPlusOffset(sp_reg_num, 0);
1919 row->SetRegisterLocationToRegister(pc_reg_num, lr_reg_num,
true);
1931 unwind_plan.
Clear();
1939 const int32_t ptr_size = 4;
1941 row->GetCFAValue().SetIsRegisterPlusOffset(fp_reg_num, 2 * ptr_size);
1943 row->SetUnspecifiedRegistersAreUndefined(
true);
1945 row->SetRegisterLocationToAtCFAPlusOffset(fp_reg_num, ptr_size * -2,
true);
1946 row->SetRegisterLocationToAtCFAPlusOffset(pc_reg_num, ptr_size * -1,
true);
1976 const char *name = reg_info->
name;
1977 if (name[0] ==
'r') {
1980 return name[2] ==
'\0';
1986 return name[3] ==
'\0';
1993 return name[2] ==
'\0';
1995 return name[2] ==
'\0';
1999 }
else if (name[0] ==
'd') {
2002 return name[2] ==
'\0';
2012 return name[3] ==
'\0';
2032 return name[3] ==
'\0';
2044 return name[3] ==
'\0';
2053 return name[2] ==
'\0';
2058 }
else if (name[0] ==
's') {
2061 return name[2] ==
'\0';
2073 return name[3] ==
'\0';
2087 return name[2] ==
'\0';
2092 }
else if (name[0] ==
'q') {
2113 return name[2] ==
'\0';
2116 return name[2] ==
'\0';
2120 }
else if (name[0] ==
's' && name[1] ==
'p' && name[2] ==
'\0')
static const uint32_t k_num_register_infos
static const RegisterInfo g_register_infos[]
static const uint32_t k_num_register_infos
static bool GetReturnValuePassedInMemory(Thread &thread, RegisterContext *reg_ctx, size_t byte_size, Value &value)
static const RegisterInfo g_register_infos[]
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_PLUGIN_DEFINE(PluginName)
bool GetArgumentValues(lldb_private::Thread &thread, lldb_private::ValueList &values) const override
bool CreateFunctionEntryUnwindPlan(lldb_private::UnwindPlan &unwind_plan) override
bool IsArmHardFloat(lldb_private::Thread &thread) const
lldb::ValueObjectSP GetReturnValueObjectImpl(lldb_private::Thread &thread, lldb_private::CompilerType &ast_type) const override
bool RegisterIsVolatile(const lldb_private::RegisterInfo *reg_info) override
static lldb::ABISP CreateInstance(lldb::ProcessSP process_sp, const lldb_private::ArchSpec &arch)
bool PrepareTrivialCall(lldb_private::Thread &thread, lldb::addr_t sp, lldb::addr_t func_addr, lldb::addr_t returnAddress, llvm::ArrayRef< lldb::addr_t > args) const override
lldb_private::Status SetReturnValueObject(lldb::StackFrameSP &frame_sp, lldb::ValueObjectSP &new_value) override
static llvm::StringRef GetPluginNameStatic()
bool CreateDefaultUnwindPlan(lldb_private::UnwindPlan &unwind_plan) override
const lldb_private::RegisterInfo * GetRegisterInfoArray(uint32_t &count) override
size_t GetRedZoneSize() const override
static std::unique_ptr< llvm::MCRegisterInfo > MakeMCRegisterInfo(const ArchSpec &arch)
Utility function to construct a MCRegisterInfo using the ArchSpec triple.
A section + offset based address class.
lldb::addr_t GetCallableLoadAddress(Target *target, bool is_indirect=false) const
Get the load address as a callable code load address.
bool SetLoadAddress(lldb::addr_t load_addr, Target *target, bool allow_section_end=false)
Set the address to represent load_addr.
An architecture specification class.
llvm::Triple & GetTriple()
Architecture triple accessor.
uint32_t GetFlags() const
Generic representation of a type in a programming language.
std::optional< uint64_t > GetByteSize(ExecutionContextScope *exe_scope) const
Return the size of the type in bytes.
uint32_t IsHomogeneousAggregate(CompilerType *base_type_ptr) const
CompilerType GetFieldAtIndex(size_t idx, std::string &name, uint64_t *bit_offset_ptr, uint32_t *bitfield_bit_size_ptr, bool *is_bitfield_ptr) const
bool IsFloatingPointType(uint32_t &count, bool &is_complex) const
uint32_t GetNumFields() const
bool IsIntegerOrEnumerationType(bool &is_signed) const
bool IsAggregateType() const
std::optional< uint64_t > GetBitSize(ExecutionContextScope *exe_scope) const
Return the size of the type in bits.
bool IsVectorType(CompilerType *element_type=nullptr, uint64_t *size=nullptr) const
bool IsPointerOrReferenceType(CompilerType *pointee_type=nullptr) const
bool IsPointerType(CompilerType *pointee_type=nullptr) const
A uniqued constant string class.
A subclass of DataBuffer that stores a data buffer on the heap.
lldb::offset_t GetByteSize() const override
Get the number of bytes in the data buffer.
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
Process & GetProcessRef() const
Returns a reference to the process object.
static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description, ABICreateInstance create_callback)
static bool UnregisterPlugin(ABICreateInstance create_callback)
size_t ReadScalarIntegerFromMemory(lldb::addr_t addr, uint32_t byte_size, bool is_signed, Scalar &scalar, Status &error)
uint32_t GetAddressByteSize() const
virtual uint32_t ConvertRegisterKindToRegisterNumber(lldb::RegisterKind kind, uint32_t num)
Convert from a given register numbering scheme to the lldb register numbering scheme.
uint64_t ReadRegisterAsUnsigned(uint32_t reg, uint64_t fail_value)
uint64_t GetSP(uint64_t fail_value=LLDB_INVALID_ADDRESS)
virtual bool WriteRegister(const RegisterInfo *reg_info, const RegisterValue ®_value)=0
const RegisterInfo * GetRegisterInfo(lldb::RegisterKind reg_kind, uint32_t reg_num)
bool WriteRegisterFromUnsigned(uint32_t reg, uint64_t uval)
const RegisterInfo * GetRegisterInfoByName(llvm::StringRef reg_name, uint32_t start_idx=0)
virtual bool ReadRegister(const RegisterInfo *reg_info, RegisterValue ®_value)=0
bool SignExtend(uint32_t sign_bitpos)
double GetAsDouble(double fail_value=0.0, bool *success_ptr=nullptr) const
uint32_t GetAsMemoryData(const RegisterInfo ®_info, void *dst, uint32_t dst_len, lldb::ByteOrder dst_byte_order, Status &error) const
float GetAsFloat(float fail_value=0.0f, bool *success_ptr=nullptr) const
bool GetScalarValue(Scalar &scalar) const
void SetUInt32(uint32_t uint, Type t=eTypeUInt32)
bool Fail() const
Test for error condition.
const char * AsCString(const char *default_error_str="unknown error") const
Get the error string associated with the current error.
virtual lldb::StackFrameSP GetStackFrameAtIndex(uint32_t idx)
virtual lldb::RegisterContextSP GetRegisterContext()=0
lldb::TargetSP CalculateTarget() override
lldb::ProcessSP GetProcess() const
void SetUnwindPlanForSignalTrap(lldb_private::LazyBool is_for_signal_trap)
void SetRegisterKind(lldb::RegisterKind kind)
void AppendRow(const RowSP &row_sp)
std::shared_ptr< Row > RowSP
void SetSourcedFromCompiler(lldb_private::LazyBool from_compiler)
void SetSourceName(const char *)
void SetUnwindPlanValidAtAllInstructions(lldb_private::LazyBool valid_at_all_insn)
Value * GetValueAtIndex(size_t idx)
static lldb::ValueObjectSP Create(ExecutionContextScope *exe_scope, lldb::ByteOrder byte_order, uint32_t addr_byte_size, lldb::addr_t address=LLDB_INVALID_ADDRESS)
const Scalar & GetScalar() const
void SetCompilerType(const CompilerType &compiler_type)
const CompilerType & GetCompilerType()
void SetBytes(const void *bytes, int len)
uint8_t * GetBytes()
Get a pointer to the data.
#define LLDB_REGNUM_GENERIC_RA
#define LLDB_REGNUM_GENERIC_SP
#define LLDB_REGNUM_GENERIC_ARG4
#define LLDB_REGNUM_GENERIC_ARG3
#define LLDB_REGNUM_GENERIC_ARG1
#define LLDB_REGNUM_GENERIC_FLAGS
#define LLDB_INVALID_REGNUM
#define LLDB_REGNUM_GENERIC_ARG2
#define LLDB_REGNUM_GENERIC_PC
#define LLDB_REGNUM_GENERIC_FP
A class that represents a running process on the host machine.
std::shared_ptr< lldb_private::ABI > ABISP
std::shared_ptr< lldb_private::StackFrame > StackFrameSP
std::shared_ptr< lldb_private::ValueObject > ValueObjectSP
std::shared_ptr< lldb_private::Process > ProcessSP
@ eEncodingUint
unsigned integer
ByteOrder
Byte ordering definitions.
std::shared_ptr< lldb_private::WritableDataBuffer > WritableDataBufferSP
std::shared_ptr< lldb_private::Target > TargetSP
@ eRegisterKindGeneric
insn ptr reg, stack ptr reg, etc not specific to any particular target
@ eRegisterKindDWARF
the register numbers seen DWARF
Every register is described in detail including its name, alternate name (optional),...
uint32_t byte_size
Size in bytes of the register.
const char * name
Name of this register, can't be NULL.