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/Symbol/FuncUnwinders.h"
17 #include "lldb/Symbol/UnwindPlan.h"
18 #include "lldb/Target/RegisterContext.h"
19 #include "lldb/Target/Unwind.h"
21 namespace lldb_private {
23 class RegisterContextLLDB;
25 class UnwindLLDB : public lldb_private::Unwind
28 UnwindLLDB (lldb_private::Thread &thread);
33 enum RegisterSearchResult
41 friend class lldb_private::RegisterContextLLDB;
43 struct RegisterLocation {
44 enum RegisterLocationTypes
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)
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
66 m_unwind_complete = false;
73 DoGetFrameInfoAtIndex (uint32_t frame_idx,
75 lldb::addr_t& start_pc);
77 lldb::RegisterContextSP
78 DoCreateRegisterContextForFrame (lldb_private::StackFrame *frame);
80 typedef std::shared_ptr<RegisterContextLLDB> RegisterContextLLDBSP;
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.
85 GetRegisterContextForFrameNum (uint32_t frame_num);
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.
90 SearchForSavedLocationForRegister (uint32_t lldb_regnum, lldb_private::UnwindLLDB::RegisterLocation ®loc, uint32_t starting_frame_num, bool pc_register);
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
102 Cursor () : start_pc (LLDB_INVALID_ADDRESS), cfa (LLDB_INVALID_ADDRESS), sctx(), reg_ctx_lldb_sp() { }
104 DISALLOW_COPY_AND_ASSIGN (Cursor);
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.
114 bool AddOneMoreFrame (ABI *abi);
115 bool AddFirstFrame ();
117 //------------------------------------------------------------------
118 // For UnwindLLDB only
119 //------------------------------------------------------------------
120 DISALLOW_COPY_AND_ASSIGN (UnwindLLDB);
123 } // namespace lldb_private
125 #endif // lldb_UnwindLLDB_h_