FuncUnwinders.h revision 309124
1#ifndef liblldb_FuncUnwinders_h
2#define liblldb_FuncUnwinders_h
3
4#include <mutex>
5#include <vector>
6
7#include "lldb/Core/AddressRange.h"
8#include "lldb/Core/ArchSpec.h"
9#include "lldb/Core/AddressRange.h"
10
11namespace lldb_private {
12
13class UnwindTable;
14
15class FuncUnwinders
16{
17public:
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
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    GetArmUnwindUnwindPlan (Target &target, int current_offset);
107
108    lldb::UnwindPlanSP
109    GetArchDefaultUnwindPlan (Thread &thread);
110
111    lldb::UnwindPlanSP
112    GetArchDefaultAtFuncEntryUnwindPlan (Thread &thread);
113
114private:
115
116    lldb::UnwindAssemblySP
117    GetUnwindAssemblyProfiler (Target& target);
118
119    // Do a simplistic comparison for the register restore rule for getting
120    // the caller's pc value on two UnwindPlans -- returns LazyBoolYes if
121    // they have the same unwind rule for the pc, LazyBoolNo if they do not
122    // have the same unwind rule for the pc, and LazyBoolCalculate if it was
123    // unable to determine this for some reason.
124    lldb_private::LazyBool
125    CompareUnwindPlansForIdenticalInitialPCLocation (Thread& thread, const lldb::UnwindPlanSP &a, const lldb::UnwindPlanSP &b);
126
127    UnwindTable& m_unwind_table;
128    AddressRange m_range;
129
130    std::recursive_mutex m_mutex;
131
132    lldb::UnwindPlanSP              m_unwind_plan_assembly_sp;
133    lldb::UnwindPlanSP              m_unwind_plan_eh_frame_sp;
134    lldb::UnwindPlanSP              m_unwind_plan_eh_frame_augmented_sp;   // augmented by assembly inspection so it's valid everywhere
135    std::vector<lldb::UnwindPlanSP> m_unwind_plan_compact_unwind;
136    lldb::UnwindPlanSP              m_unwind_plan_arm_unwind_sp;
137    lldb::UnwindPlanSP              m_unwind_plan_fast_sp;
138    lldb::UnwindPlanSP              m_unwind_plan_arch_default_sp;
139    lldb::UnwindPlanSP              m_unwind_plan_arch_default_at_func_entry_sp;
140
141    // Fetching the UnwindPlans can be expensive - if we've already attempted
142    // to get one & failed, don't try again.
143    bool m_tried_unwind_plan_assembly:1,
144         m_tried_unwind_plan_eh_frame:1,
145         m_tried_unwind_plan_eh_frame_augmented:1,
146         m_tried_unwind_plan_compact_unwind:1,
147         m_tried_unwind_plan_arm_unwind:1,
148         m_tried_unwind_fast:1,
149         m_tried_unwind_arch_default:1,
150         m_tried_unwind_arch_default_at_func_entry:1;
151
152    Address m_first_non_prologue_insn;
153
154    DISALLOW_COPY_AND_ASSIGN (FuncUnwinders);
155
156}; // class FuncUnwinders
157
158} // namespace lldb_private
159
160
161#endif //liblldb_FuncUnwinders_h
162