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