Greg Clayton | ffc922e3 | 2011-04-25 21:05:07 +0000 | [diff] [blame] | 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/lldb-private.h" |
Greg Clayton | 2ed751b | 2011-04-26 04:39:08 +0000 | [diff] [blame] | 14 | #include "lldb/Core/EmulateInstruction.h" |
Greg Clayton | 7349bd9 | 2011-05-09 20:18:18 +0000 | [diff] [blame] | 15 | #include "lldb/Core/RegisterValue.h" |
Greg Clayton | e5b3498 | 2011-04-29 22:50:31 +0000 | [diff] [blame] | 16 | #include "lldb/Symbol/UnwindPlan.h" |
Greg Clayton | 7be2542 | 2011-04-25 21:14:26 +0000 | [diff] [blame] | 17 | #include "lldb/Target/UnwindAssembly.h" |
Greg Clayton | ffc922e3 | 2011-04-25 21:05:07 +0000 | [diff] [blame] | 18 | |
Greg Clayton | 7be2542 | 2011-04-25 21:14:26 +0000 | [diff] [blame] | 19 | class UnwindAssemblyInstEmulation : public lldb_private::UnwindAssembly |
Greg Clayton | ffc922e3 | 2011-04-25 21:05:07 +0000 | [diff] [blame] | 20 | { |
| 21 | public: |
| 22 | |
| 23 | virtual |
| 24 | ~UnwindAssemblyInstEmulation () |
| 25 | { |
| 26 | } |
| 27 | |
| 28 | virtual bool |
| 29 | GetNonCallSiteUnwindPlanFromAssembly (lldb_private::AddressRange& func, |
| 30 | lldb_private::Thread& thread, |
| 31 | lldb_private::UnwindPlan& unwind_plan); |
| 32 | |
| 33 | virtual bool |
Todd Fiala | 0562524 | 2014-08-25 20:29:09 +0000 | [diff] [blame] | 34 | AugmentUnwindPlanFromCallSite (lldb_private::AddressRange& func, |
| 35 | lldb_private::Thread& thread, |
| 36 | lldb_private::UnwindPlan& unwind_plan); |
| 37 | |
| 38 | virtual bool |
Greg Clayton | ffc922e3 | 2011-04-25 21:05:07 +0000 | [diff] [blame] | 39 | GetFastUnwindPlan (lldb_private::AddressRange& func, |
| 40 | lldb_private::Thread& thread, |
| 41 | lldb_private::UnwindPlan &unwind_plan); |
| 42 | |
| 43 | // thread may be NULL in which case we only use the Target (e.g. if this is called pre-process-launch). |
| 44 | virtual bool |
| 45 | FirstNonPrologueInsn (lldb_private::AddressRange& func, |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 46 | const lldb_private::ExecutionContext &exe_ctx, |
Greg Clayton | ffc922e3 | 2011-04-25 21:05:07 +0000 | [diff] [blame] | 47 | lldb_private::Address& first_non_prologue_insn); |
| 48 | |
Greg Clayton | 7be2542 | 2011-04-25 21:14:26 +0000 | [diff] [blame] | 49 | static lldb_private::UnwindAssembly * |
Greg Clayton | ffc922e3 | 2011-04-25 21:05:07 +0000 | [diff] [blame] | 50 | CreateInstance (const lldb_private::ArchSpec &arch); |
| 51 | |
Greg Clayton | ffc922e3 | 2011-04-25 21:05:07 +0000 | [diff] [blame] | 52 | //------------------------------------------------------------------ |
| 53 | // PluginInterface protocol |
| 54 | //------------------------------------------------------------------ |
| 55 | static void |
| 56 | Initialize(); |
| 57 | |
| 58 | static void |
| 59 | Terminate(); |
| 60 | |
Greg Clayton | 57abc5d | 2013-05-10 21:47:16 +0000 | [diff] [blame] | 61 | static lldb_private::ConstString |
Greg Clayton | ffc922e3 | 2011-04-25 21:05:07 +0000 | [diff] [blame] | 62 | GetPluginNameStatic(); |
| 63 | |
| 64 | static const char * |
| 65 | GetPluginDescriptionStatic(); |
| 66 | |
Greg Clayton | 57abc5d | 2013-05-10 21:47:16 +0000 | [diff] [blame] | 67 | virtual lldb_private::ConstString |
Greg Clayton | ffc922e3 | 2011-04-25 21:05:07 +0000 | [diff] [blame] | 68 | GetPluginName(); |
| 69 | |
Greg Clayton | ffc922e3 | 2011-04-25 21:05:07 +0000 | [diff] [blame] | 70 | virtual uint32_t |
| 71 | GetPluginVersion(); |
| 72 | |
| 73 | private: |
Greg Clayton | 2ed751b | 2011-04-26 04:39:08 +0000 | [diff] [blame] | 74 | |
| 75 | static size_t |
| 76 | ReadMemory (lldb_private::EmulateInstruction *instruction, |
| 77 | void *baton, |
| 78 | const lldb_private::EmulateInstruction::Context &context, |
| 79 | lldb::addr_t addr, |
| 80 | void *dst, |
| 81 | size_t length); |
| 82 | |
| 83 | static size_t |
| 84 | WriteMemory (lldb_private::EmulateInstruction *instruction, |
| 85 | void *baton, |
| 86 | const lldb_private::EmulateInstruction::Context &context, |
| 87 | lldb::addr_t addr, |
| 88 | const void *dst, |
| 89 | size_t length); |
| 90 | |
| 91 | static bool |
| 92 | ReadRegister (lldb_private::EmulateInstruction *instruction, |
| 93 | void *baton, |
Greg Clayton | 7349bd9 | 2011-05-09 20:18:18 +0000 | [diff] [blame] | 94 | const lldb_private::RegisterInfo *reg_info, |
| 95 | lldb_private::RegisterValue ®_value); |
Greg Clayton | 2ed751b | 2011-04-26 04:39:08 +0000 | [diff] [blame] | 96 | |
| 97 | static bool |
| 98 | WriteRegister (lldb_private::EmulateInstruction *instruction, |
| 99 | void *baton, |
| 100 | const lldb_private::EmulateInstruction::Context &context, |
Greg Clayton | 7349bd9 | 2011-05-09 20:18:18 +0000 | [diff] [blame] | 101 | const lldb_private::RegisterInfo *reg_info, |
| 102 | const lldb_private::RegisterValue ®_value); |
Greg Clayton | 2ed751b | 2011-04-26 04:39:08 +0000 | [diff] [blame] | 103 | |
Greg Clayton | ffc922e3 | 2011-04-25 21:05:07 +0000 | [diff] [blame] | 104 | |
Greg Clayton | 31f1d2f | 2011-05-11 18:39:18 +0000 | [diff] [blame] | 105 | // size_t |
| 106 | // ReadMemory (lldb_private::EmulateInstruction *instruction, |
| 107 | // const lldb_private::EmulateInstruction::Context &context, |
| 108 | // lldb::addr_t addr, |
| 109 | // void *dst, |
| 110 | // size_t length); |
| 111 | |
| 112 | size_t |
| 113 | WriteMemory (lldb_private::EmulateInstruction *instruction, |
| 114 | const lldb_private::EmulateInstruction::Context &context, |
| 115 | lldb::addr_t addr, |
| 116 | const void *dst, |
| 117 | size_t length); |
| 118 | |
| 119 | bool |
| 120 | ReadRegister (lldb_private::EmulateInstruction *instruction, |
| 121 | const lldb_private::RegisterInfo *reg_info, |
| 122 | lldb_private::RegisterValue ®_value); |
| 123 | |
| 124 | bool |
| 125 | WriteRegister (lldb_private::EmulateInstruction *instruction, |
| 126 | const lldb_private::EmulateInstruction::Context &context, |
| 127 | const lldb_private::RegisterInfo *reg_info, |
| 128 | const lldb_private::RegisterValue ®_value); |
| 129 | |
Greg Clayton | ffc922e3 | 2011-04-25 21:05:07 +0000 | [diff] [blame] | 130 | // Call CreateInstance to get an instance of this class |
Greg Clayton | 2ed751b | 2011-04-26 04:39:08 +0000 | [diff] [blame] | 131 | UnwindAssemblyInstEmulation (const lldb_private::ArchSpec &arch, |
| 132 | lldb_private::EmulateInstruction *inst_emulator) : |
| 133 | UnwindAssembly (arch), |
| 134 | m_inst_emulator_ap (inst_emulator), |
| 135 | m_range_ptr (NULL), |
| 136 | m_thread_ptr (NULL), |
Greg Clayton | 31f1d2f | 2011-05-11 18:39:18 +0000 | [diff] [blame] | 137 | m_unwind_plan_ptr (NULL), |
| 138 | m_curr_row (), |
| 139 | m_cfa_reg_info (), |
| 140 | m_fp_is_cfa (false), |
| 141 | m_register_values (), |
Jason Molenda | 7cd5e83 | 2012-10-23 03:08:31 +0000 | [diff] [blame] | 142 | m_pushed_regs(), |
| 143 | m_curr_row_modified (false), |
Tamas Berghammer | 44ff9cce | 2015-06-24 11:27:32 +0000 | [diff] [blame^] | 144 | m_forward_branch_offset (0) |
Greg Clayton | ffc922e3 | 2011-04-25 21:05:07 +0000 | [diff] [blame] | 145 | { |
Greg Clayton | 2ed751b | 2011-04-26 04:39:08 +0000 | [diff] [blame] | 146 | if (m_inst_emulator_ap.get()) |
| 147 | { |
| 148 | m_inst_emulator_ap->SetBaton (this); |
| 149 | m_inst_emulator_ap->SetCallbacks (ReadMemory, WriteMemory, ReadRegister, WriteRegister); |
| 150 | } |
Greg Clayton | ffc922e3 | 2011-04-25 21:05:07 +0000 | [diff] [blame] | 151 | } |
| 152 | |
Greg Clayton | 2ed751b | 2011-04-26 04:39:08 +0000 | [diff] [blame] | 153 | static uint64_t |
Greg Clayton | 79ea878 | 2011-04-26 23:48:45 +0000 | [diff] [blame] | 154 | MakeRegisterKindValuePair (const lldb_private::RegisterInfo ®_info); |
Greg Clayton | 2ed751b | 2011-04-26 04:39:08 +0000 | [diff] [blame] | 155 | |
| 156 | void |
Greg Clayton | 7349bd9 | 2011-05-09 20:18:18 +0000 | [diff] [blame] | 157 | SetRegisterValue (const lldb_private::RegisterInfo ®_info, |
| 158 | const lldb_private::RegisterValue ®_value); |
Greg Clayton | 2ed751b | 2011-04-26 04:39:08 +0000 | [diff] [blame] | 159 | |
Greg Clayton | 7349bd9 | 2011-05-09 20:18:18 +0000 | [diff] [blame] | 160 | bool |
| 161 | GetRegisterValue (const lldb_private::RegisterInfo ®_info, |
| 162 | lldb_private::RegisterValue ®_value); |
Greg Clayton | 2ed751b | 2011-04-26 04:39:08 +0000 | [diff] [blame] | 163 | |
Greg Clayton | 7b0992d | 2013-04-18 22:45:39 +0000 | [diff] [blame] | 164 | std::unique_ptr<lldb_private::EmulateInstruction> m_inst_emulator_ap; |
Greg Clayton | 2ed751b | 2011-04-26 04:39:08 +0000 | [diff] [blame] | 165 | lldb_private::AddressRange* m_range_ptr; |
| 166 | lldb_private::Thread* m_thread_ptr; |
| 167 | lldb_private::UnwindPlan* m_unwind_plan_ptr; |
Jason Molenda | 1d42c7b | 2012-07-14 04:52:53 +0000 | [diff] [blame] | 168 | lldb_private::UnwindPlan::RowSP m_curr_row; |
Greg Clayton | 31f1d2f | 2011-05-11 18:39:18 +0000 | [diff] [blame] | 169 | typedef std::map<uint64_t, uint64_t> PushedRegisterToAddrMap; |
Greg Clayton | 7349bd9 | 2011-05-09 20:18:18 +0000 | [diff] [blame] | 170 | uint64_t m_initial_sp; |
Greg Clayton | 31f1d2f | 2011-05-11 18:39:18 +0000 | [diff] [blame] | 171 | lldb_private::RegisterInfo m_cfa_reg_info; |
| 172 | bool m_fp_is_cfa; |
Greg Clayton | 7349bd9 | 2011-05-09 20:18:18 +0000 | [diff] [blame] | 173 | typedef std::map<uint64_t, lldb_private::RegisterValue> RegisterValueMap; |
Greg Clayton | 2ed751b | 2011-04-26 04:39:08 +0000 | [diff] [blame] | 174 | RegisterValueMap m_register_values; |
Greg Clayton | 31f1d2f | 2011-05-11 18:39:18 +0000 | [diff] [blame] | 175 | PushedRegisterToAddrMap m_pushed_regs; |
Jason Molenda | 7cd5e83 | 2012-10-23 03:08:31 +0000 | [diff] [blame] | 176 | |
| 177 | // While processing the instruction stream, we need to communicate some state change |
| 178 | // information up to the higher level loop that makes decisions about how to push |
| 179 | // the unwind instructions for the UnwindPlan we're constructing. |
Tamas Berghammer | 44ff9cce | 2015-06-24 11:27:32 +0000 | [diff] [blame^] | 180 | |
Jason Molenda | 7cd5e83 | 2012-10-23 03:08:31 +0000 | [diff] [blame] | 181 | // The instruction we're processing updated the UnwindPlan::Row contents |
| 182 | bool m_curr_row_modified; |
Tamas Berghammer | 44ff9cce | 2015-06-24 11:27:32 +0000 | [diff] [blame^] | 183 | // The instruction is branching forward with the given offset. 0 value means no branching. |
| 184 | uint32_t m_forward_branch_offset; |
Greg Clayton | ffc922e3 | 2011-04-25 21:05:07 +0000 | [diff] [blame] | 185 | }; |
| 186 | |
| 187 | #endif // liblldb_UnwindAssemblyInstEmulation_h_ |