]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - contrib/llvm/tools/lldb/source/Plugins/Process/Utility/UnwindLLDB.h
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / contrib / llvm / tools / lldb / source / Plugins / Process / Utility / UnwindLLDB.h
1 //===-- UnwindLLDB.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 lldb_UnwindLLDB_h_
11 #define lldb_UnwindLLDB_h_
12
13 #include <vector>
14
15 #include "lldb/lldb-public.h"
16 #include "lldb/Symbol/FuncUnwinders.h"
17 #include "lldb/Symbol/UnwindPlan.h"
18 #include "lldb/Target/RegisterContext.h"
19 #include "lldb/Target/Unwind.h"
20
21 namespace lldb_private {
22
23 class RegisterContextLLDB;
24
25 class UnwindLLDB : public lldb_private::Unwind
26 {
27 public: 
28     UnwindLLDB (lldb_private::Thread &thread);
29     
30     virtual
31     ~UnwindLLDB() { }
32
33     enum RegisterSearchResult
34     {
35         eRegisterFound = 0,
36         eRegisterNotFound,
37         eRegisterIsVolatile
38     };
39
40 protected:
41     friend class lldb_private::RegisterContextLLDB;
42
43     struct RegisterLocation {
44         enum RegisterLocationTypes
45         {
46             eRegisterNotSaved = 0,              // register was not preserved by callee.  If volatile reg, is unavailable
47             eRegisterSavedAtMemoryLocation,     // register is saved at a specific word of target mem (target_memory_location)
48             eRegisterInRegister,                // register is available in a (possible other) register (register_number)
49             eRegisterSavedAtHostMemoryLocation, // register is saved at a word in lldb's address space
50             eRegisterValueInferred              // register val was computed (and is in inferred_value)
51         };
52         int type;
53         union
54         {
55             lldb::addr_t target_memory_location;
56             uint32_t     register_number;       // in eRegisterKindLLDB register numbering system
57             void*        host_memory_location;
58             uint64_t     inferred_value;        // eRegisterValueInferred - e.g. stack pointer == cfa + offset
59         } location;
60     };
61
62     void
63     DoClear()
64     {
65         m_frames.clear();
66         m_unwind_complete = false;
67     }
68
69     virtual uint32_t
70     DoGetFrameCount();
71
72     bool
73     DoGetFrameInfoAtIndex (uint32_t frame_idx,
74                          lldb::addr_t& cfa, 
75                          lldb::addr_t& start_pc);
76     
77     lldb::RegisterContextSP
78     DoCreateRegisterContextForFrame (lldb_private::StackFrame *frame);
79
80     typedef std::shared_ptr<RegisterContextLLDB> RegisterContextLLDBSP;
81
82     // Needed to retrieve the "next" frame (e.g. frame 2 needs to retrieve frame 1's RegisterContextLLDB)
83     // The RegisterContext for frame_num must already exist or this returns an empty shared pointer.
84     RegisterContextLLDBSP
85     GetRegisterContextForFrameNum (uint32_t frame_num);
86
87     // Iterate over the RegisterContextLLDB's in our m_frames vector, look for the first one that
88     // has a saved location for this reg.
89     bool
90     SearchForSavedLocationForRegister (uint32_t lldb_regnum, lldb_private::UnwindLLDB::RegisterLocation &regloc, uint32_t starting_frame_num, bool pc_register);
91
92
93 private:
94
95     struct Cursor
96     {
97         lldb::addr_t start_pc;  // The start address of the function/symbol for this frame - current pc if unknown
98         lldb::addr_t cfa;       // The canonical frame address for this stack frame
99         lldb_private::SymbolContext sctx;  // A symbol context we'll contribute to & provide to the StackFrame creation
100         RegisterContextLLDBSP reg_ctx_lldb_sp; // These are all RegisterContextLLDB's
101
102         Cursor () : start_pc (LLDB_INVALID_ADDRESS), cfa (LLDB_INVALID_ADDRESS), sctx(), reg_ctx_lldb_sp() { }
103     private:
104         DISALLOW_COPY_AND_ASSIGN (Cursor);
105     };
106
107     typedef std::shared_ptr<Cursor> CursorSP;
108     std::vector<CursorSP> m_frames;
109     bool m_unwind_complete; // If this is true, we've enumerated all the frames in the stack, and m_frames.size() is the 
110                             // number of frames, etc.  Otherwise we've only gone as far as directly asked, and m_frames.size()
111                             // is how far we've currently gone.
112  
113
114     bool AddOneMoreFrame (ABI *abi);
115     bool AddFirstFrame ();
116
117     //------------------------------------------------------------------
118     // For UnwindLLDB only
119     //------------------------------------------------------------------
120     DISALLOW_COPY_AND_ASSIGN (UnwindLLDB);
121 };
122
123 }   // namespace lldb_private
124
125 #endif  // lldb_UnwindLLDB_h_