LLVM  17.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"
12 #include "llvm/ADT/StringExtras.h"
13 #include "llvm/BinaryFormat/COFF.h"
17 
18 using namespace llvm;
19 using namespace llvm::codeview;
20 using 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 
40 std::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");
60  RETURN_CASE(DebugSubsectionKind, InlineeLines, "inlinee lines");
64  RETURN_CASE(DebugSubsectionKind, FuncMDTokenMap, "func md token map");
65  RETURN_CASE(DebugSubsectionKind, TypeMDTokenMap, "type md token map");
67  "merged assembly input");
68  RETURN_CASE(DebugSubsectionKind, CoffSymbolRVA, "coff symbol rva");
69  RETURN_CASE(DebugSubsectionKind, XfgHashType, "xfg hash type");
70  RETURN_CASE(DebugSubsectionKind, XfgHashVirtual, "xfg hash virtual");
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})",
123  static_cast<std::underlying_type_t<TypeLeafKind>>(K))
124  .str();
125  }
126 }
127 
129  return std::string(formatv("{0:4}:{1:4}", Segment, Offset));
130 }
131 
132 #define PUSH_CHARACTERISTIC_FLAG(Enum, TheOpt, Value, Style, Descriptive) \
133  PUSH_FLAG(Enum, TheOpt, Value, \
134  ((Style == CharacteristicStyle::HeaderDefinition) ? #TheOpt \
135  : Descriptive))
136 
137 #define PUSH_MASKED_CHARACTERISTIC_FLAG(Enum, Mask, TheOpt, Value, Style, \
138  Descriptive) \
139  PUSH_MASKED_FLAG(Enum, Mask, TheOpt, Value, \
140  ((Style == CharacteristicStyle::HeaderDefinition) \
141  ? #TheOpt \
142  : Descriptive))
143 
145  uint32_t C,
146  uint32_t FlagsPerLine,
147  StringRef Separator,
150  std::vector<std::string> Opts;
151  if (C == COFF::SC_Invalid)
152  return "invalid";
153  if (C == 0)
154  return "none";
159  "initialized data");
161  "uninitialized data");
172  Style, "1 byte align");
174  Style, "2 byte align");
176  Style, "4 byte align");
178  Style, "8 byte align");
180  Style, "16 byte align");
182  Style, "32 byte align");
184  Style, "64 byte align");
186  Style, "128 byte align");
188  Style, "256 byte align");
190  Style, "512 byte align");
192  Style, "1024 byte align");
194  Style, "2048 byte align");
196  Style, "4096 byte align");
198  Style, "8192 byte align");
200  "noreloc overflow");
202  "discardable");
204  "not cached");
208  "execute permissions");
210  "read permissions");
212  "write permissions");
213  return typesetItemList(Opts, IndentLevel, FlagsPerLine, Separator);
214 }
llvm::COFF::IMAGE_SCN_ALIGN_64BYTES
@ IMAGE_SCN_ALIGN_64BYTES
Definition: COFF.h:306
llvm::COFF::IMAGE_SCN_ALIGN_1BYTES
@ IMAGE_SCN_ALIGN_1BYTES
Definition: COFF.h:300
llvm::COFF::IMAGE_SCN_ALIGN_2048BYTES
@ IMAGE_SCN_ALIGN_2048BYTES
Definition: COFF.h:311
llvm::codeview::DebugSubsectionKind::InlineeLines
@ InlineeLines
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
llvm::COFF::IMAGE_SCN_LNK_NRELOC_OVFL
@ IMAGE_SCN_LNK_NRELOC_OVFL
Definition: COFF.h:315
llvm::COFF::IMAGE_SCN_ALIGN_16BYTES
@ IMAGE_SCN_ALIGN_16BYTES
Definition: COFF.h:304
llvm::COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA
@ IMAGE_SCN_CNT_UNINITIALIZED_DATA
Definition: COFF.h:290
llvm::COFF::IMAGE_SCN_ALIGN_4BYTES
@ IMAGE_SCN_ALIGN_4BYTES
Definition: COFF.h:302
llvm::codeview::DebugSubsectionKind::CoffSymbolRVA
@ CoffSymbolRVA
llvm::codeview::DebugSubsectionKind::Lines
@ Lines
llvm::COFF::IMAGE_SCN_ALIGN_256BYTES
@ IMAGE_SCN_ALIGN_256BYTES
Definition: COFF.h:308
llvm::codeview::SymbolKind
SymbolKind
Duplicate copy of the above enum, but using the official CV names.
Definition: CodeView.h:47
llvm::COFF::IMAGE_SCN_MEM_NOT_PAGED
@ IMAGE_SCN_MEM_NOT_PAGED
Definition: COFF.h:318
llvm::COFF::IMAGE_SCN_MEM_DISCARDABLE
@ IMAGE_SCN_MEM_DISCARDABLE
Definition: COFF.h:316
COFF.h
llvm::codeview::FrameData
Data in the SUBSEC_FRAMEDATA subection.
Definition: CodeView.h:574
llvm::codeview::DebugSubsectionKind::CrossScopeExports
@ CrossScopeExports
Offset
uint64_t Offset
Definition: ELFObjHandler.cpp:80
llvm::COFF::IMAGE_SCN_ALIGN_512BYTES
@ IMAGE_SCN_ALIGN_512BYTES
Definition: COFF.h:309
llvm::codeview::DebugSubsectionKind::StringTable
@ StringTable
STLExtras.h
llvm::codeview::DebugSubsectionKind::MergedAssemblyInput
@ MergedAssemblyInput
llvm::ArrayRef::empty
bool empty() const
empty - Check if the array is empty.
Definition: ArrayRef.h:158
llvm::codeview::DebugSubsectionKind::XfgHashVirtual
@ XfgHashVirtual
llvm::formatv
auto formatv(const char *Fmt, Ts &&... Vals) -> formatv_object< decltype(std::make_tuple(detail::build_format_adapter(std::forward< Ts >(Vals))...))>
Definition: FormatVariadic.h:251
llvm::COFF::IMAGE_SCN_LNK_INFO
@ IMAGE_SCN_LNK_INFO
Definition: COFF.h:292
llvm::COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
@ IMAGE_SCN_CNT_INITIALIZED_DATA
Definition: COFF.h:289
llvm::PPCISD::SC
@ SC
CHAIN = SC CHAIN, Imm128 - System call.
Definition: PPCISelLowering.h:420
llvm::COFF::IMAGE_SCN_LNK_REMOVE
@ IMAGE_SCN_LNK_REMOVE
Definition: COFF.h:293
llvm::codeview::DebugSubsectionKind::CrossScopeImports
@ CrossScopeImports
C
(vector float) vec_cmpeq(*A, *B) C
Definition: README_ALTIVEC.txt:86
llvm::COFF::IMAGE_SCN_MEM_READ
@ IMAGE_SCN_MEM_READ
Definition: COFF.h:321
llvm::codeview::DebugSubsectionKind::FuncMDTokenMap
@ FuncMDTokenMap
llvm::codeview::DebugSubsectionKind::FileChecksums
@ FileChecksums
llvm::COFF::IMAGE_SCN_ALIGN_32BYTES
@ IMAGE_SCN_ALIGN_32BYTES
Definition: COFF.h:305
DebugLocVerifyLevel::None
@ None
CodeView.h
FormatVariadic.h
llvm::lltok::Kind
Kind
Definition: LLToken.h:18
llvm::pdb
Definition: ConcreteSymbolEnumerator.h:20
llvm::COFF::IMAGE_SCN_TYPE_NOLOAD
@ IMAGE_SCN_TYPE_NOLOAD
Definition: COFF.h:286
llvm::COFF::IMAGE_SCN_LNK_OTHER
@ IMAGE_SCN_LNK_OTHER
Definition: COFF.h:291
llvm::COFF::IMAGE_SCN_MEM_PURGEABLE
@ IMAGE_SCN_MEM_PURGEABLE
Definition: COFF.h:296
llvm::pdb::typesetItemList
std::string typesetItemList(ArrayRef< std::string > Opts, uint32_t IndentLevel, uint32_t GroupSize, StringRef Sep)
Definition: FormatUtil.cpp:22
llvm::pdb::formatChunkKind
std::string formatChunkKind(codeview::DebugSubsectionKind Kind, bool Friendly=true)
Definition: FormatUtil.cpp:50
llvm::ArrayRef::drop_front
ArrayRef< T > drop_front(size_t N=1) const
Drop the first N elements of the array.
Definition: ArrayRef.h:202
llvm::COFF::IMAGE_SCN_TYPE_NO_PAD
@ IMAGE_SCN_TYPE_NO_PAD
Definition: COFF.h:287
llvm::COFF::IMAGE_SCN_ALIGN_8192BYTES
@ IMAGE_SCN_ALIGN_8192BYTES
Definition: COFF.h:313
llvm::COFF::IMAGE_SCN_ALIGN_2BYTES
@ IMAGE_SCN_ALIGN_2BYTES
Definition: COFF.h:301
llvm::codeview::DebugSubsectionKind::TypeMDTokenMap
@ TypeMDTokenMap
llvm::COFF::IMAGE_SCN_MEM_SHARED
@ IMAGE_SCN_MEM_SHARED
Definition: COFF.h:319
llvm::pdb::formatSegmentOffset
std::string formatSegmentOffset(uint16_t Segment, uint32_t Offset)
Definition: FormatUtil.cpp:128
llvm::fmt_repeat
detail::RepeatAdapter< T > fmt_repeat(T &&Item, size_t Count)
Definition: FormatAdapters.h:97
StringExtras.h
llvm::COFF::IMAGE_SCN_GPREL
@ IMAGE_SCN_GPREL
Definition: COFF.h:295
llvm::HexStyle::Style
Style
Definition: MCInstPrinter.h:33
RETURN_CASE
#define RETURN_CASE(Enum, X, Ret)
Definition: FormatUtil.h:32
PUSH_CHARACTERISTIC_FLAG
#define PUSH_CHARACTERISTIC_FLAG(Enum, TheOpt, Value, Style, Descriptive)
Definition: FormatUtil.cpp:132
llvm::COFF::IMAGE_SCN_LNK_COMDAT
@ IMAGE_SCN_LNK_COMDAT
Definition: COFF.h:294
llvm::pdb::formatTypeLeafKind
std::string formatTypeLeafKind(codeview::TypeLeafKind K)
Definition: FormatUtil.cpp:115
llvm::codeview::DebugSubsectionKind::XfgHashType
@ XfgHashType
llvm::ArrayRef< std::string >
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
llvm::COFF::IMAGE_SCN_ALIGN_4096BYTES
@ IMAGE_SCN_ALIGN_4096BYTES
Definition: COFF.h:312
llvm::COFF::IMAGE_SCN_ALIGN_128BYTES
@ IMAGE_SCN_ALIGN_128BYTES
Definition: COFF.h:307
llvm::COFF::IMAGE_SCN_ALIGN_8BYTES
@ IMAGE_SCN_ALIGN_8BYTES
Definition: COFF.h:303
uint32_t
S
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
Definition: README.txt:210
llvm::pdb::formatSectionCharacteristics
std::string formatSectionCharacteristics(uint32_t IndentLevel, uint32_t C, uint32_t FlagsPerLine, StringRef Separator, CharacteristicStyle Style=CharacteristicStyle::HeaderDefinition)
Definition: FormatUtil.cpp:144
PUSH_MASKED_CHARACTERISTIC_FLAG
#define PUSH_MASKED_CHARACTERISTIC_FLAG(Enum, Mask, TheOpt, Value, Style, Descriptive)
Definition: FormatUtil.cpp:137
llvm::COFF::IMAGE_SCN_MEM_LOCKED
@ IMAGE_SCN_MEM_LOCKED
Definition: COFF.h:298
uint16_t
llvm::COFF::IMAGE_SCN_MEM_PRELOAD
@ IMAGE_SCN_MEM_PRELOAD
Definition: COFF.h:299
llvm::ArrayRef::take_front
ArrayRef< T > take_front(size_t N=1) const
Return a copy of *this with only the first N elements.
Definition: ArrayRef.h:226
llvm::COFF::IMAGE_SCN_CNT_CODE
@ IMAGE_SCN_CNT_CODE
Definition: COFF.h:288
FormatUtil.h
llvm::COFF::IMAGE_SCN_ALIGN_1024BYTES
@ IMAGE_SCN_ALIGN_1024BYTES
Definition: COFF.h:310
llvm::pdb::CharacteristicStyle
CharacteristicStyle
Definition: FormatUtil.h:43
llvm::pdb::typesetStringList
std::string typesetStringList(uint32_t IndentLevel, ArrayRef< StringRef > Strings)
Definition: FormatUtil.cpp:40
llvm::pdb::formatUnknownEnum
std::string formatUnknownEnum(T Value)
Definition: FormatUtil.h:36
llvm::codeview::DebugSubsectionKind
DebugSubsectionKind
Definition: CodeView.h:312
llvm::codeview::TypeLeafKind
TypeLeafKind
Duplicate copy of the above enum, but using the official CV names.
Definition: CodeView.h:33
llvm::codeview
Definition: AppendingTypeTableBuilder.h:22
FormatAdapters.h
llvm::ArrayRef::size
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:163
llvm::COFF::IMAGE_SCN_MEM_NOT_CACHED
@ IMAGE_SCN_MEM_NOT_CACHED
Definition: COFF.h:317
llvm::COFF::IMAGE_SCN_MEM_EXECUTE
@ IMAGE_SCN_MEM_EXECUTE
Definition: COFF.h:320
llvm::COFF::IMAGE_SCN_MEM_16BIT
@ IMAGE_SCN_MEM_16BIT
Definition: COFF.h:297
llvm::codeview::DebugSubsectionKind::ILLines
@ ILLines
llvm::COFF::SectionCharacteristics
SectionCharacteristics
Definition: COFF.h:283
llvm::pdb::formatSymbolKind
std::string formatSymbolKind(codeview::SymbolKind K)
Definition: FormatUtil.cpp:104
llvm::COFF::SC_Invalid
@ SC_Invalid
Definition: COFF.h:284
llvm::COFF::IMAGE_SCN_MEM_WRITE
@ IMAGE_SCN_MEM_WRITE
Definition: COFF.h:322