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;
243 error.SetErrorString(
"Empty value object for return value.");
247 CompilerType return_value_type = new_value_sp->GetCompilerType();
248 if (!return_value_type) {
249 error.SetErrorString(
"Null clang type for return value.");
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()) {
262 error.SetErrorStringWithFormat(
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);
279 error.SetErrorString(
"failed to write register x0");
281 uint64_t raw_value = data.
GetMaxU64(&offset, 8);
286 raw_value = data.
GetMaxU64(&offset, byte_size - offset);
289 error.SetErrorString(
"failed to write register x1");
293 error.SetErrorString(
"We don't support returning longer than 128 bit "
294 "integer values at present.");
296 }
else if (type_flags & eTypeIsFloat) {
297 if (type_flags & eTypeIsComplex) {
299 error.SetErrorString(
300 "returning complex float values are not supported");
305 if (byte_size <= 16) {
310 error.SetErrorString(
"failed to write register v0");
312 error.SetErrorString(
"returning float values longer than 128 "
313 "bits are not supported");
316 error.SetErrorString(
"v0 register is not available on this target");
319 }
else if (type_flags & eTypeIsVector) {
324 if (byte_size <= v0_info->byte_size) {
327 if (
error.Success()) {
329 error.SetErrorString(
"failed to write register v0");
336 error.SetErrorString(
"no registers are available");
353 row->GetCFAValue().SetIsRegisterPlusOffset(sp_reg_num, 0);
356 row->SetRegisterLocationToRegister(pc_reg_num, lr_reg_num,
true);
376 const int32_t ptr_size = 8;
378 row->GetCFAValue().SetIsRegisterPlusOffset(fp_reg_num, 2 * ptr_size);
380 row->SetUnspecifiedRegistersAreUndefined(
true);
382 row->SetRegisterLocationToAtCFAPlusOffset(fp_reg_num, ptr_size * -2,
true);
383 row->SetRegisterLocationToAtCFAPlusOffset(pc_reg_num, ptr_size * -1,
true);
386 unwind_plan.
SetSourceName(
"arm64-apple-darwin default unwind plan");
405 const char *name = reg_info->
name;
410 if (name[0] ==
'p' && name[1] ==
'c')
412 if (name[0] ==
'f' && name[1] ==
'p')
414 if (name[0] ==
's' && name[1] ==
'p')
416 if (name[0] ==
'l' && name[1] ==
'r')
419 if (name[0] ==
'x') {
455 }
else if (name[0] ==
'v' || name[0] ==
's' || name[0] ==
'd') {
485 bool is_return_value,
489 std::optional<uint64_t> byte_size =
491 if (!byte_size || *byte_size == 0)
494 std::unique_ptr<DataBufferHeap> heap_data_up(
500 const uint32_t homogeneous_count =
502 if (homogeneous_count > 0 && homogeneous_count <= 8) {
504 if (NSRN < 8 && (8 - NSRN) >= homogeneous_count) {
507 std::optional<uint64_t> base_byte_size =
511 uint32_t data_offset = 0;
513 for (uint32_t i = 0; i < homogeneous_count; ++i) {
515 ::snprintf(v_name,
sizeof(v_name),
"v%u", NSRN);
518 if (reg_info ==
nullptr)
521 if (*base_byte_size > reg_info->
byte_size)
530 if ((data_offset + *base_byte_size) <= heap_data_up->GetByteSize()) {
532 *reg_info, heap_data_up->GetBytes() + data_offset,
533 *base_byte_size, byte_order,
error);
534 if (bytes_copied != *base_byte_size)
536 data_offset += bytes_copied;
548 const size_t max_reg_byte_size = 16;
549 if (*byte_size <= max_reg_byte_size) {
550 size_t bytes_left = *byte_size;
551 uint32_t data_offset = 0;
552 while (data_offset < *byte_size) {
562 if (reg_info ==
nullptr)
570 const size_t curr_byte_size = std::min<size_t>(8, bytes_left);
572 *reg_info, heap_data_up->GetBytes() + data_offset, curr_byte_size,
574 if (bytes_copied == 0)
576 if (bytes_copied >= bytes_left)
578 data_offset += bytes_copied;
579 bytes_left -= bytes_copied;
584 if (is_return_value) {
602 if (reg_info ==
nullptr)
614 value_addr, heap_data_up->GetBytes(), heap_data_up->GetByteSize(),
615 error) != heap_data_up->GetByteSize()) {
633 return return_valobj_sp;
640 return return_valobj_sp;
642 std::optional<uint64_t> byte_size = return_compiler_type.
GetByteSize(&thread);
644 return return_valobj_sp;
646 const uint32_t type_flags = return_compiler_type.
GetTypeInfo(
nullptr);
647 if (type_flags & eTypeIsScalar || type_flags & eTypeIsPointer) {
650 bool success =
false;
651 if (type_flags & eTypeIsInteger || type_flags & eTypeIsPointer) {
653 if (*byte_size <= 8) {
660 const bool is_signed = (type_flags & eTypeIsSigned) != 0;
661 switch (*byte_size) {
673 std::unique_ptr<DataBufferHeap> heap_data_up(
683 *x0_reg_info, heap_data_up->GetBytes() + 0, 8,
684 byte_order,
error) &&
686 *x1_reg_info, heap_data_up->GetBytes() + 8, 8,
687 byte_order,
error)) {
693 &thread, return_compiler_type,
ConstString(
""), data);
694 return return_valobj_sp;
701 case sizeof(uint64_t):
703 value.
GetScalar() = (int64_t)(raw_value);
705 value.
GetScalar() = (uint64_t)(raw_value);
709 case sizeof(uint32_t):
717 case sizeof(uint16_t):
719 value.
GetScalar() = (int16_t)(raw_value & UINT16_MAX);
721 value.
GetScalar() = (uint16_t)(raw_value & UINT16_MAX);
725 case sizeof(uint8_t):
727 value.
GetScalar() = (int8_t)(raw_value & UINT8_MAX);
729 value.
GetScalar() = (uint8_t)(raw_value & UINT8_MAX);
735 }
else if (type_flags & eTypeIsFloat) {
736 if (type_flags & eTypeIsComplex) {
739 if (*byte_size <=
sizeof(
long double)) {
747 if (*byte_size ==
sizeof(
float)) {
750 }
else if (*byte_size ==
sizeof(
double)) {
753 }
else if (*byte_size ==
sizeof(
long double)) {
766 }
else if (type_flags & eTypeIsVector) {
767 if (*byte_size > 0) {
772 if (*byte_size <= v0_info->byte_size) {
773 std::unique_ptr<DataBufferHeap> heap_data_up(
780 heap_data_up->GetByteSize(),
781 byte_order,
error)) {
786 &thread, return_compiler_type,
ConstString(
""), data);
792 }
else if (type_flags & eTypeIsStructUnion || type_flags & eTypeIsClass) {
797 const bool is_return_value =
true;
799 exe_ctx, reg_ctx, return_compiler_type, is_return_value, NGRN, NSRN,
802 &thread, return_compiler_type,
ConstString(
""), data);
805 return return_valobj_sp;
809 addr_t pac_sign_extension = 0x0080000000000000ULL;
810 addr_t tbi_mask = 0xff80000000000000ULL;
814 mask = process_sp->GetCodeAddressMask();
815 if (
pc & pac_sign_extension) {
816 addr_t highmem_mask = process_sp->GetHighmemCodeAddressMask();
824 return (
pc & pac_sign_extension) ?
pc | mask :
pc & (~mask);
828 addr_t pac_sign_extension = 0x0080000000000000ULL;
829 addr_t tbi_mask = 0xff80000000000000ULL;
833 mask = process_sp->GetDataAddressMask();
834 if (
pc & pac_sign_extension) {
835 addr_t highmem_mask = process_sp->GetHighmemDataAddressMask();
843 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)
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.