DebugLoc.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. //===- DebugLoc.h - Debug Location Information ------------------*- 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. // This file defines a number of light weight data structures used
  11. // to describe and track debug location information.
  12. //
  13. //===----------------------------------------------------------------------===//
  14. #ifndef LLVM_IR_DEBUGLOC_H
  15. #define LLVM_IR_DEBUGLOC_H
  16. #include "llvm/IR/TrackingMDRef.h"
  17. #include "llvm/Support/DataTypes.h"
  18. namespace llvm {
  19. class LLVMContext;
  20. class raw_ostream;
  21. class DILocation;
  22. /// \brief A debug info location.
  23. ///
  24. /// This class is a wrapper around a tracking reference to an \a DILocation
  25. /// pointer.
  26. ///
  27. /// To avoid extra includes, \a DebugLoc doubles the \a DILocation API with a
  28. /// one based on relatively opaque \a MDNode pointers.
  29. class DebugLoc {
  30. TrackingMDNodeRef Loc;
  31. public:
  32. DebugLoc() {}
  33. DebugLoc(DebugLoc &&X) : Loc(std::move(X.Loc)) {}
  34. DebugLoc(const DebugLoc &X) : Loc(X.Loc) {}
  35. DebugLoc &operator=(DebugLoc &&X) {
  36. Loc = std::move(X.Loc);
  37. return *this;
  38. }
  39. DebugLoc &operator=(const DebugLoc &X) {
  40. Loc = X.Loc;
  41. return *this;
  42. }
  43. /// \brief Construct from an \a DILocation.
  44. DebugLoc(const DILocation *L);
  45. /// \brief Construct from an \a MDNode.
  46. ///
  47. /// Note: if \c N is not an \a DILocation, a verifier check will fail, and
  48. /// accessors will crash. However, construction from other nodes is
  49. /// supported in order to handle forward references when reading textual
  50. /// IR.
  51. explicit DebugLoc(const MDNode *N);
  52. /// \brief Get the underlying \a DILocation.
  53. ///
  54. /// \pre !*this or \c isa<DILocation>(getAsMDNode()).
  55. /// @{
  56. DILocation *get() const;
  57. operator DILocation *() const { return get(); }
  58. DILocation *operator->() const { return get(); }
  59. DILocation &operator*() const { return *get(); }
  60. /// @}
  61. /// \brief Check for null.
  62. ///
  63. /// Check for null in a way that is safe with broken debug info. Unlike
  64. /// the conversion to \c DILocation, this doesn't require that \c Loc is of
  65. /// the right type. Important for cases like \a llvm::StripDebugInfo() and
  66. /// \a Instruction::hasMetadata().
  67. explicit operator bool() const { return Loc; }
  68. /// \brief Check whether this has a trivial destructor.
  69. bool hasTrivialDestructor() const { return Loc.hasTrivialDestructor(); }
  70. /// \brief Create a new DebugLoc.
  71. ///
  72. /// Create a new DebugLoc at the specified line/col and scope/inline. This
  73. /// forwards to \a DILocation::get().
  74. ///
  75. /// If \c !Scope, returns a default-constructed \a DebugLoc.
  76. ///
  77. /// FIXME: Remove this. Users should use DILocation::get().
  78. static DebugLoc get(unsigned Line, unsigned Col, const MDNode *Scope,
  79. const MDNode *InlinedAt = nullptr);
  80. unsigned getLine() const;
  81. unsigned getCol() const;
  82. MDNode *getScope() const;
  83. DILocation *getInlinedAt() const;
  84. /// \brief Get the fully inlined-at scope for a DebugLoc.
  85. ///
  86. /// Gets the inlined-at scope for a DebugLoc.
  87. MDNode *getInlinedAtScope() const;
  88. /// \brief Find the debug info location for the start of the function.
  89. ///
  90. /// Walk up the scope chain of given debug loc and find line number info
  91. /// for the function.
  92. ///
  93. /// FIXME: Remove this. Users should use DILocation/DILocalScope API to
  94. /// find the subprogram, and then DILocation::get().
  95. DebugLoc getFnDebugLoc() const;
  96. /// \brief Return \c this as a bar \a MDNode.
  97. MDNode *getAsMDNode() const { return Loc; }
  98. bool operator==(const DebugLoc &DL) const { return Loc == DL.Loc; }
  99. bool operator!=(const DebugLoc &DL) const { return Loc != DL.Loc; }
  100. void dump() const;
  101. /// \brief prints source location /path/to/file.exe:line:col @[inlined at]
  102. void print(raw_ostream &OS) const;
  103. };
  104. } // end namespace llvm
  105. #endif /* LLVM_SUPPORT_DEBUGLOC_H */