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 // C Includes 14 // C++ Includes 15 // Other libraries and framework includes 16 // Project 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" 22 23 class UnwindAssemblyInstEmulation : public lldb_private::UnwindAssembly { 24 public: 25 ~UnwindAssemblyInstEmulation() override = default; 26 27 bool GetNonCallSiteUnwindPlanFromAssembly( 28 lldb_private::AddressRange &func, lldb_private::Thread &thread, 29 lldb_private::UnwindPlan &unwind_plan) override; 30 31 bool 32 GetNonCallSiteUnwindPlanFromAssembly(lldb_private::AddressRange &func, 33 uint8_t *opcode_data, size_t opcode_size, 34 lldb_private::UnwindPlan &unwind_plan); 35 36 bool 37 AugmentUnwindPlanFromCallSite(lldb_private::AddressRange &func, 38 lldb_private::Thread &thread, 39 lldb_private::UnwindPlan &unwind_plan) override; 40 41 bool GetFastUnwindPlan(lldb_private::AddressRange &func, 42 lldb_private::Thread &thread, 43 lldb_private::UnwindPlan &unwind_plan) override; 44 45 // thread may be NULL in which case we only use the Target (e.g. if this is 46 // called pre-process-launch). 47 bool 48 FirstNonPrologueInsn(lldb_private::AddressRange &func, 49 const lldb_private::ExecutionContext &exe_ctx, 50 lldb_private::Address &first_non_prologue_insn) override; 51 52 static lldb_private::UnwindAssembly * 53 CreateInstance(const lldb_private::ArchSpec &arch); 54 55 //------------------------------------------------------------------ 56 // PluginInterface protocol 57 //------------------------------------------------------------------ 58 static void Initialize(); 59 60 static void Terminate(); 61 62 static lldb_private::ConstString GetPluginNameStatic(); 63 64 static const char *GetPluginDescriptionStatic(); 65 66 lldb_private::ConstString GetPluginName() override; 67 68 uint32_t GetPluginVersion() override; 69 70 private: 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, 82 WriteRegister); 83 } 84 } 85 86 static size_t 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); 90 91 static size_t 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); 95 96 static bool ReadRegister(lldb_private::EmulateInstruction *instruction, 97 void *baton, 98 const lldb_private::RegisterInfo *reg_info, 99 lldb_private::RegisterValue ®_value); 100 101 static bool 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); 106 107 // size_t 108 // ReadMemory (lldb_private::EmulateInstruction *instruction, 109 // const lldb_private::EmulateInstruction::Context &context, 110 // lldb::addr_t addr, 111 // void *dst, 112 // size_t length); 113 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); 117 118 bool ReadRegister(lldb_private::EmulateInstruction *instruction, 119 const lldb_private::RegisterInfo *reg_info, 120 lldb_private::RegisterValue ®_value); 121 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); 126 127 static uint64_t 128 MakeRegisterKindValuePair(const lldb_private::RegisterInfo ®_info); 129 130 void SetRegisterValue(const lldb_private::RegisterInfo ®_info, 131 const lldb_private::RegisterValue ®_value); 132 133 bool GetRegisterValue(const lldb_private::RegisterInfo ®_info, 134 lldb_private::RegisterValue ®_value); 135 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; 143 bool m_fp_is_cfa; 144 typedef std::map<uint64_t, lldb_private::RegisterValue> RegisterValueMap; 145 RegisterValueMap m_register_values; 146 PushedRegisterToAddrMap m_pushed_regs; 147 148 // While processing the instruction stream, we need to communicate some state 149 // change 150 // information up to the higher level loop that makes decisions about how to 151 // push 152 // the unwind instructions for the UnwindPlan we're constructing. 153 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 157 // no branching. 158 uint32_t m_forward_branch_offset; 159 }; 160 161 #endif // liblldb_UnwindAssemblyInstEmulation_h_ 162