Go to the documentation of this file.
28 #include "llvm/ADT/StringRef.h"
44 EmulateInstruction::FindPlugin(
const ArchSpec &arch,
46 const char *plugin_name) {
47 EmulateInstructionCreateInstance create_callback =
nullptr;
50 PluginManager::GetEmulateInstructionCreateCallbackForPluginName(
52 if (create_callback) {
54 create_callback(arch, supported_inst_type);
56 return emulate_insn_ptr;
61 PluginManager::GetEmulateInstructionCreateCallbackAtIndex(idx)) !=
65 create_callback(arch, supported_inst_type);
67 return emulate_insn_ptr;
73 EmulateInstruction::EmulateInstruction(
const ArchSpec &arch) : m_arch(arch) {}
85 RegisterInfo reg_info;
97 return reg_value.
GetAsUInt64(fail_value, success_ptr);
108 return reg_value.
GetAsUInt64(fail_value, success_ptr);
110 *success_ptr =
false;
115 const RegisterInfo *reg_info,
126 RegisterInfo reg_info;
135 uint64_t uint_value) {
136 RegisterInfo reg_info;
139 if (reg_value.
SetUInt(uint_value, reg_info.byte_size))
146 const RegisterInfo *reg_info,
147 uint64_t uint_value) {
148 if (reg_info !=
nullptr) {
150 if (reg_value.
SetUInt(uint_value, reg_info->byte_size))
157 void *dst,
size_t dst_len) {
170 bool success =
false;
171 if (byte_size <= 8) {
172 uint8_t buf[
sizeof(uint64_t)];
175 if (bytes_read == byte_size) {
178 uval64 = data.
GetMaxU64(&offset, byte_size);
184 *success_ptr = success;
193 size_t uval_byte_size) {
199 return (bytes_written == uval_byte_size);
203 const void *src,
size_t src_len) {
248 void *baton,
const Context &context,
251 if (baton ==
nullptr || dst ==
nullptr || dst_len == 0)
259 return process_sp->ReadMemory(addr, dst, dst_len,
error);
265 void *baton,
const Context &context,
268 if (baton ==
nullptr || src ==
nullptr || src_len == 0)
276 return process_sp->WriteMemory(addr, src, src_len,
error);
284 const RegisterInfo *reg_info,
286 if (baton ==
nullptr)
294 void *baton,
const Context &context,
295 const RegisterInfo *reg_info,
297 if (baton ==
nullptr)
310 strm.
Printf(
" Read from Memory (address = 0x%" PRIx64
", length = %" PRIu64
312 addr, (uint64_t)length);
313 context.
Dump(strm, instruction);
315 *((uint64_t *)dst) = 0xdeadbeef;
323 const void *dst,
size_t length) {
325 strm.
Printf(
" Write to Memory (address = 0x%" PRIx64
", length = %" PRIu64
327 addr, (uint64_t)length);
328 context.
Dump(strm, instruction);
335 const RegisterInfo *reg_info,
338 strm.
Printf(
" Read Register (%s)\n", reg_info->name);
342 reg_value.
SetUInt64((uint64_t)reg_kind << 24 | reg_num);
352 const RegisterInfo *reg_info,
355 strm.
Printf(
" Write to Register (name = %s, value = ", reg_info->name);
358 context.
Dump(strm, instruction);
391 strm.
PutCString(
"adjusting (writing value back to) a base register");
423 strm.
PutCString(
"write random bits to a register");
427 strm.
PutCString(
"write random bits to a memory address");
445 strm.
Printf(
" (reg_plus_offset = %s%+" PRId64
")",
446 info.RegisterPlusOffset.reg.name,
447 info.RegisterPlusOffset.signed_offset);
451 strm.
Printf(
" (reg_plus_reg = %s + %s)",
452 info.RegisterPlusIndirectOffset.base_reg.name,
453 info.RegisterPlusIndirectOffset.offset_reg.name);
457 strm.
Printf(
" (base_and_imm_offset = %s%+" PRId64
", data_reg = %s)",
458 info.RegisterToRegisterPlusOffset.base_reg.name,
459 info.RegisterToRegisterPlusOffset.offset,
460 info.RegisterToRegisterPlusOffset.data_reg.name);
464 strm.
Printf(
" (base_and_reg_offset = %s + %s, data_reg = %s)",
465 info.RegisterToRegisterPlusIndirectOffset.base_reg.name,
466 info.RegisterToRegisterPlusIndirectOffset.offset_reg.name,
467 info.RegisterToRegisterPlusIndirectOffset.data_reg.name);
471 strm.
Printf(
" (register to register binary op: %s and %s)",
472 info.RegisterRegisterOperands.operand1.name,
473 info.RegisterRegisterOperands.operand2.name);
477 strm.
Printf(
" (signed_offset = %+" PRId64
")",
info.signed_offset);
485 strm.
Printf(
" (unsigned_immediate = %" PRIu64
" (0x%16.16" PRIx64
"))",
486 info.unsigned_immediate,
info.unsigned_immediate);
490 strm.
Printf(
" (signed_immediate = %+" PRId64
" (0x%16.16" PRIx64
"))",
491 info.signed_immediate,
info.signed_immediate);
495 strm.
Printf(
" (address = 0x%" PRIx64
")",
info.address);
499 strm.
Printf(
" (isa = %u, unsigned_immediate = %u (0x%8.8x))",
500 info.ISAAndImmediate.isa,
info.ISAAndImmediate.unsigned_data32,
501 info.ISAAndImmediate.unsigned_data32);
505 strm.
Printf(
" (isa = %u, signed_immediate = %i (0x%8.8x))",
506 info.ISAAndImmediateSigned.isa,
507 info.ISAAndImmediateSigned.signed_data32,
508 info.ISAAndImmediateSigned.signed_data32);
526 if (target !=
nullptr)
573 const RegisterInfo ®_info) {
size_t PutMaxHex64(uint64_t uvalue, size_t byte_size, lldb::ByteOrder byte_order=lldb::eByteOrderInvalid)
static size_t ReadMemoryDefault(EmulateInstruction *instruction, void *baton, const Context &context, lldb::addr_t addr, void *dst, size_t length)
#define LLDB_INVALID_REGNUM
bool IsValid() const
Check if the object state is valid.
ReadRegisterCallback m_read_reg_callback
void SetReadRegCallback(ReadRegisterCallback read_reg_callback)
union lldb_private::EmulateInstruction::Context::@7 info
static bool WriteRegisterFrame(EmulateInstruction *instruction, void *baton, const Context &context, const RegisterInfo *reg_info, const RegisterValue ®_value)
@ eContextRegisterPlusOffset
@ eRegisterKindDWARF
the register numbers seen DWARF
@ eInfoTypeRegisterPlusIndirectOffset
uint32_t GetAddressByteSize() const
static bool WriteRegisterDefault(EmulateInstruction *instruction, void *baton, const Context &context, const RegisterInfo *reg_info, const RegisterValue ®_value)
@ eRegisterKindGeneric
insn ptr reg, stack ptr reg, etc not specific to any particular target
@ eContextAbsoluteBranchRegister
static size_t WriteMemoryDefault(EmulateInstruction *instruction, void *baton, const Context &context, lldb::addr_t addr, const void *dst, size_t length)
virtual bool CreateFunctionEntryUnwind(UnwindPlan &unwind_plan)
@ eContextTableBranchReadMemory
static bool WriteRegisterCallback(EmulateInstruction *instruction, void *baton, const EmulateInstruction::Context &context, const RegisterInfo *reg_info, const RegisterValue ®_value)
virtual uint32_t ConvertRegisterKindToRegisterNumber(lldb::RegisterKind kind, uint32_t num)
Convert from a given register numbering scheme to the lldb register numbering scheme.
static bool ReadRegisterFrame(EmulateInstruction *instruction, void *baton, const RegisterInfo *reg_info, RegisterValue ®_value)
@ eContextWriteMemoryRandomBits
void SetCallbacks(ReadMemoryCallback read_mem_callback, WriteMemoryCallback write_mem_callback, ReadRegisterCallback read_reg_callback, WriteRegisterCallback write_reg_callback)
static uint32_t GetInternalRegisterNumber(RegisterContext *reg_ctx, const RegisterInfo ®_info)
llvm::StringRef GetString() const
uint64_t GetAsUInt64(uint64_t fail_value=UINT64_MAX, bool *success_ptr=nullptr) const
static bool ReadRegisterDefault(EmulateInstruction *instruction, void *baton, const RegisterInfo *reg_info, RegisterValue ®_value)
@ eInfoTypeRegisterPlusOffset
@ eRegisterKindEHFrame
the register numbers seen in eh_frame
static llvm::raw_ostream & error(Stream &strm)
void SetUInt64(uint64_t uint, Type t=eTypeUInt64)
@ eInfoTypeRegisterToRegisterPlusIndirectOffset
lldb::ByteOrder GetByteOrder() const
uint64_t ReadRegisterUnsigned(const RegisterInfo *reg_info, uint64_t fail_value, bool *success_ptr)
@ eInfoTypeRegisterToRegisterPlusOffset
@ eRegisterKindLLDB
lldb's internal register numbers
@ eInfoTypeISAAndImmediate
@ eRegisterKindProcessPlugin
num used by the process plugin - e.g.
size_t ReadMemory(const Context &context, lldb::addr_t addr, void *dst, size_t dst_len)
virtual bool SetInstruction(const Opcode &insn_opcode, const Address &inst_addr, Target *target)
lldb::addr_t GetFileAddress() const
Get the file address.
WriteRegisterCallback m_write_reg_callback
void SetBaton(void *baton)
@ eInfoTypeISAAndImmediateSigned
bool DumpRegisterValue(const RegisterValue ®_val, Stream *s, const RegisterInfo *reg_info, bool prefix_with_name, bool prefix_with_alt_name, lldb::Format format, uint32_t reg_name_right_align_at=0)
void SetWriteRegCallback(WriteRegisterCallback write_reg_callback)
@ eContextReturnFromException
bool WriteMemoryUnsigned(const Context &context, lldb::addr_t addr, uint64_t uval, size_t uval_byte_size)
RegisterKind
Register numbering types.
@ eContextAdjustStackPointer
@ eInfoTypeImmediateSigned
static size_t WriteMemoryFrame(EmulateInstruction *instruction, void *baton, const Context &context, lldb::addr_t addr, const void *dst, size_t length)
@ eBinary
Get and put data as binary instead of as the default string mode.
ReadMemoryCallback m_read_mem_callback
static size_t WriteMemoryCallback(EmulateInstruction *instruction, void *baton, const EmulateInstruction::Context &context, lldb::addr_t addr, const void *dst, size_t length)
bool SetUInt(uint64_t uint, uint32_t byte_size)
void SetWriteMemCallback(WriteMemoryCallback write_mem_callback)
bool WriteRegister(const Context &context, const RegisterInfo *ref_info, const RegisterValue ®_value)
size_t EOL()
Output and End of Line character to the stream.
lldb::addr_t GetLoadAddress(Target *target) const
Get the load address.
@ eContextSetFramePointer
bool WriteMemory(const Context &context, lldb::addr_t addr, const void *src, size_t src_len)
@ eContextWriteRegisterRandomBits
#define LLDB_INVALID_ADDRESS
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
InstructionType
Instruction types.
@ eInfoTypeRegisterRegisterOperands
static bool GetBestRegisterKindAndNumber(const RegisterInfo *reg_info, lldb::RegisterKind ®_kind, uint32_t ®_num)
lldb::ProcessSP CalculateProcess() override
static size_t ReadMemoryFrame(EmulateInstruction *instruction, void *baton, const Context &context, lldb::addr_t addr, void *dst, size_t length)
A class that represents a running process on the host machine.
lldb::RegisterContextSP GetRegisterContext()
Get the RegisterContext for this frame, if possible.
bool WriteRegisterUnsigned(const Context &context, const RegisterInfo *reg_info, uint64_t reg_value)
@ eContextAdjustBaseRegister
WriteMemoryCallback m_write_mem_callback
static bool ReadRegisterCallback(EmulateInstruction *instruction, void *baton, const RegisterInfo *reg_info, RegisterValue ®_value)
uint64_t ReadMemoryUnsigned(const Context &context, lldb::addr_t addr, size_t byte_size, uint64_t fail_value, bool *success_ptr)
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
void Dump(Stream &s, EmulateInstruction *instruction) const
@ eContextPopRegisterOffStack
bool ReadRegister(const RegisterInfo *reg_info, RegisterValue ®_value)
void SetReadMemCallback(ReadMemoryCallback read_mem_callback)
@ eContextPushRegisterOnStack
@ eContextRelativeBranchImmediate
virtual bool GetRegisterInfo(lldb::RegisterKind reg_kind, uint32_t reg_num, RegisterInfo ®_info)=0
static size_t ReadMemoryCallback(EmulateInstruction *instruction, void *baton, const EmulateInstruction::Context &context, lldb::addr_t addr, void *dst, size_t length)