llvm-pdbdump: Add flags controlling the type of values to dump.
[oota-llvm.git] / lib / DebugInfo / PDB / PDBSymbolCompiland.cpp
index 03ebe2b4d4b933c68eb2f88c5aeb6830bdc14d74..f014b3959b0a3de63454ca38732c5dcbf5d725fc 100644 (file)
@@ -7,19 +7,20 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include <utility>
-#include <vector>
+#include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h"
 
 #include "llvm/DebugInfo/PDB/IPDBEnumChildren.h"
 #include "llvm/DebugInfo/PDB/IPDBSession.h"
 #include "llvm/DebugInfo/PDB/IPDBSourceFile.h"
 #include "llvm/DebugInfo/PDB/PDBExtras.h"
 #include "llvm/DebugInfo/PDB/PDBSymbol.h"
-#include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h"
 #include "llvm/DebugInfo/PDB/PDBSymbolCompilandDetails.h"
 #include "llvm/DebugInfo/PDB/PDBSymbolCompilandEnv.h"
-#include "llvm/Support/raw_ostream.h"
 #include "llvm/Support/Path.h"
+#include "llvm/Support/raw_ostream.h"
+
+#include <utility>
+#include <vector>
 
 using namespace llvm;
 
@@ -27,75 +28,43 @@ PDBSymbolCompiland::PDBSymbolCompiland(const IPDBSession &PDBSession,
                                        std::unique_ptr<IPDBRawSymbol> Symbol)
     : PDBSymbol(PDBSession, std::move(Symbol)) {}
 
+#define SKIP_SYMBOL_IF_FLAG_UNSET(Tag, Flag) \
+  case PDB_SymType::Tag: \
+    if ((Flags & Flag) == 0) \
+      continue;   \
+    break;
+
 void PDBSymbolCompiland::dump(raw_ostream &OS, int Indent,
-                              PDB_DumpLevel Level) const {
+                              PDB_DumpLevel Level, PDB_DumpFlags Flags) const {
   if (Level == PDB_DumpLevel::Detailed) {
     std::string FullName = getName();
-    StringRef Name = llvm::sys::path::filename(StringRef(FullName.c_str()));
-
-    OS.indent(Indent);
-    OS << "Compiland: " << Name << "\n";
-
-    std::string Source = getSourceFileName();
-    std::string Library = getLibraryName();
-    if (!Source.empty())
-      OS << stream_indent(Indent + 2) << "Source: " << this->getSourceFileName()
-         << "\n";
-    if (!Library.empty())
-      OS << stream_indent(Indent + 2) << "Library: " << this->getLibraryName()
-         << "\n";
-
-    TagStats Stats;
-    auto ChildrenEnum = getChildStats(Stats);
-    OS << stream_indent(Indent + 2) << "Children: " << Stats << "\n";
-    if (Level >= PDB_DumpLevel::Detailed) {
-      while (auto Child = ChildrenEnum->getNext()) {
-        if (llvm::isa<PDBSymbolCompilandDetails>(*Child))
-          continue;
-        if (llvm::isa<PDBSymbolCompilandEnv>(*Child))
-          continue;
-        PDB_DumpLevel ChildLevel = (Level == PDB_DumpLevel::Detailed)
-                                       ? PDB_DumpLevel::Normal
-                                       : PDB_DumpLevel::Compact;
-        Child->dump(OS, Indent + 4, ChildLevel);
-        OS << "\n";
+    OS << stream_indent(Indent) << FullName;
+    if (Flags & PDB_DF_Children) {
+      if (Level >= PDB_DumpLevel::Detailed) {
+        auto ChildrenEnum = findAllChildren();
+        while (auto Child = ChildrenEnum->getNext()) {
+          switch (Child->getSymTag()) {
+            SKIP_SYMBOL_IF_FLAG_UNSET(Function, PDB_DF_Functions)
+            SKIP_SYMBOL_IF_FLAG_UNSET(Data, PDB_DF_Data)
+            SKIP_SYMBOL_IF_FLAG_UNSET(Label, PDB_DF_Labels)
+            SKIP_SYMBOL_IF_FLAG_UNSET(PublicSymbol, PDB_DF_PublicSyms)
+            SKIP_SYMBOL_IF_FLAG_UNSET(UDT, PDB_DF_Classes)
+            SKIP_SYMBOL_IF_FLAG_UNSET(Enum, PDB_DF_Enums)
+            SKIP_SYMBOL_IF_FLAG_UNSET(FunctionSig, PDB_DF_Funcsigs)
+            SKIP_SYMBOL_IF_FLAG_UNSET(VTable, PDB_DF_VTables)
+            SKIP_SYMBOL_IF_FLAG_UNSET(Thunk, PDB_DF_Thunks)
+            SKIP_SYMBOL_IF_FLAG_UNSET(Compiland, PDB_DF_ObjFiles)
+            default:
+              continue;
+          }
+          PDB_DumpLevel ChildLevel = (Level == PDB_DumpLevel::Detailed)
+                                         ? PDB_DumpLevel::Normal
+                                         : PDB_DumpLevel::Compact;
+          OS << "\n";
+          Child->dump(OS, Indent + 2, ChildLevel, PDB_DF_Children);
+        }
       }
     }
-
-    auto DetailsEnum(findAllChildren<PDBSymbolCompilandDetails>());
-    if (auto CD = DetailsEnum->getNext()) {
-      VersionInfo FE;
-      VersionInfo BE;
-      CD->getFrontEndVersion(FE);
-      CD->getBackEndVersion(BE);
-      OS << stream_indent(Indent + 2) << "Compiler: " << CD->getCompilerName()
-         << "\n";
-      OS << stream_indent(Indent + 2) << "Version: " << FE << ", " << BE
-         << "\n";
-
-      OS << stream_indent(Indent + 2) << "Lang: " << CD->getLanguage() << "\n";
-      OS << stream_indent(Indent + 2) << "Attributes: ";
-      if (CD->hasDebugInfo())
-        OS << "DebugInfo ";
-      if (CD->isDataAligned())
-        OS << "DataAligned ";
-      if (CD->isLTCG())
-        OS << "LTCG ";
-      if (CD->hasSecurityChecks())
-        OS << "SecurityChecks ";
-      if (CD->isHotpatchable())
-        OS << "HotPatchable";
-
-      auto Files(Session.getSourceFilesForCompiland(*this));
-      OS << "\n";
-      OS << stream_indent(Indent + 2) << Files->getChildCount()
-         << " source files";
-    }
-    uint32_t Count = DetailsEnum->getChildCount();
-    if (Count > 1) {
-      OS << "\n";
-      OS << stream_indent(Indent + 2) << "(" << Count - 1 << " more omitted)";
-    }
   } else {
     std::string FullName = getName();
     OS << stream_indent(Indent) << "Compiland: " << FullName;