Rewrite llvm-pdbdump in terms of LLVMDebugInfoPDB.
[oota-llvm.git] / lib / DebugInfo / PDB / PDBSymbolCompiland.cpp
1 //===- PDBSymbolCompiland.cpp - compiland details --------*- 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 <utility>
11 #include <vector>
12
13 #include "llvm/DebugInfo/PDB/IPDBEnumChildren.h"
14 #include "llvm/DebugInfo/PDB/IPDBSession.h"
15 #include "llvm/DebugInfo/PDB/IPDBSourceFile.h"
16 #include "llvm/DebugInfo/PDB/PDBExtras.h"
17 #include "llvm/DebugInfo/PDB/PDBSymbol.h"
18 #include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h"
19 #include "llvm/DebugInfo/PDB/PDBSymbolCompilandDetails.h"
20 #include "llvm/DebugInfo/PDB/PDBSymbolCompilandEnv.h"
21 #include "llvm/Support/raw_ostream.h"
22
23 using namespace llvm;
24
25 PDBSymbolCompiland::PDBSymbolCompiland(const IPDBSession &PDBSession,
26                                        std::unique_ptr<IPDBRawSymbol> Symbol)
27     : PDBSymbol(PDBSession, std::move(Symbol)) {}
28
29 void PDBSymbolCompiland::dump(raw_ostream &OS, int Indent,
30                               PDB_DumpLevel Level) const {
31   std::string Name = getName();
32   OS << "---- [IDX: " << getSymIndexId() << "] Compiland: " << Name
33      << " ----\n";
34
35   std::string Source = getSourceFileName();
36   std::string Library = getLibraryName();
37   if (!Source.empty())
38     OS << stream_indent(Indent + 2) << "Source: " << this->getSourceFileName()
39        << "\n";
40   if (!Library.empty())
41     OS << stream_indent(Indent + 2) << "Library: " << this->getLibraryName()
42        << "\n";
43
44   TagStats Stats;
45   auto ChildrenEnum = getChildStats(Stats);
46   OS << stream_indent(Indent + 2) << "Children: " << Stats << "\n";
47   if (Level >= PDB_DumpLevel::Normal) {
48     while (auto Child = ChildrenEnum->getNext()) {
49       if (llvm::isa<PDBSymbolCompilandDetails>(*Child))
50         continue;
51       if (llvm::isa<PDBSymbolCompilandEnv>(*Child))
52         continue;
53       Child->dump(OS, Indent + 4, PDB_DumpLevel::Compact);
54     }
55   }
56
57   std::unique_ptr<IPDBEnumSymbols> DetailsEnum(
58       findChildren(PDB_SymType::CompilandDetails));
59   if (auto DetailsPtr = DetailsEnum->getNext()) {
60     const auto *CD = dyn_cast<PDBSymbolCompilandDetails>(DetailsPtr.get());
61     assert(CD && "We only asked for compilands, but got something else!");
62     VersionInfo FE;
63     VersionInfo BE;
64     CD->getFrontEndVersion(FE);
65     CD->getBackEndVersion(BE);
66     OS << stream_indent(Indent + 2) << "Compiler: " << CD->getCompilerName()
67        << "\n";
68     OS << stream_indent(Indent + 2) << "Version: " << FE << ", " << BE << "\n";
69
70     OS << stream_indent(Indent + 2) << "Lang: " << CD->getLanguage() << "\n";
71     OS << stream_indent(Indent + 2) << "Attributes: ";
72     if (CD->hasDebugInfo())
73       OS << "DebugInfo ";
74     if (CD->isDataAligned())
75       OS << "DataAligned ";
76     if (CD->isLTCG())
77       OS << "LTCG ";
78     if (CD->hasSecurityChecks())
79       OS << "SecurityChecks ";
80     if (CD->isHotpatchable())
81       OS << "HotPatchable";
82
83     OS << "\n";
84     auto Files(Session.getSourceFilesForCompiland(*this));
85     if (Level >= PDB_DumpLevel::Detailed) {
86       OS << stream_indent(Indent + 2) << Files->getChildCount()
87          << " source files:\n";
88       while (auto File = Files->getNext())
89         File->dump(OS, Indent + 4, PDB_DumpLevel::Compact);
90     } else {
91       OS << stream_indent(Indent + 2) << Files->getChildCount()
92          << " source files\n";
93     }
94   }
95   uint32_t Count = DetailsEnum->getChildCount();
96   if (Count > 1)
97     OS << stream_indent(Indent + 2) << "(" << Count - 1 << " more omitted)\n";
98 }