LLVM 18.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;
21class DwarfStreamer;
22
24 friend DwarfStreamer;
26
27 /// DWARFv5 section 6.3.1 Macro Information Header.
28 enum HeaderFlagMask {
29#define HANDLE_MACRO_FLAG(ID, NAME) MACRO_##NAME = ID,
30#include "llvm/BinaryFormat/Dwarf.def"
31 };
32 struct MacroHeader {
33 /// Macro version information number.
34 uint16_t Version = 0;
35
36 /// The bits of the flags field are interpreted as a set of flags, some of
37 /// which may indicate that additional fields follow. The following flags,
38 /// beginning with the least significant bit, are defined:
39 /// offset_size_flag:
40 /// If the offset_size_flag is zero, the header is for a 32-bit DWARF
41 /// format macro section and all offsets are 4 bytes long; if it is one,
42 /// the header is for a 64-bit DWARF format macro section and all offsets
43 /// are 8 bytes long.
44 /// debug_line_offset_flag:
45 /// If the debug_line_offset_flag is one, the debug_line_offset field (see
46 /// below) is present. If zero, that field is omitted.
47 /// opcode_operands_table_flag:
48 /// If the opcode_operands_table_flag is one, the opcode_operands_table
49 /// field (see below) is present. If zero, that field is omitted.
50 uint8_t Flags = 0;
51
52 /// debug_line_offset
53 /// An offset in the .debug_line section of the beginning of the line
54 /// number information in the containing compilation unit, encoded as a
55 /// 4-byte offset for a 32-bit DWARF format macro section and an 8-byte
56 /// offset for a 64-bit DWARF format macro section.
57 uint64_t DebugLineOffset;
58
59 /// Print the macro header from the debug_macro section.
60 void dumpMacroHeader(raw_ostream &OS) const;
61
62 /// Parse the debug_macro header.
63 Error parseMacroHeader(DWARFDataExtractor Data, uint64_t *Offset);
64
65 /// Get the DWARF format according to the flags.
66 dwarf::DwarfFormat getDwarfFormat() const;
67
68 /// Get the size of a reference according to the DWARF format.
69 uint8_t getOffsetByteSize() const;
70 };
71
72 /// A single macro entry within a macro list.
73 struct Entry {
74 /// The type of the macro entry.
76 union {
77 /// The source line where the macro is defined.
79 /// Vendor extension constant value.
80 uint64_t ExtConstant;
81 /// Macro unit import offset.
82 uint64_t ImportOffset;
83 };
84
85 union {
86 /// The string (name, value) of the macro entry.
87 const char *MacroStr;
88 // An unsigned integer indicating the identity of the source file.
90 /// Vendor extension string.
91 const char *ExtStr;
92 };
93 };
94
95 struct MacroList {
96 // A value 0 in the `Header.Version` field indicates that we're parsing
97 // a macinfo[.dwo] section which doesn't have header itself, hence
98 // for that case other fields in the `Header` are uninitialized.
99 MacroHeader Header;
100 SmallVector<Entry, 4> Macros;
102
103 /// Whether or not this is a .debug_macro section.
104 bool IsDebugMacro;
105 };
106
107 /// A list of all the macro entries in the debug_macinfo section.
108 std::vector<MacroList> MacroLists;
109
110public:
111 DWARFDebugMacro() = default;
112
113 /// Print the macro list found within the debug_macinfo/debug_macro section.
114 void dump(raw_ostream &OS) const;
115
117 DataExtractor StringExtractor,
118 DWARFDataExtractor MacroData) {
119 return parseImpl(Units, StringExtractor, MacroData, /*IsMacro=*/true);
120 }
121
123 return parseImpl(std::nullopt, std::nullopt, MacroData, /*IsMacro=*/false);
124 }
125
126 /// Return whether the section has any entries.
127 bool empty() const { return MacroLists.empty(); }
128
130 for (const MacroList &List : MacroLists)
131 if (Offset == List.Offset)
132 return true;
133
134 return false;
135 }
136
137private:
138 /// Parse the debug_macinfo/debug_macro section accessible via the 'MacroData'
139 /// parameter.
140 Error parseImpl(std::optional<DWARFUnitVector::compile_unit_range> Units,
141 std::optional<DataExtractor> StringExtractor,
142 DWARFDataExtractor Data, bool IsMacro);
143};
144
145} // end namespace llvm
146
147#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:139
The Dwarf streaming logic.
Definition: DWARFStreamer.h:41
Lightweight error class with error context and mandatory checking.
Definition: Error.h:160
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
const uint64_t Version
Definition: InstrProf.h:1021
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:48
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Offset
Definition: DWP.cpp:440