14#include "llvm/ADT/STLExtras.h"
15#include "llvm/TargetParser/Triple.h"
49 const llvm::Triple::ArchType arch_type = arch.
GetTriple().getArch();
50 const llvm::Triple::VendorType vendor_type = arch.
GetTriple().getVendor();
52 if (vendor_type != llvm::Triple::Apple) {
53 if (arch_type == llvm::Triple::aarch64 ||
54 arch_type == llvm::Triple::aarch64_32) {
65 llvm::ArrayRef<addr_t> args)
const {
74 s.
Printf(
"ABISysV_arm64::PrepareTrivialCall (tid = 0x%" PRIx64
75 ", sp = 0x%" PRIx64
", func_addr = 0x%" PRIx64
76 ", return_addr = 0x%" PRIx64,
77 thread.
GetID(), (uint64_t)
sp, (uint64_t)func_addr,
78 (uint64_t)return_addr);
80 for (
size_t i = 0; i < args.size(); ++i)
81 s.
Printf(
", arg%d = 0x%" PRIx64,
static_cast<int>(i + 1), args[i]);
90 for (
size_t i = 0; i < args.size(); ++i) {
93 LLDB_LOGF(log,
"About to write arg%d (0x%" PRIx64
") into %s",
94 static_cast<int>(i + 1), args[i], reg_info->
name);
125 uint32_t num_values = values.
GetSize();
138 for (uint32_t value_idx = 0; value_idx < num_values; ++value_idx) {
148 bool is_signed =
false;
149 size_t bit_width = 0;
150 std::optional<uint64_t> bit_size = value_type.
GetBitSize(&thread);
154 bit_width = *bit_size;
156 bit_width = *bit_size;
191 const uint32_t arg_byte_size = (bit_width + (8 - 1)) / 8;
215 error.SetErrorString(
"Empty value object for return value.");
219 CompilerType return_value_type = new_value_sp->GetCompilerType();
220 if (!return_value_type) {
221 error.SetErrorString(
"Null clang type for return value.");
225 Thread *thread = frame_sp->GetThread().get();
232 const uint64_t byte_size = new_value_sp->GetData(data, data_error);
233 if (data_error.
Fail()) {
234 error.SetErrorStringWithFormat(
235 "Couldn't convert return value to raw data: %s",
240 const uint32_t type_flags = return_value_type.
GetTypeInfo(
nullptr);
241 if (type_flags & eTypeIsScalar || type_flags & eTypeIsPointer) {
242 if (type_flags & eTypeIsInteger || type_flags & eTypeIsPointer) {
245 if (byte_size <= 16) {
248 if (byte_size <= 8) {
249 uint64_t raw_value = data.
GetMaxU64(&offset, byte_size);
252 error.SetErrorString(
"failed to write register x0");
254 uint64_t raw_value = data.
GetMaxU64(&offset, 8);
259 raw_value = data.
GetMaxU64(&offset, byte_size - offset);
262 error.SetErrorString(
"failed to write register x1");
266 error.SetErrorString(
"We don't support returning longer than 128 bit "
267 "integer values at present.");
269 }
else if (type_flags & eTypeIsFloat) {
270 if (type_flags & eTypeIsComplex) {
272 error.SetErrorString(
273 "returning complex float values are not supported");
278 if (byte_size <= 16) {
283 error.SetErrorString(
"failed to write register v0");
285 error.SetErrorString(
"returning float values longer than 128 "
286 "bits are not supported");
289 error.SetErrorString(
"v0 register is not available on this target");
292 }
else if (type_flags & eTypeIsVector) {
297 if (byte_size <= v0_info->byte_size) {
300 if (
error.Success()) {
302 error.SetErrorString(
"failed to write register v0");
309 error.SetErrorString(
"no registers are available");
325 row->GetCFAValue().SetIsRegisterPlusOffset(sp_reg_num, 0);
348 const int32_t ptr_size = 8;
350 row->GetCFAValue().SetIsRegisterPlusOffset(fp_reg_num, 2 * ptr_size);
352 row->SetUnspecifiedRegistersAreUndefined(
true);
354 row->SetRegisterLocationToAtCFAPlusOffset(fp_reg_num, ptr_size * -2,
true);
355 row->SetRegisterLocationToAtCFAPlusOffset(pc_reg_num, ptr_size * -1,
true);
376 const char *name = reg_info->
name;
381 if (name[0] ==
'p' && name[1] ==
'c')
383 if (name[0] ==
'f' && name[1] ==
'p')
385 if (name[0] ==
's' && name[1] ==
'p')
387 if (name[0] ==
'l' && name[1] ==
'r')
390 if (name[0] ==
'x' || name[0] ==
'r') {
423 if (name[2] ==
'0' || name[2] ==
'1')
429 }
else if (name[0] ==
'v' || name[0] ==
's' || name[0] ==
'd') {
459 bool is_return_value,
463 std::optional<uint64_t> byte_size =
466 if (byte_size || *byte_size == 0)
469 std::unique_ptr<DataBufferHeap> heap_data_up(
475 const uint32_t homogeneous_count =
477 if (homogeneous_count > 0 && homogeneous_count <= 8) {
479 if (NSRN < 8 && (8 - NSRN) >= homogeneous_count) {
482 std::optional<uint64_t> base_byte_size =
486 uint32_t data_offset = 0;
488 for (uint32_t i = 0; i < homogeneous_count; ++i) {
490 ::snprintf(v_name,
sizeof(v_name),
"v%u", NSRN);
493 if (reg_info ==
nullptr)
496 if (*base_byte_size > reg_info->
byte_size)
505 if ((data_offset + *base_byte_size) <= heap_data_up->GetByteSize()) {
507 *reg_info, heap_data_up->GetBytes() + data_offset,
508 *base_byte_size, byte_order,
error);
509 if (bytes_copied != *base_byte_size)
511 data_offset += bytes_copied;
523 const size_t max_reg_byte_size = 16;
524 if (*byte_size <= max_reg_byte_size) {
525 size_t bytes_left = *byte_size;
526 uint32_t data_offset = 0;
527 while (data_offset < *byte_size) {
533 if (reg_info ==
nullptr)
541 const size_t curr_byte_size = std::min<size_t>(8, bytes_left);
543 *reg_info, heap_data_up->GetBytes() + data_offset, curr_byte_size,
545 if (bytes_copied == 0)
547 if (bytes_copied >= bytes_left)
549 data_offset += bytes_copied;
550 bytes_left -= bytes_copied;
555 if (is_return_value) {
572 if (reg_info ==
nullptr)
584 value_addr, heap_data_up->GetBytes(), heap_data_up->GetByteSize(),
585 error) != heap_data_up->GetByteSize()) {
603 return return_valobj_sp;
610 return return_valobj_sp;
612 std::optional<uint64_t> byte_size = return_compiler_type.
GetByteSize(&thread);
614 return return_valobj_sp;
616 const uint32_t type_flags = return_compiler_type.
GetTypeInfo(
nullptr);
617 if (type_flags & eTypeIsScalar || type_flags & eTypeIsPointer) {
620 bool success =
false;
621 if (type_flags & eTypeIsInteger || type_flags & eTypeIsPointer) {
623 if (*byte_size <= 8) {
631 const bool is_signed = (type_flags & eTypeIsSigned) != 0;
632 switch (*byte_size) {
645 std::unique_ptr<DataBufferHeap> heap_data_up(
655 *x0_reg_info, heap_data_up->GetBytes() + 0, 8,
656 byte_order,
error) &&
658 *x1_reg_info, heap_data_up->GetBytes() + 8, 8,
659 byte_order,
error)) {
665 &thread, return_compiler_type,
ConstString(
""), data);
666 return return_valobj_sp;
673 case sizeof(uint64_t):
675 value.
GetScalar() = (int64_t)(raw_value);
677 value.
GetScalar() = (uint64_t)(raw_value);
681 case sizeof(uint32_t):
689 case sizeof(uint16_t):
691 value.
GetScalar() = (int16_t)(raw_value & UINT16_MAX);
693 value.
GetScalar() = (uint16_t)(raw_value & UINT16_MAX);
697 case sizeof(uint8_t):
699 value.
GetScalar() = (int8_t)(raw_value & UINT8_MAX);
701 value.
GetScalar() = (uint8_t)(raw_value & UINT8_MAX);
707 }
else if (type_flags & eTypeIsFloat) {
708 if (type_flags & eTypeIsComplex) {
711 if (*byte_size <=
sizeof(
long double)) {
719 if (*byte_size ==
sizeof(
float)) {
722 }
else if (*byte_size ==
sizeof(
double)) {
725 }
else if (*byte_size ==
sizeof(
long double)) {
738 }
else if (type_flags & eTypeIsVector && *byte_size <= 16) {
739 if (*byte_size > 0) {
743 std::unique_ptr<DataBufferHeap> heap_data_up(
750 heap_data_up->GetByteSize(), byte_order,
755 &thread, return_compiler_type,
ConstString(
""), data);
760 }
else if (type_flags & eTypeIsStructUnion || type_flags & eTypeIsClass ||
761 (type_flags & eTypeIsVector && *byte_size > 16)) {
766 const bool is_return_value =
true;
768 exe_ctx, reg_ctx, return_compiler_type, is_return_value, NGRN, NSRN,
771 &thread, return_compiler_type,
ConstString(
""), data);
774 return return_valobj_sp;
780 lldb::addr_t pac_sign_extension = 0x0080000000000000ULL;
781 return (
pc & pac_sign_extension) ?
pc | mask :
pc & (~mask);
786 llvm::StringRef reg_name) {
793 lldb::ThreadSP thread_sp = process_sp->GetThreadList().GetSelectedThread();
797 address_mask = ~((1ULL << 56) - 1);
804 reg_ctx_sp->GetRegisterInfoByName(reg_name, 0);
806 lldb::addr_t mask_reg_val = reg_ctx_sp->ReadRegisterAsUnsigned(
809 address_mask |= mask_reg_val;
818 if (process_sp->GetTarget().GetArchitecture().GetTriple().isOSLinux() &&
820 process_sp->SetCodeAddressMask(
825 const addr_t pac_sign_extension = 0x0080000000000000ULL;
826 addr_t mask = process_sp->GetCodeAddressMask();
828 if (
pc & pac_sign_extension &&
830 mask = process_sp->GetHighmemCodeAddressMask();
839 if (process_sp->GetTarget().GetArchitecture().GetTriple().isOSLinux() &&
841 process_sp->SetDataAddressMask(
846 const addr_t pac_sign_extension = 0x0080000000000000ULL;
847 addr_t mask = process_sp->GetDataAddressMask();
849 if (
pc & pac_sign_extension &&
851 mask = process_sp->GetHighmemDataAddressMask();
static bool LoadValueFromConsecutiveGPRRegisters(ExecutionContext &exe_ctx, RegisterContext *reg_ctx, const CompilerType &value_type, bool is_return_value, uint32_t &NGRN, uint32_t &NSRN, DataExtractor &data)
static bool LoadValueFromConsecutiveGPRRegisters(ExecutionContext &exe_ctx, RegisterContext *reg_ctx, const CompilerType &value_type, bool is_return_value, uint32_t &NGRN, uint32_t &NSRN, DataExtractor &data)
static lldb::addr_t ReadLinuxProcessAddressMask(lldb::ProcessSP process_sp, llvm::StringRef reg_name)
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_LOGF(log,...)
lldb::ValueObjectSP GetReturnValueObjectImpl(lldb_private::Thread &thread, lldb_private::CompilerType &ast_type) const override
bool PrepareTrivialCall(lldb_private::Thread &thread, lldb::addr_t sp, lldb::addr_t functionAddress, lldb::addr_t returnAddress, llvm::ArrayRef< lldb::addr_t > args) const override
bool GetArgumentValues(lldb_private::Thread &thread, lldb_private::ValueList &values) const override
static lldb::ABISP CreateInstance(lldb::ProcessSP process_sp, const lldb_private::ArchSpec &arch)
lldb_private::Status SetReturnValueObject(lldb::StackFrameSP &frame_sp, lldb::ValueObjectSP &new_value) override
lldb::addr_t FixCodeAddress(lldb::addr_t pc) override
Some targets might use bits in a code address to indicate a mode switch.
lldb::addr_t FixDataAddress(lldb::addr_t pc) override
bool GetPointerReturnRegister(const char *&name) override
lldb::addr_t FixAddress(lldb::addr_t pc, lldb::addr_t mask) override
bool RegisterIsVolatile(const lldb_private::RegisterInfo *reg_info) override
static llvm::StringRef GetPluginNameStatic()
size_t GetRedZoneSize() const override
bool CreateFunctionEntryUnwindPlan(lldb_private::UnwindPlan &unwind_plan) override
bool CreateDefaultUnwindPlan(lldb_private::UnwindPlan &unwind_plan) override
static std::unique_ptr< llvm::MCRegisterInfo > MakeMCRegisterInfo(const ArchSpec &arch)
Utility function to construct a MCRegisterInfo using the ArchSpec triple.
lldb::ProcessSP GetProcessSP() const
Request to get a Process shared pointer.
An architecture specification class.
llvm::Triple & GetTriple()
Architecture triple accessor.
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
bool IsIntegerOrEnumerationType(bool &is_signed) const
uint32_t GetTypeInfo(CompilerType *pointee_or_element_compiler_type=nullptr) const
std::optional< uint64_t > GetBitSize(ExecutionContextScope *exe_scope) const
Return the size of the type in bits.
bool IsPointerOrReferenceType(CompilerType *pointee_type=nullptr) const
A uniqued constant string class.
A subclass of DataBuffer that stores a data buffer on the heap.
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
ExecutionContextScope * GetBestExecutionContextScope() const
Process & GetProcessRef() const
Returns a reference to the process object.
Target * GetTargetPtr() const
Returns a pointer to the target object.
Process * GetProcessPtr() const
Returns a pointer to the process object.
void PutString(llvm::StringRef str)
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)
virtual size_t ReadMemory(lldb::addr_t vm_addr, void *buf, size_t size, Status &error)
Read of memory from a process.
lldb::ByteOrder GetByteOrder() const
uint32_t GetAddressByteSize() const
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)
bool GetData(DataExtractor &data) const
uint32_t GetAsMemoryData(const RegisterInfo ®_info, void *dst, uint32_t dst_len, lldb::ByteOrder dst_byte_order, Status &error) const
bool GetScalarValue(Scalar &scalar) const
Status SetValueFromData(const RegisterInfo ®_info, DataExtractor &data, lldb::offset_t offset, bool partial_data_ok)
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.
llvm::StringRef GetString() const
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
virtual lldb::StackFrameSP GetStackFrameAtIndex(uint32_t idx)
virtual lldb::RegisterContextSP GetRegisterContext()=0
void SetUnwindPlanForSignalTrap(lldb_private::LazyBool is_for_signal_trap)
void SetRegisterKind(lldb::RegisterKind kind)
void SetReturnAddressRegister(uint32_t regnum)
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)
void SetValueType(ValueType value_type)
const CompilerType & GetCompilerType()
#define LLDB_REGNUM_GENERIC_RA
#define LLDB_INVALID_ADDRESS_MASK
Address Mask Bits not used for addressing are set to 1 in the mask; all mask bits set is an invalid v...
#define LLDB_REGNUM_GENERIC_SP
#define LLDB_REGNUM_GENERIC_ARG1
#define LLDB_INVALID_ADDRESS
#define LLDB_REGNUM_GENERIC_ARG2
#define LLDB_REGNUM_GENERIC_PC
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
std::shared_ptr< lldb_private::ABI > ABISP
std::shared_ptr< lldb_private::StackFrame > StackFrameSP
std::shared_ptr< lldb_private::Thread > ThreadSP
std::shared_ptr< lldb_private::ValueObject > ValueObjectSP
std::shared_ptr< lldb_private::Process > ProcessSP
ByteOrder
Byte ordering definitions.
std::shared_ptr< lldb_private::DataBuffer > DataBufferSP
std::shared_ptr< lldb_private::RegisterContext > RegisterContextSP
@ eRegisterKindGeneric
insn ptr reg, stack ptr reg, etc not specific to any particular target
@ eRegisterKindLLDB
lldb's internal register numbers
@ 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.
uint32_t kinds[lldb::kNumRegisterKinds]
Holds all of the various register numbers for all register kinds.
const char * name
Name of this register, can't be NULL.
lldb::user_id_t GetID() const
Get accessor for the user ID.