1 #ifndef liblldb_FuncUnwinders_h 2 #define liblldb_FuncUnwinders_h 3 4 #include <vector> 5 6 #include "lldb/Core/AddressRange.h" 7 #include "lldb/Core/ArchSpec.h" 8 #include "lldb/Core/AddressRange.h" 9 #include "lldb/Host/Mutex.h" 10 11 namespace lldb_private { 12 13 class UnwindTable; 14 15 class FuncUnwinders 16 { 17 public: 18 // FuncUnwinders objects are used to track UnwindPlans for a function 19 // (named or not - really just an address range) 20 21 // We'll record four different UnwindPlans for each address range: 22 // 23 // 1. Unwinding from a call site (a valid exception throw location) 24 // This is often sourced from the eh_frame exception handling info 25 // 2. Unwinding from a non-call site (any location in the function) 26 // This is often done by analyzing the function prologue assembly 27 // language instructions 28 // 3. A fast unwind method for this function which only retrieves a 29 // limited set of registers necessary to walk the stack 30 // 4. An architectural default unwind plan when none of the above are 31 // available for some reason. 32 33 // Additionally, FuncUnwinds object can be asked where the prologue 34 // instructions are finished for migrating breakpoints past the 35 // stack frame setup instructions when we don't have line table information. 36 37 FuncUnwinders (lldb_private::UnwindTable& unwind_table, AddressRange range); 38 39 ~FuncUnwinders (); 40 41 // current_offset is the byte offset into the function. 42 // 0 means no instructions have executed yet. -1 means the offset is unknown. 43 // On architectures where the pc points to the next instruction that will execute, this 44 // offset value will have already been decremented by 1 to stay within the bounds of the 45 // correct function body. 46 lldb::UnwindPlanSP 47 GetUnwindPlanAtCallSite (Target &target, int current_offset); 48 49 lldb::UnwindPlanSP 50 GetUnwindPlanAtNonCallSite (Target& target, lldb_private::Thread& thread, int current_offset); 51 52 lldb::UnwindPlanSP 53 GetUnwindPlanFastUnwind (Target& target, lldb_private::Thread& thread); 54 55 lldb::UnwindPlanSP 56 GetUnwindPlanArchitectureDefault (lldb_private::Thread& thread); 57 58 lldb::UnwindPlanSP 59 GetUnwindPlanArchitectureDefaultAtFunctionEntry (lldb_private::Thread& thread); 60 61 Address& 62 GetFirstNonPrologueInsn (Target& target); 63 64 const Address& 65 GetFunctionStartAddress () const; 66 67 bool ContainsAddress(const Address & addr)68 ContainsAddress (const Address& addr) const 69 { 70 return m_range.ContainsFileAddress (addr); 71 } 72 73 // A function may have a Language Specific Data Area specified -- a block of data in 74 // the object file which is used in the processing of an exception throw / catch. 75 // If any of the UnwindPlans have the address of the LSDA region for this function, 76 // this will return it. 77 Address 78 GetLSDAAddress (Target &target); 79 80 // A function may have a Personality Routine associated with it -- used in the 81 // processing of throwing an exception. If any of the UnwindPlans have the 82 // address of the personality routine, this will return it. Read the target-pointer 83 // at this address to get the personality function address. 84 Address 85 GetPersonalityRoutinePtrAddress (Target &target); 86 87 88 89 // The following methods to retrieve specific unwind plans should rarely be used. 90 // Instead, clients should ask for the *behavior* they are looking for, using one 91 // of the above UnwindPlan retrieval methods. 92 93 lldb::UnwindPlanSP 94 GetAssemblyUnwindPlan (Target &target, Thread &thread, int current_offset); 95 96 lldb::UnwindPlanSP 97 GetEHFrameUnwindPlan (Target &target, int current_offset); 98 99 lldb::UnwindPlanSP 100 GetEHFrameAugmentedUnwindPlan (Target &target, Thread &thread, int current_offset); 101 102 lldb::UnwindPlanSP 103 GetCompactUnwindUnwindPlan (Target &target, int current_offset); 104 105 lldb::UnwindPlanSP 106 GetArchDefaultUnwindPlan (Thread &thread); 107 108 lldb::UnwindPlanSP 109 GetArchDefaultAtFuncEntryUnwindPlan (Thread &thread); 110 111 private: 112 113 lldb::UnwindAssemblySP 114 GetUnwindAssemblyProfiler (Target& target); 115 116 UnwindTable& m_unwind_table; 117 AddressRange m_range; 118 119 Mutex m_mutex; 120 121 lldb::UnwindPlanSP m_unwind_plan_assembly_sp; 122 lldb::UnwindPlanSP m_unwind_plan_eh_frame_sp; 123 lldb::UnwindPlanSP m_unwind_plan_eh_frame_augmented_sp; // augmented by assembly inspection so it's valid everywhere 124 std::vector<lldb::UnwindPlanSP> m_unwind_plan_compact_unwind; 125 lldb::UnwindPlanSP m_unwind_plan_fast_sp; 126 lldb::UnwindPlanSP m_unwind_plan_arch_default_sp; 127 lldb::UnwindPlanSP m_unwind_plan_arch_default_at_func_entry_sp; 128 129 // Fetching the UnwindPlans can be expensive - if we've already attempted 130 // to get one & failed, don't try again. 131 bool m_tried_unwind_plan_assembly:1, 132 m_tried_unwind_plan_eh_frame:1, 133 m_tried_unwind_plan_eh_frame_augmented:1, 134 m_tried_unwind_plan_compact_unwind:1, 135 m_tried_unwind_fast:1, 136 m_tried_unwind_arch_default:1, 137 m_tried_unwind_arch_default_at_func_entry:1; 138 139 Address m_first_non_prologue_insn; 140 141 DISALLOW_COPY_AND_ASSIGN (FuncUnwinders); 142 143 }; // class FuncUnwinders 144 145 } // namespace lldb_private 146 147 148 #endif //liblldb_FuncUnwinders_h 149