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