11#include "llvm/ADT/STLExtras.h"
12#include "llvm/ADT/StringSwitch.h"
13#include "llvm/TargetParser/Triple.h"
73 const llvm::Triple::ArchType arch_type = arch.
GetTriple().getArch();
74 const llvm::Triple::OSType os_type = arch.
GetTriple().getOS();
75 const llvm::Triple::EnvironmentType os_env =
77 if (arch_type == llvm::Triple::x86_64) {
79 case llvm::Triple::OSType::IOS:
80 case llvm::Triple::OSType::TvOS:
81 case llvm::Triple::OSType::WatchOS:
82 case llvm::Triple::OSType::XROS:
84 case llvm::Triple::EnvironmentType::MacABI:
85 case llvm::Triple::EnvironmentType::Simulator:
86 case llvm::Triple::EnvironmentType::UnknownEnvironment:
94 case llvm::Triple::OSType::Darwin:
95 case llvm::Triple::OSType::FreeBSD:
96 case llvm::Triple::OSType::Linux:
97 case llvm::Triple::OSType::MacOSX:
98 case llvm::Triple::OSType::NetBSD:
99 case llvm::Triple::OSType::OpenBSD:
100 case llvm::Triple::OSType::Solaris:
101 case llvm::Triple::OSType::UnknownOS:
113 llvm::ArrayRef<addr_t> args)
const {
118 s.
Printf(
"ABISysV_x86_64::PrepareTrivialCall (tid = 0x%" PRIx64
119 ", sp = 0x%" PRIx64
", func_addr = 0x%" PRIx64
120 ", return_addr = 0x%" PRIx64,
121 thread.GetID(), (uint64_t)
sp, (uint64_t)func_addr,
122 (uint64_t)return_addr);
124 for (
size_t i = 0; i < args.size(); ++i)
125 s.
Printf(
", arg%" PRIu64
" = 0x%" PRIx64,
static_cast<uint64_t
>(i + 1),
140 for (
size_t i = 0; i < args.size(); ++i) {
143 LLDB_LOGF(log,
"About to write arg%" PRIu64
" (0x%" PRIx64
") into %s",
144 static_cast<uint64_t
>(i + 1), args[i], reg_info->
name);
151 LLDB_LOGF(log,
"16-byte aligning SP: 0x%" PRIx64
" to 0x%" PRIx64,
152 (uint64_t)
sp, (uint64_t)(
sp & ~0xfull));
163 ProcessSP process_sp(thread.GetProcess());
167 "Pushing the return address onto the stack: 0x%" PRIx64
169 (uint64_t)
sp, (uint64_t)return_addr);
172 if (!process_sp->WritePointerToMemory(
sp, return_addr,
error))
177 LLDB_LOGF(log,
"Writing SP: 0x%" PRIx64, (uint64_t)
sp);
184 LLDB_LOGF(log,
"Writing IP: 0x%" PRIx64, (uint64_t)func_addr);
193 bool is_signed,
Thread &thread,
194 uint32_t *argument_register_ids,
195 unsigned int ¤t_argument_register,
196 addr_t ¤t_stack_argument) {
200 if (current_argument_register < 6) {
201 scalar = thread.GetRegisterContext()->ReadRegisterAsUnsigned(
202 argument_register_ids[current_argument_register], 0);
203 current_argument_register++;
207 uint32_t byte_size = (bit_width + (8 - 1)) / 8;
209 if (thread.GetProcess()->ReadScalarIntegerFromMemory(
210 current_stack_argument, byte_size, is_signed, scalar,
error)) {
211 current_stack_argument += byte_size;
221 unsigned int num_values = values.
GetSize();
222 unsigned int value_index;
239 addr_t current_stack_argument =
sp + 8;
241 uint32_t argument_register_ids[6];
243 argument_register_ids[0] =
246 argument_register_ids[1] =
249 argument_register_ids[2] =
252 argument_register_ids[3] =
255 argument_register_ids[4] =
258 argument_register_ids[5] =
262 unsigned int current_argument_register = 0;
264 for (value_index = 0; value_index < num_values; ++value_index) {
273 std::optional<uint64_t> bit_size =
274 llvm::expectedToOptional(compiler_type.
GetBitSize(&thread));
281 argument_register_ids, current_argument_register,
282 current_stack_argument);
285 argument_register_ids, current_argument_register,
286 current_stack_argument);
301 CompilerType compiler_type = new_value_sp->GetCompilerType();
302 if (!compiler_type) {
307 Thread *thread = frame_sp->GetThread().get();
315 bool set_it_simple =
false;
322 size_t num_bytes = new_value_sp->GetData(data, data_error);
323 if (data_error.
Fail()) {
325 "Couldn't convert return value to raw data: %s",
330 if (num_bytes <= 8) {
331 uint64_t raw_value = data.
GetMaxU64(&offset, num_bytes);
334 set_it_simple =
true;
337 "We don't support returning longer than 64 bit "
338 "integer values at present.");
343 "We don't support returning complex values at present");
345 std::optional<uint64_t> bit_width =
346 llvm::expectedToOptional(compiler_type.
GetBitSize(frame_sp.get()));
351 if (*bit_width <= 64) {
357 size_t num_bytes = new_value_sp->GetData(data, data_error);
358 if (data_error.
Fail()) {
360 "Couldn't convert return value to raw data: %s",
365 unsigned char buffer[16];
369 xmm0_value.
SetBytes(buffer, 16, byte_order);
371 set_it_simple =
true;
375 "We don't support returning float values > 64 bits at present");
380 if (!set_it_simple) {
385 "We only support setting simple integer and float "
386 "return types at present.");
397 if (!return_compiler_type)
398 return return_valobj_sp;
405 return return_valobj_sp;
407 const uint32_t type_flags = return_compiler_type.
GetTypeInfo();
408 if (type_flags & eTypeIsScalar) {
411 bool success =
false;
412 if (type_flags & eTypeIsInteger) {
415 std::optional<uint64_t> byte_size =
416 llvm::expectedToOptional(return_compiler_type.
GetByteSize(&thread));
418 return return_valobj_sp;
419 uint64_t raw_value = thread.GetRegisterContext()->ReadRegisterAsUnsigned(
421 const bool is_signed = (type_flags & eTypeIsSigned) != 0;
422 switch (*byte_size) {
426 case sizeof(uint64_t):
428 value.
GetScalar() = (int64_t)(raw_value);
430 value.
GetScalar() = (uint64_t)(raw_value);
434 case sizeof(uint32_t):
442 case sizeof(uint16_t):
444 value.
GetScalar() = (int16_t)(raw_value & UINT16_MAX);
446 value.
GetScalar() = (uint16_t)(raw_value & UINT16_MAX);
450 case sizeof(uint8_t):
452 value.
GetScalar() = (int8_t)(raw_value & UINT8_MAX);
454 value.
GetScalar() = (uint8_t)(raw_value & UINT8_MAX);
458 }
else if (type_flags & eTypeIsFloat) {
459 if (type_flags & eTypeIsComplex) {
462 std::optional<uint64_t> byte_size =
463 llvm::expectedToOptional(return_compiler_type.
GetByteSize(&thread));
464 if (byte_size && *byte_size <=
sizeof(
long double)) {
470 if (xmm0_value.
GetData(data)) {
472 if (*byte_size ==
sizeof(
float)) {
475 }
else if (*byte_size ==
sizeof(
double)) {
478 }
else if (*byte_size ==
sizeof(
long double)) {
490 thread.GetStackFrameAtIndex(0).get(), value,
ConstString(
""));
491 }
else if (type_flags & eTypeIsPointer) {
495 (uint64_t)thread.GetRegisterContext()->ReadRegisterAsUnsigned(rax_id,
499 thread.GetStackFrameAtIndex(0).get(), value,
ConstString(
""));
500 }
else if (type_flags & eTypeIsVector) {
501 std::optional<uint64_t> byte_size =
502 llvm::expectedToOptional(return_compiler_type.
GetByteSize(&thread));
503 if (byte_size && *byte_size > 0) {
506 if (altivec_reg ==
nullptr)
510 if (*byte_size <= altivec_reg->byte_size) {
511 ProcessSP process_sp(thread.GetProcess());
513 std::unique_ptr<DataBufferHeap> heap_data_up(
515 const ByteOrder byte_order = process_sp->GetByteOrder();
520 *altivec_reg, heap_data_up->GetBytes(),
521 heap_data_up->GetByteSize(), byte_order,
error)) {
524 process_sp->GetTarget()
526 .GetAddressByteSize());
528 &thread, return_compiler_type,
ConstString(
""), data);
532 }
else if (*byte_size <= altivec_reg->byte_size * 2) {
536 ProcessSP process_sp(thread.GetProcess());
538 std::unique_ptr<DataBufferHeap> heap_data_up(
540 const ByteOrder byte_order = process_sp->GetByteOrder();
548 *altivec_reg, heap_data_up->GetBytes(),
552 heap_data_up->GetBytes() + altivec_reg->
byte_size,
553 heap_data_up->GetByteSize() - altivec_reg->
byte_size,
554 byte_order,
error)) {
557 process_sp->GetTarget()
559 .GetAddressByteSize());
561 &thread, return_compiler_type,
ConstString(
""), data);
571 return return_valobj_sp;
582 uint32_t data_byte_offset,
583 std::vector<uint32_t> &aggregate_field_offsets,
584 std::vector<CompilerType> &aggregate_compiler_types) {
586 const uint32_t num_children = return_compiler_type.
GetNumFields();
587 for (uint32_t idx = 0; idx < num_children; ++idx) {
593 uint64_t field_bit_offset = 0;
595 idx, name, &field_bit_offset,
nullptr,
nullptr);
596 std::optional<uint64_t> field_bit_width =
597 llvm::expectedToOptional(field_compiler_type.
GetBitSize(&thread));
600 if (!field_bit_width || *field_bit_width == 0) {
604 uint32_t field_byte_offset = field_bit_offset / 8 + data_byte_offset;
606 const uint32_t field_type_flags = field_compiler_type.
GetTypeInfo();
610 aggregate_field_offsets.push_back(field_byte_offset);
611 aggregate_compiler_types.push_back(field_compiler_type);
612 }
else if (field_type_flags & eTypeHasChildren) {
614 field_byte_offset, aggregate_field_offsets,
615 aggregate_compiler_types)) {
627 if (!return_compiler_type)
628 return return_valobj_sp;
632 if (return_valobj_sp)
633 return return_valobj_sp;
637 return return_valobj_sp;
639 std::optional<uint64_t> bit_width =
640 llvm::expectedToOptional(return_compiler_type.
GetBitSize(&thread));
642 return return_valobj_sp;
645 bool is_memory =
true;
646 std::vector<uint32_t> aggregate_field_offsets;
647 std::vector<CompilerType> aggregate_compiler_types;
649 if (ts && ts->CanPassInRegisters(return_compiler_type) &&
652 aggregate_field_offsets,
653 aggregate_compiler_types)) {
660 reg_ctx_sp->GetRegisterInfoByName(
"rax", 0);
662 reg_ctx_sp->GetRegisterInfoByName(
"rdx", 0);
664 reg_ctx_sp->GetRegisterInfoByName(
"xmm0", 0);
666 reg_ctx_sp->GetRegisterInfoByName(
"xmm1", 0);
669 reg_ctx_sp->ReadRegister(rax_info, rax_value);
670 reg_ctx_sp->ReadRegister(rdx_info, rdx_value);
671 reg_ctx_sp->ReadRegister(xmm0_info, xmm0_value);
672 reg_ctx_sp->ReadRegister(xmm1_info, xmm1_value);
683 uint32_t integer_bytes =
688 if (aggregate_field_offsets.size()) {
689 fp_bytes = aggregate_field_offsets[0];
690 integer_bytes = aggregate_field_offsets[0];
693 const uint32_t num_children = aggregate_compiler_types.size();
697 for (uint32_t idx = 0; idx < num_children; idx++) {
702 CompilerType field_compiler_type = aggregate_compiler_types[idx];
703 uint32_t field_byte_width =
704 (uint32_t)(llvm::expectedToOptional(
707 uint32_t field_byte_offset = aggregate_field_offsets[idx];
709 uint32_t field_bit_width = field_byte_width * 8;
712 uint32_t copy_from_offset = 0;
716 if (integer_bytes < 8) {
717 if (integer_bytes + field_byte_width <= 8) {
719 copy_from_extractor = &rax_data;
720 copy_from_offset = integer_bytes;
721 integer_bytes += field_byte_width;
725 copy_from_extractor = &rdx_data;
726 copy_from_offset = 0;
727 integer_bytes = 8 + field_byte_width;
729 }
else if (integer_bytes + field_byte_width <= 16) {
730 copy_from_extractor = &rdx_data;
731 copy_from_offset = integer_bytes - 8;
732 integer_bytes += field_byte_width;
737 return return_valobj_sp;
741 if (field_bit_width == 128) {
744 }
else if (field_bit_width == 64) {
747 copy_from_extractor = &xmm0_data;
749 copy_from_extractor = &xmm1_data;
751 copy_from_offset = 0;
752 fp_bytes += field_byte_width;
753 }
else if (field_bit_width == 32) {
759 if (field_byte_offset % 8 == 0) {
762 if (idx == num_children - 1) {
766 aggregate_compiler_types[idx + 1];
771 copy_from_offset = 0;
775 }
else if (field_byte_offset % 4 == 0) {
783 aggregate_compiler_types[idx - 1];
788 copy_from_offset = 4;
800 if (integer_bytes < 8) {
802 copy_from_extractor = &rax_data;
803 copy_from_offset = integer_bytes;
804 integer_bytes += field_byte_width;
806 copy_from_extractor = &rdx_data;
807 copy_from_offset = integer_bytes - 8;
808 integer_bytes += field_byte_width;
812 copy_from_extractor = &xmm0_data;
814 copy_from_extractor = &xmm1_data;
816 fp_bytes += field_byte_width;
823 if (!copy_from_extractor)
824 return return_valobj_sp;
825 if (copy_from_offset + field_byte_width >
827 return return_valobj_sp;
829 copy_from_offset, field_byte_width,
830 data_sp->GetBytes() + field_byte_offset, field_byte_width,
837 &thread, return_compiler_type,
ConstString(
""), return_ext);
852 (uint64_t)thread.GetRegisterContext()->ReadRegisterAsUnsigned(rax_id,
855 &thread,
"",
Address(storage_addr,
nullptr), return_compiler_type);
859 return return_valobj_sp;
876 plan_sp->AppendRow(std::move(row));
877 plan_sp->SetSourceName(
"x86_64 at-func-entry default");
894 const int32_t ptr_size = 8;
904 plan_sp->AppendRow(std::move(row));
905 plan_sp->SetSourceName(
"x86_64 default unwind plan");
907 plan_sp->SetUnwindPlanValidAtAllInstructions(
eLazyBoolNo);
928 assert(reg_info->
name !=
nullptr &&
"unnamed register?");
929 std::string Name = std::string(reg_info->
name);
931 llvm::StringSwitch<bool>(Name)
932 .Cases(
"r12",
"r13",
"r14",
"r15",
"rbp",
"ebp",
"rbx",
"ebx",
true)
933 .Cases(
"rip",
"eip",
"rsp",
"esp",
"sp",
"fp",
"pc",
true)
935 return IsCalleeSaved;
939 return llvm::StringSwitch<uint32_t>(name)
static bool ReadIntegerArgument(Scalar &scalar, unsigned int bit_width, bool is_signed, Thread &thread, uint32_t *argument_register_ids, unsigned int ¤t_argument_register, addr_t ¤t_stack_argument)
static bool FlattenAggregateType(Thread &thread, ExecutionContext &exe_ctx, CompilerType &return_compiler_type, uint32_t data_byte_offset, std::vector< uint32_t > &aggregate_field_offsets, std::vector< CompilerType > &aggregate_compiler_types)
static bool ReadIntegerArgument(Scalar &scalar, unsigned int bit_width, bool is_signed, Thread &thread, uint32_t *argument_register_ids, unsigned int ¤t_argument_register, addr_t ¤t_stack_argument)
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_LOGF(log,...)
#define LLDB_PLUGIN_DEFINE(PluginName)
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)
bool RegisterIsCalleeSaved(const lldb_private::RegisterInfo *reg_info)
bool GetPointerReturnRegister(const char *&name) override
lldb_private::Status SetReturnValueObject(lldb::StackFrameSP &frame_sp, lldb::ValueObjectSP &new_value) override
uint32_t GetGenericNum(llvm::StringRef reg) override
Return the generic number of the given register.
lldb::ValueObjectSP GetReturnValueObjectImpl(lldb_private::Thread &thread, lldb_private::CompilerType &type) const override
size_t GetRedZoneSize() const override
lldb::ValueObjectSP GetReturnValueObjectSimple(lldb_private::Thread &thread, lldb_private::CompilerType &ast_type) const
lldb::UnwindPlanSP CreateDefaultUnwindPlan() override
static llvm::StringRef GetPluginNameStatic()
bool RegisterIsVolatile(const lldb_private::RegisterInfo *reg_info) override
lldb::UnwindPlanSP CreateFunctionEntryUnwindPlan() 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
static std::unique_ptr< llvm::MCRegisterInfo > MakeMCRegisterInfo(const ArchSpec &arch)
Utility function to construct a MCRegisterInfo using the ArchSpec triple.
A section + offset based address class.
An architecture specification class.
uint32_t GetAddressByteSize() const
Returns the size in bytes of an address of the current architecture.
llvm::Triple & GetTriple()
Architecture triple accessor.
lldb::ByteOrder GetByteOrder() const
Returns the byte order for the architecture specification.
Generic representation of a type in a programming language.
TypeSystemSPWrapper GetTypeSystem() const
Accessors.
CompilerType GetFieldAtIndex(size_t idx, std::string &name, uint64_t *bit_offset_ptr, uint32_t *bitfield_bit_size_ptr, bool *is_bitfield_ptr) const
llvm::Expected< uint64_t > GetByteSize(ExecutionContextScope *exe_scope) const
Return the size of the type in bytes.
bool IsFloatingPointType(uint32_t &count, bool &is_complex) const
uint32_t GetNumFields() const
bool IsIntegerOrEnumerationType(bool &is_signed) const
bool IsAggregateType() 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 IsPointerType(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.
Target * GetTargetPtr() const
Returns a pointer to the target object.
void PutString(llvm::StringRef str)
static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description, ABICreateInstance create_callback)
static bool UnregisterPlugin(ABICreateInstance create_callback)
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 GetData(DataExtractor &data) const
uint32_t GetAsMemoryData(const RegisterInfo ®_info, void *dst, uint32_t dst_len, lldb::ByteOrder dst_byte_order, Status &error) const
void SetBytes(const void *bytes, size_t length, lldb::ByteOrder byte_order)
bool SignExtend(uint32_t bit_pos)
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.
const ArchSpec & GetArchitecture() const
void SetIsRegisterPlusOffset(uint32_t reg_num, int32_t offset)
bool SetRegisterLocationToIsCFAPlusOffset(uint32_t reg_num, int32_t offset, bool can_replace)
void SetOffset(int64_t offset)
bool SetRegisterLocationToAtCFAPlusOffset(uint32_t reg_num, int32_t offset, bool can_replace)
const FAValue & GetCFAValue() const
void SetUnspecifiedRegistersAreUndefined(bool unspec_is_undef)
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)
static lldb::ValueObjectSP Create(ExecutionContextScope *exe_scope, llvm::StringRef name, const Address &address, lldb::TypeSP &type_sp)
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_ARG6
#define LLDB_REGNUM_GENERIC_SP
#define LLDB_REGNUM_GENERIC_ARG4
#define LLDB_REGNUM_GENERIC_ARG3
#define LLDB_REGNUM_GENERIC_ARG1
#define LLDB_REGNUM_GENERIC_FLAGS
#define LLDB_INVALID_REGNUM
#define LLDB_REGNUM_GENERIC_ARG2
#define LLDB_REGNUM_GENERIC_PC
#define LLDB_REGNUM_GENERIC_FP
#define LLDB_REGNUM_GENERIC_ARG5
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::UnwindPlan > UnwindPlanSP
std::shared_ptr< lldb_private::DataBuffer > DataBufferSP
std::shared_ptr< lldb_private::WritableDataBuffer > WritableDataBufferSP
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
@ 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.
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.