Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:43:49

0001 #ifndef LLVM_DWP_DWP_H
0002 #define LLVM_DWP_DWP_H
0003 
0004 #include "DWPStringPool.h"
0005 #include "llvm/ADT/ArrayRef.h"
0006 #include "llvm/ADT/MapVector.h"
0007 #include "llvm/ADT/StringRef.h"
0008 #include "llvm/DebugInfo/DWARF/DWARFContext.h"
0009 #include "llvm/DebugInfo/DWARF/DWARFUnitIndex.h"
0010 #include "llvm/MC/MCSection.h"
0011 #include "llvm/MC/MCStreamer.h"
0012 #include "llvm/Object/ObjectFile.h"
0013 #include "llvm/Support/Error.h"
0014 #include <deque>
0015 #include <vector>
0016 
0017 namespace llvm {
0018 enum OnCuIndexOverflow {
0019   HardStop,
0020   SoftStop,
0021   Continue,
0022 };
0023 
0024 struct UnitIndexEntry {
0025   DWARFUnitIndex::Entry::SectionContribution Contributions[8];
0026   std::string Name;
0027   std::string DWOName;
0028   StringRef DWPName;
0029 };
0030 
0031 // Holds data for Skeleton, Split Compilation, and Type Unit Headers (only in
0032 // v5) as defined in Dwarf 5 specification, 7.5.1.2, 7.5.1.3 and Dwarf 4
0033 // specification 7.5.1.1.
0034 struct InfoSectionUnitHeader {
0035   // unit_length field. Note that the type is uint64_t even in 32-bit dwarf.
0036   uint64_t Length = 0;
0037 
0038   // version field.
0039   uint16_t Version = 0;
0040 
0041   // unit_type field. Initialized only if Version >= 5.
0042   uint8_t UnitType = 0;
0043 
0044   // address_size field.
0045   uint8_t AddrSize = 0;
0046 
0047   // debug_abbrev_offset field. Note that the type is uint64_t even in 32-bit
0048   // dwarf. It is assumed to be 0.
0049   uint64_t DebugAbbrevOffset = 0;
0050 
0051   // dwo_id field. This resides in the header only if Version >= 5.
0052   // In earlier versions, it is read from DW_AT_GNU_dwo_id.
0053   std::optional<uint64_t> Signature;
0054 
0055   // Derived from the length of Length field.
0056   dwarf::DwarfFormat Format = dwarf::DwarfFormat::DWARF32;
0057 
0058   // The size of the Header in bytes. This is derived while parsing the header,
0059   // and is stored as a convenience.
0060   uint8_t HeaderSize = 0;
0061 };
0062 
0063 struct CompileUnitIdentifiers {
0064   uint64_t Signature = 0;
0065   const char *Name = "";
0066   const char *DWOName = "";
0067 };
0068 
0069 Error write(MCStreamer &Out, ArrayRef<std::string> Inputs,
0070             OnCuIndexOverflow OverflowOptValue);
0071 
0072 unsigned getContributionIndex(DWARFSectionKind Kind, uint32_t IndexVersion);
0073 
0074 Error handleSection(
0075     const StringMap<std::pair<MCSection *, DWARFSectionKind>> &KnownSections,
0076     const MCSection *StrSection, const MCSection *StrOffsetSection,
0077     const MCSection *TypesSection, const MCSection *CUIndexSection,
0078     const MCSection *TUIndexSection, const MCSection *InfoSection,
0079     const object::SectionRef &Section, MCStreamer &Out,
0080     std::deque<SmallString<32>> &UncompressedSections,
0081     uint32_t (&ContributionOffsets)[8], UnitIndexEntry &CurEntry,
0082     StringRef &CurStrSection, StringRef &CurStrOffsetSection,
0083     std::vector<StringRef> &CurTypesSection,
0084     std::vector<StringRef> &CurInfoSection, StringRef &AbbrevSection,
0085     StringRef &CurCUIndexSection, StringRef &CurTUIndexSection,
0086     std::vector<std::pair<DWARFSectionKind, uint32_t>> &SectionLength);
0087 
0088 Expected<InfoSectionUnitHeader> parseInfoSectionUnitHeader(StringRef Info);
0089 
0090 void writeStringsAndOffsets(MCStreamer &Out, DWPStringPool &Strings,
0091                             MCSection *StrOffsetSection,
0092                             StringRef CurStrSection,
0093                             StringRef CurStrOffsetSection, uint16_t Version);
0094 
0095 Error buildDuplicateError(const std::pair<uint64_t, UnitIndexEntry> &PrevE,
0096                           const CompileUnitIdentifiers &ID, StringRef DWPName);
0097 
0098 void writeIndex(MCStreamer &Out, MCSection *Section,
0099                 ArrayRef<unsigned> ContributionOffsets,
0100                 const MapVector<uint64_t, UnitIndexEntry> &IndexEntries,
0101                 uint32_t IndexVersion);
0102 
0103 } // namespace llvm
0104 #endif // LLVM_DWP_DWP_H