14#include "llvm/ADT/STLExtras.h"
15#include "llvm/TargetParser/Triple.h"
35static const char *
pluginDesc =
"Mac OS X ABI for arm64 targets";
43 const llvm::Triple::ArchType arch_type = arch.
GetTriple().getArch();
44 const llvm::Triple::VendorType vendor_type = arch.
GetTriple().getVendor();
46 if (vendor_type == llvm::Triple::Apple) {
47 if (arch_type == llvm::Triple::aarch64 ||
48 arch_type == llvm::Triple::aarch64_32) {
59 lldb::addr_t return_addr, llvm::ArrayRef<lldb::addr_t> args)
const {
68 s.
Printf(
"ABIMacOSX_arm64::PrepareTrivialCall (tid = 0x%" PRIx64
69 ", sp = 0x%" PRIx64
", func_addr = 0x%" PRIx64
70 ", return_addr = 0x%" PRIx64,
71 thread.GetID(), (uint64_t)
sp, (uint64_t)func_addr,
72 (uint64_t)return_addr);
74 for (
size_t i = 0; i < args.size(); ++i)
75 s.
Printf(
", arg%d = 0x%" PRIx64,
static_cast<int>(i + 1), args[i]);
91 for (
size_t i = 0; i < args.size(); ++i) {
94 LLDB_LOGF(log,
"About to write arg%d (0x%" PRIx64
") into %s",
95 static_cast<int>(i + 1), args[i], reg_info->
name);
120 uint32_t num_values = values.
GetSize();
133 for (uint32_t value_idx = 0; value_idx < num_values; ++value_idx) {
142 std::optional<uint64_t> bit_size =
143 llvm::expectedToOptional(value_type.
GetBitSize(&thread));
147 bool is_signed =
false;
148 size_t bit_width = 0;
150 bit_width = *bit_size;
152 bit_width = *bit_size;
217 const uint32_t arg_byte_size = (bit_width + (8 - 1)) / 8;
245 CompilerType return_value_type = new_value_sp->GetCompilerType();
246 if (!return_value_type) {
251 Thread *thread = frame_sp->GetThread().get();
258 const uint64_t byte_size = new_value_sp->GetData(data, data_error);
259 if (data_error.
Fail()) {
261 "Couldn't convert return value to raw data: %s",
266 const uint32_t type_flags = return_value_type.
GetTypeInfo(
nullptr);
267 if (type_flags & eTypeIsScalar || type_flags & eTypeIsPointer) {
268 if (type_flags & eTypeIsInteger || type_flags & eTypeIsPointer) {
271 if (byte_size <= 16) {
273 if (byte_size <= 8) {
274 uint64_t raw_value = data.
GetMaxU64(&offset, byte_size);
279 uint64_t raw_value = data.
GetMaxU64(&offset, 8);
284 raw_value = data.
GetMaxU64(&offset, byte_size - offset);
292 "We don't support returning longer than 128 bit "
293 "integer values at present.");
295 }
else if (type_flags & eTypeIsFloat) {
296 if (type_flags & eTypeIsComplex) {
299 "returning complex float values are not supported");
304 if (byte_size <= 16) {
313 "returning float values longer than 128 "
314 "bits are not supported");
318 "v0 register is not available on this target");
321 }
else if (type_flags & eTypeIsVector) {
326 if (byte_size <= v0_info->byte_size) {
329 if (
error.Success()) {
356 const char *name = reg_info->
name;
361 if (name[0] ==
'p' && name[1] ==
'c')
363 if (name[0] ==
'f' && name[1] ==
'p')
365 if (name[0] ==
's' && name[1] ==
'p')
367 if (name[0] ==
'l' && name[1] ==
'r')
370 if (name[0] ==
'x') {
406 }
else if (name[0] ==
'v' || name[0] ==
's' || name[0] ==
'd') {
436 bool is_return_value,
440 std::optional<uint64_t> byte_size = llvm::expectedToOptional(
442 if (!byte_size || *byte_size == 0)
445 std::unique_ptr<DataBufferHeap> heap_data_up(
451 const uint32_t homogeneous_count =
453 if (homogeneous_count > 0 && homogeneous_count <= 8) {
455 if (NSRN < 8 && (8 - NSRN) >= homogeneous_count) {
458 std::optional<uint64_t> base_byte_size = llvm::expectedToOptional(
462 uint32_t data_offset = 0;
464 for (uint32_t i = 0; i < homogeneous_count; ++i) {
466 ::snprintf(v_name,
sizeof(v_name),
"v%u", NSRN);
469 if (reg_info ==
nullptr)
472 if (*base_byte_size > reg_info->
byte_size)
481 if ((data_offset + *base_byte_size) <= heap_data_up->GetByteSize()) {
483 *reg_info, heap_data_up->GetBytes() + data_offset,
484 *base_byte_size, byte_order,
error);
485 if (bytes_copied != *base_byte_size)
487 data_offset += bytes_copied;
499 const size_t max_reg_byte_size = 16;
500 if (*byte_size <= max_reg_byte_size) {
501 size_t bytes_left = *byte_size;
502 uint32_t data_offset = 0;
503 while (data_offset < *byte_size) {
513 if (reg_info ==
nullptr)
521 const size_t curr_byte_size = std::min<size_t>(8, bytes_left);
523 *reg_info, heap_data_up->GetBytes() + data_offset, curr_byte_size,
525 if (bytes_copied == 0)
527 if (bytes_copied >= bytes_left)
529 data_offset += bytes_copied;
530 bytes_left -= bytes_copied;
535 if (is_return_value) {
553 if (reg_info ==
nullptr)
565 value_addr, heap_data_up->GetBytes(), heap_data_up->GetByteSize(),
566 error) != heap_data_up->GetByteSize()) {
584 return return_valobj_sp;
591 return return_valobj_sp;
593 std::optional<uint64_t> byte_size =
594 llvm::expectedToOptional(return_compiler_type.
GetByteSize(&thread));
596 return return_valobj_sp;
598 const uint32_t type_flags = return_compiler_type.
GetTypeInfo(
nullptr);
599 if (type_flags & eTypeIsScalar || type_flags & eTypeIsPointer) {
602 bool success =
false;
603 if (type_flags & eTypeIsInteger || type_flags & eTypeIsPointer) {
605 if (*byte_size <= 8) {
610 thread.GetRegisterContext()->ReadRegisterAsUnsigned(x0_reg_info,
612 const bool is_signed = (type_flags & eTypeIsSigned) != 0;
613 switch (*byte_size) {
625 std::unique_ptr<DataBufferHeap> heap_data_up(
635 *x0_reg_info, heap_data_up->GetBytes() + 0, 8,
636 byte_order,
error) &&
638 *x1_reg_info, heap_data_up->GetBytes() + 8, 8,
639 byte_order,
error)) {
645 &thread, return_compiler_type,
ConstString(
""), data);
646 return return_valobj_sp;
653 case sizeof(uint64_t):
655 value.
GetScalar() = (int64_t)(raw_value);
657 value.
GetScalar() = (uint64_t)(raw_value);
661 case sizeof(uint32_t):
669 case sizeof(uint16_t):
671 value.
GetScalar() = (int16_t)(raw_value & UINT16_MAX);
673 value.
GetScalar() = (uint16_t)(raw_value & UINT16_MAX);
677 case sizeof(uint8_t):
679 value.
GetScalar() = (int8_t)(raw_value & UINT8_MAX);
681 value.
GetScalar() = (uint8_t)(raw_value & UINT8_MAX);
687 }
else if (type_flags & eTypeIsFloat) {
688 if (type_flags & eTypeIsComplex) {
691 if (*byte_size <=
sizeof(
long double)) {
699 if (*byte_size ==
sizeof(
float)) {
702 }
else if (*byte_size ==
sizeof(
double)) {
705 }
else if (*byte_size ==
sizeof(
long double)) {
717 thread.GetStackFrameAtIndex(0).get(), value,
ConstString(
""));
718 }
else if (type_flags & eTypeIsVector) {
719 if (*byte_size > 0) {
724 if (*byte_size <= v0_info->byte_size) {
725 std::unique_ptr<DataBufferHeap> heap_data_up(
732 heap_data_up->GetByteSize(),
733 byte_order,
error)) {
738 &thread, return_compiler_type,
ConstString(
""), data);
744 }
else if (type_flags & eTypeIsStructUnion || type_flags & eTypeIsClass) {
749 const bool is_return_value =
true;
751 exe_ctx, reg_ctx, return_compiler_type, is_return_value, NGRN, NSRN,
754 &thread, return_compiler_type,
ConstString(
""), data);
757 return return_valobj_sp;
769 addr_t mask = is_code ? process_sp->GetCodeAddressMask()
770 : process_sp->GetDataAddressMask();
775 addr_t highmem_mask = is_code ? process_sp->GetHighmemCodeAddressMask()
776 : process_sp->GetHighmemCodeAddressMask();
778 return addr | highmem_mask;
782 return addr & (~mask);
constexpr addr_t tbi_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
constexpr addr_t pac_sign_extension
static addr_t DoFixAddr(addr_t addr, bool is_code, ProcessSP process_sp)
Consults the process for its {code, data} address masks and applies it to addr.
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 GetArgumentValues(lldb_private::Thread &thread, lldb_private::ValueList &values) const 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.
uint32_t IsHomogeneousAggregate(CompilerType *base_type_ptr) const
llvm::Expected< uint64_t > GetByteSize(ExecutionContextScope *exe_scope) const
Return the size of the type in bytes.
bool IsIntegerOrEnumerationType(bool &is_signed) const
uint32_t GetTypeInfo(CompilerType *pointee_or_element_compiler_type=nullptr) const
llvm::Expected< 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.
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
See comment on m_scalar to understand what GetScalar returns.
@ Scalar
A raw scalar value.
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
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.