LLVM 20.0.0git
DWARFDebugMacro.h
Go to the documentation of this file.
1//===- DWARFDebugMacro.h ----------------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_DEBUGINFO_DWARF_DWARFDEBUGMACRO_H
10#define LLVM_DEBUGINFO_DWARF_DWARFDEBUGMACRO_H
11
15#include "llvm/Support/Error.h"
16#include <cstdint>
17
18namespace llvm {
19
20class raw_ostream;
21
22namespace dwarf_linker {
23namespace classic {
24class DwarfStreamer;
25}
26} // namespace dwarf_linker
27
31
32 /// DWARFv5 section 6.3.1 Macro Information Header.
33 enum HeaderFlagMask {
34#define HANDLE_MACRO_FLAG(ID, NAME) MACRO_##NAME = ID,
35#include "llvm/BinaryFormat/Dwarf.def"
36 };
37 struct MacroHeader {
38 /// Macro version information number.
39 uint16_t Version = 0;
40
41 /// The bits of the flags field are interpreted as a set of flags, some of
42 /// which may indicate that additional fields follow. The following flags,
43 /// beginning with the least significant bit, are defined:
44 /// offset_size_flag:
45 /// If the offset_size_flag is zero, the header is for a 32-bit DWARF
46 /// format macro section and all offsets are 4 bytes long; if it is one,
47 /// the header is for a 64-bit DWARF format macro section and all offsets
48 /// are 8 bytes long.
49 /// debug_line_offset_flag:
50 /// If the debug_line_offset_flag is one, the debug_line_offset field (see
51 /// below) is present. If zero, that field is omitted.
52 /// opcode_operands_table_flag:
53 /// If the opcode_operands_table_flag is one, the opcode_operands_table
54 /// field (see below) is present. If zero, that field is omitted.
55 uint8_t Flags = 0;
56
57 /// debug_line_offset
58 /// An offset in the .debug_line section of the beginning of the line
59 /// number information in the containing compilation unit, encoded as a
60 /// 4-byte offset for a 32-bit DWARF format macro section and an 8-byte
61 /// offset for a 64-bit DWARF format macro section.
62 uint64_t DebugLineOffset;
63
64 /// Print the macro header from the debug_macro section.
65 void dumpMacroHeader(raw_ostream &OS) const;
66
67 /// Parse the debug_macro header.
68 Error parseMacroHeader(DWARFDataExtractor Data, uint64_t *Offset);
69
70 /// Get the DWARF format according to the flags.
71 dwarf::DwarfFormat getDwarfFormat() const;
72
73 /// Get the size of a reference according to the DWARF format.
74 uint8_t getOffsetByteSize() const;
75 };
76
77 /// A single macro entry within a macro list.
78 struct Entry {
79 /// The type of the macro entry.
81 union {
82 /// The source line where the macro is defined.
84 /// Vendor extension constant value.
85 uint64_t ExtConstant;
86 /// Macro unit import offset.
87 uint64_t ImportOffset;
88 };
89
90 union {
91 /// The string (name, value) of the macro entry.
92 const char *MacroStr;
93 // An unsigned integer indicating the identity of the source file.
95 /// Vendor extension string.
96 const char *ExtStr;
97 };
98 };
99
100 struct MacroList {
101 // A value 0 in the `Header.Version` field indicates that we're parsing
102 // a macinfo[.dwo] section which doesn't have header itself, hence
103 // for that case other fields in the `Header` are uninitialized.
104 MacroHeader Header;
105 SmallVector<Entry, 4> Macros;
107
108 /// Whether or not this is a .debug_macro section.
109 bool IsDebugMacro;
110 };
111
112 /// A list of all the macro entries in the debug_macinfo section.
113 std::vector<MacroList> MacroLists;
114
115public:
116 DWARFDebugMacro() = default;
117
118 /// Print the macro list found within the debug_macinfo/debug_macro section.
119 void dump(raw_ostream &OS) const;
120
122 DataExtractor StringExtractor,
123 DWARFDataExtractor MacroData) {
124 return parseImpl(Units, StringExtractor, MacroData, /*IsMacro=*/true);
125 }
126
128 return parseImpl(std::nullopt, std::nullopt, MacroData, /*IsMacro=*/false);
129 }
130
131 /// Return whether the section has any entries.
132 bool empty() const { return MacroLists.empty(); }
133
135 for (const MacroList &List : MacroLists)
136 if (Offset == List.Offset)
137 return true;
138
139 return false;
140 }
141
142private:
143 /// Parse the debug_macinfo/debug_macro section accessible via the 'MacroData'
144 /// parameter.
145 Error parseImpl(std::optional<DWARFUnitVector::compile_unit_range> Units,
146 std::optional<DataExtractor> StringExtractor,
147 DWARFDataExtractor Data, bool IsMacro);
148};
149
150} // end namespace llvm
151
152#endif // LLVM_DEBUGINFO_DWARF_DWARFDEBUGMACRO_H
raw_pwrite_stream & OS
This file defines the SmallVector class.
A DataExtractor (typically for an in-memory copy of an object-file section) plus a relocation map for...
void dump(raw_ostream &OS) const
Print the macro list found within the debug_macinfo/debug_macro section.
Error parseMacinfo(DWARFDataExtractor MacroData)
bool empty() const
Return whether the section has any entries.
Error parseMacro(DWARFUnitVector::compile_unit_range Units, DataExtractor StringExtractor, DWARFDataExtractor MacroData)
bool hasEntryForOffset(uint64_t Offset) const
decltype(make_filter_range(std::declval< iterator_range >(), isCompileUnit)) compile_unit_range
Definition: DWARFUnit.h:141
Lightweight error class with error context and mandatory checking.
Definition: Error.h:160
User of DwarfStreamer should call initialization code for AsmPrinter:
Definition: DWARFStreamer.h:44
Stores all information related to a compile unit, be it in its original instance of the object file o...
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
@ Entry
Definition: COFF.h:826
const uint64_t Version
Definition: InstrProf.h:1111
DwarfFormat
Constants that define the DWARF format as 32 or 64 bit.
Definition: Dwarf.h:91
Type
MessagePack types as defined in the standard, with the exception of Integer being divided into a sign...
Definition: MsgPackReader.h:53
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Offset
Definition: DWP.cpp:480