DWP.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. #ifndef LLVM_DWP_DWP_H
  7. #define LLVM_DWP_DWP_H
  8. #include "DWPStringPool.h"
  9. #include "llvm/ADT/ArrayRef.h"
  10. #include "llvm/ADT/MapVector.h"
  11. #include "llvm/ADT/StringRef.h"
  12. #include "llvm/DebugInfo/DWARF/DWARFContext.h"
  13. #include "llvm/DebugInfo/DWARF/DWARFUnitIndex.h"
  14. #include "llvm/MC/MCSection.h"
  15. #include "llvm/MC/MCStreamer.h"
  16. #include "llvm/Object/ObjectFile.h"
  17. #include "llvm/Support/Error.h"
  18. #include <deque>
  19. #include <vector>
  20. namespace llvm {
  21. struct UnitIndexEntry {
  22. DWARFUnitIndex::Entry::SectionContribution Contributions[8];
  23. std::string Name;
  24. std::string DWOName;
  25. StringRef DWPName;
  26. };
  27. // Holds data for Skeleton, Split Compilation, and Type Unit Headers (only in
  28. // v5) as defined in Dwarf 5 specification, 7.5.1.2, 7.5.1.3 and Dwarf 4
  29. // specification 7.5.1.1.
  30. struct InfoSectionUnitHeader {
  31. // unit_length field. Note that the type is uint64_t even in 32-bit dwarf.
  32. uint64_t Length = 0;
  33. // version field.
  34. uint16_t Version = 0;
  35. // unit_type field. Initialized only if Version >= 5.
  36. uint8_t UnitType = 0;
  37. // address_size field.
  38. uint8_t AddrSize = 0;
  39. // debug_abbrev_offset field. Note that the type is uint64_t even in 32-bit
  40. // dwarf. It is assumed to be 0.
  41. uint64_t DebugAbbrevOffset = 0;
  42. // dwo_id field. This resides in the header only if Version >= 5.
  43. // In earlier versions, it is read from DW_AT_GNU_dwo_id.
  44. std::optional<uint64_t> Signature;
  45. // Derived from the length of Length field.
  46. dwarf::DwarfFormat Format = dwarf::DwarfFormat::DWARF32;
  47. // The size of the Header in bytes. This is derived while parsing the header,
  48. // and is stored as a convenience.
  49. uint8_t HeaderSize = 0;
  50. };
  51. struct CompileUnitIdentifiers {
  52. uint64_t Signature = 0;
  53. const char *Name = "";
  54. const char *DWOName = "";
  55. };
  56. Error write(MCStreamer &Out, ArrayRef<std::string> Inputs);
  57. unsigned getContributionIndex(DWARFSectionKind Kind, uint32_t IndexVersion);
  58. Error handleSection(
  59. const StringMap<std::pair<MCSection *, DWARFSectionKind>> &KnownSections,
  60. const MCSection *StrSection, const MCSection *StrOffsetSection,
  61. const MCSection *TypesSection, const MCSection *CUIndexSection,
  62. const MCSection *TUIndexSection, const MCSection *InfoSection,
  63. const object::SectionRef &Section, MCStreamer &Out,
  64. std::deque<SmallString<32>> &UncompressedSections,
  65. uint32_t (&ContributionOffsets)[8], UnitIndexEntry &CurEntry,
  66. StringRef &CurStrSection, StringRef &CurStrOffsetSection,
  67. std::vector<StringRef> &CurTypesSection,
  68. std::vector<StringRef> &CurInfoSection, StringRef &AbbrevSection,
  69. StringRef &CurCUIndexSection, StringRef &CurTUIndexSection,
  70. std::vector<std::pair<DWARFSectionKind, uint32_t>> &SectionLength);
  71. Expected<InfoSectionUnitHeader> parseInfoSectionUnitHeader(StringRef Info);
  72. void writeStringsAndOffsets(MCStreamer &Out, DWPStringPool &Strings,
  73. MCSection *StrOffsetSection,
  74. StringRef CurStrSection,
  75. StringRef CurStrOffsetSection, uint16_t Version);
  76. Error buildDuplicateError(const std::pair<uint64_t, UnitIndexEntry> &PrevE,
  77. const CompileUnitIdentifiers &ID, StringRef DWPName);
  78. void writeIndex(MCStreamer &Out, MCSection *Section,
  79. ArrayRef<unsigned> ContributionOffsets,
  80. const MapVector<uint64_t, UnitIndexEntry> &IndexEntries,
  81. uint32_t IndexVersion);
  82. } // namespace llvm
  83. #endif // LLVM_DWP_DWP_H
  84. #ifdef __GNUC__
  85. #pragma GCC diagnostic pop
  86. #endif