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