15#include <unordered_map>
27 std::unordered_map<uint32_t, RegisterValue> m_register_values;
31 : m_process(process), m_reg_context(reg_context) {}
39 EmulatorBaton *emulator_baton =
static_cast<EmulatorBaton *
>(baton);
42 emulator_baton->m_process.ReadMemory(addr, dst, length, bytes_read);
47 const RegisterInfo *reg_info,
49 EmulatorBaton *emulator_baton =
static_cast<EmulatorBaton *
>(baton);
51 auto it = emulator_baton->m_register_values.find(
53 if (it != emulator_baton->m_register_values.end()) {
54 reg_value = it->second;
61 const RegisterInfo *full_reg_info =
62 emulator_baton->m_reg_context.GetRegisterInfo(
66 emulator_baton->m_reg_context.ReadRegister(full_reg_info, reg_value);
75 const RegisterInfo *reg_info,
77 EmulatorBaton *emulator_baton =
static_cast<EmulatorBaton *
>(baton);
104 std::unique_ptr<EmulateInstruction> emulator_up(
108 if (emulator_up ==
nullptr)
109 return Status(
"Instruction emulator not found!");
111 EmulatorBaton baton(process, register_context);
112 emulator_up->SetBaton(&baton);
118 if (!emulator_up->ReadInstruction())
119 return Status(
"Read instruction failed!");
121 bool emulation_result =
122 emulator_up->EvaluateInstruction(eEmulateInstructionOptionAutoAdvancePC);
131 auto flags_it = reg_info_flags ==
nullptr
132 ? baton.m_register_values.end()
133 : baton.m_register_values.find(
138 if (emulation_result) {
139 assert(pc_it != baton.m_register_values.end() &&
140 "Emulation was successfull but PC wasn't updated");
141 next_pc = pc_it->second.GetAsUInt64();
143 if (flags_it != baton.m_register_values.end())
144 next_flags = flags_it->second.GetAsUInt64();
146 next_flags =
ReadFlags(register_context);
147 }
else if (pc_it == baton.m_register_values.end()) {
152 next_pc = register_context.
GetPC() + emulator_up->GetOpcode().GetByteSize();
153 next_flags =
ReadFlags(register_context);
158 return Status(
"Instruction emulation failed unexpectedly.");
163 if (next_flags & 0x20) {
177 if (
error.GetError() == EIO ||
error.GetError() == EFAULT) {
179 }
else if (
error.Fail())
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)
static lldb::addr_t ReadFlags(NativeRegisterContext ®siter_context)
An architecture specification class.
llvm::Triple & GetTriple()
Architecture triple accessor.
bool IsMIPS() const
if MIPS architecture return true.
llvm::Triple::ArchType GetMachine() const
Returns a machine family for the current architecture.
"lldb/Core/EmulateInstruction.h" A class that allows emulation of CPU opcodes.
static EmulateInstruction * FindPlugin(const ArchSpec &arch, InstructionType supported_inst_type, const char *plugin_name)
virtual Status SetBreakpoint(lldb::addr_t addr, uint32_t size, bool hardware)=0
virtual const ArchSpec & GetArchitecture() const =0
Status SetupSoftwareSingleStepping(NativeThreadProtocol &thread)
std::map< lldb::tid_t, lldb::addr_t > m_threads_stepping_with_breakpoint
lldb::addr_t ReadRegisterAsUnsigned(uint32_t reg, lldb::addr_t fail_value)
const RegisterInfo * GetRegisterInfo(uint32_t reg_kind, uint32_t reg_num)
lldb::addr_t GetPC(lldb::addr_t fail_value=LLDB_INVALID_ADDRESS)
NativeProcessProtocol & GetProcess()
virtual NativeRegisterContext & GetRegisterContext()=0
lldb::tid_t GetID() const
#define LLDB_REGNUM_GENERIC_FLAGS
#define LLDB_INVALID_ADDRESS
#define LLDB_REGNUM_GENERIC_PC
A class that represents a running process on the host machine.
@ eInstructionTypePCModifying
@ eRegisterKindGeneric
insn ptr reg, stack ptr reg, etc not specific to any particular target
@ eRegisterKindDWARF
the register numbers seen DWARF