LLVM  4.0.0
PDBExtras.cpp
Go to the documentation of this file.
1 //===- PDBExtras.cpp - helper functions and classes for PDBs -----*- C++-*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
11 
12 #include "llvm/ADT/ArrayRef.h"
13 
14 using namespace llvm;
15 using namespace llvm::pdb;
16 
17 #define CASE_OUTPUT_ENUM_CLASS_STR(Class, Value, Str, Stream) \
18  case Class::Value: \
19  Stream << Str; \
20  break;
21 
22 #define CASE_OUTPUT_ENUM_CLASS_NAME(Class, Value, Stream) \
23  CASE_OUTPUT_ENUM_CLASS_STR(Class, Value, #Value, Stream)
24 
26  const PDB_VariantType &Type) {
27  switch (Type) {
39  default:
40  OS << "Unknown";
41  }
42  return OS;
43 }
44 
46  const PDB_CallingConv &Conv) {
47  OS << "__";
48  switch (Conv) {
49  CASE_OUTPUT_ENUM_CLASS_STR(PDB_CallingConv, NearC , "cdecl", OS)
50  CASE_OUTPUT_ENUM_CLASS_STR(PDB_CallingConv, FarC , "cdecl", OS)
51  CASE_OUTPUT_ENUM_CLASS_STR(PDB_CallingConv, NearPascal , "pascal", OS)
52  CASE_OUTPUT_ENUM_CLASS_STR(PDB_CallingConv, FarPascal , "pascal", OS)
53  CASE_OUTPUT_ENUM_CLASS_STR(PDB_CallingConv, NearFast , "fastcall", OS)
54  CASE_OUTPUT_ENUM_CLASS_STR(PDB_CallingConv, FarFast , "fastcall", OS)
55  CASE_OUTPUT_ENUM_CLASS_STR(PDB_CallingConv, NearStdCall, "stdcall", OS)
56  CASE_OUTPUT_ENUM_CLASS_STR(PDB_CallingConv, FarStdCall , "stdcall", OS)
57  CASE_OUTPUT_ENUM_CLASS_STR(PDB_CallingConv, NearSysCall, "syscall", OS)
58  CASE_OUTPUT_ENUM_CLASS_STR(PDB_CallingConv, FarSysCall , "syscall", OS)
59  CASE_OUTPUT_ENUM_CLASS_STR(PDB_CallingConv, ThisCall , "thiscall", OS)
60  CASE_OUTPUT_ENUM_CLASS_STR(PDB_CallingConv, MipsCall , "mipscall", OS)
62  CASE_OUTPUT_ENUM_CLASS_STR(PDB_CallingConv, AlphaCall , "alphacall", OS)
63  CASE_OUTPUT_ENUM_CLASS_STR(PDB_CallingConv, PpcCall , "ppccall", OS)
64  CASE_OUTPUT_ENUM_CLASS_STR(PDB_CallingConv, SHCall , "superhcall", OS)
65  CASE_OUTPUT_ENUM_CLASS_STR(PDB_CallingConv, ArmCall , "armcall", OS)
66  CASE_OUTPUT_ENUM_CLASS_STR(PDB_CallingConv, AM33Call , "am33call", OS)
67  CASE_OUTPUT_ENUM_CLASS_STR(PDB_CallingConv, TriCall , "tricall", OS)
68  CASE_OUTPUT_ENUM_CLASS_STR(PDB_CallingConv, SH5Call , "sh5call", OS)
69  CASE_OUTPUT_ENUM_CLASS_STR(PDB_CallingConv, M32RCall , "m32rcall", OS)
70  CASE_OUTPUT_ENUM_CLASS_STR(PDB_CallingConv, ClrCall , "clrcall", OS)
71  CASE_OUTPUT_ENUM_CLASS_STR(PDB_CallingConv, Inline , "inlinecall", OS)
72  CASE_OUTPUT_ENUM_CLASS_STR(PDB_CallingConv, NearVector , "vectorcall", OS)
73  }
74  return OS;
75 }
76 
78  switch (Data) {
80  CASE_OUTPUT_ENUM_CLASS_STR(PDB_DataKind, Local, "local", OS)
85  CASE_OUTPUT_ENUM_CLASS_STR(PDB_DataKind, Global, "global", OS)
89  }
90  return OS;
91 }
92 
94  const codeview::RegisterId &Reg) {
95  switch (Reg) {
143  default:
144  OS << static_cast<int>(Reg);
145  }
146  return OS;
147 }
148 
150  switch (Loc) {
151  CASE_OUTPUT_ENUM_CLASS_STR(PDB_LocType, Static, "static", OS)
161  default:
162  OS << "Unknown";
163  }
164  return OS;
165 }
166 
168  const codeview::ThunkOrdinal &Thunk) {
169  switch (Thunk) {
177  }
178  return OS;
179 }
180 
182  const PDB_Checksum &Checksum) {
183  switch (Checksum) {
187  }
188  return OS;
189 }
190 
192  switch (Lang) {
210  }
211  return OS;
212 }
213 
215  switch (Tag) {
246  default:
247  OS << "Unknown";
248  }
249  return OS;
250 }
251 
253  const PDB_MemberAccess &Access) {
254  switch (Access) {
255  CASE_OUTPUT_ENUM_CLASS_STR(PDB_MemberAccess, Public, "public", OS)
256  CASE_OUTPUT_ENUM_CLASS_STR(PDB_MemberAccess, Protected, "protected", OS)
257  CASE_OUTPUT_ENUM_CLASS_STR(PDB_MemberAccess, Private, "private", OS)
258  }
259  return OS;
260 }
261 
263  switch (Type) {
264  CASE_OUTPUT_ENUM_CLASS_STR(PDB_UdtType, Class, "class", OS)
265  CASE_OUTPUT_ENUM_CLASS_STR(PDB_UdtType, Struct, "struct", OS)
266  CASE_OUTPUT_ENUM_CLASS_STR(PDB_UdtType, Interface, "interface", OS)
268  }
269  return OS;
270 }
271 
273  static const char *Lookup = "0123456789ABCDEF";
274 
275  static_assert(sizeof(PDB_UniqueId) == 16, "Expected 16-byte GUID");
276  ArrayRef<uint8_t> GuidBytes(reinterpret_cast<const uint8_t*>(&Id), 16);
277  OS << "{";
278  for (int i=0; i < 16;) {
279  uint8_t Byte = GuidBytes[i];
280  uint8_t HighNibble = (Byte >> 4) & 0xF;
281  uint8_t LowNibble = Byte & 0xF;
282  OS << Lookup[HighNibble] << Lookup[LowNibble];
283  ++i;
284  if (i>=4 && i<=10 && i%2==0)
285  OS << "-";
286  }
287  OS << "}";
288  return OS;
289 }
290 
292  const PDB_Machine &Machine) {
293  switch (Machine) {
314  default:
315  OS << "Unknown";
316  }
317  return OS;
318 }
319 
321  switch (Value.Type) {
323  OS << (Value.Value.Bool ? "true" : "false");
324  break;
326  OS << Value.Value.Double;
327  break;
329  OS << Value.Value.Int16;
330  break;
332  OS << Value.Value.Int32;
333  break;
335  OS << Value.Value.Int64;
336  break;
338  OS << static_cast<int>(Value.Value.Int8);
339  break;
341  OS << Value.Value.Single;
342  break;
344  OS << Value.Value.Double;
345  break;
347  OS << Value.Value.UInt32;
348  break;
350  OS << Value.Value.UInt64;
351  break;
353  OS << static_cast<unsigned>(Value.Value.UInt8);
354  break;
356  OS << Value.Value.String;
357  break;
358  default:
359  OS << Value.Type;
360  }
361  return OS;
362 }
363 
365  const VersionInfo &Version) {
366  OS << Version.Major << "." << Version.Minor << "." << Version.Build;
367  return OS;
368 }
369 
371  for (auto Tag : Stats) {
372  OS << Tag.first << ":" << Tag.second << " ";
373  }
374  return OS;
375 }
const NoneType None
Definition: None.h:23
size_t i
PDB_UdtType
These values correspond to the UdtKind enumeration, and are documented here: https://msdn.microsoft.com/en-us/library/wcstk66t.aspx.
Definition: PDBTypes.h:216
A class that wrap the SHA1 algorithm.
Definition: SHA1.h:29
PDB_Checksum
Specifies the hash algorithm that a source file from a PDB was hashed with.
Definition: PDBTypes.h:103
raw_ostream & operator<<(raw_ostream &OS, const PDB_VariantType &Value)
Definition: PDBExtras.cpp:25
#define CASE_OUTPUT_ENUM_CLASS_NAME(Class, Value, Stream)
Definition: PDBExtras.cpp:22
static int Lookup(ArrayRef< TableEntry > Table, unsigned Opcode)
Reg
All possible values of the reg field in the ModR/M byte.
#define CASE_OUTPUT_ENUM_CLASS_STR(Class, Value, Str, Stream)
Definition: PDBExtras.cpp:17
block placement Basic Block Placement Stats
Class to represent array types.
Definition: DerivedTypes.h:345
COFF::MachineTypes Machine
Definition: COFFYAML.cpp:303
Class to represent pointers.
Definition: DerivedTypes.h:443
PDB_SymType
These values correspond to the SymTagEnum enumeration, and are documented here: https://msdn.microsoft.com/en-us/library/bkedss5f.aspx.
Definition: PDBTypes.h:162
uint32_t UInt32
Definition: PDBTypes.h:298
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:45
This is an important base class in LLVM.
Definition: Constant.h:42
Defines a 128-bit unique identifier.
Definition: RawTypes.h:265
PDB_DataKind
These values correspond to the DataKind enumeration, and are documented here: https://msdn.microsoft.com/en-us/library/b2x2t313.aspx.
Definition: PDBTypes.h:147
PDB_LocType
These values correspond to the LocationType enumeration, and are documented here: https://msdn...
Definition: PDBTypes.h:199
uint64_t UInt64
Definition: PDBTypes.h:299
SourceLanguage
These values correspond to the CV_CFL_LANG enumeration, and are documented here: https://msdn.microsoft.com/en-us/library/bw3aekw6.aspx.
Definition: CodeView.h:137
static GCRegistry::Add< ShadowStackGC > C("shadow-stack","Very portable GC for uncooperative code generators")
PDB_VariantType
Definition: PDBTypes.h:258
Definition: MD5.h:39
ThunkOrdinal
These values correspond to the THUNK_ORDINAL enumeration.
Definition: CodeView.h:528
LLVM Value Representation.
Definition: Value.h:71
CallingConvention
These values correspond to the CV_call_e enumeration, and are documented at the following locations: ...
Definition: CodeView.h:162
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:44
PDB_VariantType Type
Definition: PDBTypes.h:287
std::unordered_map< PDB_SymType, int > TagStats
Definition: PDBExtras.h:21
const uint64_t Version
Definition: InstrProf.h:799
union llvm::pdb::Variant::@75 Value
PDB_MemberAccess
Definition: PDBTypes.h:249