14#include "llvm/ADT/STLExtras.h"
15#include "llvm/TargetParser/Triple.h"
47 const llvm::Triple::ArchType arch_type = arch.
GetTriple().getArch();
48 const llvm::Triple::VendorType vendor_type = arch.
GetTriple().getVendor();
50 if (vendor_type != llvm::Triple::Apple) {
51 if (arch_type == llvm::Triple::aarch64 ||
52 arch_type == llvm::Triple::aarch64_32) {
70 if (!gcs_features_enabled_info)
76 return Status(
"Could not read GCS features enabled register.");
80 if ((gcs_features_enabled & 1) == 0)
86 return Status(
"Could not get register info for gcspr_el0.");
91 return Status(
"Could not read gcspr_el0.");
97 "Attempted to decrement gcspr_el0, but could not write to it.");
100 size_t wrote = thread.GetProcess()->WriteMemory(gcspr_el0, &return_addr,
101 sizeof(return_addr),
error);
102 if ((wrote !=
sizeof(return_addr) ||
error.Fail())) {
104 return Status(
"Failed to write new Guarded Control Stack entry.");
109 "Pushed return address 0x%" PRIx64
" to Guarded Control Stack. "
110 "gcspr_el0 was 0%" PRIx64
", is now 0x%" PRIx64
".",
111 return_addr, gcspr_el0 - 8, gcspr_el0);
121 llvm::ArrayRef<addr_t> args)
const {
130 s.
Printf(
"ABISysV_arm64::PrepareTrivialCall (tid = 0x%" PRIx64
131 ", sp = 0x%" PRIx64
", func_addr = 0x%" PRIx64
132 ", return_addr = 0x%" PRIx64,
133 thread.GetID(), (uint64_t)
sp, (uint64_t)func_addr,
134 (uint64_t)return_addr);
136 for (
size_t i = 0; i < args.size(); ++i)
137 s.
Printf(
", arg%d = 0x%" PRIx64,
static_cast<int>(i + 1), args[i]);
146 if (
GetProcessSP()->GetTarget().GetArchitecture().GetTriple().isOSLinux()) {
156 for (
size_t i = 0; i < args.size(); ++i) {
159 LLDB_LOGF(log,
"About to write arg%d (0x%" PRIx64
") into %s",
160 static_cast<int>(i + 1), args[i], reg_info->
name);
191 uint32_t num_values = values.
GetSize();
204 for (uint32_t value_idx = 0; value_idx < num_values; ++value_idx) {
214 bool is_signed =
false;
215 size_t bit_width = 0;
216 std::optional<uint64_t> bit_size =
217 llvm::expectedToOptional(value_type.
GetBitSize(&thread));
221 bit_width = *bit_size;
223 bit_width = *bit_size;
258 const uint32_t arg_byte_size = (bit_width + (8 - 1)) / 8;
286 CompilerType return_value_type = new_value_sp->GetCompilerType();
287 if (!return_value_type) {
292 Thread *thread = frame_sp->GetThread().get();
299 const uint64_t byte_size = new_value_sp->GetData(data, data_error);
300 if (data_error.
Fail()) {
302 "Couldn't convert return value to raw data: %s",
307 const uint32_t type_flags = return_value_type.
GetTypeInfo(
nullptr);
308 if (type_flags & eTypeIsScalar || type_flags & eTypeIsPointer) {
309 if (type_flags & eTypeIsInteger || type_flags & eTypeIsPointer) {
312 if (byte_size <= 16) {
315 if (byte_size <= 8) {
316 uint64_t raw_value = data.
GetMaxU64(&offset, byte_size);
321 uint64_t raw_value = data.
GetMaxU64(&offset, 8);
326 raw_value = data.
GetMaxU64(&offset, byte_size - offset);
334 "We don't support returning longer than 128 bit "
335 "integer values at present.");
337 }
else if (type_flags & eTypeIsFloat) {
338 if (type_flags & eTypeIsComplex) {
341 "returning complex float values are not supported");
346 if (byte_size <= 16) {
355 "returning float values longer than 128 "
356 "bits are not supported");
360 "v0 register is not available on this target");
363 }
else if (type_flags & eTypeIsVector) {
368 if (byte_size <= v0_info->byte_size) {
371 if (
error.Success()) {
396 const char *name = reg_info->
name;
401 if (name[0] ==
'p' && name[1] ==
'c')
403 if (name[0] ==
'f' && name[1] ==
'p')
405 if (name[0] ==
's' && name[1] ==
'p')
407 if (name[0] ==
'l' && name[1] ==
'r')
410 if (name[0] ==
'x' || name[0] ==
'r') {
443 if (name[2] ==
'0' || name[2] ==
'1')
449 }
else if (name[0] ==
'v' || name[0] ==
's' || name[0] ==
'd') {
479 bool is_return_value,
483 std::optional<uint64_t> byte_size = llvm::expectedToOptional(
486 if (byte_size || *byte_size == 0)
489 std::unique_ptr<DataBufferHeap> heap_data_up(
495 const uint32_t homogeneous_count =
497 if (homogeneous_count > 0 && homogeneous_count <= 8) {
499 if (NSRN < 8 && (8 - NSRN) >= homogeneous_count) {
502 std::optional<uint64_t> base_byte_size = llvm::expectedToOptional(
506 uint32_t data_offset = 0;
508 for (uint32_t i = 0; i < homogeneous_count; ++i) {
510 ::snprintf(v_name,
sizeof(v_name),
"v%u", NSRN);
513 if (reg_info ==
nullptr)
516 if (*base_byte_size > reg_info->
byte_size)
525 if ((data_offset + *base_byte_size) <= heap_data_up->GetByteSize()) {
527 *reg_info, heap_data_up->GetBytes() + data_offset,
528 *base_byte_size, byte_order,
error);
529 if (bytes_copied != *base_byte_size)
531 data_offset += bytes_copied;
543 const size_t max_reg_byte_size = 16;
544 if (*byte_size <= max_reg_byte_size) {
545 size_t bytes_left = *byte_size;
546 uint32_t data_offset = 0;
547 while (data_offset < *byte_size) {
553 if (reg_info ==
nullptr)
561 const size_t curr_byte_size = std::min<size_t>(8, bytes_left);
563 *reg_info, heap_data_up->GetBytes() + data_offset, curr_byte_size,
565 if (bytes_copied == 0)
567 if (bytes_copied >= bytes_left)
569 data_offset += bytes_copied;
570 bytes_left -= bytes_copied;
575 if (is_return_value) {
592 if (reg_info ==
nullptr)
604 value_addr, heap_data_up->GetBytes(), heap_data_up->GetByteSize(),
605 error) != heap_data_up->GetByteSize()) {
623 return return_valobj_sp;
630 return return_valobj_sp;
632 std::optional<uint64_t> byte_size =
633 llvm::expectedToOptional(return_compiler_type.
GetByteSize(&thread));
635 return return_valobj_sp;
637 const uint32_t type_flags = return_compiler_type.
GetTypeInfo(
nullptr);
638 if (type_flags & eTypeIsScalar || type_flags & eTypeIsPointer) {
641 bool success =
false;
642 if (type_flags & eTypeIsInteger || type_flags & eTypeIsPointer) {
644 if (*byte_size <= 8) {
650 thread.GetRegisterContext()->ReadRegisterAsUnsigned(x0_reg_info,
652 const bool is_signed = (type_flags & eTypeIsSigned) != 0;
653 switch (*byte_size) {
666 std::unique_ptr<DataBufferHeap> heap_data_up(
676 *x0_reg_info, heap_data_up->GetBytes() + 0, 8,
677 byte_order,
error) &&
679 *x1_reg_info, heap_data_up->GetBytes() + 8, 8,
680 byte_order,
error)) {
686 &thread, return_compiler_type,
ConstString(
""), data);
687 return return_valobj_sp;
694 case sizeof(uint64_t):
696 value.
GetScalar() = (int64_t)(raw_value);
698 value.
GetScalar() = (uint64_t)(raw_value);
702 case sizeof(uint32_t):
710 case sizeof(uint16_t):
712 value.
GetScalar() = (int16_t)(raw_value & UINT16_MAX);
714 value.
GetScalar() = (uint16_t)(raw_value & UINT16_MAX);
718 case sizeof(uint8_t):
720 value.
GetScalar() = (int8_t)(raw_value & UINT8_MAX);
722 value.
GetScalar() = (uint8_t)(raw_value & UINT8_MAX);
728 }
else if (type_flags & eTypeIsFloat) {
729 if (type_flags & eTypeIsComplex) {
732 if (*byte_size <=
sizeof(
long double)) {
740 if (*byte_size ==
sizeof(
float)) {
743 }
else if (*byte_size ==
sizeof(
double)) {
746 }
else if (*byte_size ==
sizeof(
long double)) {
758 thread.GetStackFrameAtIndex(0).get(), value,
ConstString(
""));
759 }
else if (type_flags & eTypeIsVector && *byte_size <= 16) {
760 if (*byte_size > 0) {
764 std::unique_ptr<DataBufferHeap> heap_data_up(
771 heap_data_up->GetByteSize(), byte_order,
776 &thread, return_compiler_type,
ConstString(
""), data);
781 }
else if (type_flags & eTypeIsStructUnion || type_flags & eTypeIsClass ||
782 (type_flags & eTypeIsVector && *byte_size > 16)) {
787 const bool is_return_value =
true;
789 exe_ctx, reg_ctx, return_compiler_type, is_return_value, NGRN, NSRN,
792 &thread, return_compiler_type,
ConstString(
""), data);
795 return return_valobj_sp;
807 llvm::StringRef reg_name) {
814 lldb::ThreadSP thread_sp = process_sp->GetThreadList().GetSelectedThread();
818 address_mask = ~((1ULL << 56) - 1);
825 reg_ctx_sp->GetRegisterInfoByName(reg_name, 0);
827 lldb::addr_t mask_reg_val = reg_ctx_sp->ReadRegisterAsUnsigned(
830 address_mask |= mask_reg_val;
839 if (process_sp->GetTarget().GetArchitecture().GetTriple().isOSLinux() &&
841 process_sp->SetCodeAddressMask(
847 addr_t mask = process_sp->GetCodeAddressMask();
851 mask = process_sp->GetHighmemCodeAddressMask();
860 if (process_sp->GetTarget().GetArchitecture().GetTriple().isOSLinux() &&
862 process_sp->SetDataAddressMask(
868 addr_t mask = process_sp->GetDataAddressMask();
872 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)
constexpr addr_t pac_sign_extension
static Status PushToLinuxGuardedControlStack(addr_t return_addr, RegisterContext *reg_ctx, Thread &thread)
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
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
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 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_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
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.