39bb9bc90f1fda98c9d347ae5003288a7641b1d1
[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   std::string FullName = getName();
33   StringRef Name = llvm::sys::path::filename(StringRef(FullName.c_str()));
34
35   OS.indent(Indent);
36   OS << "Compiland: " << Name << "\n";
37
38   std::string Source = getSourceFileName();
39   std::string Library = getLibraryName();
40   if (!Source.empty())
41     OS << stream_indent(Indent + 2) << "Source: " << this->getSourceFileName()
42        << "\n";
43   if (!Library.empty())
44     OS << stream_indent(Indent + 2) << "Library: " << this->getLibraryName()
45        << "\n";
46
47   TagStats Stats;
48   auto ChildrenEnum = getChildStats(Stats);
49   OS << stream_indent(Indent + 2) << "Children: " << Stats << "\n";
50   if (Level >= PDB_DumpLevel::Normal) {
51     while (auto Child = ChildrenEnum->getNext()) {
52       if (llvm::isa<PDBSymbolCompilandDetails>(*Child))
53         continue;
54       if (llvm::isa<PDBSymbolCompilandEnv>(*Child))
55         continue;
56       Child->dump(OS, Indent + 4, PDB_DumpLevel::Compact);
57     }
58   }
59
60   auto DetailsEnum(findAllChildren<PDBSymbolCompilandDetails>());
61   if (auto CD = DetailsEnum->getNext()) {
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 }