1 //===-- StackID.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 liblldb_StackID_h_ 11 #define liblldb_StackID_h_ 12 13 #include "lldb/Core/AddressRange.h" 14 #include "lldb/lldb-private.h" 15 16 namespace lldb_private { 17 18 class StackID { 19 public: 20 //------------------------------------------------------------------ 21 // Constructors and Destructors 22 //------------------------------------------------------------------ StackID()23 StackID() 24 : m_pc(LLDB_INVALID_ADDRESS), m_cfa(LLDB_INVALID_ADDRESS), 25 m_symbol_scope(nullptr) {} 26 StackID(lldb::addr_t pc,lldb::addr_t cfa,SymbolContextScope * symbol_scope)27 explicit StackID(lldb::addr_t pc, lldb::addr_t cfa, 28 SymbolContextScope *symbol_scope) 29 : m_pc(pc), m_cfa(cfa), m_symbol_scope(symbol_scope) {} 30 StackID(const StackID & rhs)31 StackID(const StackID &rhs) 32 : m_pc(rhs.m_pc), m_cfa(rhs.m_cfa), m_symbol_scope(rhs.m_symbol_scope) {} 33 34 ~StackID() = default; 35 GetPC()36 lldb::addr_t GetPC() const { return m_pc; } 37 GetCallFrameAddress()38 lldb::addr_t GetCallFrameAddress() const { return m_cfa; } 39 GetSymbolContextScope()40 SymbolContextScope *GetSymbolContextScope() const { return m_symbol_scope; } 41 SetSymbolContextScope(SymbolContextScope * symbol_scope)42 void SetSymbolContextScope(SymbolContextScope *symbol_scope) { 43 m_symbol_scope = symbol_scope; 44 } 45 Clear()46 void Clear() { 47 m_pc = LLDB_INVALID_ADDRESS; 48 m_cfa = LLDB_INVALID_ADDRESS; 49 m_symbol_scope = nullptr; 50 } 51 IsValid()52 bool IsValid() const { 53 return m_pc != LLDB_INVALID_ADDRESS || m_cfa != LLDB_INVALID_ADDRESS; 54 } 55 56 void Dump(Stream *s); 57 58 //------------------------------------------------------------------ 59 // Operators 60 //------------------------------------------------------------------ 61 const StackID &operator=(const StackID &rhs) { 62 if (this != &rhs) { 63 m_pc = rhs.m_pc; 64 m_cfa = rhs.m_cfa; 65 m_symbol_scope = rhs.m_symbol_scope; 66 } 67 return *this; 68 } 69 70 protected: 71 friend class StackFrame; 72 SetPC(lldb::addr_t pc)73 void SetPC(lldb::addr_t pc) { m_pc = pc; } 74 SetCFA(lldb::addr_t cfa)75 void SetCFA(lldb::addr_t cfa) { m_cfa = cfa; } 76 77 lldb::addr_t 78 m_pc; // The pc value for the function/symbol for this frame. This will 79 // only get used if the symbol scope is nullptr (the code where we are 80 // stopped is not represented by any function or symbol in any shared 81 // library). 82 lldb::addr_t m_cfa; // The call frame address (stack pointer) value 83 // at the beginning of the function that uniquely 84 // identifies this frame (along with m_symbol_scope 85 // below) 86 SymbolContextScope * 87 m_symbol_scope; // If nullptr, there is no block or symbol for this frame. 88 // If not nullptr, this will either be the scope for the 89 // lexical block for the frame, or the scope for the 90 // symbol. Symbol context scopes are always be unique 91 // pointers since the are part of the Block and Symbol 92 // objects and can easily be used to tell if a stack ID 93 // is the same as another. 94 }; 95 96 bool operator==(const StackID &lhs, const StackID &rhs); 97 bool operator!=(const StackID &lhs, const StackID &rhs); 98 99 // frame_id_1 < frame_id_2 means "frame_id_1 is YOUNGER than frame_id_2" 100 bool operator<(const StackID &lhs, const StackID &rhs); 101 102 } // namespace lldb_private 103 104 #endif // liblldb_StackID_h_ 105