1 //===-- UnwindLLDB.h --------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef lldb_UnwindLLDB_h_
11 #define lldb_UnwindLLDB_h_
15 #include "lldb/Symbol/FuncUnwinders.h"
16 #include "lldb/Symbol/SymbolContext.h"
17 #include "lldb/Symbol/UnwindPlan.h"
18 #include "lldb/Target/RegisterContext.h"
19 #include "lldb/Target/Unwind.h"
20 #include "lldb/Utility/ConstString.h"
21 #include "lldb/lldb-public.h"
23 namespace lldb_private {
25 class RegisterContextLLDB;
27 class UnwindLLDB : public lldb_private::Unwind {
29 UnwindLLDB(lldb_private::Thread &thread);
31 ~UnwindLLDB() override = default;
33 enum RegisterSearchResult {
40 friend class lldb_private::RegisterContextLLDB;
42 struct RegisterLocation {
43 enum RegisterLocationTypes {
44 eRegisterNotSaved = 0, // register was not preserved by callee. If
45 // volatile reg, is unavailable
46 eRegisterSavedAtMemoryLocation, // register is saved at a specific word of
47 // target mem (target_memory_location)
48 eRegisterInRegister, // register is available in a (possible other)
49 // register (register_number)
50 eRegisterSavedAtHostMemoryLocation, // register is saved at a word in
51 // lldb's address space
52 eRegisterValueInferred, // register val was computed (and is in
54 eRegisterInLiveRegisterContext // register value is in a live (stack frame
59 lldb::addr_t target_memory_location;
61 register_number; // in eRegisterKindLLDB register numbering system
62 void *host_memory_location;
63 uint64_t inferred_value; // eRegisterValueInferred - e.g. stack pointer ==
68 void DoClear() override {
70 m_candidate_frame.reset();
71 m_unwind_complete = false;
74 uint32_t DoGetFrameCount() override;
76 bool DoGetFrameInfoAtIndex(uint32_t frame_idx, lldb::addr_t &cfa,
77 lldb::addr_t &start_pc) override;
79 lldb::RegisterContextSP
80 DoCreateRegisterContextForFrame(lldb_private::StackFrame *frame) override;
82 typedef std::shared_ptr<RegisterContextLLDB> RegisterContextLLDBSP;
84 // Needed to retrieve the "next" frame (e.g. frame 2 needs to retrieve frame
85 // 1's RegisterContextLLDB)
86 // The RegisterContext for frame_num must already exist or this returns an
87 // empty shared pointer.
88 RegisterContextLLDBSP GetRegisterContextForFrameNum(uint32_t frame_num);
90 // Iterate over the RegisterContextLLDB's in our m_frames vector, look for the
92 // has a saved location for this reg.
93 bool SearchForSavedLocationForRegister(
94 uint32_t lldb_regnum, lldb_private::UnwindLLDB::RegisterLocation ®loc,
95 uint32_t starting_frame_num, bool pc_register);
97 //------------------------------------------------------------------
98 /// Provide the list of user-specified trap handler functions
100 /// The Platform is one source of trap handler function names; that
101 /// may be augmented via a setting. The setting needs to be converted
102 /// into an array of ConstStrings before it can be used - we only want
103 /// to do that once per thread so it's here in the UnwindLLDB object.
106 /// Vector of ConstStrings of trap handler function names. May be
108 //------------------------------------------------------------------
109 const std::vector<ConstString> &GetUserSpecifiedTrapHandlerFunctionNames() {
110 return m_user_supplied_trap_handler_functions;
115 lldb::addr_t start_pc; // The start address of the function/symbol for this
116 // frame - current pc if unknown
117 lldb::addr_t cfa; // The canonical frame address for this stack frame
118 lldb_private::SymbolContext sctx; // A symbol context we'll contribute to &
119 // provide to the StackFrame creation
120 RegisterContextLLDBSP
121 reg_ctx_lldb_sp; // These are all RegisterContextLLDB's
124 : start_pc(LLDB_INVALID_ADDRESS), cfa(LLDB_INVALID_ADDRESS), sctx(),
128 DISALLOW_COPY_AND_ASSIGN(Cursor);
131 typedef std::shared_ptr<Cursor> CursorSP;
132 std::vector<CursorSP> m_frames;
133 CursorSP m_candidate_frame;
134 bool m_unwind_complete; // If this is true, we've enumerated all the frames in
135 // the stack, and m_frames.size() is the
136 // number of frames, etc. Otherwise we've only gone as far as directly asked,
137 // and m_frames.size()
138 // is how far we've currently gone.
140 std::vector<ConstString> m_user_supplied_trap_handler_functions;
142 //-----------------------------------------------------------------
143 // Check if Full UnwindPlan of First frame is valid or not.
144 // If not then try Fallback UnwindPlan of the frame. If Fallback
145 // UnwindPlan succeeds then update the Full UnwindPlan with the
146 // Fallback UnwindPlan.
147 //-----------------------------------------------------------------
148 void UpdateUnwindPlanForFirstFrameIfInvalid(ABI *abi);
150 CursorSP GetOneMoreFrame(ABI *abi);
152 bool AddOneMoreFrame(ABI *abi);
154 bool AddFirstFrame();
156 //------------------------------------------------------------------
157 // For UnwindLLDB only
158 //------------------------------------------------------------------
159 DISALLOW_COPY_AND_ASSIGN(UnwindLLDB);
162 } // namespace lldb_private
164 #endif // lldb_UnwindLLDB_h_