10#include "llvm/ADT/STLExtras.h"
11#include "llvm/TargetParser/Triple.h"
75 if (arch.
GetTriple().getVendor() != llvm::Triple::Apple) {
76 if (arch.
GetTriple().getArch() == llvm::Triple::x86) {
86 llvm::ArrayRef<addr_t> args)
const {
109 sp -= 4 * args.size();
112 sp &= ~(16ull - 1ull);
119 reg_info_32, arg_pos, reg_info_32->
byte_size, reg_value);
129 reg_info_32,
sp, reg_info_32->
byte_size, reg_value);
145 bool is_signed,
Process *process,
146 addr_t ¤t_stack_argument) {
147 uint32_t byte_size = (bit_width + (8 - 1)) / 8;
154 is_signed, scalar,
error)) {
155 current_stack_argument += byte_size;
162 unsigned int num_values = values.
GetSize();
163 unsigned int value_index;
175 addr_t current_stack_argument =
sp + 4;
177 for (value_index = 0; value_index < num_values; ++value_index) {
185 std::optional<uint64_t> bit_size =
186 llvm::expectedToOptional(compiler_type.
GetBitSize(&thread));
191 thread.GetProcess().get(), current_stack_argument);
194 thread.GetProcess().get(), current_stack_argument);
209 CompilerType compiler_type = new_value_sp->GetCompilerType();
210 if (!compiler_type) {
215 const uint32_t type_flags = compiler_type.
GetTypeInfo();
216 Thread *thread = frame_sp->GetThread().get();
220 size_t num_bytes = new_value_sp->GetData(data, data_error);
221 bool register_write_successful =
true;
223 if (data_error.
Fail()) {
225 "Couldn't convert return value to raw data: %s",
234 if (type_flags & eTypeIsPointer)
236 if (num_bytes !=
sizeof(uint32_t)) {
243 uint32_t raw_value = data.
GetMaxU32(&offset, num_bytes);
244 register_write_successful =
246 }
else if ((type_flags & eTypeIsScalar) ||
247 (type_flags & eTypeIsEnumeration))
252 if (type_flags & eTypeIsInteger)
262 uint32_t raw_value_low = data.
GetMaxU32(&offset, 4);
264 uint32_t raw_value_high = data.
GetMaxU32(&offset, num_bytes - offset);
265 register_write_successful =
273 uint32_t raw_value = data.
GetMaxU32(&offset, num_bytes);
274 register_write_successful =
279 }
else if (type_flags & eTypeIsEnumeration)
281 uint32_t raw_value = data.
GetMaxU32(&offset, num_bytes);
282 register_write_successful =
284 }
else if (type_flags & eTypeIsFloat)
303 uint32_t value_fstat_u32 = 0x00003800;
311 uint32_t value_ftag_u32 = 0x00000080;
315 long double value_long_dbl = 0.0;
317 value_long_dbl = data.
GetFloat(&offset);
318 else if (num_bytes == 8)
319 value_long_dbl = data.
GetDouble(&offset);
320 else if (num_bytes == 12)
324 "Invalid number of bytes for this return type");
330 register_write_successful =
334 }
else if (num_bytes == 16)
337 "Implementation is missing for this clang type.");
349 "Currently only Integral and Floating Point clang "
350 "types are supported.");
352 if (!register_write_successful)
362 if (!return_compiler_type)
363 return return_valobj_sp;
369 return return_valobj_sp;
371 const uint32_t type_flags = return_compiler_type.
GetTypeInfo();
382 if (type_flags & eTypeIsPointer)
385 thread.GetRegisterContext()->ReadRegisterAsUnsigned(eax_id, 0) &
390 thread.GetStackFrameAtIndex(0).get(), value,
ConstString(
""));
391 }
else if ((type_flags & eTypeIsScalar) ||
392 (type_flags & eTypeIsEnumeration))
395 std::optional<uint64_t> byte_size =
396 llvm::expectedToOptional(return_compiler_type.
GetByteSize(&thread));
398 return return_valobj_sp;
399 bool success =
false;
401 if (type_flags & eTypeIsInteger)
403 const bool is_signed = ((type_flags & eTypeIsSigned) != 0);
405 thread.GetRegisterContext()->ReadRegisterAsUnsigned(eax_id, 0) &
408 (thread.GetRegisterContext()->ReadRegisterAsUnsigned(edx_id, 0) &
412 switch (*byte_size) {
423 value.
GetScalar() = (int64_t)(raw_value);
425 value.
GetScalar() = (uint64_t)(raw_value);
439 value.
GetScalar() = (int16_t)(raw_value & UINT16_MAX);
441 value.
GetScalar() = (uint16_t)(raw_value & UINT16_MAX);
447 value.
GetScalar() = (int8_t)(raw_value & UINT8_MAX);
449 value.
GetScalar() = (uint8_t)(raw_value & UINT8_MAX);
456 thread.GetStackFrameAtIndex(0).get(), value,
ConstString(
""));
457 }
else if (type_flags & eTypeIsEnumeration)
460 thread.GetRegisterContext()->ReadRegisterAsUnsigned(eax_id, 0) &
465 thread.GetStackFrameAtIndex(0).get(), value,
ConstString(
""));
466 }
else if (type_flags & eTypeIsFloat)
468 if (*byte_size <= 12)
480 if (*byte_size == 4) {
481 float value_float = (float)value_long_double;
484 }
else if (*byte_size == 8) {
488 double value_double = (double)value_long_double;
491 }
else if (*byte_size == 12) {
501 thread.GetStackFrameAtIndex(0).get(), value,
ConstString(
""));
502 }
else if (*byte_size == 16)
505 thread.GetRegisterContext()->ReadRegisterAsUnsigned(eax_id, 0) &
508 &thread,
"",
Address(storage_addr,
nullptr), return_compiler_type);
515 }
else if (type_flags & eTypeIsComplex)
518 }
else if (type_flags & eTypeIsVector)
520 std::optional<uint64_t> byte_size =
521 llvm::expectedToOptional(return_compiler_type.
GetByteSize(&thread));
522 if (byte_size && *byte_size > 0) {
524 if (vec_reg ==
nullptr)
528 if (*byte_size <= vec_reg->byte_size) {
529 ProcessSP process_sp(thread.GetProcess());
531 std::unique_ptr<DataBufferHeap> heap_data_up(
533 const ByteOrder byte_order = process_sp->GetByteOrder();
538 heap_data_up->GetByteSize(),
539 byte_order,
error)) {
542 process_sp->GetTarget()
544 .GetAddressByteSize());
546 &thread, return_compiler_type,
ConstString(
""), data);
550 }
else if (*byte_size <= vec_reg->byte_size * 2) {
554 ProcessSP process_sp(thread.GetProcess());
556 std::unique_ptr<DataBufferHeap> heap_data_up(
558 const ByteOrder byte_order = process_sp->GetByteOrder();
566 *vec_reg, heap_data_up->GetBytes(), vec_reg->
byte_size,
567 byte_order,
error) &&
570 heap_data_up->GetBytes() + vec_reg->
byte_size,
571 heap_data_up->GetByteSize() - vec_reg->
byte_size,
572 byte_order,
error)) {
575 process_sp->GetTarget()
577 .GetAddressByteSize());
579 &thread, return_compiler_type,
ConstString(
""), data);
591 return return_valobj_sp;
598 if (!return_compiler_type)
599 return return_valobj_sp;
603 if (return_valobj_sp)
604 return return_valobj_sp;
608 return return_valobj_sp;
614 thread.GetRegisterContext()->ReadRegisterAsUnsigned(eax_id, 0) &
617 &thread,
"",
Address(storage_addr,
nullptr), return_compiler_type);
620 return return_valobj_sp;
637 plan_sp->AppendRow(std::move(row));
638 plan_sp->SetSourceName(
"i386 at-func-entry default");
654 const int32_t ptr_size = 4;
664 plan_sp->AppendRow(std::move(row));
665 plan_sp->SetSourceName(
"i386 default unwind plan");
667 plan_sp->SetUnwindPlanValidAtAllInstructions(
eLazyBoolNo);
680 const char *name = reg_info->
name;
681 if (name[0] ==
'e') {
684 if (name[2] ==
'x' || name[2] ==
'p')
685 return name[3] ==
'\0';
689 return name[3] ==
'\0';
693 return name[3] ==
'\0';
696 if (name[2] ==
'i' || name[2] ==
'p')
697 return name[3] ==
'\0';
702 if (name[0] ==
's' && name[1] ==
'p' && name[2] ==
'\0')
704 if (name[0] ==
'f' && name[1] ==
'p' && name[2] ==
'\0')
706 if (name[0] ==
'p' && name[1] ==
'c' && name[2] ==
'\0')
static bool ReadIntegerArgument(Scalar &scalar, unsigned int bit_width, bool is_signed, Process *process, addr_t ¤t_stack_argument)
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_PLUGIN_DEFINE(PluginName)
bool GetArgumentValues(lldb_private::Thread &thread, lldb_private::ValueList &values) const override
bool RegisterIsCalleeSaved(const lldb_private::RegisterInfo *reg_info)
lldb::ValueObjectSP GetReturnValueObjectImpl(lldb_private::Thread &thread, lldb_private::CompilerType &type) const override
static lldb::ABISP CreateInstance(lldb::ProcessSP process_sp, const lldb_private::ArchSpec &arch)
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
lldb::UnwindPlanSP CreateDefaultUnwindPlan() override
lldb::UnwindPlanSP CreateFunctionEntryUnwindPlan() override
lldb::ValueObjectSP GetReturnValueObjectSimple(lldb_private::Thread &thread, lldb_private::CompilerType &ast_type) const
static llvm::StringRef GetPluginNameStatic()
lldb_private::Status SetReturnValueObject(lldb::StackFrameSP &frame_sp, lldb::ValueObjectSP &new_value) 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.
llvm::Triple & GetTriple()
Architecture triple accessor.
Generic representation of a type in a programming language.
llvm::Expected< uint64_t > GetByteSize(ExecutionContextScope *exe_scope) const
Return the size of the type in bytes.
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.
static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description, ABICreateInstance create_callback)
static bool UnregisterPlugin(ABICreateInstance create_callback)
A plug-in interface definition class for debugging a process.
size_t ReadScalarIntegerFromMemory(lldb::addr_t addr, uint32_t byte_size, bool is_signed, Scalar &scalar, Status &error)
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 GetSP(uint64_t fail_value=LLDB_INVALID_ADDRESS)
virtual bool WriteRegister(const RegisterInfo *reg_info, const RegisterValue ®_value)=0
virtual Status WriteRegisterValueToMemory(const lldb_private::RegisterInfo *reg_info, lldb::addr_t dst_addr, uint32_t dst_len, const RegisterValue ®_value)
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 SetLongDouble(long double f)
void SetUInt32(uint32_t uint, Type t=eTypeUInt32)
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.
void SetIsRegisterPlusOffset(uint32_t reg_num, int32_t offset)
bool SetRegisterLocationToIsCFAPlusOffset(uint32_t reg_num, int32_t offset, bool can_replace)
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_PC
A class that represents a running process on the host machine.
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::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.