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);
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;
165 const RegisterInfo *reg_info =
nullptr;
191 const uint32_t arg_byte_size = (bit_width + (8 - 1)) / 8;
212 lldb::ValueObjectSP &new_value_sp) {
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",
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) {
282 if (
error.Success()) {
284 error.SetErrorString(
"failed to write register v0");
287 error.SetErrorStringWithFormat(
288 "returning float values with a byte size of %" PRIu64
289 " are not supported",
293 error.SetErrorString(
"returning float values longer than 128 "
294 "bits are not supported");
297 error.SetErrorString(
"v0 register is not available on this target");
301 }
else if (type_flags & eTypeIsVector) {
306 if (byte_size <= v0_info->byte_size) {
309 if (
error.Success()) {
311 error.SetErrorString(
"failed to write register v0");
318 error.SetErrorString(
"no registers are available");
334 row->GetCFAValue().SetIsRegisterPlusOffset(sp_reg_num, 0);
357 const int32_t ptr_size = 8;
359 row->GetCFAValue().SetIsRegisterPlusOffset(fp_reg_num, 2 * ptr_size);
361 row->SetUnspecifiedRegistersAreUndefined(
true);
363 row->SetRegisterLocationToAtCFAPlusOffset(fp_reg_num, ptr_size * -2,
true);
364 row->SetRegisterLocationToAtCFAPlusOffset(pc_reg_num, ptr_size * -1,
true);
385 const char *name = reg_info->name;
390 if (name[0] ==
'p' && name[1] ==
'c')
392 if (name[0] ==
'f' && name[1] ==
'p')
394 if (name[0] ==
's' && name[1] ==
'p')
396 if (name[0] ==
'l' && name[1] ==
'r')
399 if (name[0] ==
'x' || name[0] ==
'r') {
432 if (name[2] ==
'0' || name[2] ==
'1')
438 }
else if (name[0] ==
'v' || name[0] ==
's' || name[0] ==
'd') {
468 bool is_return_value,
472 std::optional<uint64_t> byte_size =
475 if (byte_size || *byte_size == 0)
478 std::unique_ptr<DataBufferHeap> heap_data_up(
486 if (homogeneous_count > 0 && homogeneous_count <= 8) {
488 if (NSRN < 8 && (8 - NSRN) >= homogeneous_count) {
491 std::optional<uint64_t> base_byte_size =
497 for (
uint32_t i = 0; i < homogeneous_count; ++i) {
499 ::snprintf(v_name,
sizeof(v_name),
"v%u", NSRN);
500 const RegisterInfo *reg_info =
502 if (reg_info ==
nullptr)
505 if (*base_byte_size > reg_info->byte_size)
514 if ((data_offset + *base_byte_size) <= heap_data_up->GetByteSize()) {
516 *reg_info, heap_data_up->GetBytes() + data_offset,
517 *base_byte_size, byte_order,
error);
518 if (bytes_copied != *base_byte_size)
520 data_offset += bytes_copied;
527 data.
SetData(DataBufferSP(heap_data_up.release()));
532 const size_t max_reg_byte_size = 16;
533 if (*byte_size <= max_reg_byte_size) {
534 size_t bytes_left = *byte_size;
536 while (data_offset < *byte_size) {
542 if (reg_info ==
nullptr)
550 const size_t curr_byte_size = std::min<size_t>(8, bytes_left);
552 *reg_info, heap_data_up->GetBytes() + data_offset, curr_byte_size,
554 if (bytes_copied == 0)
556 if (bytes_copied >= bytes_left)
558 data_offset += bytes_copied;
559 bytes_left -= bytes_copied;
563 const RegisterInfo *reg_info =
nullptr;
564 if (is_return_value) {
581 if (reg_info ==
nullptr)
593 value_addr, heap_data_up->GetBytes(), heap_data_up->GetByteSize(),
594 error) != heap_data_up->GetByteSize()) {
601 data.
SetData(DataBufferSP(heap_data_up.release()));
607 ValueObjectSP return_valobj_sp;
612 return return_valobj_sp;
619 return return_valobj_sp;
621 std::optional<uint64_t> byte_size = return_compiler_type.
GetByteSize(&thread);
623 return return_valobj_sp;
626 if (type_flags & eTypeIsScalar || type_flags & eTypeIsPointer) {
629 bool success =
false;
630 if (type_flags & eTypeIsInteger || type_flags & eTypeIsPointer) {
632 if (*byte_size <= 8) {
633 const RegisterInfo *x0_reg_info =
nullptr;
640 const bool is_signed = (type_flags & eTypeIsSigned) != 0;
641 switch (*byte_size) {
647 const RegisterInfo *x1_reg_info =
nullptr;
653 x0_reg_info->byte_size + x1_reg_info->byte_size) {
654 std::unique_ptr<DataBufferHeap> heap_data_up(
664 *x0_reg_info, heap_data_up->GetBytes() + 0, 8,
665 byte_order,
error) &&
667 *x1_reg_info, heap_data_up->GetBytes() + 8, 8,
668 byte_order,
error)) {
670 DataBufferSP(heap_data_up.release()), byte_order,
674 &thread, return_compiler_type,
ConstString(
""), data);
675 return return_valobj_sp;
682 case sizeof(uint64_t):
684 value.
GetScalar() = (int64_t)(raw_value);
686 value.
GetScalar() = (uint64_t)(raw_value);
700 value.
GetScalar() = (int16_t)(raw_value & UINT16_MAX);
706 case sizeof(uint8_t):
708 value.
GetScalar() = (int8_t)(raw_value & UINT8_MAX);
710 value.
GetScalar() = (uint8_t)(raw_value & UINT8_MAX);
716 }
else if (type_flags & eTypeIsFloat) {
717 if (type_flags & eTypeIsComplex) {
720 if (*byte_size <=
sizeof(
long double)) {
721 const RegisterInfo *v0_reg_info =
728 if (*byte_size ==
sizeof(
float)) {
731 }
else if (*byte_size ==
sizeof(
double)) {
734 }
else if (*byte_size ==
sizeof(
long double)) {
747 }
else if (type_flags & eTypeIsVector && *byte_size <= 16) {
748 if (*byte_size > 0) {
752 std::unique_ptr<DataBufferHeap> heap_data_up(
759 heap_data_up->GetByteSize(), byte_order,
761 DataExtractor data(DataBufferSP(heap_data_up.release()), byte_order,
764 &thread, return_compiler_type,
ConstString(
""), data);
769 }
else if (type_flags & eTypeIsStructUnion || type_flags & eTypeIsClass ||
770 (type_flags & eTypeIsVector && *byte_size > 16)) {
775 const bool is_return_value =
true;
777 exe_ctx, reg_ctx, return_compiler_type, is_return_value, NGRN, NSRN,
780 &thread, return_compiler_type,
ConstString(
""), data);
783 return return_valobj_sp;
787 lldb::addr_t pac_sign_extension = 0x0080000000000000ULL;
788 return (
pc & pac_sign_extension) ?
pc | mask :
pc & (~mask);
793 llvm::StringRef reg_name) {
799 uint64_t address_mask = 0;
800 lldb::ThreadSP thread_sp = process_sp->GetThreadList().GetSelectedThread();
804 address_mask = ~((1ULL << 56) - 1);
808 lldb::RegisterContextSP reg_ctx_sp = thread_sp->GetRegisterContext();
810 const RegisterInfo *reg_info =
811 reg_ctx_sp->GetRegisterInfoByName(reg_name, 0);
813 lldb::addr_t mask_reg_val = reg_ctx_sp->ReadRegisterAsUnsigned(
816 address_mask |= mask_reg_val;
825 if (process_sp->GetTarget().GetArchitecture().GetTriple().isOSLinux() &&
826 !process_sp->GetCodeAddressMask())
827 process_sp->SetCodeAddressMask(
830 return FixAddress(
pc, process_sp->GetCodeAddressMask());
837 if (process_sp->GetTarget().GetArchitecture().GetTriple().isOSLinux() &&
838 !process_sp->GetDataAddressMask())
839 process_sp->SetDataAddressMask(
842 return FixAddress(
pc, process_sp->GetDataAddressMask());
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)
static uint32_t GetMaxByteSize()
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_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.
ByteOrder
Byte ordering definitions.
@ 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
lldb::user_id_t GetID() const
Get accessor for the user ID.