Path: blob/main/contrib/llvm-project/lldb/source/Plugins/UnwindAssembly/InstEmulation/UnwindAssemblyInstEmulation.h
39645 views
//===-- UnwindAssemblyInstEmulation.h ---------------------------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#ifndef LLDB_SOURCE_PLUGINS_UNWINDASSEMBLY_INSTEMULATION_UNWINDASSEMBLYINSTEMULATION_H9#define LLDB_SOURCE_PLUGINS_UNWINDASSEMBLY_INSTEMULATION_UNWINDASSEMBLYINSTEMULATION_H1011#include "lldb/Core/EmulateInstruction.h"12#include "lldb/Symbol/UnwindPlan.h"13#include "lldb/Target/UnwindAssembly.h"14#include "lldb/Utility/RegisterValue.h"15#include "lldb/lldb-private.h"1617class UnwindAssemblyInstEmulation : public lldb_private::UnwindAssembly {18public:19~UnwindAssemblyInstEmulation() override = default;2021bool GetNonCallSiteUnwindPlanFromAssembly(22lldb_private::AddressRange &func, lldb_private::Thread &thread,23lldb_private::UnwindPlan &unwind_plan) override;2425bool26GetNonCallSiteUnwindPlanFromAssembly(lldb_private::AddressRange &func,27uint8_t *opcode_data, size_t opcode_size,28lldb_private::UnwindPlan &unwind_plan);2930bool31AugmentUnwindPlanFromCallSite(lldb_private::AddressRange &func,32lldb_private::Thread &thread,33lldb_private::UnwindPlan &unwind_plan) override;3435bool GetFastUnwindPlan(lldb_private::AddressRange &func,36lldb_private::Thread &thread,37lldb_private::UnwindPlan &unwind_plan) override;3839// thread may be NULL in which case we only use the Target (e.g. if this is40// called pre-process-launch).41bool42FirstNonPrologueInsn(lldb_private::AddressRange &func,43const lldb_private::ExecutionContext &exe_ctx,44lldb_private::Address &first_non_prologue_insn) override;4546static lldb_private::UnwindAssembly *47CreateInstance(const lldb_private::ArchSpec &arch);4849// PluginInterface protocol50static void Initialize();5152static void Terminate();5354static llvm::StringRef GetPluginNameStatic() { return "inst-emulation"; }5556static llvm::StringRef GetPluginDescriptionStatic();5758llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }5960private:61// Call CreateInstance to get an instance of this class62UnwindAssemblyInstEmulation(const lldb_private::ArchSpec &arch,63lldb_private::EmulateInstruction *inst_emulator)64: UnwindAssembly(arch), m_inst_emulator_up(inst_emulator),65m_range_ptr(nullptr), m_unwind_plan_ptr(nullptr), m_curr_row(),66m_initial_sp(0), m_cfa_reg_info(), m_fp_is_cfa(false),67m_register_values(), m_pushed_regs(), m_curr_row_modified(false),68m_forward_branch_offset(0) {69if (m_inst_emulator_up) {70m_inst_emulator_up->SetBaton(this);71m_inst_emulator_up->SetCallbacks(ReadMemory, WriteMemory, ReadRegister,72WriteRegister);73}74}7576static size_t77ReadMemory(lldb_private::EmulateInstruction *instruction, void *baton,78const lldb_private::EmulateInstruction::Context &context,79lldb::addr_t addr, void *dst, size_t length);8081static size_t82WriteMemory(lldb_private::EmulateInstruction *instruction, void *baton,83const lldb_private::EmulateInstruction::Context &context,84lldb::addr_t addr, const void *dst, size_t length);8586static bool ReadRegister(lldb_private::EmulateInstruction *instruction,87void *baton,88const lldb_private::RegisterInfo *reg_info,89lldb_private::RegisterValue ®_value);9091static bool92WriteRegister(lldb_private::EmulateInstruction *instruction, void *baton,93const lldb_private::EmulateInstruction::Context &context,94const lldb_private::RegisterInfo *reg_info,95const lldb_private::RegisterValue ®_value);9697// size_t98// ReadMemory (lldb_private::EmulateInstruction *instruction,99// const lldb_private::EmulateInstruction::Context &context,100// lldb::addr_t addr,101// void *dst,102// size_t length);103104size_t WriteMemory(lldb_private::EmulateInstruction *instruction,105const lldb_private::EmulateInstruction::Context &context,106lldb::addr_t addr, const void *dst, size_t length);107108bool ReadRegister(lldb_private::EmulateInstruction *instruction,109const lldb_private::RegisterInfo *reg_info,110lldb_private::RegisterValue ®_value);111112bool WriteRegister(lldb_private::EmulateInstruction *instruction,113const lldb_private::EmulateInstruction::Context &context,114const lldb_private::RegisterInfo *reg_info,115const lldb_private::RegisterValue ®_value);116117static uint64_t118MakeRegisterKindValuePair(const lldb_private::RegisterInfo ®_info);119120void SetRegisterValue(const lldb_private::RegisterInfo ®_info,121const lldb_private::RegisterValue ®_value);122123bool GetRegisterValue(const lldb_private::RegisterInfo ®_info,124lldb_private::RegisterValue ®_value);125126std::unique_ptr<lldb_private::EmulateInstruction> m_inst_emulator_up;127lldb_private::AddressRange *m_range_ptr;128lldb_private::UnwindPlan *m_unwind_plan_ptr;129lldb_private::UnwindPlan::RowSP m_curr_row;130typedef std::map<uint64_t, uint64_t> PushedRegisterToAddrMap;131uint64_t m_initial_sp;132lldb_private::RegisterInfo m_cfa_reg_info;133bool m_fp_is_cfa;134typedef std::map<uint64_t, lldb_private::RegisterValue> RegisterValueMap;135RegisterValueMap m_register_values;136PushedRegisterToAddrMap m_pushed_regs;137138// While processing the instruction stream, we need to communicate some state139// change140// information up to the higher level loop that makes decisions about how to141// push142// the unwind instructions for the UnwindPlan we're constructing.143144// The instruction we're processing updated the UnwindPlan::Row contents145bool m_curr_row_modified;146// The instruction is branching forward with the given offset. 0 value means147// no branching.148uint32_t m_forward_branch_offset;149};150151#endif // LLDB_SOURCE_PLUGINS_UNWINDASSEMBLY_INSTEMULATION_UNWINDASSEMBLYINSTEMULATION_H152153154