StackID.h 3.2 KB

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