11#include "llvm/ADT/STLExtras.h"
12#include "llvm/TargetParser/Triple.h"
114#define DEFINE_GPR(reg, alt, kind1, kind2, kind3, kind4) \
116 #reg, alt, 8, 0, eEncodingUint, eFormatHex, {kind1, kind2, kind3, kind4 }, \
210const lldb_private::RegisterInfo *
222 if (arch.
GetTriple().getArch() == llvm::Triple::ppc) {
231 llvm::ArrayRef<addr_t> args)
const {
236 s.
Printf(
"ABISysV_ppc::PrepareTrivialCall (tid = 0x%" PRIx64
237 ", sp = 0x%" PRIx64
", func_addr = 0x%" PRIx64
238 ", return_addr = 0x%" PRIx64,
239 thread.
GetID(), (uint64_t)
sp, (uint64_t)func_addr,
240 (uint64_t)return_addr);
242 for (
size_t i = 0; i < args.size(); ++i)
243 s.
Printf(
", arg%" PRIu64
" = 0x%" PRIx64,
static_cast<uint64_t
>(i + 1),
253 const RegisterInfo *reg_info =
nullptr;
258 for (
size_t i = 0; i < args.size(); ++i) {
261 LLDB_LOGF(log,
"About to write arg%" PRIu64
" (0x%" PRIx64
") into %s",
262 static_cast<uint64_t
>(i + 1), args[i], reg_info->name);
269 LLDB_LOGF(log,
"16-byte aligning SP: 0x%" PRIx64
" to 0x%" PRIx64,
270 (uint64_t)
sp, (uint64_t)(
sp & ~0xfull));
277 const RegisterInfo *pc_reg_info =
279 const RegisterInfo *sp_reg_info =
286 "Pushing the return address onto the stack: 0x%" PRIx64
288 (uint64_t)
sp, (uint64_t)return_addr);
291 if (!process_sp->WritePointerToMemory(
sp, return_addr,
error))
296 LLDB_LOGF(log,
"Writing SP: 0x%" PRIx64, (uint64_t)
sp);
303 LLDB_LOGF(log,
"Writing IP: 0x%" PRIx64, (uint64_t)func_addr);
312 bool is_signed,
Thread &thread,
314 unsigned int ¤t_argument_register,
315 addr_t ¤t_stack_argument) {
319 if (current_argument_register < 6) {
321 argument_register_ids[current_argument_register], 0);
322 current_argument_register++;
326 uint32_t byte_size = (bit_width + (8 - 1)) / 8;
328 if (thread.
GetProcess()->ReadScalarIntegerFromMemory(
329 current_stack_argument, byte_size, is_signed, scalar,
error)) {
330 current_stack_argument += byte_size;
339 unsigned int num_values = values.
GetSize();
340 unsigned int value_index;
357 addr_t current_stack_argument =
sp + 48;
361 argument_register_ids[0] =
364 argument_register_ids[1] =
367 argument_register_ids[2] =
370 argument_register_ids[3] =
373 argument_register_ids[4] =
376 argument_register_ids[5] =
379 argument_register_ids[6] =
382 argument_register_ids[7] =
386 unsigned int current_argument_register = 0;
388 for (value_index = 0; value_index < num_values; ++value_index) {
397 std::optional<uint64_t> bit_size = compiler_type.
GetBitSize(&thread);
403 argument_register_ids, current_argument_register,
404 current_stack_argument);
407 argument_register_ids, current_argument_register,
408 current_stack_argument);
415 lldb::ValueObjectSP &new_value_sp) {
418 error.SetErrorString(
"Empty value object for return value.");
422 CompilerType compiler_type = new_value_sp->GetCompilerType();
423 if (!compiler_type) {
424 error.SetErrorString(
"Null clang type for return value.");
428 Thread *thread = frame_sp->GetThread().get();
436 bool set_it_simple =
false;
443 size_t num_bytes = new_value_sp->GetData(data, data_error);
444 if (data_error.
Fail()) {
445 error.SetErrorStringWithFormat(
446 "Couldn't convert return value to raw data: %s",
451 if (num_bytes <= 8) {
452 uint64_t raw_value = data.
GetMaxU64(&offset, num_bytes);
455 set_it_simple =
true;
457 error.SetErrorString(
"We don't support returning longer than 64 bit "
458 "integer values at present.");
462 error.SetErrorString(
463 "We don't support returning complex values at present");
465 std::optional<uint64_t> bit_width =
468 error.SetErrorString(
"can't get type size");
471 if (*bit_width <= 64) {
474 size_t num_bytes = new_value_sp->GetData(data, data_error);
475 if (data_error.
Fail()) {
476 error.SetErrorStringWithFormat(
477 "Couldn't convert return value to raw data: %s",
482 unsigned char buffer[16];
486 set_it_simple =
true;
489 error.SetErrorString(
490 "We don't support returning float values > 64 bits at present");
495 if (!set_it_simple) {
499 error.SetErrorString(
"We only support setting simple integer and float "
500 "return types at present.");
508 ValueObjectSP return_valobj_sp;
511 if (!return_compiler_type)
512 return return_valobj_sp;
519 return return_valobj_sp;
522 if (type_flags & eTypeIsScalar) {
525 bool success =
false;
526 if (type_flags & eTypeIsInteger) {
529 std::optional<uint64_t> byte_size =
532 return return_valobj_sp;
535 const bool is_signed = (type_flags & eTypeIsSigned) != 0;
536 switch (*byte_size) {
540 case sizeof(uint64_t):
542 value.
GetScalar() = (int64_t)(raw_value);
544 value.
GetScalar() = (uint64_t)(raw_value);
558 value.
GetScalar() = (int16_t)(raw_value & UINT16_MAX);
564 case sizeof(uint8_t):
566 value.
GetScalar() = (int8_t)(raw_value & UINT8_MAX);
568 value.
GetScalar() = (uint8_t)(raw_value & UINT8_MAX);
572 }
else if (type_flags & eTypeIsFloat) {
573 if (type_flags & eTypeIsComplex) {
576 std::optional<uint64_t> byte_size =
578 if (byte_size && *byte_size <=
sizeof(
long double)) {
585 if (*byte_size ==
sizeof(
float)) {
588 }
else if (*byte_size ==
sizeof(
double)) {
601 }
else if (type_flags & eTypeIsPointer) {
609 }
else if (type_flags & eTypeIsVector) {
610 std::optional<uint64_t> byte_size =
612 if (byte_size && *byte_size > 0) {
615 if (*byte_size <= altivec_reg->byte_size) {
618 std::unique_ptr<DataBufferHeap> heap_data_up(
620 const ByteOrder byte_order = process_sp->GetByteOrder();
625 *altivec_reg, heap_data_up->GetBytes(),
626 heap_data_up->GetByteSize(), byte_order,
error)) {
629 process_sp->GetTarget()
631 .GetAddressByteSize());
633 &thread, return_compiler_type,
ConstString(
""), data);
642 return return_valobj_sp;
647 ValueObjectSP return_valobj_sp;
649 if (!return_compiler_type)
650 return return_valobj_sp;
654 if (return_valobj_sp)
655 return return_valobj_sp;
659 return return_valobj_sp;
661 std::optional<uint64_t> bit_width = return_compiler_type.
GetBitSize(&thread);
663 return return_valobj_sp;
666 bool is_memory =
true;
667 if (*bit_width <= 128) {
673 const RegisterInfo *r3_info = reg_ctx_sp->GetRegisterInfoByName(
"r3", 0);
674 const RegisterInfo *rdx_info =
675 reg_ctx_sp->GetRegisterInfoByName(
"rdx", 0);
678 reg_ctx_sp->ReadRegister(r3_info, r3_value);
679 reg_ctx_sp->ReadRegister(rdx_info, rdx_value);
694 for (
uint32_t idx = 0; idx < num_children; idx++) {
696 uint64_t field_bit_offset = 0;
702 idx, name, &field_bit_offset,
nullptr,
nullptr);
703 std::optional<uint64_t> field_bit_width =
705 if (!field_bit_width)
706 return return_valobj_sp;
709 if (field_bit_offset % *field_bit_width != 0) {
714 uint32_t field_byte_width = *field_bit_width / 8;
715 uint32_t field_byte_offset = field_bit_offset / 8;
722 if (integer_bytes < 8) {
723 if (integer_bytes + field_byte_width <= 8) {
725 copy_from_extractor = &r3_data;
726 copy_from_offset = integer_bytes;
727 integer_bytes += field_byte_width;
731 copy_from_extractor = &rdx_data;
732 copy_from_offset = 0;
733 integer_bytes = 8 + field_byte_width;
735 }
else if (integer_bytes + field_byte_width <= 16) {
736 copy_from_extractor = &rdx_data;
737 copy_from_offset = integer_bytes - 8;
738 integer_bytes += field_byte_width;
743 return return_valobj_sp;
747 if (*field_bit_width == 128) {
750 }
else if (*field_bit_width == 64) {
751 copy_from_offset = 0;
752 }
else if (*field_bit_width == 32) {
758 if (field_byte_offset % 8 == 0) {
761 if (idx == num_children - 1)
764 uint64_t next_field_bit_offset = 0;
767 &next_field_bit_offset,
773 copy_from_offset = 0;
777 }
else if (field_byte_offset % 4 == 0) {
784 uint64_t prev_field_bit_offset = 0;
787 &prev_field_bit_offset,
793 copy_from_offset = 4;
805 if (integer_bytes < 8) {
807 copy_from_extractor = &r3_data;
808 copy_from_offset = integer_bytes;
809 integer_bytes += field_byte_width;
811 copy_from_extractor = &rdx_data;
812 copy_from_offset = integer_bytes - 8;
813 integer_bytes += field_byte_width;
822 if (!copy_from_extractor)
823 return return_valobj_sp;
824 if (copy_from_offset + field_byte_width >
826 return return_valobj_sp;
829 copy_from_offset, field_byte_width,
830 data_sp->GetBytes() + field_byte_offset, field_byte_width,
838 &thread, return_compiler_type,
ConstString(
""), return_ext);
856 &thread,
"",
Address(storage_addr,
nullptr), return_compiler_type);
860 return return_valobj_sp;
874 row->GetCFAValue().SetIsRegisterPlusOffset(sp_reg_num, 0);
877 row->SetRegisterLocationToRegister(pc_reg_num, lr_reg_num,
true);
897 const int32_t ptr_size = 4;
898 row->SetUnspecifiedRegistersAreUndefined(
true);
899 row->GetCFAValue().SetIsRegisterDereferenced(sp_reg_num);
901 row->SetRegisterLocationToAtCFAPlusOffset(pc_reg_num, ptr_size * 1,
true);
902 row->SetRegisterLocationToIsCFAPlusOffset(sp_reg_num, 0,
true);
931 const char *name = reg_info->name;
932 if (name[0] ==
'r') {
933 if ((name[1] ==
'1' || name[1] ==
'2') && name[2] ==
'\0')
935 if (name[1] ==
'1' && name[2] >
'2')
937 if ((name[1] ==
'2' || name[1] ==
'3') && name[2] !=
'\0')
941 if (name[0] ==
'f' && name[1] >=
'0' && name[1] <=
'9') {
942 if (name[3] ==
'1' && name[4] >=
'4')
944 if ((name[3] ==
'2' || name[3] ==
'3') && name[4] !=
'\0')
948 if (name[0] ==
's' && name[1] ==
'p' && name[2] ==
'\0')
950 if (name[0] ==
'f' && name[1] ==
'p' && name[2] ==
'\0')
952 if (name[0] ==
'p' && name[1] ==
'c' && name[2] ==
'\0')
static const uint32_t k_num_register_infos
static const RegisterInfo g_register_infos[]
static const uint32_t k_num_register_infos
static const RegisterInfo g_register_infos[]
#define DEFINE_GPR(reg, alt, kind1, kind2, kind3, kind4)
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)
static lldb::ABISP CreateInstance(lldb::ProcessSP process_sp, const lldb_private::ArchSpec &arch)
const lldb_private::RegisterInfo * GetRegisterInfoArray(uint32_t &count) override
lldb::ValueObjectSP GetReturnValueObjectImpl(lldb_private::Thread &thread, lldb_private::CompilerType &type) const override
bool CreateFunctionEntryUnwindPlan(lldb_private::UnwindPlan &unwind_plan) override
bool RegisterIsVolatile(const lldb_private::RegisterInfo *reg_info) override
static llvm::StringRef GetPluginNameStatic()
lldb_private::Status SetReturnValueObject(lldb::StackFrameSP &frame_sp, lldb::ValueObjectSP &new_value) override
bool CreateDefaultUnwindPlan(lldb_private::UnwindPlan &unwind_plan) override
bool RegisterIsCalleeSaved(const lldb_private::RegisterInfo *reg_info)
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
lldb::ValueObjectSP GetReturnValueObjectSimple(lldb_private::Thread &thread, lldb_private::CompilerType &ast_type) const
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.
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.
std::optional< uint64_t > GetByteSize(ExecutionContextScope *exe_scope) const
Return the size of the type in bytes.
CompilerType GetFieldAtIndex(size_t idx, std::string &name, uint64_t *bit_offset_ptr, uint32_t *bitfield_bit_size_ptr, bool *is_bitfield_ptr) const
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
std::optional< 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)
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
bool SignExtend(uint32_t bit_pos)
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
virtual lldb::StackFrameSP GetStackFrameAtIndex(uint32_t idx)
virtual lldb::RegisterContextSP GetRegisterContext()=0
lldb::ProcessSP GetProcess() const
void SetUnwindPlanForSignalTrap(lldb_private::LazyBool is_for_signal_trap)
void SetRegisterKind(lldb::RegisterKind kind)
void SetReturnAddressRegister(uint32_t regnum)
void AppendRow(const RowSP &row_sp)
std::shared_ptr< Row > RowSP
void SetSourcedFromCompiler(lldb_private::LazyBool from_compiler)
void SetSourceName(const char *)
void SetUnwindPlanValidAtAllInstructions(lldb_private::LazyBool valid_at_all_insn)
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
void SetCompilerType(const CompilerType &compiler_type)
void SetValueType(ValueType value_type)
const CompilerType & GetCompilerType()
#define LLDB_REGNUM_GENERIC_RA
#define LLDB_REGNUM_GENERIC_ARG8
#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_ARG7
#define LLDB_REGNUM_GENERIC_FLAGS
#define LLDB_INVALID_REGNUM
#define LLDB_REGNUM_GENERIC_ARG2
#define LLDB_REGNUM_GENERIC_PC
#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.
@ eEncodingUint
unsigned integer
ByteOrder
Byte ordering definitions.
@ 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
lldb::user_id_t GetID() const
Get accessor for the user ID.