llvm-pdbdump: Add more comprehensive dumping of symbol types.
[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 #include "llvm/Support/Path.h"
23
24 using namespace llvm;
25
26 PDBSymbolCompiland::PDBSymbolCompiland(const IPDBSession &PDBSession,
27                                        std::unique_ptr<IPDBRawSymbol> Symbol)
28     : PDBSymbol(PDBSession, std::move(Symbol)) {}
29
30 void PDBSymbolCompiland::dump(raw_ostream &OS, int Indent,
31                               PDB_DumpLevel Level) const {
32   if (Level == PDB_DumpLevel::Detailed) {
33     std::string FullName = getName();
34     StringRef Name = llvm::sys::path::filename(StringRef(FullName.c_str()));
35
36     OS.indent(Indent);
37     OS << "Compiland: " << Name << "\n";
38
39     std::string Source = getSourceFileName();
40     std::string Library = getLibraryName();
41     if (!Source.empty())
42       OS << stream_indent(Indent + 2) << "Source: " << this->getSourceFileName()
43          << "\n";
44     if (!Library.empty())
45       OS << stream_indent(Indent + 2) << "Library: " << this->getLibraryName()
46          << "\n";
47
48     TagStats Stats;
49     auto ChildrenEnum = getChildStats(Stats);
50     OS << stream_indent(Indent + 2) << "Children: " << Stats << "\n";
51     if (Level >= PDB_DumpLevel::Detailed) {
52       while (auto Child = ChildrenEnum->getNext()) {
53         if (llvm::isa<PDBSymbolCompilandDetails>(*Child))
54           continue;
55         if (llvm::isa<PDBSymbolCompilandEnv>(*Child))
56           continue;
57         PDB_DumpLevel ChildLevel = (Level == PDB_DumpLevel::Detailed)
58                                        ? PDB_DumpLevel::Normal
59                                        : PDB_DumpLevel::Compact;
60         Child->dump(OS, Indent + 4, ChildLevel);
61         OS << "\n";
62       }
63     }
64
65     auto DetailsEnum(findAllChildren<PDBSymbolCompilandDetails>());
66     if (auto CD = DetailsEnum->getNext()) {
67       VersionInfo FE;
68       VersionInfo BE;
69       CD->getFrontEndVersion(FE);
70       CD->getBackEndVersion(BE);
71       OS << stream_indent(Indent + 2) << "Compiler: " << CD->getCompilerName()
72          << "\n";
73       OS << stream_indent(Indent + 2) << "Version: " << FE << ", " << BE
74          << "\n";
75
76       OS << stream_indent(Indent + 2) << "Lang: " << CD->getLanguage() << "\n";
77       OS << stream_indent(Indent + 2) << "Attributes: ";
78       if (CD->hasDebugInfo())
79         OS << "DebugInfo ";
80       if (CD->isDataAligned())
81         OS << "DataAligned ";
82       if (CD->isLTCG())
83         OS << "LTCG ";
84       if (CD->hasSecurityChecks())
85         OS << "SecurityChecks ";
86       if (CD->isHotpatchable())
87         OS << "HotPatchable";
88
89       auto Files(Session.getSourceFilesForCompiland(*this));
90       OS << "\n";
91       OS << stream_indent(Indent + 2) << Files->getChildCount()
92          << " source files";
93     }
94     uint32_t Count = DetailsEnum->getChildCount();
95     if (Count > 1) {
96       OS << "\n";
97       OS << stream_indent(Indent + 2) << "(" << Count - 1 << " more omitted)";
98     }
99   } else {
100     std::string FullName = getName();
101     OS << stream_indent(Indent) << "Compiland: " << FullName;
102   }
103 }