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