FuncUnwinders.h revision 37816a3429a075e19b74f64fd642d5a5d7ec6f2f
1#ifndef liblldb_FuncUnwinders_h
2#define liblldb_FuncUnwinders_h
3
4
5#include <memory>
6
7#include "lldb/Core/AddressRange.h"
8#include "lldb/Core/ArchSpec.h"
9#include "lldb/Core/AddressRange.h"
10#include "lldb/Host/Mutex.h"
11
12namespace lldb_private {
13
14class UnwindTable;
15
16class FuncUnwinders
17{
18public:
19    // FuncUnwinders objects are used to track UnwindPlans for a function
20    // (named or not - really just an address range)
21
22    // We'll record three different UnwindPlans for each address range:
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    //      langauge 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, lldb_private::UnwindAssembly *assembly_profiler, 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 (int current_offset);
48
49    lldb::UnwindPlanSP
50    GetUnwindPlanAtNonCallSite (lldb_private::Thread& thread);
51
52    lldb::UnwindPlanSP
53    GetUnwindPlanFastUnwind (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    // When we're doing an unwind using the UnwindPlanAtNonCallSite and we find an
74    // impossible unwind condition, we know that the UnwindPlan is invalid.  Calling
75    // this method on the FuncUnwinder will tell it to replace that UnwindPlan with
76    // the architectural default UnwindPlan so hopefully our stack walk will get past
77    // this frame.
78    void
79    InvalidateNonCallSiteUnwindPlan (lldb_private::Thread& Thread);
80
81private:
82    UnwindTable& m_unwind_table;
83    UnwindAssembly *m_assembly_profiler;
84    AddressRange m_range;
85
86    Mutex m_mutex;
87    lldb::UnwindPlanSP m_unwind_plan_call_site_sp;
88    lldb::UnwindPlanSP m_unwind_plan_non_call_site_sp;
89    lldb::UnwindPlanSP m_unwind_plan_fast_sp;
90    lldb::UnwindPlanSP m_unwind_plan_arch_default_sp;
91    lldb::UnwindPlanSP m_unwind_plan_arch_default_at_func_entry_sp;
92
93    bool m_tried_unwind_at_call_site:1,
94         m_tried_unwind_at_non_call_site:1,
95         m_tried_unwind_fast:1,
96         m_tried_unwind_arch_default:1,
97         m_tried_unwind_arch_default_at_func_entry:1;
98
99
100    Address m_first_non_prologue_insn;
101
102    DISALLOW_COPY_AND_ASSIGN (FuncUnwinders);
103
104}; // class FuncUnwinders
105
106} // namespace lldb_private
107
108
109#endif //liblldb_FuncUnwinders_h
110