]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/source/Plugins/UnwindAssembly/InstEmulation/UnwindAssemblyInstEmulation.h
Merge llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / source / Plugins / UnwindAssembly / InstEmulation / UnwindAssemblyInstEmulation.h
1 //===-- UnwindAssemblyInstEmulation.h ---------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef liblldb_UnwindAssemblyInstEmulation_h_
11 #define liblldb_UnwindAssemblyInstEmulation_h_
12
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"
18
19 class UnwindAssemblyInstEmulation : public lldb_private::UnwindAssembly {
20 public:
21   ~UnwindAssemblyInstEmulation() override = default;
22
23   bool GetNonCallSiteUnwindPlanFromAssembly(
24       lldb_private::AddressRange &func, lldb_private::Thread &thread,
25       lldb_private::UnwindPlan &unwind_plan) override;
26
27   bool
28   GetNonCallSiteUnwindPlanFromAssembly(lldb_private::AddressRange &func,
29                                        uint8_t *opcode_data, size_t opcode_size,
30                                        lldb_private::UnwindPlan &unwind_plan);
31
32   bool
33   AugmentUnwindPlanFromCallSite(lldb_private::AddressRange &func,
34                                 lldb_private::Thread &thread,
35                                 lldb_private::UnwindPlan &unwind_plan) override;
36
37   bool GetFastUnwindPlan(lldb_private::AddressRange &func,
38                          lldb_private::Thread &thread,
39                          lldb_private::UnwindPlan &unwind_plan) override;
40
41   // thread may be NULL in which case we only use the Target (e.g. if this is
42   // called pre-process-launch).
43   bool
44   FirstNonPrologueInsn(lldb_private::AddressRange &func,
45                        const lldb_private::ExecutionContext &exe_ctx,
46                        lldb_private::Address &first_non_prologue_insn) override;
47
48   static lldb_private::UnwindAssembly *
49   CreateInstance(const lldb_private::ArchSpec &arch);
50
51   //------------------------------------------------------------------
52   // PluginInterface protocol
53   //------------------------------------------------------------------
54   static void Initialize();
55
56   static void Terminate();
57
58   static lldb_private::ConstString GetPluginNameStatic();
59
60   static const char *GetPluginDescriptionStatic();
61
62   lldb_private::ConstString GetPluginName() override;
63
64   uint32_t GetPluginVersion() override;
65
66 private:
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,
78                                        WriteRegister);
79     }
80   }
81
82   static size_t
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);
86
87   static size_t
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);
91
92   static bool ReadRegister(lldb_private::EmulateInstruction *instruction,
93                            void *baton,
94                            const lldb_private::RegisterInfo *reg_info,
95                            lldb_private::RegisterValue &reg_value);
96
97   static bool
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 &reg_value);
102
103   //    size_t
104   //    ReadMemory (lldb_private::EmulateInstruction *instruction,
105   //                const lldb_private::EmulateInstruction::Context &context,
106   //                lldb::addr_t addr,
107   //                void *dst,
108   //                size_t length);
109
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);
113
114   bool ReadRegister(lldb_private::EmulateInstruction *instruction,
115                     const lldb_private::RegisterInfo *reg_info,
116                     lldb_private::RegisterValue &reg_value);
117
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 &reg_value);
122
123   static uint64_t
124   MakeRegisterKindValuePair(const lldb_private::RegisterInfo &reg_info);
125
126   void SetRegisterValue(const lldb_private::RegisterInfo &reg_info,
127                         const lldb_private::RegisterValue &reg_value);
128
129   bool GetRegisterValue(const lldb_private::RegisterInfo &reg_info,
130                         lldb_private::RegisterValue &reg_value);
131
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;
139   bool m_fp_is_cfa;
140   typedef std::map<uint64_t, lldb_private::RegisterValue> RegisterValueMap;
141   RegisterValueMap m_register_values;
142   PushedRegisterToAddrMap m_pushed_regs;
143
144   // While processing the instruction stream, we need to communicate some state
145   // change
146   // information up to the higher level loop that makes decisions about how to
147   // push
148   // the unwind instructions for the UnwindPlan we're constructing.
149
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
153   // no branching.
154   uint32_t m_forward_branch_offset;
155 };
156
157 #endif // liblldb_UnwindAssemblyInstEmulation_h_