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 |
| 34 | GetFastUnwindPlan (lldb_private::AddressRange& func, |
| 35 | lldb_private::Thread& thread, |
| 36 | lldb_private::UnwindPlan &unwind_plan); |
| 37 | |
| 38 | // thread may be NULL in which case we only use the Target (e.g. if this is called pre-process-launch). |
| 39 | virtual bool |
| 40 | FirstNonPrologueInsn (lldb_private::AddressRange& func, |
| 41 | lldb_private::Target& target, |
| 42 | lldb_private::Thread* thread, |
| 43 | lldb_private::Address& first_non_prologue_insn); |
| 44 | |
Greg Clayton | 7be2542 | 2011-04-25 21:14:26 +0000 | [diff] [blame] | 45 | static lldb_private::UnwindAssembly * |
Greg Clayton | ffc922e3 | 2011-04-25 21:05:07 +0000 | [diff] [blame] | 46 | CreateInstance (const lldb_private::ArchSpec &arch); |
| 47 | |
Greg Clayton | ffc922e3 | 2011-04-25 21:05:07 +0000 | [diff] [blame] | 48 | //------------------------------------------------------------------ |
| 49 | // PluginInterface protocol |
| 50 | //------------------------------------------------------------------ |
| 51 | static void |
| 52 | Initialize(); |
| 53 | |
| 54 | static void |
| 55 | Terminate(); |
| 56 | |
| 57 | static const char * |
| 58 | GetPluginNameStatic(); |
| 59 | |
| 60 | static const char * |
| 61 | GetPluginDescriptionStatic(); |
| 62 | |
| 63 | virtual const char * |
| 64 | GetPluginName(); |
| 65 | |
| 66 | virtual const char * |
| 67 | GetShortPluginName(); |
| 68 | |
| 69 | virtual uint32_t |
| 70 | GetPluginVersion(); |
| 71 | |
| 72 | private: |
Greg Clayton | 2ed751b | 2011-04-26 04:39:08 +0000 | [diff] [blame] | 73 | |
| 74 | static size_t |
| 75 | ReadMemory (lldb_private::EmulateInstruction *instruction, |
| 76 | void *baton, |
| 77 | const lldb_private::EmulateInstruction::Context &context, |
| 78 | lldb::addr_t addr, |
| 79 | void *dst, |
| 80 | size_t length); |
| 81 | |
| 82 | static size_t |
| 83 | WriteMemory (lldb_private::EmulateInstruction *instruction, |
| 84 | void *baton, |
| 85 | const lldb_private::EmulateInstruction::Context &context, |
| 86 | lldb::addr_t addr, |
| 87 | const void *dst, |
| 88 | size_t length); |
| 89 | |
| 90 | static bool |
| 91 | ReadRegister (lldb_private::EmulateInstruction *instruction, |
| 92 | void *baton, |
Greg Clayton | 7349bd9 | 2011-05-09 20:18:18 +0000 | [diff] [blame^] | 93 | const lldb_private::RegisterInfo *reg_info, |
| 94 | lldb_private::RegisterValue ®_value); |
Greg Clayton | 2ed751b | 2011-04-26 04:39:08 +0000 | [diff] [blame] | 95 | |
| 96 | static bool |
| 97 | WriteRegister (lldb_private::EmulateInstruction *instruction, |
| 98 | void *baton, |
| 99 | const lldb_private::EmulateInstruction::Context &context, |
Greg Clayton | 7349bd9 | 2011-05-09 20:18:18 +0000 | [diff] [blame^] | 100 | const lldb_private::RegisterInfo *reg_info, |
| 101 | const lldb_private::RegisterValue ®_value); |
Greg Clayton | 2ed751b | 2011-04-26 04:39:08 +0000 | [diff] [blame] | 102 | |
Greg Clayton | ffc922e3 | 2011-04-25 21:05:07 +0000 | [diff] [blame] | 103 | |
| 104 | // Call CreateInstance to get an instance of this class |
Greg Clayton | 2ed751b | 2011-04-26 04:39:08 +0000 | [diff] [blame] | 105 | UnwindAssemblyInstEmulation (const lldb_private::ArchSpec &arch, |
| 106 | lldb_private::EmulateInstruction *inst_emulator) : |
| 107 | UnwindAssembly (arch), |
| 108 | m_inst_emulator_ap (inst_emulator), |
| 109 | m_range_ptr (NULL), |
| 110 | m_thread_ptr (NULL), |
| 111 | m_unwind_plan_ptr (NULL) |
Greg Clayton | ffc922e3 | 2011-04-25 21:05:07 +0000 | [diff] [blame] | 112 | { |
Greg Clayton | 2ed751b | 2011-04-26 04:39:08 +0000 | [diff] [blame] | 113 | if (m_inst_emulator_ap.get()) |
| 114 | { |
| 115 | m_inst_emulator_ap->SetBaton (this); |
| 116 | m_inst_emulator_ap->SetCallbacks (ReadMemory, WriteMemory, ReadRegister, WriteRegister); |
| 117 | } |
Greg Clayton | ffc922e3 | 2011-04-25 21:05:07 +0000 | [diff] [blame] | 118 | } |
| 119 | |
Greg Clayton | 2ed751b | 2011-04-26 04:39:08 +0000 | [diff] [blame] | 120 | static uint64_t |
Greg Clayton | 79ea878 | 2011-04-26 23:48:45 +0000 | [diff] [blame] | 121 | MakeRegisterKindValuePair (const lldb_private::RegisterInfo ®_info); |
Greg Clayton | 2ed751b | 2011-04-26 04:39:08 +0000 | [diff] [blame] | 122 | |
| 123 | void |
Greg Clayton | 7349bd9 | 2011-05-09 20:18:18 +0000 | [diff] [blame^] | 124 | SetRegisterValue (const lldb_private::RegisterInfo ®_info, |
| 125 | const lldb_private::RegisterValue ®_value); |
Greg Clayton | 2ed751b | 2011-04-26 04:39:08 +0000 | [diff] [blame] | 126 | |
Greg Clayton | 7349bd9 | 2011-05-09 20:18:18 +0000 | [diff] [blame^] | 127 | bool |
| 128 | GetRegisterValue (const lldb_private::RegisterInfo ®_info, |
| 129 | lldb_private::RegisterValue ®_value); |
Greg Clayton | 2ed751b | 2011-04-26 04:39:08 +0000 | [diff] [blame] | 130 | |
| 131 | std::auto_ptr<lldb_private::EmulateInstruction> m_inst_emulator_ap; |
| 132 | lldb_private::AddressRange* m_range_ptr; |
| 133 | lldb_private::Thread* m_thread_ptr; |
| 134 | lldb_private::UnwindPlan* m_unwind_plan_ptr; |
Greg Clayton | e5b3498 | 2011-04-29 22:50:31 +0000 | [diff] [blame] | 135 | lldb_private::UnwindPlan::Row m_curr_row; |
Greg Clayton | 7349bd9 | 2011-05-09 20:18:18 +0000 | [diff] [blame^] | 136 | uint64_t m_initial_sp; |
| 137 | typedef std::map<uint64_t, lldb_private::RegisterValue> RegisterValueMap; |
Greg Clayton | 2ed751b | 2011-04-26 04:39:08 +0000 | [diff] [blame] | 138 | RegisterValueMap m_register_values; |
Greg Clayton | ffc922e3 | 2011-04-25 21:05:07 +0000 | [diff] [blame] | 139 | }; |
| 140 | |
| 141 | #endif // liblldb_UnwindAssemblyInstEmulation_h_ |