LLVM  13.0.0git
PDBExtras.cpp
Go to the documentation of this file.
1 //===- PDBExtras.cpp - helper functions and classes for PDBs --------------===//
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 #include "llvm/ADT/ArrayRef.h"
12 
13 using namespace llvm;
14 using namespace llvm::pdb;
15 
16 #define CASE_OUTPUT_ENUM_CLASS_STR(Class, Value, Str, Stream) \
17  case Class::Value: \
18  Stream << Str; \
19  break;
20 
21 #define CASE_OUTPUT_ENUM_CLASS_NAME(Class, Value, Stream) \
22  CASE_OUTPUT_ENUM_CLASS_STR(Class, Value, #Value, Stream)
23 
25  const PDB_VariantType &Type) {
26  switch (Type) {
38  default:
39  OS << "Unknown";
40  }
41  return OS;
42 }
43 
45  const PDB_BuiltinType &Type) {
46  switch (Type) {
67  }
68  return OS;
69 }
70 
72  const PDB_CallingConv &Conv) {
73  OS << "__";
74  switch (Conv) {
75  CASE_OUTPUT_ENUM_CLASS_STR(PDB_CallingConv, NearC , "cdecl", OS)
76  CASE_OUTPUT_ENUM_CLASS_STR(PDB_CallingConv, FarC , "cdecl", OS)
77  CASE_OUTPUT_ENUM_CLASS_STR(PDB_CallingConv, NearPascal , "pascal", OS)
78  CASE_OUTPUT_ENUM_CLASS_STR(PDB_CallingConv, FarPascal , "pascal", OS)
79  CASE_OUTPUT_ENUM_CLASS_STR(PDB_CallingConv, NearFast , "fastcall", OS)
80  CASE_OUTPUT_ENUM_CLASS_STR(PDB_CallingConv, FarFast , "fastcall", OS)
81  CASE_OUTPUT_ENUM_CLASS_STR(PDB_CallingConv, NearStdCall, "stdcall", OS)
82  CASE_OUTPUT_ENUM_CLASS_STR(PDB_CallingConv, FarStdCall , "stdcall", OS)
83  CASE_OUTPUT_ENUM_CLASS_STR(PDB_CallingConv, NearSysCall, "syscall", OS)
84  CASE_OUTPUT_ENUM_CLASS_STR(PDB_CallingConv, FarSysCall , "syscall", OS)
85  CASE_OUTPUT_ENUM_CLASS_STR(PDB_CallingConv, ThisCall , "thiscall", OS)
86  CASE_OUTPUT_ENUM_CLASS_STR(PDB_CallingConv, MipsCall , "mipscall", OS)
88  CASE_OUTPUT_ENUM_CLASS_STR(PDB_CallingConv, AlphaCall , "alphacall", OS)
89  CASE_OUTPUT_ENUM_CLASS_STR(PDB_CallingConv, PpcCall , "ppccall", OS)
90  CASE_OUTPUT_ENUM_CLASS_STR(PDB_CallingConv, SHCall , "superhcall", OS)
91  CASE_OUTPUT_ENUM_CLASS_STR(PDB_CallingConv, ArmCall , "armcall", OS)
92  CASE_OUTPUT_ENUM_CLASS_STR(PDB_CallingConv, AM33Call , "am33call", OS)
93  CASE_OUTPUT_ENUM_CLASS_STR(PDB_CallingConv, TriCall , "tricall", OS)
94  CASE_OUTPUT_ENUM_CLASS_STR(PDB_CallingConv, SH5Call , "sh5call", OS)
95  CASE_OUTPUT_ENUM_CLASS_STR(PDB_CallingConv, M32RCall , "m32rcall", OS)
96  CASE_OUTPUT_ENUM_CLASS_STR(PDB_CallingConv, ClrCall , "clrcall", OS)
97  CASE_OUTPUT_ENUM_CLASS_STR(PDB_CallingConv, Inline , "inlinecall", OS)
98  CASE_OUTPUT_ENUM_CLASS_STR(PDB_CallingConv, NearVector , "vectorcall", OS)
99  }
100  return OS;
101 }
102 
104  switch (Data) {
110  CASE_OUTPUT_ENUM_CLASS_STR(PDB_DataKind, FileStatic, "static global", OS)
115  }
116  return OS;
117 }
118 
120  const llvm::codeview::CPURegister &CpuReg) {
121  if (CpuReg.Cpu == llvm::codeview::CPUType::ARMNT) {
122  switch (CpuReg.Reg) {
123 #define CV_REGISTERS_ARM
124 #define CV_REGISTER(name, val) \
125  case codeview::RegisterId::name: \
126  OS << #name; \
127  return OS;
128 #include "llvm/DebugInfo/CodeView/CodeViewRegisters.def"
129 #undef CV_REGISTER
130 #undef CV_REGISTERS_ARM
131 
132  default:
133  break;
134  }
135  } else if (CpuReg.Cpu == llvm::codeview::CPUType::ARM64) {
136  switch (CpuReg.Reg) {
137 #define CV_REGISTERS_ARM64
138 #define CV_REGISTER(name, val) \
139  case codeview::RegisterId::name: \
140  OS << #name; \
141  return OS;
142 #include "llvm/DebugInfo/CodeView/CodeViewRegisters.def"
143 #undef CV_REGISTER
144 #undef CV_REGISTERS_ARM64
145 
146  default:
147  break;
148  }
149  } else {
150  switch (CpuReg.Reg) {
151 #define CV_REGISTERS_X86
152 #define CV_REGISTER(name, val) \
153  case codeview::RegisterId::name: \
154  OS << #name; \
155  return OS;
156 #include "llvm/DebugInfo/CodeView/CodeViewRegisters.def"
157 #undef CV_REGISTER
158 #undef CV_REGISTERS_X86
159 
160  default:
161  break;
162  }
163  }
164  OS << static_cast<int>(CpuReg.Reg);
165  return OS;
166 }
167 
169  switch (Loc) {
170  CASE_OUTPUT_ENUM_CLASS_STR(PDB_LocType, Static, "static", OS)
181  "regrelaliasindir", OS)
182  default:
183  OS << "Unknown";
184  }
185  return OS;
186 }
187 
189  const codeview::ThunkOrdinal &Thunk) {
190  switch (Thunk) {
198  }
199  return OS;
200 }
201 
203  const PDB_Checksum &Checksum) {
204  switch (Checksum) {
209  }
210  return OS;
211 }
212 
214  switch (Lang) {
234  }
235  return OS;
236 }
237 
239  switch (Tag) {
282  default:
283  OS << "Unknown SymTag " << uint32_t(Tag);
284  }
285  return OS;
286 }
287 
289  const PDB_MemberAccess &Access) {
290  switch (Access) {
291  CASE_OUTPUT_ENUM_CLASS_STR(PDB_MemberAccess, Public, "public", OS)
292  CASE_OUTPUT_ENUM_CLASS_STR(PDB_MemberAccess, Protected, "protected", OS)
293  CASE_OUTPUT_ENUM_CLASS_STR(PDB_MemberAccess, Private, "private", OS)
294  }
295  return OS;
296 }
297 
299  switch (Type) {
300  CASE_OUTPUT_ENUM_CLASS_STR(PDB_UdtType, Class, "class", OS)
302  CASE_OUTPUT_ENUM_CLASS_STR(PDB_UdtType, Interface, "interface", OS)
304  }
305  return OS;
306 }
307 
309  const PDB_Machine &Machine) {
310  switch (Machine) {
331  default:
332  OS << "Unknown";
333  }
334  return OS;
335 }
336 
338  uint32_t Compression) {
339  switch (Compression) {
343  CASE_OUTPUT_ENUM_CLASS_STR(PDB_SourceCompression, RunLengthEncoded, "RLE",
344  OS)
346  default:
347  OS << "Unknown (" << Compression << ")";
348  }
349  return OS;
350 }
351 
353  switch (Value.Type) {
355  OS << (Value.Value.Bool ? "true" : "false");
356  break;
358  OS << Value.Value.Double;
359  break;
361  OS << Value.Value.Int16;
362  break;
364  OS << Value.Value.Int32;
365  break;
367  OS << Value.Value.Int64;
368  break;
370  OS << static_cast<int>(Value.Value.Int8);
371  break;
373  OS << Value.Value.Single;
374  break;
376  OS << Value.Value.UInt16;
377  break;
379  OS << Value.Value.UInt32;
380  break;
382  OS << Value.Value.UInt64;
383  break;
385  OS << static_cast<unsigned>(Value.Value.UInt8);
386  break;
388  OS << Value.Value.String;
389  break;
390  default:
391  OS << Value.Type;
392  }
393  return OS;
394 }
395 
397  const VersionInfo &Version) {
398  OS << Version.Major << "." << Version.Minor << "." << Version.Build;
399  return OS;
400 }
401 
403  for (auto Tag : Stats) {
404  OS << Tag.first << ":" << Tag.second << " ";
405  }
406  return OS;
407 }
llvm::codeview::JScript
@ JScript
Definition: CodeView.h:158
llvm::codeview::CPUType::ARM64
@ ARM64
llvm::pdb::PDB_SymType::UsingNamespace
@ UsingNamespace
llvm::pdb::PDB_SymType::CustomType
@ CustomType
llvm::pdb::PDB_BuiltinType::ULong
@ ULong
llvm::pdb::PDB_UdtType::Struct
@ Struct
llvm
Definition: AllocatorList.h:23
llvm::pdb::PDB_DataKind::FileStatic
@ FileStatic
llvm::InlineSite
std::tuple< uint64_t, uint32_t > InlineSite
Definition: MCPseudoProbe.h:100
llvm::pdb::PDB_BuiltinType::Char
@ Char
llvm::pdb::PDB_SymType::FunctionSig
@ FunctionSig
llvm::pdb::PDB_SymType::BaseClass
@ BaseClass
llvm::pdb::PDB_DataKind::Member
@ Member
llvm::pdb::PDB_SymType::MatrixType
@ MatrixType
llvm::Function
Definition: Function.h:61
llvm::pdb::Int64
@ Int64
Definition: PDBTypes.h:399
llvm::pdb::PDB_Machine::PowerPC
@ PowerPC
llvm::pdb::PDB_SymType::CoffGroup
@ CoffGroup
llvm::pdb::PDB_SymType::HeapAllocationSite
@ HeapAllocationSite
llvm::SHA256
Definition: SHA256.h:33
llvm::pdb::UInt16
@ UInt16
Definition: PDBTypes.h:403
llvm::pdb::PDB_DataKind::StaticMember
@ StaticMember
llvm::pdb::PDB_BuiltinType::Char32
@ Char32
llvm::pdb::PDB_UdtType
PDB_UdtType
These values correspond to the UdtKind enumeration, and are documented here: https://msdn....
Definition: PDBTypes.h:310
llvm::pdb::PDB_LocType
PDB_LocType
These values correspond to the LocationType enumeration, and are documented here: https://msdn....
Definition: PDBTypes.h:292
llvm::pdb::PDB_SymType::BaseInterface
@ BaseInterface
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:46
llvm::pdb::VersionInfo
Definition: PDBTypes.h:386
llvm::pdb::PDB_Machine::PowerPCFP
@ PowerPCFP
llvm::codeview::Link
@ Link
Definition: CodeView.h:151
llvm::ArrayType
Class to represent array types.
Definition: DerivedTypes.h:359
x86
Note that only the low bits of effective_addr2 are used On bit we don t eliminate the computation of the top half of effective_addr2 because we don t have whole function selection dags On x86
Definition: README.txt:318
llvm::codeview::CPUType::ARMNT
@ ARMNT
llvm::Data
@ Data
Definition: SIMachineScheduler.h:56
llvm::Bitfield
Holds functions to get, set or test bitfields.
Definition: Bitfields.h:212
llvm::pdb::Double
@ Double
Definition: PDBTypes.h:401
llvm::pdb::PDB_SymType
PDB_SymType
These values correspond to the SymTagEnum enumeration, and are documented here: https://msdn....
Definition: PDBTypes.h:243
llvm::pdb::PDB_Machine::SH5
@ SH5
llvm::pdb::PDB_SymType::FuncDebugStart
@ FuncDebugStart
llvm::pdb::PDB_LocType::BitField
@ BitField
llvm::pdb::PDB_Machine::Am33
@ Am33
llvm::codeview::Cvtres
@ Cvtres
Definition: CodeView.h:152
llvm::pdb::PDB_Machine::Ebc
@ Ebc
llvm::pdb::PDB_BuiltinType::Currency
@ Currency
llvm::codeview::HLSL
@ HLSL
Definition: CodeView.h:160
llvm::pdb::PDB_LocType::RegRel
@ RegRel
llvm::pdb::PDB_DataKind::StaticLocal
@ StaticLocal
llvm::SHA1
A class that wrap the SHA1 algorithm.
Definition: SHA1.h:26
C
(vector float) vec_cmpeq(*A, *B) C
Definition: README_ALTIVEC.txt:86
llvm::pdb::PDB_DataKind
PDB_DataKind
These values correspond to the DataKind enumeration, and are documented here: https://msdn....
Definition: PDBTypes.h:228
llvm::codeview::Masm
@ Masm
Definition: CodeView.h:147
llvm::pdb::PDB_SymType::FunctionArg
@ FunctionArg
llvm::codeview::CPURegister::Cpu
CPUType Cpu
Definition: CodeView.h:530
Param
Value * Param
Definition: NVPTXLowerArgs.cpp:163
llvm::pdb::PDB_SourceCompression
Definition: PDBTypes.h:154
llvm::pdb::PDB_SymType::UDT
@ UDT
llvm::pdb::UInt32
@ UInt32
Definition: PDBTypes.h:404
llvm::pdb::PDB_SymType::Caller
@ Caller
llvm::pdb::PDB_SymType::CompilandDetails
@ CompilandDetails
llvm::pdb::Int8
@ Int8
Definition: PDBTypes.h:396
llvm::pdb::PDB_Machine::MipsFpu16
@ MipsFpu16
llvm::codeview::CPURegister
Definition: CodeView.h:524
llvm::pdb::PDB_Machine::Arm
@ Arm
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:50
llvm::pdb::PDB_BuiltinType::BCD
@ BCD
llvm::pdb::PDB_LocType::TLS
@ TLS
llvm::IndexedInstrProf::Version
const uint64_t Version
Definition: InstrProf.h:991
llvm::pdb::PDB_Machine::Mips16
@ Mips16
llvm::codeview::Java
@ Java
Definition: CodeView.h:157
llvm::None
const NoneType None
Definition: None.h:23
llvm::pdb::PDB_SymType::VTableShape
@ VTableShape
llvm::pdb
Definition: ConcreteSymbolEnumerator.h:20
llvm::pdb::PDB_BuiltinType::Char16
@ Char16
llvm::VectorType
Base class of all SIMD vector types.
Definition: DerivedTypes.h:391
llvm::pdb::PDB_Machine::R4000
@ R4000
llvm::codeview::Fortran
@ Fortran
Definition: CodeView.h:146
llvm::Value::Value
Value(Type *Ty, unsigned scid)
Definition: Value.cpp:53
llvm::pdb::PDB_BuiltinType::Date
@ Date
llvm::Constant
This is an important base class in LLVM.
Definition: Constant.h:41
llvm::pdb::PDB_Machine::ArmNT
@ ArmNT
llvm::pdb::Unknown
@ Unknown
Definition: PDBTypes.h:395
D
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
llvm::pdb::PDB_BuiltinType::WCharT
@ WCharT
Generic
@ Generic
Definition: AArch64MCAsmInfo.cpp:23
llvm::MD5
Definition: MD5.h:41
CASE_OUTPUT_ENUM_CLASS_NAME
#define CASE_OUTPUT_ENUM_CLASS_NAME(Class, Value, Stream)
Definition: PDBExtras.cpp:21
llvm::pdb::Int32
@ Int32
Definition: PDBTypes.h:398
llvm::codeview::Cvtpgd
@ Cvtpgd
Definition: CodeView.h:153
llvm::pdb::PDB_LocType::Enregistered
@ Enregistered
llvm::PointerType
Class to represent pointers.
Definition: DerivedTypes.h:634
ArrayRef.h
llvm::pdb::PDB_SymType::VTable
@ VTable
llvm::codeview::ILAsm
@ ILAsm
Definition: CodeView.h:156
llvm::pdb::PDB_VariantType
PDB_VariantType
Definition: PDBTypes.h:393
llvm::pdb::PDB_SymType::Thunk
@ Thunk
llvm::pdb::PDB_SymType::Dimension
@ Dimension
llvm::pdb::PDB_Machine::WceMipsV2
@ WceMipsV2
llvm::pdb::PDB_UdtType::Union
@ Union
llvm::codeview::SourceLanguage
SourceLanguage
These values correspond to the CV_CFL_LANG enumeration, and are documented here: https://msdn....
Definition: CodeView.h:143
llvm::codeview::CPURegister::Reg
RegisterId Reg
Definition: CodeView.h:531
llvm::pdb::operator<<
raw_ostream & operator<<(raw_ostream &OS, const PDB_VariantType &Value)
Definition: PDBExtras.cpp:24
llvm::pdb::PDB_Machine::Amd64
@ Amd64
llvm::pdb::PDB_Machine
PDB_Machine
Definition: PDBTypes.h:125
llvm::pdb::PDB_LocType::MetaData
@ MetaData
llvm::pdb::PDB_SymType::FuncDebugEnd
@ FuncDebugEnd
uint32_t
llvm::pdb::PDB_BuiltinType
PDB_BuiltinType
These values correspond to the Basictype enumeration, and are documented here: https://msdn....
Definition: PDBTypes.h:335
llvm::pdb::PDB_SymType::Enum
@ Enum
llvm::pdb::Bool
@ Bool
Definition: PDBTypes.h:406
llvm::pdb::PDB_BuiltinType::Complex
@ Complex
llvm::pdb::TagStats
std::unordered_map< PDB_SymType, int > TagStats
Definition: PDBExtras.h:23
llvm::pdb::Single
@ Single
Definition: PDBTypes.h:400
llvm::pdb::PDB_SymType::HLSLType
@ HLSLType
Callee
amdgpu Simplify well known AMD library false FunctionCallee Callee
Definition: AMDGPULibCalls.cpp:206
llvm::pdb::PDB_DataKind::Local
@ Local
llvm::pdb::PDB_SymType::Annotation
@ Annotation
llvm::pdb::Variant
Definition: PDBTypes.h:410
CASE_OUTPUT_ENUM_CLASS_STR
#define CASE_OUTPUT_ENUM_CLASS_STR(Class, Value, Str, Stream)
Definition: PDBExtras.cpp:16
llvm::pdb::PDB_SymType::Label
@ Label
llvm::pdb::PDB_SymType::CompilandEnv
@ CompilandEnv
llvm::pdb::PDB_SymType::Inlinee
@ Inlinee
Stats
block placement Basic Block Placement Stats
Definition: MachineBlockPlacement.cpp:3463
llvm::pdb::PDB_Checksum
PDB_Checksum
Specifies the hash algorithm that a source file from a PDB was hashed with.
Definition: PDBTypes.h:119
llvm::pdb::PDB_LocType::Slot
@ Slot
llvm::pdb::PDB_SymType::Compiland
@ Compiland
llvm::pdb::PDB_SymType::ManagedType
@ ManagedType
llvm::pdb::PDB_SymType::CallSite
@ CallSite
llvm::pdb::Int16
@ Int16
Definition: PDBTypes.h:397
llvm::pdb::PDB_LocType::ThisRel
@ ThisRel
llvm::pdb::dumpPDBSourceCompression
raw_ostream & dumpPDBSourceCompression(raw_ostream &OS, uint32_t Compression)
Definition: PDBExtras.cpp:337
llvm::codeview::CSharp
@ CSharp
Definition: CodeView.h:154
llvm::pdb::PDB_Machine::MipsFpu
@ MipsFpu
llvm::codeview::VB
@ VB
Definition: CodeView.h:155
llvm::codeview::Cobol
@ Cobol
Definition: CodeView.h:150
llvm::pdb::PDB_BuiltinType::Long
@ Long
llvm::codeview::ThunkOrdinal
ThunkOrdinal
These values correspond to the THUNK_ORDINAL enumeration.
Definition: CodeView.h:548
llvm::pdb::PDB_MemberAccess
PDB_MemberAccess
Definition: PDBTypes.h:384
llvm::codeview::Cpp
@ Cpp
Definition: CodeView.h:145
llvm::pdb::PDB_SymType::BuiltinType
@ BuiltinType
Machine
COFF::MachineTypes Machine
Definition: COFFYAML.cpp:365
llvm::pdb::PDB_SymType::Typedef
@ Typedef
llvm::pdb::PDB_LocType::RegRelAliasIndir
@ RegRelAliasIndir
llvm::pdb::PDB_SymType::Exe
@ Exe
PDBExtras.h
llvm::codeview::CallingConvention
CallingConvention
These values correspond to the CV_call_e enumeration, and are documented at the following locations: ...
Definition: CodeView.h:173
llvm::pdb::PDB_DataKind::Global
@ Global
llvm::pdb::PDB_DataKind::ObjectPtr
@ ObjectPtr
llvm::pdb::PDB_SymType::PublicSymbol
@ PublicSymbol
llvm::pdb::String
@ String
Definition: PDBTypes.h:407
raw_ostream.h
llvm::pdb::UInt64
@ UInt64
Definition: PDBTypes.h:405
llvm::pdb::UInt8
@ UInt8
Definition: PDBTypes.h:402
llvm::pdb::PDB_SymType::Block
@ Block
llvm::pdb::PDB_BuiltinType::BSTR
@ BSTR
llvm::pdb::PDB_LocType::IlRel
@ IlRel
llvm::Value
LLVM Value Representation.
Definition: Value.h:75
llvm::pdb::PDB_SymType::Export
@ Export