14#include "llvm/ADT/STLExtras.h"
15#include "llvm/TargetParser/Triple.h"
1195const lldb_private::RegisterInfo *
1207 const llvm::Triple::ArchType arch_type = arch.
GetTriple().getArch();
1208 const llvm::Triple::VendorType vendor_type = arch.
GetTriple().getVendor();
1210 if (vendor_type != llvm::Triple::Apple) {
1211 if ((arch_type == llvm::Triple::arm) ||
1212 (arch_type == llvm::Triple::thumb)) {
1223 llvm::ArrayRef<addr_t> args)
const {
1237 const uint8_t reg_names[] = {
1241 llvm::ArrayRef<addr_t>::iterator ai = args.begin(), ae = args.end();
1243 for (
size_t i = 0; i < std::size(reg_names); ++i) {
1258 size_t num_stack_regs = ae - ai;
1260 sp -= (num_stack_regs * 4);
1262 sp &= ~(8ull - 1ull);
1270 for (; ai != ae; ++ai) {
1273 ->WriteRegisterValueToMemory(reg_info, arg_pos,
1274 reg_info->byte_size, reg_value)
1277 arg_pos += reg_info->byte_size;
1303 const RegisterInfo *cpsr_reg_info =
1308 uint32_t new_cpsr = curr_cpsr & ~MASK_CPSR_IT_MASK;
1310 if (function_addr & 1ull)
1313 new_cpsr &= ~MASK_CPSR_T;
1315 if (new_cpsr != curr_cpsr) {
1343 for (
uint32_t value_idx = 0; value_idx < num_values; ++value_idx) {
1352 if (compiler_type) {
1353 bool is_signed =
false;
1354 size_t bit_width = 0;
1357 if (std::optional<uint64_t> size = compiler_type.
GetBitSize(&thread))
1365 if (value_idx < 4) {
1367 const RegisterInfo *arg_reg_info =
nullptr;
1391 const uint32_t arg_byte_size = (bit_width + (8 - 1)) / 8;
1397 sp += arg_byte_size;
1407 size_t byte_size,
Value &value) {
1411 const RegisterInfo *r0_reg_info =
1415 thread.
GetProcess()->ReadMemory(address, buffer.GetBytes(),
1428 const ArchSpec &arch(process_sp->GetTarget().GetArchitecture());
1439 ValueObjectSP return_valobj_sp;
1442 return return_valobj_sp;
1450 return return_valobj_sp;
1455 bool is_vfp_candidate =
false;
1456 uint8_t vfp_count = 0;
1457 uint8_t vfp_byte_size = 0;
1462 const RegisterInfo *r0_reg_info =
1464 std::optional<uint64_t> bit_width = compiler_type.
GetBitSize(&thread);
1465 std::optional<uint64_t> byte_size = compiler_type.
GetByteSize(&thread);
1466 if (!bit_width || !byte_size)
1467 return return_valobj_sp;
1470 switch (*bit_width) {
1472 return return_valobj_sp;
1484 value.
GetScalar() = (uint64_t)raw_value;
1517 if (
IsArmHardFloat(thread) && (*byte_size == 8 || *byte_size == 16)) {
1518 is_vfp_candidate =
true;
1520 vfp_count = (*byte_size == 8 ? 1 : 2);
1521 }
else if (*byte_size <= 16) {
1525 for (
uint32_t i = 0; 4 * i < *byte_size; ++i) {
1531 value.
SetBytes(buffer.GetBytes(), *byte_size);
1534 return return_valobj_sp;
1537 if (float_count == 1 && !is_complex) {
1538 switch (*bit_width) {
1540 return return_valobj_sp;
1542 static_assert(
sizeof(double) ==
sizeof(uint64_t));
1546 const RegisterInfo *d0_reg_info =
1560 value.
GetScalar() = *
reinterpret_cast<double *
>(&raw_value);
1566 static_assert(
sizeof(float) ==
sizeof(
uint32_t));
1570 const RegisterInfo *s0_reg_info =
1578 value.
GetScalar() = *
reinterpret_cast<float *
>(&raw_value);
1583 }
else if (is_complex && float_count == 2) {
1585 is_vfp_candidate =
true;
1586 vfp_byte_size = *byte_size / 2;
1590 return return_valobj_sp;
1593 return return_valobj_sp;
1600 if (homogeneous_count > 0 && homogeneous_count <= 4) {
1601 std::optional<uint64_t> base_byte_size = base_type.
GetByteSize(&thread);
1603 if (base_byte_size &&
1604 (*base_byte_size == 8 || *base_byte_size == 16)) {
1605 is_vfp_candidate =
true;
1607 vfp_count = (*base_byte_size == 8 ? homogeneous_count
1608 : homogeneous_count * 2);
1611 if (float_count == 1 && !is_complex) {
1612 is_vfp_candidate =
true;
1614 vfp_byte_size = *base_byte_size;
1615 vfp_count = homogeneous_count;
1618 }
else if (homogeneous_count == 0) {
1621 if (num_children > 0 && num_children <= 2) {
1623 for (index = 0; index < num_children; index++) {
1629 std::optional<uint64_t> base_byte_size =
1631 if (float_count == 2 && is_complex) {
1632 if (index != 0 && base_byte_size &&
1633 vfp_byte_size != *base_byte_size)
1635 else if (base_byte_size)
1636 vfp_byte_size = *base_byte_size;
1643 if (index == num_children) {
1644 is_vfp_candidate =
true;
1645 vfp_byte_size = (vfp_byte_size >> 1);
1646 vfp_count = (num_children << 1);
1652 if (*byte_size <= 4) {
1656 value.
SetBytes(&raw_value, *byte_size);
1657 }
else if (!is_vfp_candidate) {
1659 return return_valobj_sp;
1663 return return_valobj_sp;
1666 if (is_vfp_candidate) {
1668 ByteOrder byte_order = process_sp->GetByteOrder();
1673 for (
uint32_t reg_index = 0; reg_index < vfp_count; reg_index++) {
1676 if (vfp_byte_size == 4)
1678 else if (vfp_byte_size == 8)
1683 const RegisterInfo *reg_info =
1685 if (reg_info ==
nullptr)
1693 if ((data_offset + vfp_byte_size) <= data_sp->GetByteSize()) {
1696 *reg_info, data_sp->GetBytes() + data_offset, vfp_byte_size,
1698 if (bytes_copied != vfp_byte_size)
1701 data_offset += bytes_copied;
1705 if (data_offset == *byte_size) {
1714 return return_valobj_sp;
1722 return return_valobj_sp;
1726 lldb::ValueObjectSP &new_value_sp) {
1728 if (!new_value_sp) {
1729 error.SetErrorString(
"Empty value object for return value.");
1733 CompilerType compiler_type = new_value_sp->GetCompilerType();
1734 if (!compiler_type) {
1735 error.SetErrorString(
"Null clang type for return value.");
1739 Thread *thread = frame_sp->GetThread().get();
1747 bool set_it_simple =
false;
1752 size_t num_bytes = new_value_sp->GetData(data, data_error);
1753 if (data_error.
Fail()) {
1754 error.SetErrorStringWithFormat(
1755 "Couldn't convert return value to raw data: %s",
1760 if (num_bytes <= 8) {
1763 if (num_bytes <= 4) {
1767 set_it_simple =
true;
1777 set_it_simple =
true;
1781 error.SetErrorString(
"We don't support returning longer than 64 bit "
1782 "integer values at present.");
1786 error.SetErrorString(
1787 "We don't support returning complex values at present");
1789 error.SetErrorString(
1790 "We don't support returning float values at present");
1794 error.SetErrorString(
1795 "We only support setting simple integer return types at present.");
1801 unwind_plan.
Clear();
1811 row->GetCFAValue().SetIsRegisterPlusOffset(sp_reg_num, 0);
1814 row->SetRegisterLocationToRegister(pc_reg_num, lr_reg_num,
true);
1826 unwind_plan.
Clear();
1834 const int32_t ptr_size = 4;
1836 row->GetCFAValue().SetIsRegisterPlusOffset(fp_reg_num, 2 * ptr_size);
1838 row->SetUnspecifiedRegistersAreUndefined(
true);
1840 row->SetRegisterLocationToAtCFAPlusOffset(fp_reg_num, ptr_size * -2,
true);
1841 row->SetRegisterLocationToAtCFAPlusOffset(pc_reg_num, ptr_size * -1,
true);
1871 const char *name = reg_info->name;
1872 if (name[0] ==
'r') {
1875 return name[2] ==
'\0';
1881 return name[3] ==
'\0';
1888 return name[2] ==
'\0';
1890 return name[2] ==
'\0';
1894 }
else if (name[0] ==
'd') {
1897 return name[2] ==
'\0';
1907 return name[3] ==
'\0';
1927 return name[3] ==
'\0';
1939 return name[3] ==
'\0';
1948 return name[2] ==
'\0';
1953 }
else if (name[0] ==
's') {
1956 return name[2] ==
'\0';
1968 return name[3] ==
'\0';
1982 return name[2] ==
'\0';
1987 }
else if (name[0] ==
'q') {
2008 return name[2] ==
'\0';
2011 return name[2] ==
'\0';
2015 }
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
"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)
#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.
@ eEncodingUint
unsigned integer
ByteOrder
Byte ordering definitions.
@ eRegisterKindGeneric
insn ptr reg, stack ptr reg, etc not specific to any particular target
@ eRegisterKindDWARF
the register numbers seen DWARF