1 //===-- UnwindAssemblyInstEmulation.h ---------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef liblldb_UnwindAssemblyInstEmulation_h_
11 #define liblldb_UnwindAssemblyInstEmulation_h_
13 #include "lldb/Core/EmulateInstruction.h"
14 #include "lldb/Symbol/UnwindPlan.h"
15 #include "lldb/Target/UnwindAssembly.h"
16 #include "lldb/Utility/RegisterValue.h"
17 #include "lldb/lldb-private.h"
19 class UnwindAssemblyInstEmulation : public lldb_private::UnwindAssembly {
21 ~UnwindAssemblyInstEmulation() override = default;
23 bool GetNonCallSiteUnwindPlanFromAssembly(
24 lldb_private::AddressRange &func, lldb_private::Thread &thread,
25 lldb_private::UnwindPlan &unwind_plan) override;
28 GetNonCallSiteUnwindPlanFromAssembly(lldb_private::AddressRange &func,
29 uint8_t *opcode_data, size_t opcode_size,
30 lldb_private::UnwindPlan &unwind_plan);
33 AugmentUnwindPlanFromCallSite(lldb_private::AddressRange &func,
34 lldb_private::Thread &thread,
35 lldb_private::UnwindPlan &unwind_plan) override;
37 bool GetFastUnwindPlan(lldb_private::AddressRange &func,
38 lldb_private::Thread &thread,
39 lldb_private::UnwindPlan &unwind_plan) override;
41 // thread may be NULL in which case we only use the Target (e.g. if this is
42 // called pre-process-launch).
44 FirstNonPrologueInsn(lldb_private::AddressRange &func,
45 const lldb_private::ExecutionContext &exe_ctx,
46 lldb_private::Address &first_non_prologue_insn) override;
48 static lldb_private::UnwindAssembly *
49 CreateInstance(const lldb_private::ArchSpec &arch);
51 //------------------------------------------------------------------
52 // PluginInterface protocol
53 //------------------------------------------------------------------
54 static void Initialize();
56 static void Terminate();
58 static lldb_private::ConstString GetPluginNameStatic();
60 static const char *GetPluginDescriptionStatic();
62 lldb_private::ConstString GetPluginName() override;
64 uint32_t GetPluginVersion() override;
67 // Call CreateInstance to get an instance of this class
68 UnwindAssemblyInstEmulation(const lldb_private::ArchSpec &arch,
69 lldb_private::EmulateInstruction *inst_emulator)
70 : UnwindAssembly(arch), m_inst_emulator_ap(inst_emulator),
71 m_range_ptr(NULL), m_unwind_plan_ptr(NULL), m_curr_row(),
72 m_cfa_reg_info(), m_fp_is_cfa(false), m_register_values(),
73 m_pushed_regs(), m_curr_row_modified(false),
74 m_forward_branch_offset(0) {
75 if (m_inst_emulator_ap.get()) {
76 m_inst_emulator_ap->SetBaton(this);
77 m_inst_emulator_ap->SetCallbacks(ReadMemory, WriteMemory, ReadRegister,
83 ReadMemory(lldb_private::EmulateInstruction *instruction, void *baton,
84 const lldb_private::EmulateInstruction::Context &context,
85 lldb::addr_t addr, void *dst, size_t length);
88 WriteMemory(lldb_private::EmulateInstruction *instruction, void *baton,
89 const lldb_private::EmulateInstruction::Context &context,
90 lldb::addr_t addr, const void *dst, size_t length);
92 static bool ReadRegister(lldb_private::EmulateInstruction *instruction,
94 const lldb_private::RegisterInfo *reg_info,
95 lldb_private::RegisterValue ®_value);
98 WriteRegister(lldb_private::EmulateInstruction *instruction, void *baton,
99 const lldb_private::EmulateInstruction::Context &context,
100 const lldb_private::RegisterInfo *reg_info,
101 const lldb_private::RegisterValue ®_value);
104 // ReadMemory (lldb_private::EmulateInstruction *instruction,
105 // const lldb_private::EmulateInstruction::Context &context,
106 // lldb::addr_t addr,
110 size_t WriteMemory(lldb_private::EmulateInstruction *instruction,
111 const lldb_private::EmulateInstruction::Context &context,
112 lldb::addr_t addr, const void *dst, size_t length);
114 bool ReadRegister(lldb_private::EmulateInstruction *instruction,
115 const lldb_private::RegisterInfo *reg_info,
116 lldb_private::RegisterValue ®_value);
118 bool WriteRegister(lldb_private::EmulateInstruction *instruction,
119 const lldb_private::EmulateInstruction::Context &context,
120 const lldb_private::RegisterInfo *reg_info,
121 const lldb_private::RegisterValue ®_value);
124 MakeRegisterKindValuePair(const lldb_private::RegisterInfo ®_info);
126 void SetRegisterValue(const lldb_private::RegisterInfo ®_info,
127 const lldb_private::RegisterValue ®_value);
129 bool GetRegisterValue(const lldb_private::RegisterInfo ®_info,
130 lldb_private::RegisterValue ®_value);
132 std::unique_ptr<lldb_private::EmulateInstruction> m_inst_emulator_ap;
133 lldb_private::AddressRange *m_range_ptr;
134 lldb_private::UnwindPlan *m_unwind_plan_ptr;
135 lldb_private::UnwindPlan::RowSP m_curr_row;
136 typedef std::map<uint64_t, uint64_t> PushedRegisterToAddrMap;
137 uint64_t m_initial_sp;
138 lldb_private::RegisterInfo m_cfa_reg_info;
140 typedef std::map<uint64_t, lldb_private::RegisterValue> RegisterValueMap;
141 RegisterValueMap m_register_values;
142 PushedRegisterToAddrMap m_pushed_regs;
144 // While processing the instruction stream, we need to communicate some state
146 // information up to the higher level loop that makes decisions about how to
148 // the unwind instructions for the UnwindPlan we're constructing.
150 // The instruction we're processing updated the UnwindPlan::Row contents
151 bool m_curr_row_modified;
152 // The instruction is branching forward with the given offset. 0 value means
154 uint32_t m_forward_branch_offset;
157 #endif // liblldb_UnwindAssemblyInstEmulation_h_