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_
17 // Other libraries and framework includes
19 #include "lldb/lldb-public.h"
20 #include "lldb/Core/ConstString.h"
21 #include "lldb/Symbol/FuncUnwinders.h"
22 #include "lldb/Symbol/UnwindPlan.h"
23 #include "lldb/Target/RegisterContext.h"
24 #include "lldb/Target/Unwind.h"
26 namespace lldb_private {
28 class RegisterContextLLDB;
30 class UnwindLLDB : public lldb_private::Unwind
33 UnwindLLDB (lldb_private::Thread &thread);
35 ~UnwindLLDB() override = default;
37 enum RegisterSearchResult
45 friend class lldb_private::RegisterContextLLDB;
47 struct RegisterLocation {
48 enum RegisterLocationTypes
50 eRegisterNotSaved = 0, // register was not preserved by callee. If volatile reg, is unavailable
51 eRegisterSavedAtMemoryLocation, // register is saved at a specific word of target mem (target_memory_location)
52 eRegisterInRegister, // register is available in a (possible other) register (register_number)
53 eRegisterSavedAtHostMemoryLocation, // register is saved at a word in lldb's address space
54 eRegisterValueInferred, // register val was computed (and is in inferred_value)
55 eRegisterInLiveRegisterContext // register value is in a live (stack frame #0) register
60 lldb::addr_t target_memory_location;
61 uint32_t register_number; // in eRegisterKindLLDB register numbering system
62 void* host_memory_location;
63 uint64_t inferred_value; // eRegisterValueInferred - e.g. stack pointer == cfa + offset
71 m_candidate_frame.reset();
72 m_unwind_complete = false;
76 DoGetFrameCount() override;
79 DoGetFrameInfoAtIndex(uint32_t frame_idx,
81 lldb::addr_t& start_pc) override;
83 lldb::RegisterContextSP
84 DoCreateRegisterContextForFrame(lldb_private::StackFrame *frame) override;
86 typedef std::shared_ptr<RegisterContextLLDB> RegisterContextLLDBSP;
88 // Needed to retrieve the "next" frame (e.g. frame 2 needs to retrieve frame 1's RegisterContextLLDB)
89 // The RegisterContext for frame_num must already exist or this returns an empty shared pointer.
91 GetRegisterContextForFrameNum (uint32_t frame_num);
93 // Iterate over the RegisterContextLLDB's in our m_frames vector, look for the first one that
94 // has a saved location for this reg.
96 SearchForSavedLocationForRegister (uint32_t lldb_regnum, lldb_private::UnwindLLDB::RegisterLocation ®loc, uint32_t starting_frame_num, bool pc_register);
99 //------------------------------------------------------------------
100 /// Provide the list of user-specified trap handler functions
102 /// The Platform is one source of trap handler function names; that
103 /// may be augmented via a setting. The setting needs to be converted
104 /// into an array of ConstStrings before it can be used - we only want
105 /// to do that once per thread so it's here in the UnwindLLDB object.
108 /// Vector of ConstStrings of trap handler function names. May be
110 //------------------------------------------------------------------
111 const std::vector<ConstString> &
112 GetUserSpecifiedTrapHandlerFunctionNames ()
114 return m_user_supplied_trap_handler_functions;
120 lldb::addr_t start_pc; // The start address of the function/symbol for this frame - current pc if unknown
121 lldb::addr_t cfa; // The canonical frame address for this stack frame
122 lldb_private::SymbolContext sctx; // A symbol context we'll contribute to & provide to the StackFrame creation
123 RegisterContextLLDBSP reg_ctx_lldb_sp; // These are all RegisterContextLLDB's
125 Cursor () : start_pc (LLDB_INVALID_ADDRESS), cfa (LLDB_INVALID_ADDRESS), sctx(), reg_ctx_lldb_sp() { }
127 DISALLOW_COPY_AND_ASSIGN (Cursor);
130 typedef std::shared_ptr<Cursor> CursorSP;
131 std::vector<CursorSP> m_frames;
132 CursorSP m_candidate_frame;
133 bool m_unwind_complete; // If this is true, we've enumerated all the frames in the stack, and m_frames.size() is the
134 // number of frames, etc. Otherwise we've only gone as far as directly asked, and m_frames.size()
135 // is how far we've currently gone.
137 std::vector<ConstString> m_user_supplied_trap_handler_functions;
139 //-----------------------------------------------------------------
140 // Check if Full UnwindPlan of First frame is valid or not.
141 // If not then try Fallback UnwindPlan of the frame. If Fallback
142 // UnwindPlan succeeds then update the Full UnwindPlan with the
143 // Fallback UnwindPlan.
144 //-----------------------------------------------------------------
146 UpdateUnwindPlanForFirstFrameIfInvalid (ABI* abi);
149 GetOneMoreFrame (ABI* abi);
152 AddOneMoreFrame (ABI *abi);
157 //------------------------------------------------------------------
158 // For UnwindLLDB only
159 //------------------------------------------------------------------
160 DISALLOW_COPY_AND_ASSIGN (UnwindLLDB);
163 } // namespace lldb_private
165 #endif // lldb_UnwindLLDB_h_