SymbolContextScope.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. //===-- SymbolContextScope.h ------------------------------------*- C++ -*-===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. #ifndef LLDB_SYMBOL_SYMBOLCONTEXTSCOPE_H
  9. #define LLDB_SYMBOL_SYMBOLCONTEXTSCOPE_H
  10. #include "lldb/lldb-private.h"
  11. namespace lldb_private {
  12. /// \class SymbolContextScope SymbolContextScope.h
  13. /// "lldb/Symbol/SymbolContextScope.h" Inherit from this if your object is
  14. /// part of a symbol context
  15. /// and can reconstruct its symbol context.
  16. ///
  17. /// Many objects that are part of a symbol context that have pointers back to
  18. /// parent objects that own them. Any members of a symbol context that, once
  19. /// they are built, will not go away, can inherit from this pure virtual class
  20. /// and can then reconstruct their symbol context without having to keep a
  21. /// complete SymbolContext object in the object.
  22. ///
  23. /// Examples of these objects include:
  24. /// \li Module
  25. /// \li CompileUnit
  26. /// \li Function
  27. /// \li Block
  28. /// \li Symbol
  29. ///
  30. /// Other objects can store a "SymbolContextScope *" using any pointers to one
  31. /// of the above objects. This allows clients to hold onto a pointer that
  32. /// uniquely will identify a symbol context. Those clients can then always
  33. /// reconstruct the symbol context using the pointer, or use it to uniquely
  34. /// identify a symbol context for an object.
  35. ///
  36. /// Example objects include that currently use "SymbolContextScope *" objects
  37. /// include:
  38. /// \li Variable objects that can reconstruct where they are scoped
  39. /// by making sure the SymbolContextScope * comes from the scope
  40. /// in which the variable was declared. If a variable is a global,
  41. /// the appropriate CompileUnit * will be used when creating the
  42. /// variable. A static function variables, can the Block scope
  43. /// in which the variable is defined. Function arguments can use
  44. /// the Function object as their scope. The SymbolFile parsers
  45. /// will set these correctly as the variables are parsed.
  46. /// \li Type objects that know exactly in which scope they
  47. /// originated much like the variables above.
  48. /// \li StackID objects that are able to know that if the CFA
  49. /// (stack pointer at the beginning of a function) and the
  50. /// start PC for the function/symbol and the SymbolContextScope
  51. /// pointer (a unique pointer that identifies a symbol context
  52. /// location) match within the same thread, that the stack
  53. /// frame is the same as the previous stack frame.
  54. ///
  55. /// Objects that adhere to this protocol can reconstruct enough of a symbol
  56. /// context to allow functions that take a symbol context to be called. Lists
  57. /// can also be created using a SymbolContextScope* and and object pairs that
  58. /// allow large collections of objects to be passed around with minimal
  59. /// overhead.
  60. class SymbolContextScope {
  61. public:
  62. virtual ~SymbolContextScope() = default;
  63. /// Reconstruct the object's symbol context into \a sc.
  64. ///
  65. /// The object should fill in as much of the SymbolContext as it can so
  66. /// function calls that require a symbol context can be made for the given
  67. /// object.
  68. ///
  69. /// \param[out] sc
  70. /// A symbol context object pointer that gets filled in.
  71. virtual void CalculateSymbolContext(SymbolContext *sc) = 0;
  72. virtual lldb::ModuleSP CalculateSymbolContextModule() {
  73. return lldb::ModuleSP();
  74. }
  75. virtual CompileUnit *CalculateSymbolContextCompileUnit() { return nullptr; }
  76. virtual Function *CalculateSymbolContextFunction() { return nullptr; }
  77. virtual Block *CalculateSymbolContextBlock() { return nullptr; }
  78. virtual Symbol *CalculateSymbolContextSymbol() { return nullptr; }
  79. /// Dump the object's symbol context to the stream \a s.
  80. ///
  81. /// The object should dump its symbol context to the stream \a s. This
  82. /// function is widely used in the DumpDebug and verbose output for lldb
  83. /// objects.
  84. ///
  85. /// \param[in] s
  86. /// The stream to which to dump the object's symbol context.
  87. virtual void DumpSymbolContext(Stream *s) = 0;
  88. };
  89. } // namespace lldb_private
  90. #endif // LLDB_SYMBOL_SYMBOLCONTEXTSCOPE_H