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_
15 // Other libraries and framework includes
17 #include "lldb/Core/EmulateInstruction.h"
18 #include "lldb/Core/RegisterValue.h"
19 #include "lldb/Symbol/UnwindPlan.h"
20 #include "lldb/Target/UnwindAssembly.h"
21 #include "lldb/lldb-private.h"
23 class UnwindAssemblyInstEmulation : public lldb_private::UnwindAssembly {
25 ~UnwindAssemblyInstEmulation() override = default;
27 bool GetNonCallSiteUnwindPlanFromAssembly(
28 lldb_private::AddressRange &func, lldb_private::Thread &thread,
29 lldb_private::UnwindPlan &unwind_plan) override;
32 GetNonCallSiteUnwindPlanFromAssembly(lldb_private::AddressRange &func,
33 uint8_t *opcode_data, size_t opcode_size,
34 lldb_private::UnwindPlan &unwind_plan);
37 AugmentUnwindPlanFromCallSite(lldb_private::AddressRange &func,
38 lldb_private::Thread &thread,
39 lldb_private::UnwindPlan &unwind_plan) override;
41 bool GetFastUnwindPlan(lldb_private::AddressRange &func,
42 lldb_private::Thread &thread,
43 lldb_private::UnwindPlan &unwind_plan) override;
45 // thread may be NULL in which case we only use the Target (e.g. if this is
46 // called pre-process-launch).
48 FirstNonPrologueInsn(lldb_private::AddressRange &func,
49 const lldb_private::ExecutionContext &exe_ctx,
50 lldb_private::Address &first_non_prologue_insn) override;
52 static lldb_private::UnwindAssembly *
53 CreateInstance(const lldb_private::ArchSpec &arch);
55 //------------------------------------------------------------------
56 // PluginInterface protocol
57 //------------------------------------------------------------------
58 static void Initialize();
60 static void Terminate();
62 static lldb_private::ConstString GetPluginNameStatic();
64 static const char *GetPluginDescriptionStatic();
66 lldb_private::ConstString GetPluginName() override;
68 uint32_t GetPluginVersion() override;
71 // Call CreateInstance to get an instance of this class
72 UnwindAssemblyInstEmulation(const lldb_private::ArchSpec &arch,
73 lldb_private::EmulateInstruction *inst_emulator)
74 : UnwindAssembly(arch), m_inst_emulator_ap(inst_emulator),
75 m_range_ptr(NULL), m_unwind_plan_ptr(NULL), m_curr_row(),
76 m_cfa_reg_info(), m_fp_is_cfa(false), m_register_values(),
77 m_pushed_regs(), m_curr_row_modified(false),
78 m_forward_branch_offset(0) {
79 if (m_inst_emulator_ap.get()) {
80 m_inst_emulator_ap->SetBaton(this);
81 m_inst_emulator_ap->SetCallbacks(ReadMemory, WriteMemory, ReadRegister,
87 ReadMemory(lldb_private::EmulateInstruction *instruction, void *baton,
88 const lldb_private::EmulateInstruction::Context &context,
89 lldb::addr_t addr, void *dst, size_t length);
92 WriteMemory(lldb_private::EmulateInstruction *instruction, void *baton,
93 const lldb_private::EmulateInstruction::Context &context,
94 lldb::addr_t addr, const void *dst, size_t length);
96 static bool ReadRegister(lldb_private::EmulateInstruction *instruction,
98 const lldb_private::RegisterInfo *reg_info,
99 lldb_private::RegisterValue ®_value);
102 WriteRegister(lldb_private::EmulateInstruction *instruction, void *baton,
103 const lldb_private::EmulateInstruction::Context &context,
104 const lldb_private::RegisterInfo *reg_info,
105 const lldb_private::RegisterValue ®_value);
108 // ReadMemory (lldb_private::EmulateInstruction *instruction,
109 // const lldb_private::EmulateInstruction::Context &context,
110 // lldb::addr_t addr,
114 size_t WriteMemory(lldb_private::EmulateInstruction *instruction,
115 const lldb_private::EmulateInstruction::Context &context,
116 lldb::addr_t addr, const void *dst, size_t length);
118 bool ReadRegister(lldb_private::EmulateInstruction *instruction,
119 const lldb_private::RegisterInfo *reg_info,
120 lldb_private::RegisterValue ®_value);
122 bool WriteRegister(lldb_private::EmulateInstruction *instruction,
123 const lldb_private::EmulateInstruction::Context &context,
124 const lldb_private::RegisterInfo *reg_info,
125 const lldb_private::RegisterValue ®_value);
128 MakeRegisterKindValuePair(const lldb_private::RegisterInfo ®_info);
130 void SetRegisterValue(const lldb_private::RegisterInfo ®_info,
131 const lldb_private::RegisterValue ®_value);
133 bool GetRegisterValue(const lldb_private::RegisterInfo ®_info,
134 lldb_private::RegisterValue ®_value);
136 std::unique_ptr<lldb_private::EmulateInstruction> m_inst_emulator_ap;
137 lldb_private::AddressRange *m_range_ptr;
138 lldb_private::UnwindPlan *m_unwind_plan_ptr;
139 lldb_private::UnwindPlan::RowSP m_curr_row;
140 typedef std::map<uint64_t, uint64_t> PushedRegisterToAddrMap;
141 uint64_t m_initial_sp;
142 lldb_private::RegisterInfo m_cfa_reg_info;
144 typedef std::map<uint64_t, lldb_private::RegisterValue> RegisterValueMap;
145 RegisterValueMap m_register_values;
146 PushedRegisterToAddrMap m_pushed_regs;
148 // While processing the instruction stream, we need to communicate some state
150 // information up to the higher level loop that makes decisions about how to
152 // the unwind instructions for the UnwindPlan we're constructing.
154 // The instruction we're processing updated the UnwindPlan::Row contents
155 bool m_curr_row_modified;
156 // The instruction is branching forward with the given offset. 0 value means
158 uint32_t m_forward_branch_offset;
161 #endif // liblldb_UnwindAssemblyInstEmulation_h_