Home | History | Annotate | Download | only in llvm-pdbdump
      1 //===- YAMLOutputStyle.cpp ------------------------------------ *- 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 
     10 #include "YAMLOutputStyle.h"
     11 
     12 #include "PdbYaml.h"
     13 #include "llvm-pdbdump.h"
     14 
     15 #include "llvm/DebugInfo/PDB/Raw/DbiStream.h"
     16 #include "llvm/DebugInfo/PDB/Raw/InfoStream.h"
     17 #include "llvm/DebugInfo/PDB/Raw/PDBFile.h"
     18 #include "llvm/DebugInfo/PDB/Raw/RawConstants.h"
     19 
     20 using namespace llvm;
     21 using namespace llvm::pdb;
     22 
     23 YAMLOutputStyle::YAMLOutputStyle(PDBFile &File) : File(File), Out(outs()) {}
     24 
     25 Error YAMLOutputStyle::dump() {
     26   if (opts::pdb2yaml::StreamDirectory || opts::pdb2yaml::PdbStream ||
     27       opts::pdb2yaml::DbiStream)
     28     opts::pdb2yaml::StreamMetadata = true;
     29 
     30   if (auto EC = dumpFileHeaders())
     31     return EC;
     32 
     33   if (auto EC = dumpStreamMetadata())
     34     return EC;
     35 
     36   if (auto EC = dumpStreamDirectory())
     37     return EC;
     38 
     39   if (auto EC = dumpPDBStream())
     40     return EC;
     41 
     42   if (auto EC = dumpDbiStream())
     43     return EC;
     44 
     45   flush();
     46   return Error::success();
     47 }
     48 
     49 Error YAMLOutputStyle::dumpFileHeaders() {
     50   if (opts::pdb2yaml::NoFileHeaders)
     51     return Error::success();
     52 
     53   yaml::MsfHeaders Headers;
     54   Obj.Headers.emplace();
     55   Obj.Headers->SuperBlock.NumBlocks = File.getBlockCount();
     56   Obj.Headers->SuperBlock.BlockMapAddr = File.getBlockMapIndex();
     57   Obj.Headers->BlockMapOffset = File.getBlockMapOffset();
     58   Obj.Headers->SuperBlock.BlockSize = File.getBlockSize();
     59   auto Blocks = File.getDirectoryBlockArray();
     60   Obj.Headers->DirectoryBlocks.assign(Blocks.begin(), Blocks.end());
     61   Obj.Headers->NumDirectoryBlocks = File.getNumDirectoryBlocks();
     62   Obj.Headers->SuperBlock.NumDirectoryBytes = File.getNumDirectoryBytes();
     63   Obj.Headers->NumStreams =
     64       opts::pdb2yaml::StreamMetadata ? File.getNumStreams() : 0;
     65   Obj.Headers->SuperBlock.Unknown0 = File.getUnknown0();
     66   Obj.Headers->SuperBlock.Unknown1 = File.getUnknown1();
     67   Obj.Headers->FileSize = File.getFileSize();
     68 
     69   return Error::success();
     70 }
     71 
     72 Error YAMLOutputStyle::dumpStreamMetadata() {
     73   if (!opts::pdb2yaml::StreamMetadata)
     74     return Error::success();
     75 
     76   Obj.StreamSizes = File.getStreamSizes();
     77   return Error::success();
     78 }
     79 
     80 Error YAMLOutputStyle::dumpStreamDirectory() {
     81   if (!opts::pdb2yaml::StreamDirectory)
     82     return Error::success();
     83 
     84   auto StreamMap = File.getStreamMap();
     85   Obj.StreamMap.emplace();
     86   for (auto &Stream : StreamMap) {
     87     pdb::yaml::StreamBlockList BlockList;
     88     BlockList.Blocks = Stream;
     89     Obj.StreamMap->push_back(BlockList);
     90   }
     91 
     92   return Error::success();
     93 }
     94 
     95 Error YAMLOutputStyle::dumpPDBStream() {
     96   if (!opts::pdb2yaml::PdbStream)
     97     return Error::success();
     98 
     99   auto IS = File.getPDBInfoStream();
    100   if (!IS)
    101     return IS.takeError();
    102 
    103   auto &InfoS = IS.get();
    104   Obj.PdbStream.emplace();
    105   Obj.PdbStream->Age = InfoS.getAge();
    106   Obj.PdbStream->Guid = InfoS.getGuid();
    107   Obj.PdbStream->Signature = InfoS.getSignature();
    108   Obj.PdbStream->Version = InfoS.getVersion();
    109 
    110   return Error::success();
    111 }
    112 
    113 Error YAMLOutputStyle::dumpDbiStream() {
    114   if (!opts::pdb2yaml::DbiStream)
    115     return Error::success();
    116 
    117   auto DbiS = File.getPDBDbiStream();
    118   if (!DbiS)
    119     return DbiS.takeError();
    120 
    121   auto &DS = DbiS.get();
    122   Obj.DbiStream.emplace();
    123   Obj.DbiStream->Age = DS.getAge();
    124   Obj.DbiStream->BuildNumber = DS.getBuildNumber();
    125   Obj.DbiStream->Flags = DS.getFlags();
    126   Obj.DbiStream->MachineType = DS.getMachineType();
    127   Obj.DbiStream->PdbDllRbld = DS.getPdbDllRbld();
    128   Obj.DbiStream->PdbDllVersion = DS.getPdbDllVersion();
    129   Obj.DbiStream->VerHeader = DS.getDbiVersion();
    130   return Error::success();
    131 }
    132 
    133 void YAMLOutputStyle::flush() {
    134   Out << Obj;
    135   outs().flush();
    136 }
    137