LLVM 20.0.0git
FormatUtil.cpp
Go to the documentation of this file.
1//===- FormatUtil.cpp ----------------------------------------- *- 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
10
17
18using namespace llvm;
19using namespace llvm::codeview;
20using namespace llvm::pdb;
21
23 uint32_t IndentLevel, uint32_t GroupSize,
24 StringRef Sep) {
25 std::string Result;
26 while (!Opts.empty()) {
27 ArrayRef<std::string> ThisGroup;
28 ThisGroup = Opts.take_front(GroupSize);
29 Opts = Opts.drop_front(ThisGroup.size());
30 Result += join(ThisGroup, Sep);
31 if (!Opts.empty()) {
32 Result += Sep;
33 Result += "\n";
34 Result += std::string(formatv("{0}", fmt_repeat(' ', IndentLevel)));
35 }
36 }
37 return Result;
38}
39
40std::string llvm::pdb::typesetStringList(uint32_t IndentLevel,
41 ArrayRef<StringRef> Strings) {
42 std::string Result = "[";
43 for (const auto &S : Strings) {
44 Result += std::string(formatv("\n{0}{1}", fmt_repeat(' ', IndentLevel), S));
45 }
46 Result += "]";
47 return Result;
48}
49
51 bool Friendly) {
52 if (Friendly) {
53 switch (Kind) {
55 RETURN_CASE(DebugSubsectionKind, Symbols, "symbols");
64 RETURN_CASE(DebugSubsectionKind, FuncMDTokenMap, "func md token map");
65 RETURN_CASE(DebugSubsectionKind, TypeMDTokenMap, "type md token map");
67 "merged assembly input");
71 }
72 } else {
73 switch (Kind) {
75 RETURN_CASE(DebugSubsectionKind, Symbols, "DEBUG_S_SYMBOLS");
76 RETURN_CASE(DebugSubsectionKind, Lines, "DEBUG_S_LINES");
77 RETURN_CASE(DebugSubsectionKind, StringTable, "DEBUG_S_STRINGTABLE");
78 RETURN_CASE(DebugSubsectionKind, FileChecksums, "DEBUG_S_FILECHKSMS");
79 RETURN_CASE(DebugSubsectionKind, FrameData, "DEBUG_S_FRAMEDATA");
80 RETURN_CASE(DebugSubsectionKind, InlineeLines, "DEBUG_S_INLINEELINES");
82 "DEBUG_S_CROSSSCOPEIMPORTS");
84 "DEBUG_S_CROSSSCOPEEXPORTS");
85 RETURN_CASE(DebugSubsectionKind, ILLines, "DEBUG_S_IL_LINES");
87 "DEBUG_S_FUNC_MDTOKEN_MAP");
89 "DEBUG_S_TYPE_MDTOKEN_MAP");
91 "DEBUG_S_MERGED_ASSEMBLYINPUT");
93 "DEBUG_S_COFF_SYMBOL_RVA");
95 "DEBUG_S_XFGHASH_TYPE");
97 "DEBUG_S_XFGHASH_VIRTUAL");
98
99 }
100 }
101 return formatUnknownEnum(Kind);
102}
103
105 switch (uint32_t(K)) {
106#define SYMBOL_RECORD(EnumName, value, name) \
107 case EnumName: \
108 return #EnumName;
109#define CV_SYMBOL(EnumName, value) SYMBOL_RECORD(EnumName, value, EnumName)
110#include "llvm/DebugInfo/CodeView/CodeViewSymbols.def"
111 }
112 return formatUnknownEnum(K);
113}
114
116 switch (K) {
117#define TYPE_RECORD(EnumName, value, name) \
118 case EnumName: \
119 return #EnumName;
120#include "llvm/DebugInfo/CodeView/CodeViewTypes.def"
121 default:
122 return formatv("UNKNOWN RECORD ({0:X})", llvm::to_underlying(K)).str();
123 }
124}
125
127 return std::string(formatv("{0:4}:{1:4}", Segment, Offset));
128}
129
130#define PUSH_CHARACTERISTIC_FLAG(Enum, TheOpt, Value, Style, Descriptive) \
131 PUSH_FLAG(Enum, TheOpt, Value, \
132 ((Style == CharacteristicStyle::HeaderDefinition) ? #TheOpt \
133 : Descriptive))
134
135#define PUSH_MASKED_CHARACTERISTIC_FLAG(Enum, Mask, TheOpt, Value, Style, \
136 Descriptive) \
137 PUSH_MASKED_FLAG(Enum, Mask, TheOpt, Value, \
138 ((Style == CharacteristicStyle::HeaderDefinition) \
139 ? #TheOpt \
140 : Descriptive))
141
143 uint32_t C,
144 uint32_t FlagsPerLine,
145 StringRef Separator,
146 CharacteristicStyle Style) {
148 std::vector<std::string> Opts;
149 if (C == COFF::SC_Invalid)
150 return "invalid";
151 if (C == 0)
152 return "none";
153 PUSH_CHARACTERISTIC_FLAG(SC, IMAGE_SCN_TYPE_NOLOAD, C, Style, "noload");
154 PUSH_CHARACTERISTIC_FLAG(SC, IMAGE_SCN_TYPE_NO_PAD, C, Style, "no padding");
155 PUSH_CHARACTERISTIC_FLAG(SC, IMAGE_SCN_CNT_CODE, C, Style, "code");
156 PUSH_CHARACTERISTIC_FLAG(SC, IMAGE_SCN_CNT_INITIALIZED_DATA, C, Style,
157 "initialized data");
158 PUSH_CHARACTERISTIC_FLAG(SC, IMAGE_SCN_CNT_UNINITIALIZED_DATA, C, Style,
159 "uninitialized data");
160 PUSH_CHARACTERISTIC_FLAG(SC, IMAGE_SCN_LNK_OTHER, C, Style, "other");
161 PUSH_CHARACTERISTIC_FLAG(SC, IMAGE_SCN_LNK_INFO, C, Style, "info");
162 PUSH_CHARACTERISTIC_FLAG(SC, IMAGE_SCN_LNK_REMOVE, C, Style, "remove");
163 PUSH_CHARACTERISTIC_FLAG(SC, IMAGE_SCN_LNK_COMDAT, C, Style, "comdat");
164 PUSH_CHARACTERISTIC_FLAG(SC, IMAGE_SCN_GPREL, C, Style, "gp rel");
165 PUSH_CHARACTERISTIC_FLAG(SC, IMAGE_SCN_MEM_PURGEABLE, C, Style, "purgeable");
166 PUSH_CHARACTERISTIC_FLAG(SC, IMAGE_SCN_MEM_16BIT, C, Style, "16-bit");
167 PUSH_CHARACTERISTIC_FLAG(SC, IMAGE_SCN_MEM_LOCKED, C, Style, "locked");
168 PUSH_CHARACTERISTIC_FLAG(SC, IMAGE_SCN_MEM_PRELOAD, C, Style, "preload");
169 PUSH_MASKED_CHARACTERISTIC_FLAG(SC, 0xF00000, IMAGE_SCN_ALIGN_1BYTES, C,
170 Style, "1 byte align");
171 PUSH_MASKED_CHARACTERISTIC_FLAG(SC, 0xF00000, IMAGE_SCN_ALIGN_2BYTES, C,
172 Style, "2 byte align");
173 PUSH_MASKED_CHARACTERISTIC_FLAG(SC, 0xF00000, IMAGE_SCN_ALIGN_4BYTES, C,
174 Style, "4 byte align");
175 PUSH_MASKED_CHARACTERISTIC_FLAG(SC, 0xF00000, IMAGE_SCN_ALIGN_8BYTES, C,
176 Style, "8 byte align");
177 PUSH_MASKED_CHARACTERISTIC_FLAG(SC, 0xF00000, IMAGE_SCN_ALIGN_16BYTES, C,
178 Style, "16 byte align");
179 PUSH_MASKED_CHARACTERISTIC_FLAG(SC, 0xF00000, IMAGE_SCN_ALIGN_32BYTES, C,
180 Style, "32 byte align");
181 PUSH_MASKED_CHARACTERISTIC_FLAG(SC, 0xF00000, IMAGE_SCN_ALIGN_64BYTES, C,
182 Style, "64 byte align");
183 PUSH_MASKED_CHARACTERISTIC_FLAG(SC, 0xF00000, IMAGE_SCN_ALIGN_128BYTES, C,
184 Style, "128 byte align");
185 PUSH_MASKED_CHARACTERISTIC_FLAG(SC, 0xF00000, IMAGE_SCN_ALIGN_256BYTES, C,
186 Style, "256 byte align");
187 PUSH_MASKED_CHARACTERISTIC_FLAG(SC, 0xF00000, IMAGE_SCN_ALIGN_512BYTES, C,
188 Style, "512 byte align");
189 PUSH_MASKED_CHARACTERISTIC_FLAG(SC, 0xF00000, IMAGE_SCN_ALIGN_1024BYTES, C,
190 Style, "1024 byte align");
191 PUSH_MASKED_CHARACTERISTIC_FLAG(SC, 0xF00000, IMAGE_SCN_ALIGN_2048BYTES, C,
192 Style, "2048 byte align");
193 PUSH_MASKED_CHARACTERISTIC_FLAG(SC, 0xF00000, IMAGE_SCN_ALIGN_4096BYTES, C,
194 Style, "4096 byte align");
195 PUSH_MASKED_CHARACTERISTIC_FLAG(SC, 0xF00000, IMAGE_SCN_ALIGN_8192BYTES, C,
196 Style, "8192 byte align");
197 PUSH_CHARACTERISTIC_FLAG(SC, IMAGE_SCN_LNK_NRELOC_OVFL, C, Style,
198 "noreloc overflow");
199 PUSH_CHARACTERISTIC_FLAG(SC, IMAGE_SCN_MEM_DISCARDABLE, C, Style,
200 "discardable");
201 PUSH_CHARACTERISTIC_FLAG(SC, IMAGE_SCN_MEM_NOT_CACHED, C, Style,
202 "not cached");
203 PUSH_CHARACTERISTIC_FLAG(SC, IMAGE_SCN_MEM_NOT_PAGED, C, Style, "not paged");
204 PUSH_CHARACTERISTIC_FLAG(SC, IMAGE_SCN_MEM_SHARED, C, Style, "shared");
205 PUSH_CHARACTERISTIC_FLAG(SC, IMAGE_SCN_MEM_EXECUTE, C, Style,
206 "execute permissions");
207 PUSH_CHARACTERISTIC_FLAG(SC, IMAGE_SCN_MEM_READ, C, Style,
208 "read permissions");
209 PUSH_CHARACTERISTIC_FLAG(SC, IMAGE_SCN_MEM_WRITE, C, Style,
210 "write permissions");
211 return typesetItemList(Opts, IndentLevel, FlagsPerLine, Separator);
212}
#define PUSH_CHARACTERISTIC_FLAG(Enum, TheOpt, Value, Style, Descriptive)
Definition: FormatUtil.cpp:130
#define PUSH_MASKED_CHARACTERISTIC_FLAG(Enum, Mask, TheOpt, Value, Style, Descriptive)
Definition: FormatUtil.cpp:135
#define RETURN_CASE(Enum, X, Ret)
Definition: FormatUtil.h:33
This file contains library features backported from future STL versions.
This file contains some functions that are useful when dealing with strings.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
ArrayRef< T > take_front(size_t N=1) const
Return a copy of *this with only the first N elements.
Definition: ArrayRef.h:231
ArrayRef< T > drop_front(size_t N=1) const
Drop the first N elements of the array.
Definition: ArrayRef.h:207
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:168
bool empty() const
empty - Check if the array is empty.
Definition: ArrayRef.h:163
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:51
A table of densely packed, null-terminated strings indexed by offset.
Definition: StringTable.h:31
SectionCharacteristics
Definition: COFF.h:297
@ SC_Invalid
Definition: COFF.h:298
TypeLeafKind
Duplicate copy of the above enum, but using the official CV names.
Definition: CodeView.h:34
SymbolKind
Duplicate copy of the above enum, but using the official CV names.
Definition: CodeView.h:48
std::string formatSegmentOffset(uint16_t Segment, uint32_t Offset)
Definition: FormatUtil.cpp:126
std::string formatUnknownEnum(T Value)
Definition: FormatUtil.h:37
std::string typesetStringList(uint32_t IndentLevel, ArrayRef< StringRef > Strings)
Definition: FormatUtil.cpp:40
CharacteristicStyle
Definition: FormatUtil.h:43
std::string formatSymbolKind(codeview::SymbolKind K)
Definition: FormatUtil.cpp:104
std::string formatTypeLeafKind(codeview::TypeLeafKind K)
Definition: FormatUtil.cpp:115
std::string formatChunkKind(codeview::DebugSubsectionKind Kind, bool Friendly=true)
Definition: FormatUtil.cpp:50
std::string formatSectionCharacteristics(uint32_t IndentLevel, uint32_t C, uint32_t FlagsPerLine, StringRef Separator, CharacteristicStyle Style=CharacteristicStyle::HeaderDefinition)
Definition: FormatUtil.cpp:142
std::string typesetItemList(ArrayRef< std::string > Opts, uint32_t IndentLevel, uint32_t GroupSize, StringRef Sep)
Definition: FormatUtil.cpp:22
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Offset
Definition: DWP.cpp:480
auto formatv(bool Validate, const char *Fmt, Ts &&...Vals)
@ None
Definition: CodeGenData.h:106
constexpr std::underlying_type_t< Enum > to_underlying(Enum E)
Returns underlying integer value of an enum.
support::detail::RepeatAdapter< T > fmt_repeat(T &&Item, size_t Count)
Data in the SUBSEC_FRAMEDATA subection.
Definition: CodeView.h:584