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/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" 21 22 namespace lldb_private { 23 24 class RegisterContextLLDB; 25 26 class UnwindLLDB : public lldb_private::Unwind 27 { 28 public: 29 UnwindLLDB (lldb_private::Thread &thread); 30 31 virtual ~UnwindLLDB()32 ~UnwindLLDB() { } 33 34 enum RegisterSearchResult 35 { 36 eRegisterFound = 0, 37 eRegisterNotFound, 38 eRegisterIsVolatile 39 }; 40 41 protected: 42 friend class lldb_private::RegisterContextLLDB; 43 44 struct RegisterLocation { 45 enum RegisterLocationTypes 46 { 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) 52 eRegisterInLiveRegisterContext // register value is in a live (stack frame #0) register 53 }; 54 int type; 55 union 56 { 57 lldb::addr_t target_memory_location; 58 uint32_t register_number; // in eRegisterKindLLDB register numbering system 59 void* host_memory_location; 60 uint64_t inferred_value; // eRegisterValueInferred - e.g. stack pointer == cfa + offset 61 } location; 62 }; 63 64 void DoClear()65 DoClear() 66 { 67 m_frames.clear(); 68 m_candidate_frame.reset(); 69 m_unwind_complete = false; 70 } 71 72 virtual uint32_t 73 DoGetFrameCount(); 74 75 bool 76 DoGetFrameInfoAtIndex (uint32_t frame_idx, 77 lldb::addr_t& cfa, 78 lldb::addr_t& start_pc); 79 80 lldb::RegisterContextSP 81 DoCreateRegisterContextForFrame (lldb_private::StackFrame *frame); 82 83 typedef std::shared_ptr<RegisterContextLLDB> RegisterContextLLDBSP; 84 85 // Needed to retrieve the "next" frame (e.g. frame 2 needs to retrieve frame 1's RegisterContextLLDB) 86 // The RegisterContext for frame_num must already exist or this returns an empty shared pointer. 87 RegisterContextLLDBSP 88 GetRegisterContextForFrameNum (uint32_t frame_num); 89 90 // Iterate over the RegisterContextLLDB's in our m_frames vector, look for the first one that 91 // has a saved location for this reg. 92 bool 93 SearchForSavedLocationForRegister (uint32_t lldb_regnum, lldb_private::UnwindLLDB::RegisterLocation ®loc, uint32_t starting_frame_num, bool pc_register); 94 95 96 //------------------------------------------------------------------ 97 /// Provide the list of user-specified trap handler functions 98 /// 99 /// The Platform is one source of trap handler function names; that 100 /// may be augmented via a setting. The setting needs to be converted 101 /// into an array of ConstStrings before it can be used - we only want 102 /// to do that once per thread so it's here in the UnwindLLDB object. 103 /// 104 /// @return 105 /// Vector of ConstStrings of trap handler function names. May be 106 /// empty. 107 //------------------------------------------------------------------ 108 const std::vector<ConstString> & GetUserSpecifiedTrapHandlerFunctionNames()109 GetUserSpecifiedTrapHandlerFunctionNames () 110 { 111 return m_user_supplied_trap_handler_functions; 112 } 113 114 private: 115 116 struct Cursor 117 { 118 lldb::addr_t start_pc; // The start address of the function/symbol for this frame - current pc if unknown 119 lldb::addr_t cfa; // The canonical frame address for this stack frame 120 lldb_private::SymbolContext sctx; // A symbol context we'll contribute to & provide to the StackFrame creation 121 RegisterContextLLDBSP reg_ctx_lldb_sp; // These are all RegisterContextLLDB's 122 CursorCursor123 Cursor () : start_pc (LLDB_INVALID_ADDRESS), cfa (LLDB_INVALID_ADDRESS), sctx(), reg_ctx_lldb_sp() { } 124 private: 125 DISALLOW_COPY_AND_ASSIGN (Cursor); 126 }; 127 128 typedef std::shared_ptr<Cursor> CursorSP; 129 std::vector<CursorSP> m_frames; 130 CursorSP m_candidate_frame; 131 bool m_unwind_complete; // If this is true, we've enumerated all the frames in the stack, and m_frames.size() is the 132 // number of frames, etc. Otherwise we've only gone as far as directly asked, and m_frames.size() 133 // is how far we've currently gone. 134 135 std::vector<ConstString> m_user_supplied_trap_handler_functions; 136 137 CursorSP 138 GetOneMoreFrame (ABI* abi); 139 140 bool 141 AddOneMoreFrame (ABI *abi); 142 143 bool 144 AddFirstFrame (); 145 146 //------------------------------------------------------------------ 147 // For UnwindLLDB only 148 //------------------------------------------------------------------ 149 DISALLOW_COPY_AND_ASSIGN (UnwindLLDB); 150 }; 151 152 } // namespace lldb_private 153 154 #endif // lldb_UnwindLLDB_h_ 155