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/lldb-public.h"
16 #include "lldb/Core/ConstString.h"
17 #include "lldb/Symbol/FuncUnwinders.h"
18 #include "lldb/Symbol/UnwindPlan.h"
19 #include "lldb/Target/RegisterContext.h"
20 #include "lldb/Target/Unwind.h"
22 namespace lldb_private {
24 class RegisterContextLLDB;
26 class UnwindLLDB : public lldb_private::Unwind
29 UnwindLLDB (lldb_private::Thread &thread);
34 enum RegisterSearchResult
42 friend class lldb_private::RegisterContextLLDB;
44 struct RegisterLocation {
45 enum RegisterLocationTypes
47 eRegisterNotSaved = 0, // register was not preserved by callee. If volatile reg, is unavailable
48 eRegisterSavedAtMemoryLocation, // register is saved at a specific word of target mem (target_memory_location)
49 eRegisterInRegister, // register is available in a (possible other) register (register_number)
50 eRegisterSavedAtHostMemoryLocation, // register is saved at a word in lldb's address space
51 eRegisterValueInferred // register val was computed (and is in inferred_value)
56 lldb::addr_t target_memory_location;
57 uint32_t register_number; // in eRegisterKindLLDB register numbering system
58 void* host_memory_location;
59 uint64_t inferred_value; // eRegisterValueInferred - e.g. stack pointer == cfa + offset
67 m_unwind_complete = false;
74 DoGetFrameInfoAtIndex (uint32_t frame_idx,
76 lldb::addr_t& start_pc);
78 lldb::RegisterContextSP
79 DoCreateRegisterContextForFrame (lldb_private::StackFrame *frame);
81 typedef std::shared_ptr<RegisterContextLLDB> RegisterContextLLDBSP;
83 // Needed to retrieve the "next" frame (e.g. frame 2 needs to retrieve frame 1's RegisterContextLLDB)
84 // The RegisterContext for frame_num must already exist or this returns an empty shared pointer.
86 GetRegisterContextForFrameNum (uint32_t frame_num);
88 // Iterate over the RegisterContextLLDB's in our m_frames vector, look for the first one that
89 // has a saved location for this reg.
91 SearchForSavedLocationForRegister (uint32_t lldb_regnum, lldb_private::UnwindLLDB::RegisterLocation ®loc, uint32_t starting_frame_num, bool pc_register);
94 //------------------------------------------------------------------
95 /// Provide the list of user-specified trap handler functions
97 /// The Platform is one source of trap handler function names; that
98 /// may be augmented via a setting. The setting needs to be converted
99 /// into an array of ConstStrings before it can be used - we only want
100 /// to do that once per thread so it's here in the UnwindLLDB object.
103 /// Vector of ConstStrings of trap handler function names. May be
105 //------------------------------------------------------------------
106 const std::vector<ConstString> &
107 GetUserSpecifiedTrapHandlerFunctionNames ()
109 return m_user_supplied_trap_handler_functions;
116 lldb::addr_t start_pc; // The start address of the function/symbol for this 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 & provide to the StackFrame creation
119 RegisterContextLLDBSP reg_ctx_lldb_sp; // These are all RegisterContextLLDB's
121 Cursor () : start_pc (LLDB_INVALID_ADDRESS), cfa (LLDB_INVALID_ADDRESS), sctx(), reg_ctx_lldb_sp() { }
123 DISALLOW_COPY_AND_ASSIGN (Cursor);
126 typedef std::shared_ptr<Cursor> CursorSP;
127 std::vector<CursorSP> m_frames;
128 bool m_unwind_complete; // If this is true, we've enumerated all the frames in the stack, and m_frames.size() is the
129 // number of frames, etc. Otherwise we've only gone as far as directly asked, and m_frames.size()
130 // is how far we've currently gone.
132 std::vector<ConstString> m_user_supplied_trap_handler_functions;
134 bool AddOneMoreFrame (ABI *abi);
135 bool AddFirstFrame ();
137 //------------------------------------------------------------------
138 // For UnwindLLDB only
139 //------------------------------------------------------------------
140 DISALLOW_COPY_AND_ASSIGN (UnwindLLDB);
143 } // namespace lldb_private
145 #endif // lldb_UnwindLLDB_h_