28#include "llvm/ADT/StringRef.h"
47 const char *plugin_name) {
53 if (create_callback) {
55 create_callback(arch, supported_inst_type);
57 return emulate_insn_ptr;
60 for (uint32_t idx = 0;
66 create_callback(arch, supported_inst_type);
68 return emulate_insn_ptr;
76std::optional<RegisterValue>
91 std::optional<RegisterInfo> reg_info =
GetRegisterInfo(reg_kind, reg_num);
95 std::optional<RegisterValue> value =
ReadRegister(*reg_info);
98 return value.has_value();
107 return reg_value.
GetAsUInt64(fail_value, success_ptr);
109 *success_ptr =
false;
116 std::optional<RegisterValue> reg_value =
ReadRegister(reg_info);
119 *success_ptr =
false;
123 return reg_value->GetAsUInt64(fail_value, success_ptr);
138 std::optional<RegisterInfo> reg_info =
GetRegisterInfo(reg_kind, reg_num);
147 uint64_t uint_value) {
148 std::optional<RegisterInfo> reg_info =
GetRegisterInfo(reg_kind, reg_num);
151 if (reg_value.
SetUInt(uint_value, reg_info->byte_size))
159 uint64_t uint_value) {
167 void *dst,
size_t dst_len) {
180 bool success =
false;
181 if (byte_size <= 8) {
182 uint8_t buf[
sizeof(uint64_t)];
185 if (bytes_read == byte_size) {
188 uval64 = data.
GetMaxU64(&offset, byte_size);
194 *success_ptr = success;
203 size_t uval_byte_size) {
209 return (bytes_written == uval_byte_size);
213 const void *src,
size_t src_len) {
258 void *baton,
const Context &context,
261 if (baton ==
nullptr || dst ==
nullptr || dst_len == 0)
269 return process_sp->ReadMemory(addr, dst, dst_len,
error);
275 void *baton,
const Context &context,
278 if (baton ==
nullptr || src ==
nullptr || src_len == 0)
286 return process_sp->WriteMemory(addr, src, src_len,
error);
296 if (baton ==
nullptr)
304 void *baton,
const Context &context,
307 if (baton ==
nullptr)
320 strm.
Printf(
" Read from Memory (address = 0x%" PRIx64
", length = %" PRIu64
322 addr, (uint64_t)length);
323 context.
Dump(strm, instruction);
325 *((uint64_t *)dst) = 0xdeadbeef;
333 const void *dst,
size_t length) {
335 strm.
Printf(
" Write to Memory (address = 0x%" PRIx64
", length = %" PRIu64
337 addr, (uint64_t)length);
338 context.
Dump(strm, instruction);
348 strm.
Printf(
" Read Register (%s)\n", reg_info->
name);
352 reg_value.
SetUInt64((uint64_t)reg_kind << 24 | reg_num);
365 strm.
Printf(
" Write to Register (name = %s, value = ", reg_info->
name);
368 context.
Dump(strm, instruction);
401 strm.
PutCString(
"adjusting (writing value back to) a base register");
433 strm.
PutCString(
"write random bits to a register");
437 strm.
PutCString(
"write random bits to a memory address");
455 strm.
Printf(
" (reg_plus_offset = %s%+" PRId64
")",
461 strm.
Printf(
" (reg_plus_reg = %s + %s)",
467 strm.
Printf(
" (base_and_imm_offset = %s%+" PRId64
", data_reg = %s)",
474 strm.
Printf(
" (base_and_reg_offset = %s + %s, data_reg = %s)",
481 strm.
Printf(
" (register to register binary op: %s and %s)",
495 strm.
Printf(
" (unsigned_immediate = %" PRIu64
" (0x%16.16" PRIx64
"))",
500 strm.
Printf(
" (signed_immediate = %+" PRId64
" (0x%16.16" PRIx64
"))",
509 strm.
Printf(
" (isa = %u, unsigned_immediate = %u (0x%8.8x))",
515 strm.
Printf(
" (isa = %u, signed_immediate = %i (0x%8.8x))",
536 if (target !=
nullptr)
static llvm::raw_ostream & error(Stream &strm)
static bool ReadRegisterCallback(EmulateInstruction *instruction, void *baton, const RegisterInfo *reg_info, RegisterValue ®_value)
static size_t WriteMemoryCallback(EmulateInstruction *instruction, void *baton, const EmulateInstruction::Context &context, lldb::addr_t addr, const void *dst, size_t length)
static size_t ReadMemoryCallback(EmulateInstruction *instruction, void *baton, const EmulateInstruction::Context &context, lldb::addr_t addr, void *dst, size_t length)
static bool WriteRegisterCallback(EmulateInstruction *instruction, void *baton, const EmulateInstruction::Context &context, const RegisterInfo *reg_info, const RegisterValue ®_value)
A section + offset based address class.
lldb::addr_t GetLoadAddress(Target *target) const
Get the load address.
lldb::addr_t GetFileAddress() const
Get the file address.
bool IsValid() const
Check if the object state is valid.
An architecture specification class.
"lldb/Core/EmulateInstruction.h" A class that allows emulation of CPU opcodes.
static bool GetBestRegisterKindAndNumber(const RegisterInfo *reg_info, lldb::RegisterKind ®_kind, uint32_t ®_num)
static bool WriteRegisterDefault(EmulateInstruction *instruction, void *baton, const Context &context, const RegisterInfo *reg_info, const RegisterValue ®_value)
static size_t WriteMemoryFrame(EmulateInstruction *instruction, void *baton, const Context &context, lldb::addr_t addr, const void *dst, size_t length)
@ eContextRelativeBranchImmediate
@ eContextSetFramePointer
@ eContextAdjustBaseRegister
@ eContextWriteMemoryRandomBits
@ eContextTableBranchReadMemory
@ eContextWriteRegisterRandomBits
@ eContextAdjustStackPointer
@ eContextReturnFromException
@ eContextPushRegisterOnStack
@ eContextPopRegisterOffStack
@ eContextAbsoluteBranchRegister
@ eContextRegisterPlusOffset
@ eInfoTypeRegisterPlusOffset
@ eInfoTypeRegisterRegisterOperands
@ eInfoTypeImmediateSigned
@ eInfoTypeISAAndImmediate
@ eInfoTypeRegisterToRegisterPlusOffset
@ eInfoTypeRegisterToRegisterPlusIndirectOffset
@ eInfoTypeRegisterPlusIndirectOffset
@ eInfoTypeISAAndImmediateSigned
WriteMemoryCallback m_write_mem_callback
lldb::ByteOrder GetByteOrder() const
void SetWriteRegCallback(WriteRegisterCallback write_reg_callback)
void SetCallbacks(ReadMemoryCallback read_mem_callback, WriteMemoryCallback write_mem_callback, ReadRegisterCallback read_reg_callback, WriteRegisterCallback write_reg_callback)
static bool ReadRegisterDefault(EmulateInstruction *instruction, void *baton, const RegisterInfo *reg_info, RegisterValue ®_value)
virtual bool CreateFunctionEntryUnwind(UnwindPlan &unwind_plan)
bool WriteMemoryUnsigned(const Context &context, lldb::addr_t addr, uint64_t uval, size_t uval_byte_size)
static uint32_t GetInternalRegisterNumber(RegisterContext *reg_ctx, const RegisterInfo ®_info)
void SetReadRegCallback(ReadRegisterCallback read_reg_callback)
size_t ReadMemory(const Context &context, lldb::addr_t addr, void *dst, size_t dst_len)
std::optional< RegisterValue > ReadRegister(const RegisterInfo ®_info)
ReadRegisterCallback m_read_reg_callback
static size_t ReadMemoryFrame(EmulateInstruction *instruction, void *baton, const Context &context, lldb::addr_t addr, void *dst, size_t length)
bool WriteRegister(const Context &context, const RegisterInfo &ref_info, const RegisterValue ®_value)
bool WriteRegisterUnsigned(const Context &context, const RegisterInfo ®_info, uint64_t reg_value)
bool WriteMemory(const Context &context, lldb::addr_t addr, const void *src, size_t src_len)
uint64_t ReadMemoryUnsigned(const Context &context, lldb::addr_t addr, size_t byte_size, uint64_t fail_value, bool *success_ptr)
WriteRegisterCallback m_write_reg_callback
EmulateInstruction(const ArchSpec &arch)
static size_t WriteMemoryDefault(EmulateInstruction *instruction, void *baton, const Context &context, lldb::addr_t addr, const void *dst, size_t length)
void SetReadMemCallback(ReadMemoryCallback read_mem_callback)
static bool WriteRegisterFrame(EmulateInstruction *instruction, void *baton, const Context &context, const RegisterInfo *reg_info, const RegisterValue ®_value)
uint32_t GetAddressByteSize() const
ReadMemoryCallback m_read_mem_callback
static bool ReadRegisterFrame(EmulateInstruction *instruction, void *baton, const RegisterInfo *reg_info, RegisterValue ®_value)
virtual std::optional< RegisterInfo > GetRegisterInfo(lldb::RegisterKind reg_kind, uint32_t reg_num)=0
void SetBaton(void *baton)
static size_t ReadMemoryDefault(EmulateInstruction *instruction, void *baton, const Context &context, lldb::addr_t addr, void *dst, size_t length)
virtual bool SetInstruction(const Opcode &insn_opcode, const Address &inst_addr, Target *target)
static EmulateInstruction * FindPlugin(const ArchSpec &arch, InstructionType supported_inst_type, const char *plugin_name)
uint64_t ReadRegisterUnsigned(const RegisterInfo ®_info, uint64_t fail_value, bool *success_ptr)
void SetWriteMemCallback(WriteMemoryCallback write_mem_callback)
static EmulateInstructionCreateInstance GetEmulateInstructionCreateCallbackForPluginName(llvm::StringRef name)
static EmulateInstructionCreateInstance GetEmulateInstructionCreateCallbackAtIndex(uint32_t idx)
virtual uint32_t ConvertRegisterKindToRegisterNumber(lldb::RegisterKind kind, uint32_t num)
Convert from a given register numbering scheme to the lldb register numbering scheme.
void SetUInt64(uint64_t uint, Type t=eTypeUInt64)
bool SetUInt(uint64_t uint, uint32_t byte_size)
uint64_t GetAsUInt64(uint64_t fail_value=UINT64_MAX, bool *success_ptr=nullptr) const
This base class provides an interface to stack frames.
lldb::RegisterContextSP GetRegisterContext()
Get the RegisterContext for this frame, if possible.
lldb::ProcessSP CalculateProcess() override
llvm::StringRef GetString() const
A stream class that can stream formatted output to a file.
@ eBinary
Get and put data as binary instead of as the default string mode.
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.
size_t EOL()
Output and End of Line character to the stream.
size_t PutMaxHex64(uint64_t uvalue, size_t byte_size, lldb::ByteOrder byte_order=lldb::eByteOrderInvalid)
#define LLDB_INVALID_ADDRESS
#define LLDB_INVALID_REGNUM
A class that represents a running process on the host machine.
EmulateInstruction *(* EmulateInstructionCreateInstance)(const ArchSpec &arch, InstructionType inst_type)
InstructionType
Instruction types.
void DumpRegisterValue(const RegisterValue ®_val, Stream &s, const RegisterInfo ®_info, bool prefix_with_name, bool prefix_with_alt_name, lldb::Format format, uint32_t reg_name_right_align_at=0, ExecutionContextScope *exe_scope=nullptr, bool print_flags=false, lldb::TargetSP target_sp=nullptr)
std::shared_ptr< lldb_private::Process > ProcessSP
RegisterKind
Register numbering types.
@ 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
@ eRegisterKindEHFrame
the register numbers seen in eh_frame
@ eRegisterKindProcessPlugin
num used by the process plugin - e.g.
void Dump(Stream &s, EmulateInstruction *instruction) const
union lldb_private::EmulateInstruction::Context::ContextInfo info
enum InfoType GetInfoType() const
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.
struct lldb_private::EmulateInstruction::Context::ContextInfo::ISAAndImmediateSigned ISAAndImmediateSigned
struct lldb_private::EmulateInstruction::Context::ContextInfo::RegisterRegisterOperands RegisterRegisterOperands
struct lldb_private::EmulateInstruction::Context::ContextInfo::RegisterPlusOffset RegisterPlusOffset
struct lldb_private::EmulateInstruction::Context::ContextInfo::RegisterPlusIndirectOffset RegisterPlusIndirectOffset
uint64_t unsigned_immediate
struct lldb_private::EmulateInstruction::Context::ContextInfo::RegisterToRegisterPlusIndirectOffset RegisterToRegisterPlusIndirectOffset
struct lldb_private::EmulateInstruction::Context::ContextInfo::RegisterToRegisterPlusOffset RegisterToRegisterPlusOffset
struct lldb_private::EmulateInstruction::Context::ContextInfo::ISAAndImmediate ISAAndImmediate