Home | History | Annotate | Download | only in PDB
      1 //===- PDBExtras.cpp - helper functions and classes for PDBs --------------===//
      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 
     10 #include "llvm/DebugInfo/PDB/PDBExtras.h"
     11 #include "llvm/ADT/ArrayRef.h"
     12 #include "llvm/Support/raw_ostream.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 
     25 raw_ostream &llvm::pdb::operator<<(raw_ostream &OS,
     26                                    const PDB_VariantType &Type) {
     27   switch (Type) {
     28     CASE_OUTPUT_ENUM_CLASS_NAME(PDB_VariantType, Bool, OS)
     29     CASE_OUTPUT_ENUM_CLASS_NAME(PDB_VariantType, Single, OS)
     30     CASE_OUTPUT_ENUM_CLASS_NAME(PDB_VariantType, Double, OS)
     31     CASE_OUTPUT_ENUM_CLASS_NAME(PDB_VariantType, Int8, OS)
     32     CASE_OUTPUT_ENUM_CLASS_NAME(PDB_VariantType, Int16, OS)
     33     CASE_OUTPUT_ENUM_CLASS_NAME(PDB_VariantType, Int32, OS)
     34     CASE_OUTPUT_ENUM_CLASS_NAME(PDB_VariantType, Int64, OS)
     35     CASE_OUTPUT_ENUM_CLASS_NAME(PDB_VariantType, UInt8, OS)
     36     CASE_OUTPUT_ENUM_CLASS_NAME(PDB_VariantType, UInt16, OS)
     37     CASE_OUTPUT_ENUM_CLASS_NAME(PDB_VariantType, UInt32, OS)
     38     CASE_OUTPUT_ENUM_CLASS_NAME(PDB_VariantType, UInt64, OS)
     39     default:
     40       OS << "Unknown";
     41   }
     42   return OS;
     43 }
     44 
     45 raw_ostream &llvm::pdb::operator<<(raw_ostream &OS,
     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)
     61     CASE_OUTPUT_ENUM_CLASS_STR(PDB_CallingConv, Generic    , "genericcall", 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 
     77 raw_ostream &llvm::pdb::operator<<(raw_ostream &OS, const PDB_DataKind &Data) {
     78   switch (Data) {
     79     CASE_OUTPUT_ENUM_CLASS_STR(PDB_DataKind, Unknown, "unknown", OS)
     80     CASE_OUTPUT_ENUM_CLASS_STR(PDB_DataKind, Local, "local", OS)
     81     CASE_OUTPUT_ENUM_CLASS_STR(PDB_DataKind, StaticLocal, "static local", OS)
     82     CASE_OUTPUT_ENUM_CLASS_STR(PDB_DataKind, Param, "param", OS)
     83     CASE_OUTPUT_ENUM_CLASS_STR(PDB_DataKind, ObjectPtr, "this ptr", OS)
     84     CASE_OUTPUT_ENUM_CLASS_STR(PDB_DataKind, FileStatic, "static global", OS)
     85     CASE_OUTPUT_ENUM_CLASS_STR(PDB_DataKind, Global, "global", OS)
     86     CASE_OUTPUT_ENUM_CLASS_STR(PDB_DataKind, Member, "member", OS)
     87     CASE_OUTPUT_ENUM_CLASS_STR(PDB_DataKind, StaticMember, "static member", OS)
     88     CASE_OUTPUT_ENUM_CLASS_STR(PDB_DataKind, Constant, "const", OS)
     89   }
     90   return OS;
     91 }
     92 
     93 raw_ostream &llvm::pdb::operator<<(raw_ostream &OS,
     94                                    const codeview::RegisterId &Reg) {
     95   switch (Reg) {
     96 #define CV_REGISTER(name, val) case codeview::RegisterId::name: OS << #name; return OS;
     97 #include "llvm/DebugInfo/CodeView/CodeViewRegisters.def"
     98 #undef CV_REGISTER
     99   }
    100   OS << static_cast<int>(Reg);
    101   return OS;
    102 }
    103 
    104 raw_ostream &llvm::pdb::operator<<(raw_ostream &OS, const PDB_LocType &Loc) {
    105   switch (Loc) {
    106     CASE_OUTPUT_ENUM_CLASS_STR(PDB_LocType, Static, "static", OS)
    107     CASE_OUTPUT_ENUM_CLASS_STR(PDB_LocType, TLS, "tls", OS)
    108     CASE_OUTPUT_ENUM_CLASS_STR(PDB_LocType, RegRel, "regrel", OS)
    109     CASE_OUTPUT_ENUM_CLASS_STR(PDB_LocType, ThisRel, "thisrel", OS)
    110     CASE_OUTPUT_ENUM_CLASS_STR(PDB_LocType, Enregistered, "register", OS)
    111     CASE_OUTPUT_ENUM_CLASS_STR(PDB_LocType, BitField, "bitfield", OS)
    112     CASE_OUTPUT_ENUM_CLASS_STR(PDB_LocType, Slot, "slot", OS)
    113     CASE_OUTPUT_ENUM_CLASS_STR(PDB_LocType, IlRel, "IL rel", OS)
    114     CASE_OUTPUT_ENUM_CLASS_STR(PDB_LocType, MetaData, "metadata", OS)
    115     CASE_OUTPUT_ENUM_CLASS_STR(PDB_LocType, Constant, "constant", OS)
    116     CASE_OUTPUT_ENUM_CLASS_STR(PDB_LocType, RegRelAliasIndir,
    117                                "regrelaliasindir", OS)
    118   default:
    119     OS << "Unknown";
    120   }
    121   return OS;
    122 }
    123 
    124 raw_ostream &llvm::pdb::operator<<(raw_ostream &OS,
    125                                    const codeview::ThunkOrdinal &Thunk) {
    126   switch (Thunk) {
    127     CASE_OUTPUT_ENUM_CLASS_NAME(codeview::ThunkOrdinal, BranchIsland, OS)
    128     CASE_OUTPUT_ENUM_CLASS_NAME(codeview::ThunkOrdinal, Pcode, OS)
    129     CASE_OUTPUT_ENUM_CLASS_NAME(codeview::ThunkOrdinal, Standard, OS)
    130     CASE_OUTPUT_ENUM_CLASS_NAME(codeview::ThunkOrdinal, ThisAdjustor, OS)
    131     CASE_OUTPUT_ENUM_CLASS_NAME(codeview::ThunkOrdinal, TrampIncremental, OS)
    132     CASE_OUTPUT_ENUM_CLASS_NAME(codeview::ThunkOrdinal, UnknownLoad, OS)
    133     CASE_OUTPUT_ENUM_CLASS_NAME(codeview::ThunkOrdinal, Vcall, OS)
    134   }
    135   return OS;
    136 }
    137 
    138 raw_ostream &llvm::pdb::operator<<(raw_ostream &OS,
    139                                    const PDB_Checksum &Checksum) {
    140   switch (Checksum) {
    141     CASE_OUTPUT_ENUM_CLASS_NAME(PDB_Checksum, None, OS)
    142     CASE_OUTPUT_ENUM_CLASS_NAME(PDB_Checksum, MD5, OS)
    143     CASE_OUTPUT_ENUM_CLASS_NAME(PDB_Checksum, SHA1, OS)
    144     CASE_OUTPUT_ENUM_CLASS_NAME(PDB_Checksum, SHA256, OS)
    145   }
    146   return OS;
    147 }
    148 
    149 raw_ostream &llvm::pdb::operator<<(raw_ostream &OS, const PDB_Lang &Lang) {
    150   switch (Lang) {
    151     CASE_OUTPUT_ENUM_CLASS_NAME(PDB_Lang, C, OS)
    152     CASE_OUTPUT_ENUM_CLASS_STR(PDB_Lang, Cpp, "C++", OS)
    153     CASE_OUTPUT_ENUM_CLASS_NAME(PDB_Lang, Fortran, OS)
    154     CASE_OUTPUT_ENUM_CLASS_NAME(PDB_Lang, Masm, OS)
    155     CASE_OUTPUT_ENUM_CLASS_NAME(PDB_Lang, Pascal, OS)
    156     CASE_OUTPUT_ENUM_CLASS_NAME(PDB_Lang, Basic, OS)
    157     CASE_OUTPUT_ENUM_CLASS_NAME(PDB_Lang, Cobol, OS)
    158     CASE_OUTPUT_ENUM_CLASS_NAME(PDB_Lang, Link, OS)
    159     CASE_OUTPUT_ENUM_CLASS_NAME(PDB_Lang, Cvtres, OS)
    160     CASE_OUTPUT_ENUM_CLASS_NAME(PDB_Lang, Cvtpgd, OS)
    161     CASE_OUTPUT_ENUM_CLASS_NAME(PDB_Lang, CSharp, OS)
    162     CASE_OUTPUT_ENUM_CLASS_NAME(PDB_Lang, VB, OS)
    163     CASE_OUTPUT_ENUM_CLASS_NAME(PDB_Lang, ILAsm, OS)
    164     CASE_OUTPUT_ENUM_CLASS_NAME(PDB_Lang, Java, OS)
    165     CASE_OUTPUT_ENUM_CLASS_NAME(PDB_Lang, JScript, OS)
    166     CASE_OUTPUT_ENUM_CLASS_NAME(PDB_Lang, MSIL, OS)
    167     CASE_OUTPUT_ENUM_CLASS_NAME(PDB_Lang, HLSL, OS)
    168     CASE_OUTPUT_ENUM_CLASS_NAME(PDB_Lang, D, OS)
    169   }
    170   return OS;
    171 }
    172 
    173 raw_ostream &llvm::pdb::operator<<(raw_ostream &OS, const PDB_SymType &Tag) {
    174   switch (Tag) {
    175     CASE_OUTPUT_ENUM_CLASS_NAME(PDB_SymType, Exe, OS)
    176     CASE_OUTPUT_ENUM_CLASS_NAME(PDB_SymType, Compiland, OS)
    177     CASE_OUTPUT_ENUM_CLASS_NAME(PDB_SymType, CompilandDetails, OS)
    178     CASE_OUTPUT_ENUM_CLASS_NAME(PDB_SymType, CompilandEnv, OS)
    179     CASE_OUTPUT_ENUM_CLASS_NAME(PDB_SymType, Function, OS)
    180     CASE_OUTPUT_ENUM_CLASS_NAME(PDB_SymType, Block, OS)
    181     CASE_OUTPUT_ENUM_CLASS_NAME(PDB_SymType, Data, OS)
    182     CASE_OUTPUT_ENUM_CLASS_NAME(PDB_SymType, Annotation, OS)
    183     CASE_OUTPUT_ENUM_CLASS_NAME(PDB_SymType, Label, OS)
    184     CASE_OUTPUT_ENUM_CLASS_NAME(PDB_SymType, PublicSymbol, OS)
    185     CASE_OUTPUT_ENUM_CLASS_NAME(PDB_SymType, UDT, OS)
    186     CASE_OUTPUT_ENUM_CLASS_NAME(PDB_SymType, Enum, OS)
    187     CASE_OUTPUT_ENUM_CLASS_NAME(PDB_SymType, FunctionSig, OS)
    188     CASE_OUTPUT_ENUM_CLASS_NAME(PDB_SymType, PointerType, OS)
    189     CASE_OUTPUT_ENUM_CLASS_NAME(PDB_SymType, ArrayType, OS)
    190     CASE_OUTPUT_ENUM_CLASS_NAME(PDB_SymType, BuiltinType, OS)
    191     CASE_OUTPUT_ENUM_CLASS_NAME(PDB_SymType, Typedef, OS)
    192     CASE_OUTPUT_ENUM_CLASS_NAME(PDB_SymType, BaseClass, OS)
    193     CASE_OUTPUT_ENUM_CLASS_NAME(PDB_SymType, Friend, OS)
    194     CASE_OUTPUT_ENUM_CLASS_NAME(PDB_SymType, FunctionArg, OS)
    195     CASE_OUTPUT_ENUM_CLASS_NAME(PDB_SymType, FuncDebugStart, OS)
    196     CASE_OUTPUT_ENUM_CLASS_NAME(PDB_SymType, FuncDebugEnd, OS)
    197     CASE_OUTPUT_ENUM_CLASS_NAME(PDB_SymType, UsingNamespace, OS)
    198     CASE_OUTPUT_ENUM_CLASS_NAME(PDB_SymType, VTableShape, OS)
    199     CASE_OUTPUT_ENUM_CLASS_NAME(PDB_SymType, VTable, OS)
    200     CASE_OUTPUT_ENUM_CLASS_NAME(PDB_SymType, Custom, OS)
    201     CASE_OUTPUT_ENUM_CLASS_NAME(PDB_SymType, Thunk, OS)
    202     CASE_OUTPUT_ENUM_CLASS_NAME(PDB_SymType, CustomType, OS)
    203     CASE_OUTPUT_ENUM_CLASS_NAME(PDB_SymType, ManagedType, OS)
    204     CASE_OUTPUT_ENUM_CLASS_NAME(PDB_SymType, Dimension, OS)
    205   default:
    206     OS << "Unknown";
    207   }
    208   return OS;
    209 }
    210 
    211 raw_ostream &llvm::pdb::operator<<(raw_ostream &OS,
    212                                    const PDB_MemberAccess &Access) {
    213   switch (Access) {
    214     CASE_OUTPUT_ENUM_CLASS_STR(PDB_MemberAccess, Public, "public", OS)
    215     CASE_OUTPUT_ENUM_CLASS_STR(PDB_MemberAccess, Protected, "protected", OS)
    216     CASE_OUTPUT_ENUM_CLASS_STR(PDB_MemberAccess, Private, "private", OS)
    217   }
    218   return OS;
    219 }
    220 
    221 raw_ostream &llvm::pdb::operator<<(raw_ostream &OS, const PDB_UdtType &Type) {
    222   switch (Type) {
    223     CASE_OUTPUT_ENUM_CLASS_STR(PDB_UdtType, Class, "class", OS)
    224     CASE_OUTPUT_ENUM_CLASS_STR(PDB_UdtType, Struct, "struct", OS)
    225     CASE_OUTPUT_ENUM_CLASS_STR(PDB_UdtType, Interface, "interface", OS)
    226     CASE_OUTPUT_ENUM_CLASS_STR(PDB_UdtType, Union, "union", OS)
    227   }
    228   return OS;
    229 }
    230 
    231 raw_ostream &llvm::pdb::operator<<(raw_ostream &OS,
    232                                    const PDB_Machine &Machine) {
    233   switch (Machine) {
    234     CASE_OUTPUT_ENUM_CLASS_NAME(PDB_Machine, Am33, OS)
    235     CASE_OUTPUT_ENUM_CLASS_NAME(PDB_Machine, Amd64, OS)
    236     CASE_OUTPUT_ENUM_CLASS_NAME(PDB_Machine, Arm, OS)
    237     CASE_OUTPUT_ENUM_CLASS_NAME(PDB_Machine, ArmNT, OS)
    238     CASE_OUTPUT_ENUM_CLASS_NAME(PDB_Machine, Ebc, OS)
    239     CASE_OUTPUT_ENUM_CLASS_NAME(PDB_Machine, x86, OS)
    240     CASE_OUTPUT_ENUM_CLASS_NAME(PDB_Machine, Ia64, OS)
    241     CASE_OUTPUT_ENUM_CLASS_NAME(PDB_Machine, M32R, OS)
    242     CASE_OUTPUT_ENUM_CLASS_NAME(PDB_Machine, Mips16, OS)
    243     CASE_OUTPUT_ENUM_CLASS_NAME(PDB_Machine, MipsFpu, OS)
    244     CASE_OUTPUT_ENUM_CLASS_NAME(PDB_Machine, MipsFpu16, OS)
    245     CASE_OUTPUT_ENUM_CLASS_NAME(PDB_Machine, PowerPC, OS)
    246     CASE_OUTPUT_ENUM_CLASS_NAME(PDB_Machine, PowerPCFP, OS)
    247     CASE_OUTPUT_ENUM_CLASS_NAME(PDB_Machine, R4000, OS)
    248     CASE_OUTPUT_ENUM_CLASS_NAME(PDB_Machine, SH3, OS)
    249     CASE_OUTPUT_ENUM_CLASS_NAME(PDB_Machine, SH3DSP, OS)
    250     CASE_OUTPUT_ENUM_CLASS_NAME(PDB_Machine, SH4, OS)
    251     CASE_OUTPUT_ENUM_CLASS_NAME(PDB_Machine, SH5, OS)
    252     CASE_OUTPUT_ENUM_CLASS_NAME(PDB_Machine, Thumb, OS)
    253     CASE_OUTPUT_ENUM_CLASS_NAME(PDB_Machine, WceMipsV2, OS)
    254   default:
    255     OS << "Unknown";
    256   }
    257   return OS;
    258 }
    259 
    260 raw_ostream &llvm::pdb::operator<<(raw_ostream &OS,
    261                                    const PDB_SourceCompression &Compression) {
    262   switch (Compression) {
    263     CASE_OUTPUT_ENUM_CLASS_NAME(PDB_SourceCompression, None, OS)
    264     CASE_OUTPUT_ENUM_CLASS_NAME(PDB_SourceCompression, Huffman, OS)
    265     CASE_OUTPUT_ENUM_CLASS_NAME(PDB_SourceCompression, LZ, OS)
    266     CASE_OUTPUT_ENUM_CLASS_STR(PDB_SourceCompression, RunLengthEncoded, "RLE",
    267                                OS)
    268   }
    269   return OS;
    270 }
    271 
    272 raw_ostream &llvm::pdb::operator<<(raw_ostream &OS, const Variant &Value) {
    273   switch (Value.Type) {
    274     case PDB_VariantType::Bool:
    275       OS << (Value.Value.Bool ? "true" : "false");
    276       break;
    277     case PDB_VariantType::Double:
    278       OS << Value.Value.Double;
    279       break;
    280     case PDB_VariantType::Int16:
    281       OS << Value.Value.Int16;
    282       break;
    283     case PDB_VariantType::Int32:
    284       OS << Value.Value.Int32;
    285       break;
    286     case PDB_VariantType::Int64:
    287       OS << Value.Value.Int64;
    288       break;
    289     case PDB_VariantType::Int8:
    290       OS << static_cast<int>(Value.Value.Int8);
    291       break;
    292     case PDB_VariantType::Single:
    293       OS << Value.Value.Single;
    294       break;
    295     case PDB_VariantType::UInt16:
    296       OS << Value.Value.Double;
    297       break;
    298     case PDB_VariantType::UInt32:
    299       OS << Value.Value.UInt32;
    300       break;
    301     case PDB_VariantType::UInt64:
    302       OS << Value.Value.UInt64;
    303       break;
    304     case PDB_VariantType::UInt8:
    305       OS << static_cast<unsigned>(Value.Value.UInt8);
    306       break;
    307     case PDB_VariantType::String:
    308       OS << Value.Value.String;
    309       break;
    310     default:
    311       OS << Value.Type;
    312   }
    313   return OS;
    314 }
    315 
    316 raw_ostream &llvm::pdb::operator<<(raw_ostream &OS,
    317                                    const VersionInfo &Version) {
    318   OS << Version.Major << "." << Version.Minor << "." << Version.Build;
    319   return OS;
    320 }
    321 
    322 raw_ostream &llvm::pdb::operator<<(raw_ostream &OS, const TagStats &Stats) {
    323   for (auto Tag : Stats) {
    324     OS << Tag.first << ":" << Tag.second << " ";
    325   }
    326   return OS;
    327 }
    328