Eugene Zelenko | ab7f6d0 | 2015-10-21 18:46:17 +0000 | [diff] [blame] | 1 | //===-- UnwindAssemblyInstEmulation.h ---------------------------*- C++ -*-===// |
Greg Clayton | ffc922e3 | 2011-04-25 21:05:07 +0000 | [diff] [blame] | 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Greg Clayton | ffc922e3 | 2011-04-25 21:05:07 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #ifndef liblldb_UnwindAssemblyInstEmulation_h_ |
| 10 | #define liblldb_UnwindAssemblyInstEmulation_h_ |
| 11 | |
Greg Clayton | 2ed751b | 2011-04-26 04:39:08 +0000 | [diff] [blame] | 12 | #include "lldb/Core/EmulateInstruction.h" |
Greg Clayton | e5b3498 | 2011-04-29 22:50:31 +0000 | [diff] [blame] | 13 | #include "lldb/Symbol/UnwindPlan.h" |
Greg Clayton | 7be2542 | 2011-04-25 21:14:26 +0000 | [diff] [blame] | 14 | #include "lldb/Target/UnwindAssembly.h" |
Pavel Labath | d821c99 | 2018-08-07 11:07:21 +0000 | [diff] [blame] | 15 | #include "lldb/Utility/RegisterValue.h" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 16 | #include "lldb/lldb-private.h" |
Greg Clayton | ffc922e3 | 2011-04-25 21:05:07 +0000 | [diff] [blame] | 17 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 18 | class UnwindAssemblyInstEmulation : public lldb_private::UnwindAssembly { |
Greg Clayton | ffc922e3 | 2011-04-25 21:05:07 +0000 | [diff] [blame] | 19 | public: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 20 | ~UnwindAssemblyInstEmulation() override = default; |
Greg Clayton | ffc922e3 | 2011-04-25 21:05:07 +0000 | [diff] [blame] | 21 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 22 | bool GetNonCallSiteUnwindPlanFromAssembly( |
| 23 | lldb_private::AddressRange &func, lldb_private::Thread &thread, |
| 24 | lldb_private::UnwindPlan &unwind_plan) override; |
Greg Clayton | ffc922e3 | 2011-04-25 21:05:07 +0000 | [diff] [blame] | 25 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 26 | bool |
Jason Molenda | 6853cca | 2016-10-11 02:24:00 +0000 | [diff] [blame] | 27 | GetNonCallSiteUnwindPlanFromAssembly(lldb_private::AddressRange &func, |
| 28 | uint8_t *opcode_data, size_t opcode_size, |
| 29 | lldb_private::UnwindPlan &unwind_plan); |
| 30 | |
| 31 | bool |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 32 | AugmentUnwindPlanFromCallSite(lldb_private::AddressRange &func, |
| 33 | lldb_private::Thread &thread, |
| 34 | lldb_private::UnwindPlan &unwind_plan) override; |
Greg Clayton | ffc922e3 | 2011-04-25 21:05:07 +0000 | [diff] [blame] | 35 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 36 | bool GetFastUnwindPlan(lldb_private::AddressRange &func, |
| 37 | lldb_private::Thread &thread, |
| 38 | lldb_private::UnwindPlan &unwind_plan) override; |
Greg Clayton | ffc922e3 | 2011-04-25 21:05:07 +0000 | [diff] [blame] | 39 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 40 | // thread may be NULL in which case we only use the Target (e.g. if this is |
| 41 | // called pre-process-launch). |
| 42 | bool |
| 43 | FirstNonPrologueInsn(lldb_private::AddressRange &func, |
| 44 | const lldb_private::ExecutionContext &exe_ctx, |
| 45 | lldb_private::Address &first_non_prologue_insn) override; |
Greg Clayton | ffc922e3 | 2011-04-25 21:05:07 +0000 | [diff] [blame] | 46 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 47 | static lldb_private::UnwindAssembly * |
| 48 | CreateInstance(const lldb_private::ArchSpec &arch); |
Greg Clayton | ffc922e3 | 2011-04-25 21:05:07 +0000 | [diff] [blame] | 49 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 50 | // PluginInterface protocol |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 51 | static void Initialize(); |
Greg Clayton | ffc922e3 | 2011-04-25 21:05:07 +0000 | [diff] [blame] | 52 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 53 | static void Terminate(); |
Greg Clayton | ffc922e3 | 2011-04-25 21:05:07 +0000 | [diff] [blame] | 54 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 55 | static lldb_private::ConstString GetPluginNameStatic(); |
Greg Clayton | ffc922e3 | 2011-04-25 21:05:07 +0000 | [diff] [blame] | 56 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 57 | static const char *GetPluginDescriptionStatic(); |
Greg Clayton | ffc922e3 | 2011-04-25 21:05:07 +0000 | [diff] [blame] | 58 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 59 | lldb_private::ConstString GetPluginName() override; |
| 60 | |
| 61 | uint32_t GetPluginVersion() override; |
| 62 | |
Greg Clayton | ffc922e3 | 2011-04-25 21:05:07 +0000 | [diff] [blame] | 63 | private: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 64 | // Call CreateInstance to get an instance of this class |
| 65 | UnwindAssemblyInstEmulation(const lldb_private::ArchSpec &arch, |
| 66 | lldb_private::EmulateInstruction *inst_emulator) |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 67 | : UnwindAssembly(arch), m_inst_emulator_up(inst_emulator), |
Konrad Kleine | 248a130 | 2019-05-23 11:14:47 +0000 | [diff] [blame] | 68 | m_range_ptr(nullptr), m_unwind_plan_ptr(nullptr), m_curr_row(), |
Jason Molenda | 6853cca | 2016-10-11 02:24:00 +0000 | [diff] [blame] | 69 | m_cfa_reg_info(), m_fp_is_cfa(false), m_register_values(), |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 70 | m_pushed_regs(), m_curr_row_modified(false), |
| 71 | m_forward_branch_offset(0) { |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 72 | if (m_inst_emulator_up.get()) { |
| 73 | m_inst_emulator_up->SetBaton(this); |
| 74 | m_inst_emulator_up->SetCallbacks(ReadMemory, WriteMemory, ReadRegister, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 75 | WriteRegister); |
Eugene Zelenko | ab7f6d0 | 2015-10-21 18:46:17 +0000 | [diff] [blame] | 76 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 77 | } |
Eugene Zelenko | ab7f6d0 | 2015-10-21 18:46:17 +0000 | [diff] [blame] | 78 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 79 | static size_t |
| 80 | ReadMemory(lldb_private::EmulateInstruction *instruction, void *baton, |
| 81 | const lldb_private::EmulateInstruction::Context &context, |
| 82 | lldb::addr_t addr, void *dst, size_t length); |
Greg Clayton | 2ed751b | 2011-04-26 04:39:08 +0000 | [diff] [blame] | 83 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 84 | static size_t |
| 85 | WriteMemory(lldb_private::EmulateInstruction *instruction, void *baton, |
| 86 | const lldb_private::EmulateInstruction::Context &context, |
| 87 | lldb::addr_t addr, const void *dst, size_t length); |
Greg Clayton | 2ed751b | 2011-04-26 04:39:08 +0000 | [diff] [blame] | 88 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 89 | static bool ReadRegister(lldb_private::EmulateInstruction *instruction, |
| 90 | void *baton, |
| 91 | const lldb_private::RegisterInfo *reg_info, |
| 92 | lldb_private::RegisterValue ®_value); |
Greg Clayton | 31f1d2f | 2011-05-11 18:39:18 +0000 | [diff] [blame] | 93 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 94 | static bool |
| 95 | WriteRegister(lldb_private::EmulateInstruction *instruction, void *baton, |
| 96 | const lldb_private::EmulateInstruction::Context &context, |
| 97 | const lldb_private::RegisterInfo *reg_info, |
| 98 | const lldb_private::RegisterValue ®_value); |
Greg Clayton | 31f1d2f | 2011-05-11 18:39:18 +0000 | [diff] [blame] | 99 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 100 | // size_t |
| 101 | // ReadMemory (lldb_private::EmulateInstruction *instruction, |
| 102 | // const lldb_private::EmulateInstruction::Context &context, |
| 103 | // lldb::addr_t addr, |
| 104 | // void *dst, |
| 105 | // size_t length); |
Greg Clayton | 31f1d2f | 2011-05-11 18:39:18 +0000 | [diff] [blame] | 106 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 107 | size_t WriteMemory(lldb_private::EmulateInstruction *instruction, |
| 108 | const lldb_private::EmulateInstruction::Context &context, |
| 109 | lldb::addr_t addr, const void *dst, size_t length); |
Greg Clayton | 2ed751b | 2011-04-26 04:39:08 +0000 | [diff] [blame] | 110 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 111 | bool ReadRegister(lldb_private::EmulateInstruction *instruction, |
| 112 | const lldb_private::RegisterInfo *reg_info, |
| 113 | lldb_private::RegisterValue ®_value); |
Greg Clayton | 2ed751b | 2011-04-26 04:39:08 +0000 | [diff] [blame] | 114 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 115 | bool WriteRegister(lldb_private::EmulateInstruction *instruction, |
| 116 | const lldb_private::EmulateInstruction::Context &context, |
| 117 | const lldb_private::RegisterInfo *reg_info, |
| 118 | const lldb_private::RegisterValue ®_value); |
Jason Molenda | 7cd5e83 | 2012-10-23 03:08:31 +0000 | [diff] [blame] | 119 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 120 | static uint64_t |
| 121 | MakeRegisterKindValuePair(const lldb_private::RegisterInfo ®_info); |
Tamas Berghammer | 44ff9cce | 2015-06-24 11:27:32 +0000 | [diff] [blame] | 122 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 123 | void SetRegisterValue(const lldb_private::RegisterInfo ®_info, |
| 124 | const lldb_private::RegisterValue ®_value); |
| 125 | |
| 126 | bool GetRegisterValue(const lldb_private::RegisterInfo ®_info, |
| 127 | lldb_private::RegisterValue ®_value); |
| 128 | |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 129 | std::unique_ptr<lldb_private::EmulateInstruction> m_inst_emulator_up; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 130 | lldb_private::AddressRange *m_range_ptr; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 131 | lldb_private::UnwindPlan *m_unwind_plan_ptr; |
| 132 | lldb_private::UnwindPlan::RowSP m_curr_row; |
| 133 | typedef std::map<uint64_t, uint64_t> PushedRegisterToAddrMap; |
| 134 | uint64_t m_initial_sp; |
| 135 | lldb_private::RegisterInfo m_cfa_reg_info; |
| 136 | bool m_fp_is_cfa; |
| 137 | typedef std::map<uint64_t, lldb_private::RegisterValue> RegisterValueMap; |
| 138 | RegisterValueMap m_register_values; |
| 139 | PushedRegisterToAddrMap m_pushed_regs; |
| 140 | |
| 141 | // While processing the instruction stream, we need to communicate some state |
| 142 | // change |
| 143 | // information up to the higher level loop that makes decisions about how to |
| 144 | // push |
| 145 | // the unwind instructions for the UnwindPlan we're constructing. |
| 146 | |
| 147 | // The instruction we're processing updated the UnwindPlan::Row contents |
| 148 | bool m_curr_row_modified; |
| 149 | // The instruction is branching forward with the given offset. 0 value means |
| 150 | // no branching. |
| 151 | uint32_t m_forward_branch_offset; |
Greg Clayton | ffc922e3 | 2011-04-25 21:05:07 +0000 | [diff] [blame] | 152 | }; |
| 153 | |
| 154 | #endif // liblldb_UnwindAssemblyInstEmulation_h_ |