DwarfFile.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. //===-- llvm/CodeGen/DwarfFile.h - Dwarf Debug Framework -------*- 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. #ifndef LLVM_LIB_CODEGEN_ASMPRINTER_DWARFFILE_H
  10. #define LLVM_LIB_CODEGEN_ASMPRINTER_DWARFFILE_H
  11. #include "AddressPool.h"
  12. #include "DwarfStringPool.h"
  13. #include "llvm/ADT/DenseMap.h"
  14. #include "llvm/ADT/FoldingSet.h"
  15. #include "llvm/ADT/SmallVector.h"
  16. #include "llvm/ADT/StringMap.h"
  17. #include "llvm/Support/Allocator.h"
  18. #include <memory>
  19. #include <string>
  20. #include <vector>
  21. namespace llvm {
  22. class AsmPrinter;
  23. class DbgVariable;
  24. class DwarfUnit;
  25. class DIEAbbrev;
  26. class MCSymbol;
  27. class DIE;
  28. class LexicalScope;
  29. class StringRef;
  30. class DwarfDebug;
  31. class MCSection;
  32. class MDNode;
  33. class DwarfFile {
  34. // Target of Dwarf emission, used for sizing of abbreviations.
  35. AsmPrinter *Asm;
  36. BumpPtrAllocator AbbrevAllocator;
  37. // Used to uniquely define abbreviations.
  38. FoldingSet<DIEAbbrev> AbbreviationsSet;
  39. // A list of all the unique abbreviations in use.
  40. std::vector<DIEAbbrev *> Abbreviations;
  41. // A pointer to all units in the section.
  42. SmallVector<std::unique_ptr<DwarfUnit>, 1> CUs;
  43. DwarfStringPool StrPool;
  44. // Collection of dbg variables of a scope.
  45. DenseMap<LexicalScope *, SmallVector<DbgVariable *, 8>> ScopeVariables;
  46. // Collection of abstract subprogram DIEs.
  47. DenseMap<const MDNode *, DIE *> AbstractSPDies;
  48. /// Maps MDNodes for type system with the corresponding DIEs. These DIEs can
  49. /// be shared across CUs, that is why we keep the map here instead
  50. /// of in DwarfCompileUnit.
  51. DenseMap<const MDNode *, DIE *> DITypeNodeToDieMap;
  52. public:
  53. DwarfFile(AsmPrinter *AP, StringRef Pref, BumpPtrAllocator &DA);
  54. ~DwarfFile();
  55. const SmallVectorImpl<std::unique_ptr<DwarfUnit>> &getUnits() { return CUs; }
  56. /// \brief Compute the size and offset of a DIE given an incoming Offset.
  57. unsigned computeSizeAndOffset(DIE &Die, unsigned Offset);
  58. /// \brief Compute the size and offset of all the DIEs.
  59. void computeSizeAndOffsets();
  60. /// Define a unique number for the abbreviation.
  61. ///
  62. /// Compute the abbreviation for \c Die, look up its unique number, and
  63. /// return a reference to it in the uniquing table.
  64. DIEAbbrev &assignAbbrevNumber(DIE &Die);
  65. /// \brief Add a unit to the list of CUs.
  66. void addUnit(std::unique_ptr<DwarfUnit> U);
  67. /// \brief Emit all of the units to the section listed with the given
  68. /// abbreviation section.
  69. void emitUnits(bool UseOffsets);
  70. /// \brief Emit a set of abbreviations to the specific section.
  71. void emitAbbrevs(MCSection *);
  72. /// \brief Emit all of the strings to the section given.
  73. void emitStrings(MCSection *StrSection, MCSection *OffsetSection = nullptr);
  74. /// \brief Returns the string pool.
  75. DwarfStringPool &getStringPool() { return StrPool; }
  76. /// \returns false if the variable was merged with a previous one.
  77. bool addScopeVariable(LexicalScope *LS, DbgVariable *Var);
  78. DenseMap<LexicalScope *, SmallVector<DbgVariable *, 8>> &getScopeVariables() {
  79. return ScopeVariables;
  80. }
  81. DenseMap<const MDNode *, DIE *> &getAbstractSPDies() {
  82. return AbstractSPDies;
  83. }
  84. void insertDIE(const MDNode *TypeMD, DIE *Die) {
  85. DITypeNodeToDieMap.insert(std::make_pair(TypeMD, Die));
  86. }
  87. DIE *getDIE(const MDNode *TypeMD) {
  88. return DITypeNodeToDieMap.lookup(TypeMD);
  89. }
  90. };
  91. }
  92. #endif