14#include "llvm/ADT/STLExtras.h"
15#include "llvm/TargetParser/Triple.h"
38static const char *
pluginDesc =
"Mac OS X ABI for arm64 targets";
46 const llvm::Triple::ArchType arch_type = arch.
GetTriple().getArch();
47 const llvm::Triple::VendorType vendor_type = arch.
GetTriple().getVendor();
49 if (vendor_type == llvm::Triple::Apple) {
50 if (arch_type == llvm::Triple::aarch64 ||
51 arch_type == llvm::Triple::aarch64_32) {
62 lldb::addr_t return_addr, llvm::ArrayRef<lldb::addr_t> args)
const {
71 s.
Printf(
"ABIMacOSX_arm64::PrepareTrivialCall (tid = 0x%" PRIx64
72 ", sp = 0x%" PRIx64
", func_addr = 0x%" PRIx64
73 ", return_addr = 0x%" PRIx64,
74 thread.
GetID(), (uint64_t)
sp, (uint64_t)func_addr,
75 (uint64_t)return_addr);
77 for (
size_t i = 0; i < args.size(); ++i)
78 s.
Printf(
", arg%d = 0x%" PRIx64,
static_cast<int>(i + 1), args[i]);
94 for (
size_t i = 0; i < args.size(); ++i) {
97 LLDB_LOGF(log,
"About to write arg%d (0x%" PRIx64
") into %s",
98 static_cast<int>(i + 1), args[i], reg_info->
name);
123 uint32_t num_values = values.
GetSize();
136 for (uint32_t value_idx = 0; value_idx < num_values; ++value_idx) {
145 std::optional<uint64_t> bit_size = value_type.
GetBitSize(&thread);
149 bool is_signed =
false;
150 size_t bit_width = 0;
152 bit_width = *bit_size;
154 bit_width = *bit_size;
219 const uint32_t arg_byte_size = (bit_width + (8 - 1)) / 8;
247 CompilerType return_value_type = new_value_sp->GetCompilerType();
248 if (!return_value_type) {
253 Thread *thread = frame_sp->GetThread().get();
260 const uint64_t byte_size = new_value_sp->GetData(data, data_error);
261 if (data_error.
Fail()) {
263 "Couldn't convert return value to raw data: %s",
268 const uint32_t type_flags = return_value_type.
GetTypeInfo(
nullptr);
269 if (type_flags & eTypeIsScalar || type_flags & eTypeIsPointer) {
270 if (type_flags & eTypeIsInteger || type_flags & eTypeIsPointer) {
273 if (byte_size <= 16) {
275 if (byte_size <= 8) {
276 uint64_t raw_value = data.
GetMaxU64(&offset, byte_size);
281 uint64_t raw_value = data.
GetMaxU64(&offset, 8);
286 raw_value = data.
GetMaxU64(&offset, byte_size - offset);
294 "We don't support returning longer than 128 bit "
295 "integer values at present.");
297 }
else if (type_flags & eTypeIsFloat) {
298 if (type_flags & eTypeIsComplex) {
301 "returning complex float values are not supported");
306 if (byte_size <= 16) {
315 "returning float values longer than 128 "
316 "bits are not supported");
320 "v0 register is not available on this target");
323 }
else if (type_flags & eTypeIsVector) {
328 if (byte_size <= v0_info->byte_size) {
331 if (
error.Success()) {
357 row->GetCFAValue().SetIsRegisterPlusOffset(sp_reg_num, 0);
360 row->SetRegisterLocationToRegister(pc_reg_num, lr_reg_num,
true);
380 const int32_t ptr_size = 8;
382 row->GetCFAValue().SetIsRegisterPlusOffset(fp_reg_num, 2 * ptr_size);
384 row->SetUnspecifiedRegistersAreUndefined(
true);
386 row->SetRegisterLocationToAtCFAPlusOffset(fp_reg_num, ptr_size * -2,
true);
387 row->SetRegisterLocationToAtCFAPlusOffset(pc_reg_num, ptr_size * -1,
true);
390 unwind_plan.
SetSourceName(
"arm64-apple-darwin default unwind plan");
409 const char *name = reg_info->
name;
414 if (name[0] ==
'p' && name[1] ==
'c')
416 if (name[0] ==
'f' && name[1] ==
'p')
418 if (name[0] ==
's' && name[1] ==
'p')
420 if (name[0] ==
'l' && name[1] ==
'r')
423 if (name[0] ==
'x') {
459 }
else if (name[0] ==
'v' || name[0] ==
's' || name[0] ==
'd') {
489 bool is_return_value,
493 std::optional<uint64_t> byte_size =
495 if (!byte_size || *byte_size == 0)
498 std::unique_ptr<DataBufferHeap> heap_data_up(
504 const uint32_t homogeneous_count =
506 if (homogeneous_count > 0 && homogeneous_count <= 8) {
508 if (NSRN < 8 && (8 - NSRN) >= homogeneous_count) {
511 std::optional<uint64_t> base_byte_size =
515 uint32_t data_offset = 0;
517 for (uint32_t i = 0; i < homogeneous_count; ++i) {
519 ::snprintf(v_name,
sizeof(v_name),
"v%u", NSRN);
522 if (reg_info ==
nullptr)
525 if (*base_byte_size > reg_info->
byte_size)
534 if ((data_offset + *base_byte_size) <= heap_data_up->GetByteSize()) {
536 *reg_info, heap_data_up->GetBytes() + data_offset,
537 *base_byte_size, byte_order,
error);
538 if (bytes_copied != *base_byte_size)
540 data_offset += bytes_copied;
552 const size_t max_reg_byte_size = 16;
553 if (*byte_size <= max_reg_byte_size) {
554 size_t bytes_left = *byte_size;
555 uint32_t data_offset = 0;
556 while (data_offset < *byte_size) {
566 if (reg_info ==
nullptr)
574 const size_t curr_byte_size = std::min<size_t>(8, bytes_left);
576 *reg_info, heap_data_up->GetBytes() + data_offset, curr_byte_size,
578 if (bytes_copied == 0)
580 if (bytes_copied >= bytes_left)
582 data_offset += bytes_copied;
583 bytes_left -= bytes_copied;
588 if (is_return_value) {
606 if (reg_info ==
nullptr)
618 value_addr, heap_data_up->GetBytes(), heap_data_up->GetByteSize(),
619 error) != heap_data_up->GetByteSize()) {
637 return return_valobj_sp;
644 return return_valobj_sp;
646 std::optional<uint64_t> byte_size = return_compiler_type.
GetByteSize(&thread);
648 return return_valobj_sp;
650 const uint32_t type_flags = return_compiler_type.
GetTypeInfo(
nullptr);
651 if (type_flags & eTypeIsScalar || type_flags & eTypeIsPointer) {
654 bool success =
false;
655 if (type_flags & eTypeIsInteger || type_flags & eTypeIsPointer) {
657 if (*byte_size <= 8) {
664 const bool is_signed = (type_flags & eTypeIsSigned) != 0;
665 switch (*byte_size) {
677 std::unique_ptr<DataBufferHeap> heap_data_up(
687 *x0_reg_info, heap_data_up->GetBytes() + 0, 8,
688 byte_order,
error) &&
690 *x1_reg_info, heap_data_up->GetBytes() + 8, 8,
691 byte_order,
error)) {
697 &thread, return_compiler_type,
ConstString(
""), data);
698 return return_valobj_sp;
705 case sizeof(uint64_t):
707 value.
GetScalar() = (int64_t)(raw_value);
709 value.
GetScalar() = (uint64_t)(raw_value);
713 case sizeof(uint32_t):
721 case sizeof(uint16_t):
723 value.
GetScalar() = (int16_t)(raw_value & UINT16_MAX);
725 value.
GetScalar() = (uint16_t)(raw_value & UINT16_MAX);
729 case sizeof(uint8_t):
731 value.
GetScalar() = (int8_t)(raw_value & UINT8_MAX);
733 value.
GetScalar() = (uint8_t)(raw_value & UINT8_MAX);
739 }
else if (type_flags & eTypeIsFloat) {
740 if (type_flags & eTypeIsComplex) {
743 if (*byte_size <=
sizeof(
long double)) {
751 if (*byte_size ==
sizeof(
float)) {
754 }
else if (*byte_size ==
sizeof(
double)) {
757 }
else if (*byte_size ==
sizeof(
long double)) {
770 }
else if (type_flags & eTypeIsVector) {
771 if (*byte_size > 0) {
776 if (*byte_size <= v0_info->byte_size) {
777 std::unique_ptr<DataBufferHeap> heap_data_up(
784 heap_data_up->GetByteSize(),
785 byte_order,
error)) {
790 &thread, return_compiler_type,
ConstString(
""), data);
796 }
else if (type_flags & eTypeIsStructUnion || type_flags & eTypeIsClass) {
801 const bool is_return_value =
true;
803 exe_ctx, reg_ctx, return_compiler_type, is_return_value, NGRN, NSRN,
806 &thread, return_compiler_type,
ConstString(
""), data);
809 return return_valobj_sp;
813 addr_t pac_sign_extension = 0x0080000000000000ULL;
814 addr_t tbi_mask = 0xff80000000000000ULL;
818 mask = process_sp->GetCodeAddressMask();
819 if (
pc & pac_sign_extension) {
820 addr_t highmem_mask = process_sp->GetHighmemCodeAddressMask();
828 return (
pc & pac_sign_extension) ?
pc | mask :
pc & (~mask);
832 addr_t pac_sign_extension = 0x0080000000000000ULL;
833 addr_t tbi_mask = 0xff80000000000000ULL;
837 mask = process_sp->GetDataAddressMask();
838 if (
pc & pac_sign_extension) {
839 addr_t highmem_mask = process_sp->GetHighmemDataAddressMask();
847 return (
pc & pac_sign_extension) ?
pc | mask :
pc & (~mask);
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 const char * pluginDesc
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_LOGF(log,...)
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
static llvm::StringRef GetPluginNameStatic()
lldb_private::Status SetReturnValueObject(lldb::StackFrameSP &frame_sp, lldb::ValueObjectSP &new_value) override
bool RegisterIsVolatile(const lldb_private::RegisterInfo *reg_info) override
size_t GetRedZoneSize() const override
static lldb::ABISP CreateInstance(lldb::ProcessSP process_sp, const lldb_private::ArchSpec &arch)
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
lldb::ValueObjectSP GetReturnValueObjectImpl(lldb_private::Thread &thread, lldb_private::CompilerType &ast_type) const override
bool CreateFunctionEntryUnwindPlan(lldb_private::UnwindPlan &unwind_plan) override
bool GetArgumentValues(lldb_private::Thread &thread, lldb_private::ValueList &values) const 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
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)
virtual const RegisterInfo * GetRegisterInfoAtIndex(size_t reg)=0
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 Status FromErrorStringWithFormat(const char *format,...) __attribute__((format(printf
static Status FromErrorString(const char *str)
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 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_INVALID_REGNUM
#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::ValueObject > ValueObjectSP
std::shared_ptr< lldb_private::Process > ProcessSP
ByteOrder
Byte ordering definitions.
std::shared_ptr< lldb_private::DataBuffer > DataBufferSP
@ 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.
lldb::user_id_t GetID() const
Get accessor for the user ID.