Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

141 lines
4.2 KiB

  1. //===-- DIContext.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. // This file defines DIContext, an abstract data structure that holds
  11. // debug information data.
  12. //
  13. //===----------------------------------------------------------------------===//
  14. #ifndef LLVM_DEBUGINFO_DICONTEXT_H
  15. #define LLVM_DEBUGINFO_DICONTEXT_H
  16. #include "llvm/ADT/DenseMap.h"
  17. #include "llvm/ADT/SmallString.h"
  18. #include "llvm/ADT/SmallVector.h"
  19. #include "llvm/ADT/StringRef.h"
  20. #include "llvm/Object/ObjectFile.h"
  21. #include "llvm/Object/RelocVisitor.h"
  22. #include "llvm/Support/DataTypes.h"
  23. namespace llvm {
  24. class raw_ostream;
  25. /// DILineInfo - a format-neutral container for source line information.
  26. class DILineInfo {
  27. SmallString<16> FileName;
  28. SmallString<16> FunctionName;
  29. uint32_t Line;
  30. uint32_t Column;
  31. public:
  32. DILineInfo()
  33. : FileName("<invalid>"), FunctionName("<invalid>"),
  34. Line(0), Column(0) {}
  35. DILineInfo(const SmallString<16> &fileName,
  36. const SmallString<16> &functionName,
  37. uint32_t line, uint32_t column)
  38. : FileName(fileName), FunctionName(functionName),
  39. Line(line), Column(column) {}
  40. const char *getFileName() { return FileName.c_str(); }
  41. const char *getFunctionName() { return FunctionName.c_str(); }
  42. uint32_t getLine() const { return Line; }
  43. uint32_t getColumn() const { return Column; }
  44. bool operator==(const DILineInfo &RHS) const {
  45. return Line == RHS.Line && Column == RHS.Column &&
  46. FileName.equals(RHS.FileName) &&
  47. FunctionName.equals(RHS.FunctionName);
  48. }
  49. bool operator!=(const DILineInfo &RHS) const {
  50. return !(*this == RHS);
  51. }
  52. };
  53. typedef SmallVector<std::pair<uint64_t, DILineInfo>, 16> DILineInfoTable;
  54. /// DIInliningInfo - a format-neutral container for inlined code description.
  55. class DIInliningInfo {
  56. SmallVector<DILineInfo, 4> Frames;
  57. public:
  58. DIInliningInfo() {}
  59. DILineInfo getFrame(unsigned Index) const {
  60. assert(Index < Frames.size());
  61. return Frames[Index];
  62. }
  63. uint32_t getNumberOfFrames() const {
  64. return Frames.size();
  65. }
  66. void addFrame(const DILineInfo &Frame) {
  67. Frames.push_back(Frame);
  68. }
  69. };
  70. /// DILineInfoSpecifier - controls which fields of DILineInfo container
  71. /// should be filled with data.
  72. class DILineInfoSpecifier {
  73. const uint32_t Flags; // Or'ed flags that set the info we want to fetch.
  74. public:
  75. enum Specification {
  76. FileLineInfo = 1 << 0,
  77. AbsoluteFilePath = 1 << 1,
  78. FunctionName = 1 << 2
  79. };
  80. // Use file/line info by default.
  81. DILineInfoSpecifier(uint32_t flags = FileLineInfo) : Flags(flags) {}
  82. bool needs(Specification spec) const {
  83. return (Flags & spec) > 0;
  84. }
  85. };
  86. /// Selects which debug sections get dumped.
  87. enum DIDumpType {
  88. DIDT_Null,
  89. DIDT_All,
  90. DIDT_Abbrev,
  91. DIDT_AbbrevDwo,
  92. DIDT_Aranges,
  93. DIDT_Frames,
  94. DIDT_Info,
  95. DIDT_InfoDwo,
  96. DIDT_Line,
  97. DIDT_Ranges,
  98. DIDT_Pubnames,
  99. DIDT_Str,
  100. DIDT_StrDwo,
  101. DIDT_StrOffsetsDwo
  102. };
  103. // In place of applying the relocations to the data we've read from disk we use
  104. // a separate mapping table to the side and checking that at locations in the
  105. // dwarf where we expect relocated values. This adds a bit of complexity to the
  106. // dwarf parsing/extraction at the benefit of not allocating memory for the
  107. // entire size of the debug info sections.
  108. typedef DenseMap<uint64_t, std::pair<uint8_t, int64_t> > RelocAddrMap;
  109. class DIContext {
  110. public:
  111. virtual ~DIContext();
  112. /// getDWARFContext - get a context for binary DWARF data.
  113. static DIContext *getDWARFContext(object::ObjectFile *);
  114. virtual void dump(raw_ostream &OS, DIDumpType DumpType = DIDT_All) = 0;
  115. virtual DILineInfo getLineInfoForAddress(uint64_t Address,
  116. DILineInfoSpecifier Specifier = DILineInfoSpecifier()) = 0;
  117. virtual DILineInfoTable getLineInfoForAddressRange(uint64_t Address,
  118. uint64_t Size, DILineInfoSpecifier Specifier = DILineInfoSpecifier()) = 0;
  119. virtual DIInliningInfo getInliningInfoForAddress(uint64_t Address,
  120. DILineInfoSpecifier Specifier = DILineInfoSpecifier()) = 0;
  121. };
  122. }
  123. #endif