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