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" 14 #include "lldb/Core/EmulateInstruction.h" 15 #include "lldb/Core/RegisterValue.h" 16 #include "lldb/Symbol/UnwindPlan.h" 17 #include "lldb/Target/UnwindAssembly.h" 18 19 class UnwindAssemblyInstEmulation : public lldb_private::UnwindAssembly 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 45 static lldb_private::UnwindAssembly * 46 CreateInstance (const lldb_private::ArchSpec &arch); 47 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: 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, 93 const lldb_private::RegisterInfo *reg_info, 94 lldb_private::RegisterValue ®_value); 95 96 static bool 97 WriteRegister (lldb_private::EmulateInstruction *instruction, 98 void *baton, 99 const lldb_private::EmulateInstruction::Context &context, 100 const lldb_private::RegisterInfo *reg_info, 101 const lldb_private::RegisterValue ®_value); 102 103 104 // size_t 105 // ReadMemory (lldb_private::EmulateInstruction *instruction, 106 // const lldb_private::EmulateInstruction::Context &context, 107 // lldb::addr_t addr, 108 // void *dst, 109 // size_t length); 110 111 size_t 112 WriteMemory (lldb_private::EmulateInstruction *instruction, 113 const lldb_private::EmulateInstruction::Context &context, 114 lldb::addr_t addr, 115 const void *dst, 116 size_t length); 117 118 bool 119 ReadRegister (lldb_private::EmulateInstruction *instruction, 120 const lldb_private::RegisterInfo *reg_info, 121 lldb_private::RegisterValue ®_value); 122 123 bool 124 WriteRegister (lldb_private::EmulateInstruction *instruction, 125 const lldb_private::EmulateInstruction::Context &context, 126 const lldb_private::RegisterInfo *reg_info, 127 const lldb_private::RegisterValue ®_value); 128 129 // Call CreateInstance to get an instance of this class 130 UnwindAssemblyInstEmulation (const lldb_private::ArchSpec &arch, 131 lldb_private::EmulateInstruction *inst_emulator) : 132 UnwindAssembly (arch), 133 m_inst_emulator_ap (inst_emulator), 134 m_range_ptr (NULL), 135 m_thread_ptr (NULL), 136 m_unwind_plan_ptr (NULL), 137 m_curr_row (), 138 m_cfa_reg_info (), 139 m_fp_is_cfa (false), 140 m_register_values (), 141 m_pushed_regs() 142 { 143 if (m_inst_emulator_ap.get()) 144 { 145 m_inst_emulator_ap->SetBaton (this); 146 m_inst_emulator_ap->SetCallbacks (ReadMemory, WriteMemory, ReadRegister, WriteRegister); 147 } 148 } 149 150 static uint64_t 151 MakeRegisterKindValuePair (const lldb_private::RegisterInfo ®_info); 152 153 void 154 SetRegisterValue (const lldb_private::RegisterInfo ®_info, 155 const lldb_private::RegisterValue ®_value); 156 157 bool 158 GetRegisterValue (const lldb_private::RegisterInfo ®_info, 159 lldb_private::RegisterValue ®_value); 160 161 std::auto_ptr<lldb_private::EmulateInstruction> m_inst_emulator_ap; 162 lldb_private::AddressRange* m_range_ptr; 163 lldb_private::Thread* m_thread_ptr; 164 lldb_private::UnwindPlan* m_unwind_plan_ptr; 165 lldb_private::UnwindPlan::Row m_curr_row; 166 typedef std::map<uint64_t, uint64_t> PushedRegisterToAddrMap; 167 uint64_t m_initial_sp; 168 lldb_private::RegisterInfo m_cfa_reg_info; 169 bool m_fp_is_cfa; 170 typedef std::map<uint64_t, lldb_private::RegisterValue> RegisterValueMap; 171 RegisterValueMap m_register_values; 172 PushedRegisterToAddrMap m_pushed_regs; 173 }; 174 175 #endif // liblldb_UnwindAssemblyInstEmulation_h_ 176