xref: /freebsd/contrib/llvm-project/llvm/include/llvm/DWP/DWP.h (revision d5b0e70f7e04d971691517ce1304d86a1e367e2e)
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   Optional<uint64_t> Signature = None;
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 
65 unsigned getContributionIndex(DWARFSectionKind Kind, uint32_t IndexVersion);
66 
67 Error handleSection(
68     const StringMap<std::pair<MCSection *, DWARFSectionKind>> &KnownSections,
69     const MCSection *StrSection, const MCSection *StrOffsetSection,
70     const MCSection *TypesSection, const MCSection *CUIndexSection,
71     const MCSection *TUIndexSection, const MCSection *InfoSection,
72     const object::SectionRef &Section, MCStreamer &Out,
73     std::deque<SmallString<32>> &UncompressedSections,
74     uint32_t (&ContributionOffsets)[8], UnitIndexEntry &CurEntry,
75     StringRef &CurStrSection, StringRef &CurStrOffsetSection,
76     std::vector<StringRef> &CurTypesSection,
77     std::vector<StringRef> &CurInfoSection, StringRef &AbbrevSection,
78     StringRef &CurCUIndexSection, StringRef &CurTUIndexSection,
79     std::vector<std::pair<DWARFSectionKind, uint32_t>> &SectionLength);
80 
81 Expected<InfoSectionUnitHeader> parseInfoSectionUnitHeader(StringRef Info);
82 
83 void writeStringsAndOffsets(MCStreamer &Out, DWPStringPool &Strings,
84                             MCSection *StrOffsetSection,
85                             StringRef CurStrSection,
86                             StringRef CurStrOffsetSection, uint16_t Version);
87 
88 Error buildDuplicateError(const std::pair<uint64_t, UnitIndexEntry> &PrevE,
89                           const CompileUnitIdentifiers &ID, StringRef DWPName);
90 
91 void writeIndex(MCStreamer &Out, MCSection *Section,
92                 ArrayRef<unsigned> ContributionOffsets,
93                 const MapVector<uint64_t, UnitIndexEntry> &IndexEntries,
94                 uint32_t IndexVersion);
95 
96 } // namespace llvm
97 #endif // LLVM_DWP_DWP_H
98