SymbolContextScope.h revision 296417
1//===-- SymbolContextScope.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_SymbolContextScope_h_ 11#define liblldb_SymbolContextScope_h_ 12 13// C Includes 14// C++ Includes 15// Other libraries and framework includes 16// Project includes 17#include "lldb/lldb-private.h" 18 19namespace lldb_private { 20 21//---------------------------------------------------------------------- 22/// @class SymbolContextScope SymbolContextScope.h "lldb/Symbol/SymbolContextScope.h" 23/// @brief Inherit from this if your object is part of a symbol context 24/// and can reconstruct its symbol context. 25/// 26/// Many objects that are part of a symbol context that have pointers 27/// back to parent objects that own them. Any members of a symbol 28/// context that, once they are built, will not go away, can inherit 29/// from this pure virtual class and can then reconstruct their symbol 30/// context without having to keep a complete SymbolContext object in 31/// the object. 32/// 33/// Examples of these objects include: 34/// @li Module 35/// @li CompileUnit 36/// @li Function 37/// @li Block 38/// @li Symbol 39/// 40/// Other objects can store a "SymbolContextScope *" using any pointers 41/// to one of the above objects. This allows clients to hold onto a 42/// pointer that uniquely will identify a symbol context. Those clients 43/// can then always reconstruct the symbol context using the pointer, or 44/// use it to uniquely identify a symbol context for an object. 45/// 46/// Example objects include that currently use "SymbolContextScope *" 47/// objects include: 48/// @li Variable objects that can reconstruct where they are scoped 49/// by making sure the SymbolContextScope * comes from the scope 50/// in which the variable was declared. If a variable is a global, 51/// the appropriate CompileUnit * will be used when creating the 52/// variable. A static function variables, can the Block scope 53/// in which the variable is defined. Function arguments can use 54/// the Function object as their scope. The SymbolFile parsers 55/// will set these correctly as the variables are parsed. 56/// @li Type objects that know exactly in which scope they 57/// originated much like the variables above. 58/// @li StackID objects that are able to know that if the CFA 59/// (stack pointer at the beginning of a function) and the 60/// start PC for the function/symbol and the SymbolContextScope 61/// pointer (a unique pointer that identifies a symbol context 62/// location) match within the same thread, that the stack 63/// frame is the same as the previous stack frame. 64/// 65/// Objects that adhere to this protocol can reconstruct enough of a 66/// symbol context to allow functions that take a symbol context to be 67/// called. Lists can also be created using a SymbolContextScope* and 68/// and object pairs that allow large collections of objects to be 69/// passed around with minimal overhead. 70//---------------------------------------------------------------------- 71class SymbolContextScope 72{ 73public: 74 virtual 75 ~SymbolContextScope() = default; 76 77 //------------------------------------------------------------------ 78 /// Reconstruct the object's symbol context into \a sc. 79 /// 80 /// The object should fill in as much of the SymbolContext as it 81 /// can so function calls that require a symbol context can be made 82 /// for the given object. 83 /// 84 /// @param[out] sc 85 /// A symbol context object pointer that gets filled in. 86 //------------------------------------------------------------------ 87 virtual void 88 CalculateSymbolContext (SymbolContext *sc) = 0; 89 90 virtual lldb::ModuleSP 91 CalculateSymbolContextModule () 92 { 93 return lldb::ModuleSP(); 94 } 95 96 virtual CompileUnit * 97 CalculateSymbolContextCompileUnit () 98 { 99 return nullptr; 100 } 101 102 virtual Function * 103 CalculateSymbolContextFunction () 104 { 105 return nullptr; 106 } 107 108 virtual Block * 109 CalculateSymbolContextBlock () 110 { 111 return nullptr; 112 } 113 114 virtual Symbol * 115 CalculateSymbolContextSymbol () 116 { 117 return nullptr; 118 } 119 120 //------------------------------------------------------------------ 121 /// Dump the object's symbol context to the stream \a s. 122 /// 123 /// The object should dump its symbol context to the stream \a s. 124 /// This function is widely used in the DumpDebug and verbose output 125 /// for lldb objects. 126 /// 127 /// @param[in] s 128 /// The stream to which to dump the object's symbol context. 129 //------------------------------------------------------------------ 130 virtual void 131 DumpSymbolContext (Stream *s) = 0; 132}; 133 134} // namespace lldb_private 135 136#endif // liblldb_SymbolContextScope_h_ 137