11#include "llvm/ADT/STLExtras.h"
12#include "llvm/ADT/StringSwitch.h"
13#include "llvm/TargetParser/Triple.h"
117 if (arch.
GetTriple().getArch() == llvm::Triple::x86_64 &&
127 llvm::ArrayRef<addr_t> args)
const {
132 s.
Printf(
"ABIWindows_x86_64::PrepareTrivialCall (tid = 0x%" PRIx64
133 ", sp = 0x%" PRIx64
", func_addr = 0x%" PRIx64
134 ", return_addr = 0x%" PRIx64,
135 thread.GetID(), (uint64_t)
sp, (uint64_t)func_addr,
136 (uint64_t)return_addr);
138 for (
size_t i = 0; i < args.size(); ++i)
139 s.
Printf(
", arg%" PRIu64
" = 0x%" PRIx64,
static_cast<uint64_t
>(i + 1),
154 for (
size_t i = 0; i < args.size(); ++i) {
157 LLDB_LOGF(log,
"About to write arg%" PRIu64
" (0x%" PRIx64
") into %s",
158 static_cast<uint64_t
>(i + 1), args[i], reg_info->
name);
165 LLDB_LOGF(log,
"16-byte aligning SP: 0x%" PRIx64
" to 0x%" PRIx64,
166 (uint64_t)
sp, (uint64_t)(
sp & ~0xfull));
177 ProcessSP process_sp(thread.GetProcess());
181 "Pushing the return address onto the stack: 0x%" PRIx64
183 (uint64_t)
sp, (uint64_t)return_addr);
186 if (!process_sp->WritePointerToMemory(
sp, return_addr,
error))
191 LLDB_LOGF(log,
"Writing SP: 0x%" PRIx64, (uint64_t)
sp);
198 LLDB_LOGF(log,
"Writing IP: 0x%" PRIx64, (uint64_t)func_addr);
207 bool is_signed,
Thread &thread,
208 uint32_t *argument_register_ids,
209 unsigned int ¤t_argument_register,
210 addr_t ¤t_stack_argument) {
214 if (current_argument_register < 4) {
215 scalar = thread.GetRegisterContext()->ReadRegisterAsUnsigned(
216 argument_register_ids[current_argument_register], 0);
217 current_argument_register++;
222 uint32_t byte_size = (bit_width + (CHAR_BIT - 1)) / CHAR_BIT;
224 if (thread.GetProcess()->ReadScalarIntegerFromMemory(
225 current_stack_argument, byte_size, is_signed, scalar,
error)) {
226 current_stack_argument += byte_size;
234 unsigned int num_values = values.
GetSize();
235 unsigned int value_index;
252 addr_t current_stack_argument =
sp + 8;
254 uint32_t argument_register_ids[4];
256 argument_register_ids[0] =
259 argument_register_ids[1] =
262 argument_register_ids[2] =
265 argument_register_ids[3] =
269 unsigned int current_argument_register = 0;
271 for (value_index = 0; value_index < num_values; ++value_index) {
278 std::optional<uint64_t> bit_size =
279 llvm::expectedToOptional(compiler_type.
GetBitSize(&thread));
286 argument_register_ids, current_argument_register,
287 current_stack_argument);
290 argument_register_ids, current_argument_register,
291 current_stack_argument);
306 CompilerType compiler_type = new_value_sp->GetCompilerType();
307 if (!compiler_type) {
312 Thread *thread = frame_sp->GetThread().get();
320 bool set_it_simple =
false;
327 size_t num_bytes = new_value_sp->GetData(data, data_error);
328 if (data_error.
Fail()) {
330 "Couldn't convert return value to raw data: %s",
335 if (num_bytes <= 8) {
336 uint64_t raw_value = data.
GetMaxU64(&offset, num_bytes);
339 set_it_simple =
true;
342 "We don't support returning longer than 64 bit "
343 "integer values at present.");
348 "We don't support returning complex values at present");
350 std::optional<uint64_t> bit_width =
351 llvm::expectedToOptional(compiler_type.
GetBitSize(frame_sp.get()));
356 if (*bit_width <= 64) {
362 size_t num_bytes = new_value_sp->GetData(data, data_error);
363 if (data_error.
Fail()) {
365 "Couldn't convert return value to raw data: %s",
370 unsigned char buffer[16];
374 xmm0_value.
SetBytes(buffer, 16, byte_order);
376 set_it_simple =
true;
380 "Windows-x86_64 doesn't allow FP larger than 64 bits.");
385 if (!set_it_simple) {
393 "We only support setting simple integer and float "
394 "return types at present.");
405 if (!return_compiler_type)
406 return return_valobj_sp;
412 return return_valobj_sp;
414 const uint32_t type_flags = return_compiler_type.
GetTypeInfo();
415 if (type_flags & eTypeIsScalar) {
418 bool success =
false;
419 if (type_flags & eTypeIsInteger) {
421 std::optional<uint64_t> byte_size =
422 llvm::expectedToOptional(return_compiler_type.
GetByteSize(&thread));
424 return return_valobj_sp;
425 uint64_t raw_value = thread.GetRegisterContext()->ReadRegisterAsUnsigned(
427 const bool is_signed = (type_flags & eTypeIsSigned) != 0;
428 switch (*byte_size) {
432 case sizeof(uint64_t):
434 value.
GetScalar() = (int64_t)(raw_value);
436 value.
GetScalar() = (uint64_t)(raw_value);
440 case sizeof(uint32_t):
448 case sizeof(uint16_t):
450 value.
GetScalar() = (int16_t)(raw_value & UINT16_MAX);
452 value.
GetScalar() = (uint16_t)(raw_value & UINT16_MAX);
456 case sizeof(uint8_t):
458 value.
GetScalar() = (int8_t)(raw_value & UINT8_MAX);
460 value.
GetScalar() = (uint8_t)(raw_value & UINT8_MAX);
464 }
else if (type_flags & eTypeIsFloat) {
465 if (type_flags & eTypeIsComplex) {
468 std::optional<uint64_t> byte_size =
469 llvm::expectedToOptional(return_compiler_type.
GetByteSize(&thread));
470 if (byte_size && *byte_size <=
sizeof(
long double)) {
476 if (xmm0_value.
GetData(data)) {
478 if (*byte_size ==
sizeof(
float)) {
481 }
else if (*byte_size ==
sizeof(
double)) {
494 thread.GetStackFrameAtIndex(0).get(), value,
ConstString(
""));
495 }
else if ((type_flags & eTypeIsPointer) ||
496 (type_flags & eTypeInstanceIsPointer)) {
500 (uint64_t)thread.GetRegisterContext()->ReadRegisterAsUnsigned(rax_id,
504 thread.GetStackFrameAtIndex(0).get(), value,
ConstString(
""));
505 }
else if (type_flags & eTypeIsVector) {
506 std::optional<uint64_t> byte_size =
507 llvm::expectedToOptional(return_compiler_type.
GetByteSize(&thread));
508 if (byte_size && *byte_size > 0) {
511 if (xmm_reg ==
nullptr)
515 if (*byte_size <= xmm_reg->byte_size) {
516 ProcessSP process_sp(thread.GetProcess());
518 std::unique_ptr<DataBufferHeap> heap_data_up(
520 const ByteOrder byte_order = process_sp->GetByteOrder();
525 heap_data_up->GetByteSize(),
526 byte_order,
error)) {
529 process_sp->GetTarget()
531 .GetAddressByteSize());
533 &thread, return_compiler_type,
ConstString(
""), data);
542 return return_valobj_sp;
553 uint32_t data_byte_offset,
554 std::vector<uint32_t> &aggregate_field_offsets,
555 std::vector<CompilerType> &aggregate_compiler_types) {
557 const uint32_t num_children = return_compiler_type.
GetNumFields();
558 for (uint32_t idx = 0; idx < num_children; ++idx) {
564 uint64_t field_bit_offset = 0;
566 idx, name, &field_bit_offset,
nullptr,
nullptr);
567 std::optional<uint64_t> field_bit_width =
568 llvm::expectedToOptional(field_compiler_type.
GetBitSize(&thread));
571 if (!field_bit_width || *field_bit_width == 0) {
575 if (field_bit_offset % *field_bit_width != 0) {
580 uint32_t field_byte_offset = field_bit_offset / 8 + data_byte_offset;
582 const uint32_t field_type_flags = field_compiler_type.
GetTypeInfo();
586 aggregate_field_offsets.push_back(field_byte_offset);
587 aggregate_compiler_types.push_back(field_compiler_type);
588 }
else if (field_type_flags & eTypeHasChildren) {
590 field_byte_offset, aggregate_field_offsets,
591 aggregate_compiler_types)) {
603 if (!return_compiler_type) {
604 return return_valobj_sp;
609 if (return_valobj_sp) {
610 return return_valobj_sp;
615 return return_valobj_sp;
618 std::optional<uint64_t> bit_width =
619 llvm::expectedToOptional(return_compiler_type.
GetBitSize(&thread));
621 return return_valobj_sp;
626 return return_valobj_sp;
631 uint32_t max_register_value_bit_width = 64;
641 bool is_memory = *bit_width > max_register_value_bit_width ||
642 *bit_width & (*bit_width - 1);
643 std::vector<uint32_t> aggregate_field_offsets;
644 std::vector<CompilerType> aggregate_compiler_types;
647 0, aggregate_field_offsets,
648 aggregate_compiler_types)) {
657 reg_ctx_sp->GetRegisterInfoByName(
"rax", 0);
659 reg_ctx_sp->ReadRegister(rax_info, rax_value);
663 uint32_t used_bytes =
668 if (aggregate_field_offsets.size())
669 used_bytes = aggregate_field_offsets[0];
671 const uint32_t num_children = aggregate_compiler_types.size();
672 for (uint32_t idx = 0; idx < num_children; idx++) {
677 CompilerType field_compiler_type = aggregate_compiler_types[idx];
678 uint32_t field_byte_width =
679 (uint32_t)(llvm::expectedToOptional(
682 uint32_t field_byte_offset = aggregate_field_offsets[idx];
686 if (used_bytes >= 8 || used_bytes + field_byte_width > 8) {
687 return return_valobj_sp;
691 uint32_t copy_from_offset = 0;
695 copy_from_extractor = &rax_data;
696 copy_from_offset = used_bytes;
697 used_bytes += field_byte_width;
702 if (!copy_from_extractor) {
703 return return_valobj_sp;
705 if (copy_from_offset + field_byte_width >
707 return return_valobj_sp;
710 field_byte_width, data_sp->GetBytes() + field_byte_offset,
711 field_byte_width, byte_order);
717 &thread, return_compiler_type,
ConstString(
""), return_ext);
734 (uint64_t)thread.GetRegisterContext()->ReadRegisterAsUnsigned(rax_id,
737 &thread,
"",
Address(storage_addr,
nullptr), return_compiler_type);
739 return return_valobj_sp;
756 plan_sp->AppendRow(std::move(row));
757 plan_sp->SetSourceName(
"x86_64 at-func-entry default");
772 const int32_t ptr_size = 8;
782 plan_sp->AppendRow(std::move(row));
783 plan_sp->SetSourceName(
"x86_64 default unwind plan");
785 plan_sp->SetUnwindPlanValidAtAllInstructions(
eLazyBoolNo);
796 assert(reg_info->
name !=
nullptr &&
"unnamed register?");
797 std::string Name = std::string(reg_info->
name);
799 llvm::StringSwitch<bool>(Name)
800 .Cases(
"rbx",
"ebx",
"rbp",
"ebp",
"rdi",
"edi",
"rsi",
"esi",
true)
801 .Cases(
"rsp",
"esp",
"r12",
"r13",
"r14",
"r15",
"sp",
"fp",
true)
802 .Cases(
"xmm6",
"xmm7",
"xmm8",
"xmm9",
"xmm10",
"xmm11",
"xmm12",
803 "xmm13",
"xmm14",
"xmm15",
true)
805 return IsCalleeSaved;
809 return llvm::StringSwitch<uint32_t>(reg)
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 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)
lldb_private::Status SetReturnValueObject(lldb::StackFrameSP &frame_sp, lldb::ValueObjectSP &new_value) override
static llvm::StringRef GetPluginNameStatic()
static lldb::ABISP CreateInstance(lldb::ProcessSP process_sp, const lldb_private::ArchSpec &arch)
lldb::ValueObjectSP GetReturnValueObjectImpl(lldb_private::Thread &thread, lldb_private::CompilerType &type) const override
lldb::ValueObjectSP GetReturnValueObjectSimple(lldb_private::Thread &thread, lldb_private::CompilerType &ast_type) const
bool GetPointerReturnRegister(const char *&name) override
bool GetArgumentValues(lldb_private::Thread &thread, lldb_private::ValueList &values) const override
size_t GetRedZoneSize() const override
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
bool RegisterIsCalleeSaved(const lldb_private::RegisterInfo *reg_info)
lldb::UnwindPlanSP CreateDefaultUnwindPlan() override
uint32_t GetGenericNum(llvm::StringRef reg) override
Return the generic number of the given register.
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.
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_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
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 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.