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 }, \
117 nullptr, nullptr, nullptr, \
223 if (arch.
GetTriple().getArch() == llvm::Triple::ppc) {
232 llvm::ArrayRef<addr_t> args)
const {
237 s.
Printf(
"ABISysV_ppc::PrepareTrivialCall (tid = 0x%" PRIx64
238 ", sp = 0x%" PRIx64
", func_addr = 0x%" PRIx64
239 ", return_addr = 0x%" PRIx64,
240 thread.GetID(), (uint64_t)
sp, (uint64_t)func_addr,
241 (uint64_t)return_addr);
243 for (
size_t i = 0; i < args.size(); ++i)
244 s.
Printf(
", arg%" PRIu64
" = 0x%" PRIx64,
static_cast<uint64_t
>(i + 1),
259 for (
size_t i = 0; i < args.size(); ++i) {
262 LLDB_LOGF(log,
"About to write arg%" PRIu64
" (0x%" PRIx64
") into %s",
263 static_cast<uint64_t
>(i + 1), args[i], reg_info->
name);
270 LLDB_LOGF(log,
"16-byte aligning SP: 0x%" PRIx64
" to 0x%" PRIx64,
271 (uint64_t)
sp, (uint64_t)(
sp & ~0xfull));
282 ProcessSP process_sp(thread.GetProcess());
287 "Pushing the return address onto the stack: 0x%" PRIx64
289 (uint64_t)
sp, (uint64_t)return_addr);
292 if (!process_sp->WritePointerToMemory(
sp, return_addr,
error))
297 LLDB_LOGF(log,
"Writing SP: 0x%" PRIx64, (uint64_t)
sp);
304 LLDB_LOGF(log,
"Writing IP: 0x%" PRIx64, (uint64_t)func_addr);
313 bool is_signed,
Thread &thread,
314 uint32_t *argument_register_ids,
315 unsigned int ¤t_argument_register,
316 addr_t ¤t_stack_argument) {
320 if (current_argument_register < 6) {
321 scalar = thread.GetRegisterContext()->ReadRegisterAsUnsigned(
322 argument_register_ids[current_argument_register], 0);
323 current_argument_register++;
327 uint32_t byte_size = (bit_width + (8 - 1)) / 8;
329 if (thread.GetProcess()->ReadScalarIntegerFromMemory(
330 current_stack_argument, byte_size, is_signed, scalar,
error)) {
331 current_stack_argument += byte_size;
340 unsigned int num_values = values.
GetSize();
341 unsigned int value_index;
358 addr_t current_stack_argument =
sp + 48;
360 uint32_t argument_register_ids[8];
362 argument_register_ids[0] =
365 argument_register_ids[1] =
368 argument_register_ids[2] =
371 argument_register_ids[3] =
374 argument_register_ids[4] =
377 argument_register_ids[5] =
380 argument_register_ids[6] =
383 argument_register_ids[7] =
387 unsigned int current_argument_register = 0;
389 for (value_index = 0; value_index < num_values; ++value_index) {
398 std::optional<uint64_t> bit_size =
399 llvm::expectedToOptional(compiler_type.
GetBitSize(&thread));
405 argument_register_ids, current_argument_register,
406 current_stack_argument);
409 argument_register_ids, current_argument_register,
410 current_stack_argument);
422 CompilerType compiler_type = new_value_sp->GetCompilerType();
426 Thread *thread = frame_sp->GetThread().get();
432 bool set_it_simple =
false;
439 size_t num_bytes = new_value_sp->GetData(data, data_error);
440 if (data_error.
Fail())
442 "Couldn't convert return value to raw data: %s",
445 if (num_bytes <= 8) {
446 uint64_t raw_value = data.
GetMaxU64(&offset, num_bytes);
449 set_it_simple =
true;
452 "We don't support returning longer than 64 bit "
453 "integer values at present.");
456 std::optional<uint64_t> bit_width =
457 llvm::expectedToOptional(compiler_type.
GetBitSize(frame_sp.get()));
462 if (*bit_width <= 64) {
465 size_t num_bytes = new_value_sp->GetData(data, data_error);
466 if (data_error.
Fail()) {
468 "Couldn't convert return value to raw data: %s",
473 unsigned char buffer[16];
477 set_it_simple =
true;
481 "We don't support returning float values > 64 bits at present");
485 if (!set_it_simple) {
490 "We only support setting simple integer and float "
491 "return types at present.");
502 if (!return_compiler_type)
503 return return_valobj_sp;
510 return return_valobj_sp;
512 const uint32_t type_flags = return_compiler_type.
GetTypeInfo();
513 if (type_flags & eTypeIsScalar) {
516 bool success =
false;
517 if (type_flags & eTypeIsInteger) {
520 std::optional<uint64_t> byte_size =
521 llvm::expectedToOptional(return_compiler_type.
GetByteSize(&thread));
523 return return_valobj_sp;
524 uint64_t raw_value = thread.GetRegisterContext()->ReadRegisterAsUnsigned(
526 const bool is_signed = (type_flags & eTypeIsSigned) != 0;
527 switch (*byte_size) {
531 case sizeof(uint64_t):
533 value.
GetScalar() = (int64_t)(raw_value);
535 value.
GetScalar() = (uint64_t)(raw_value);
539 case sizeof(uint32_t):
547 case sizeof(uint16_t):
549 value.
GetScalar() = (int16_t)(raw_value & UINT16_MAX);
551 value.
GetScalar() = (uint16_t)(raw_value & UINT16_MAX);
555 case sizeof(uint8_t):
557 value.
GetScalar() = (int8_t)(raw_value & UINT8_MAX);
559 value.
GetScalar() = (uint8_t)(raw_value & UINT8_MAX);
563 }
else if (type_flags & eTypeIsFloat) {
564 if (type_flags & eTypeIsComplex) {
567 std::optional<uint64_t> byte_size =
568 llvm::expectedToOptional(return_compiler_type.
GetByteSize(&thread));
569 if (byte_size && *byte_size <=
sizeof(
long double)) {
576 if (*byte_size ==
sizeof(
float)) {
579 }
else if (*byte_size ==
sizeof(
double)) {
591 thread.GetStackFrameAtIndex(0).get(), value,
ConstString(
""));
592 }
else if (type_flags & eTypeIsPointer) {
596 (uint64_t)thread.GetRegisterContext()->ReadRegisterAsUnsigned(r3_id, 0);
599 thread.GetStackFrameAtIndex(0).get(), value,
ConstString(
""));
600 }
else if (type_flags & eTypeIsVector) {
601 std::optional<uint64_t> byte_size =
602 llvm::expectedToOptional(return_compiler_type.
GetByteSize(&thread));
603 if (byte_size && *byte_size > 0) {
606 if (*byte_size <= altivec_reg->byte_size) {
607 ProcessSP process_sp(thread.GetProcess());
609 std::unique_ptr<DataBufferHeap> heap_data_up(
611 const ByteOrder byte_order = process_sp->GetByteOrder();
616 *altivec_reg, heap_data_up->GetBytes(),
617 heap_data_up->GetByteSize(), byte_order,
error)) {
620 process_sp->GetTarget()
622 .GetAddressByteSize());
624 &thread, return_compiler_type,
ConstString(
""), data);
633 return return_valobj_sp;
640 if (!return_compiler_type)
641 return return_valobj_sp;
645 if (return_valobj_sp)
646 return return_valobj_sp;
650 return return_valobj_sp;
652 std::optional<uint64_t> bit_width =
653 llvm::expectedToOptional(return_compiler_type.
GetBitSize(&thread));
655 return return_valobj_sp;
658 bool is_memory =
true;
659 if (*bit_width <= 128) {
665 const RegisterInfo *r3_info = reg_ctx_sp->GetRegisterInfoByName(
"r3", 0);
667 reg_ctx_sp->GetRegisterInfoByName(
"rdx", 0);
670 reg_ctx_sp->ReadRegister(r3_info, r3_value);
671 reg_ctx_sp->ReadRegister(rdx_info, rdx_value);
678 uint32_t integer_bytes =
681 const uint32_t num_children = return_compiler_type.
GetNumFields();
686 for (uint32_t idx = 0; idx < num_children; idx++) {
688 uint64_t field_bit_offset = 0;
692 idx, name, &field_bit_offset,
nullptr,
nullptr);
693 std::optional<uint64_t> field_bit_width =
694 llvm::expectedToOptional(field_compiler_type.
GetBitSize(&thread));
695 if (!field_bit_width)
696 return return_valobj_sp;
699 if (field_bit_offset % *field_bit_width != 0) {
704 uint32_t field_byte_width = *field_bit_width / 8;
705 uint32_t field_byte_offset = field_bit_offset / 8;
708 uint32_t copy_from_offset = 0;
712 if (integer_bytes < 8) {
713 if (integer_bytes + field_byte_width <= 8) {
715 copy_from_extractor = &r3_data;
716 copy_from_offset = integer_bytes;
717 integer_bytes += field_byte_width;
721 copy_from_extractor = &rdx_data;
722 copy_from_offset = 0;
723 integer_bytes = 8 + field_byte_width;
725 }
else if (integer_bytes + field_byte_width <= 16) {
726 copy_from_extractor = &rdx_data;
727 copy_from_offset = integer_bytes - 8;
728 integer_bytes += field_byte_width;
733 return return_valobj_sp;
735 }
else if (field_compiler_type.
GetTypeInfo() & eTypeIsFloat) {
737 if (*field_bit_width == 128) {
740 }
else if (*field_bit_width == 64) {
741 copy_from_offset = 0;
742 }
else if (*field_bit_width == 32) {
748 if (field_byte_offset % 8 == 0) {
751 if (idx == num_children - 1)
754 uint64_t next_field_bit_offset = 0;
757 &next_field_bit_offset,
763 copy_from_offset = 0;
767 }
else if (field_byte_offset % 4 == 0) {
774 uint64_t prev_field_bit_offset = 0;
777 &prev_field_bit_offset,
783 copy_from_offset = 4;
795 if (integer_bytes < 8) {
797 copy_from_extractor = &r3_data;
798 copy_from_offset = integer_bytes;
799 integer_bytes += field_byte_width;
801 copy_from_extractor = &rdx_data;
802 copy_from_offset = integer_bytes - 8;
803 integer_bytes += field_byte_width;
812 if (!copy_from_extractor)
813 return return_valobj_sp;
814 if (copy_from_offset + field_byte_width >
816 return return_valobj_sp;
819 copy_from_offset, field_byte_width,
820 data_sp->GetBytes() + field_byte_offset, field_byte_width,
828 &thread, return_compiler_type,
ConstString(
""), return_ext);
843 (uint64_t)thread.GetRegisterContext()->ReadRegisterAsUnsigned(r3_id,
846 &thread,
"",
Address(storage_addr,
nullptr), return_compiler_type);
850 return return_valobj_sp;
867 plan_sp->AppendRow(std::move(row));
868 plan_sp->SetSourceName(
"ppc at-func-entry default");
880 const int32_t ptr_size = 4;
888 plan_sp->AppendRow(std::move(row));
889 plan_sp->SetSourceName(
"ppc default unwind plan");
891 plan_sp->SetUnwindPlanValidAtAllInstructions(
eLazyBoolNo);
893 plan_sp->SetReturnAddressRegister(
dwarf_lr);
915 const char *name = reg_info->
name;
916 if (name[0] ==
'r') {
917 if ((name[1] ==
'1' || name[1] ==
'2') && name[2] ==
'\0')
919 if (name[1] ==
'1' && name[2] >
'2')
921 if ((name[1] ==
'2' || name[1] ==
'3') && name[2] !=
'\0')
925 if (name[0] ==
'f' && name[1] >=
'0' && name[1] <=
'9') {
926 if (name[3] ==
'1' && name[4] >=
'4')
928 if ((name[3] ==
'2' || name[3] ==
'3') && name[4] !=
'\0')
932 if (name[0] ==
's' && name[1] ==
'p' && name[2] ==
'\0')
934 if (name[0] ==
'f' && name[1] ==
'p' && name[2] ==
'\0')
936 if (name[0] ==
'p' && name[1] ==
'c' && name[2] ==
'\0')
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
lldb::UnwindPlanSP CreateDefaultUnwindPlan() 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 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
lldb::UnwindPlanSP CreateFunctionEntryUnwindPlan() 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.
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.
uint32_t GetNumFields() const
bool IsIntegerOrEnumerationType(bool &is_signed) const
bool IsAggregateType() const
uint32_t GetTypeInfo(CompilerType *pointee_or_element_compiler_type=nullptr) const
bool IsRealFloatingPointType() const
Returns true for non-complex float types.
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)
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)
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 SetIsRegisterDereferenced(uint32_t reg_num)
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
bool SetRegisterLocationToRegister(uint32_t reg_num, uint32_t other_reg_num, bool can_replace)
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_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.
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
@ eEncodingUint
unsigned integer
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.