|
|
|||
File indexing completed on 2026-05-10 08:43:41
0001 //===- DWARFDebugMacro.h ----------------------------------------*- C++ -*-===// 0002 // 0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 0004 // See https://llvm.org/LICENSE.txt for license information. 0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 0006 // 0007 //===----------------------------------------------------------------------===// 0008 0009 #ifndef LLVM_DEBUGINFO_DWARF_DWARFDEBUGMACRO_H 0010 #define LLVM_DEBUGINFO_DWARF_DWARFDEBUGMACRO_H 0011 0012 #include "llvm/ADT/SmallVector.h" 0013 #include "llvm/DebugInfo/DWARF/DWARFDataExtractor.h" 0014 #include "llvm/DebugInfo/DWARF/DWARFUnit.h" 0015 #include "llvm/Support/Error.h" 0016 #include <cstdint> 0017 0018 namespace llvm { 0019 0020 class raw_ostream; 0021 0022 namespace dwarf_linker { 0023 namespace classic { 0024 class DwarfStreamer; 0025 } 0026 } // namespace dwarf_linker 0027 0028 class DWARFDebugMacro { 0029 friend dwarf_linker::classic::DwarfStreamer; 0030 friend dwarf_linker::parallel::CompileUnit; 0031 0032 /// DWARFv5 section 6.3.1 Macro Information Header. 0033 enum HeaderFlagMask { 0034 #define HANDLE_MACRO_FLAG(ID, NAME) MACRO_##NAME = ID, 0035 #include "llvm/BinaryFormat/Dwarf.def" 0036 }; 0037 struct MacroHeader { 0038 /// Macro version information number. 0039 uint16_t Version = 0; 0040 0041 /// The bits of the flags field are interpreted as a set of flags, some of 0042 /// which may indicate that additional fields follow. The following flags, 0043 /// beginning with the least significant bit, are defined: 0044 /// offset_size_flag: 0045 /// If the offset_size_flag is zero, the header is for a 32-bit DWARF 0046 /// format macro section and all offsets are 4 bytes long; if it is one, 0047 /// the header is for a 64-bit DWARF format macro section and all offsets 0048 /// are 8 bytes long. 0049 /// debug_line_offset_flag: 0050 /// If the debug_line_offset_flag is one, the debug_line_offset field (see 0051 /// below) is present. If zero, that field is omitted. 0052 /// opcode_operands_table_flag: 0053 /// If the opcode_operands_table_flag is one, the opcode_operands_table 0054 /// field (see below) is present. If zero, that field is omitted. 0055 uint8_t Flags = 0; 0056 0057 /// debug_line_offset 0058 /// An offset in the .debug_line section of the beginning of the line 0059 /// number information in the containing compilation unit, encoded as a 0060 /// 4-byte offset for a 32-bit DWARF format macro section and an 8-byte 0061 /// offset for a 64-bit DWARF format macro section. 0062 uint64_t DebugLineOffset; 0063 0064 /// Print the macro header from the debug_macro section. 0065 void dumpMacroHeader(raw_ostream &OS) const; 0066 0067 /// Parse the debug_macro header. 0068 Error parseMacroHeader(DWARFDataExtractor Data, uint64_t *Offset); 0069 0070 /// Get the DWARF format according to the flags. 0071 dwarf::DwarfFormat getDwarfFormat() const; 0072 0073 /// Get the size of a reference according to the DWARF format. 0074 uint8_t getOffsetByteSize() const; 0075 }; 0076 0077 /// A single macro entry within a macro list. 0078 struct Entry { 0079 /// The type of the macro entry. 0080 uint32_t Type; 0081 union { 0082 /// The source line where the macro is defined. 0083 uint64_t Line; 0084 /// Vendor extension constant value. 0085 uint64_t ExtConstant; 0086 /// Macro unit import offset. 0087 uint64_t ImportOffset; 0088 }; 0089 0090 union { 0091 /// The string (name, value) of the macro entry. 0092 const char *MacroStr; 0093 // An unsigned integer indicating the identity of the source file. 0094 uint64_t File; 0095 /// Vendor extension string. 0096 const char *ExtStr; 0097 }; 0098 }; 0099 0100 struct MacroList { 0101 // A value 0 in the `Header.Version` field indicates that we're parsing 0102 // a macinfo[.dwo] section which doesn't have header itself, hence 0103 // for that case other fields in the `Header` are uninitialized. 0104 MacroHeader Header; 0105 SmallVector<Entry, 4> Macros; 0106 uint64_t Offset; 0107 0108 /// Whether or not this is a .debug_macro section. 0109 bool IsDebugMacro; 0110 }; 0111 0112 /// A list of all the macro entries in the debug_macinfo section. 0113 std::vector<MacroList> MacroLists; 0114 0115 public: 0116 DWARFDebugMacro() = default; 0117 0118 /// Print the macro list found within the debug_macinfo/debug_macro section. 0119 void dump(raw_ostream &OS) const; 0120 0121 Error parseMacro(DWARFUnitVector::compile_unit_range Units, 0122 DataExtractor StringExtractor, 0123 DWARFDataExtractor MacroData) { 0124 return parseImpl(Units, StringExtractor, MacroData, /*IsMacro=*/true); 0125 } 0126 0127 Error parseMacinfo(DWARFDataExtractor MacroData) { 0128 return parseImpl(std::nullopt, std::nullopt, MacroData, /*IsMacro=*/false); 0129 } 0130 0131 /// Return whether the section has any entries. 0132 bool empty() const { return MacroLists.empty(); } 0133 0134 bool hasEntryForOffset(uint64_t Offset) const { 0135 for (const MacroList &List : MacroLists) 0136 if (Offset == List.Offset) 0137 return true; 0138 0139 return false; 0140 } 0141 0142 private: 0143 /// Parse the debug_macinfo/debug_macro section accessible via the 'MacroData' 0144 /// parameter. 0145 Error parseImpl(std::optional<DWARFUnitVector::compile_unit_range> Units, 0146 std::optional<DataExtractor> StringExtractor, 0147 DWARFDataExtractor Data, bool IsMacro); 0148 }; 0149 0150 } // end namespace llvm 0151 0152 #endif // LLVM_DEBUGINFO_DWARF_DWARFDEBUGMACRO_H
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|