[llvm] 7511213 - [llvm-pdbutil] Move InputFile/FormatUtil/LinePrinter to PDB library.

Carlos Alberto Enciso via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 25 00:27:57 PDT 2022


Author: Carlos Alberto Enciso
Date: 2022-03-25T07:12:58Z
New Revision: 75112133b83e5d27128dc1d6d2a282b297952f59

URL: https://github.com/llvm/llvm-project/commit/75112133b83e5d27128dc1d6d2a282b297952f59
DIFF: https://github.com/llvm/llvm-project/commit/75112133b83e5d27128dc1d6d2a282b297952f59.diff

LOG: [llvm-pdbutil] Move InputFile/FormatUtil/LinePrinter to PDB library.

At Sony we are developing llvm-dva

https://lists.llvm.org/pipermail/llvm-dev/2020-August/144174.html

For its PDB support, it requires functionality already present in
llvm-pdbutil.

We intend to move that functionaly into the PDB library to be
shared by both tools. That change will be done in 2 steps, that
will be submitted as 2 patches:

(1) Replace 'ExitOnError' with explicit error handling.
(2) Move the intended shared code to the PDB library.

Patch for step (1): https://reviews.llvm.org/D121801

This patch is for step (2).

Move InputFile.cpp[h], FormatUtil.cpp[h] and LinePrinter.cpp[h]
files to the debug PDB library.

It exposes the following functionality that can be used by tools:

- Open a PDB file.
- Get module debug stream.
- Traverse module sections.
- Traverse module subsections.

Most of the needed functionality is in InputFile, but there are
dependencies from LinePrinter and FormatUtil.

Some other functionality is in the following functions in
DumpOutputStyle.cpp file:

- iterateModuleSubsections
- getModuleDebugStream
- iterateOneModule
- iterateSymbolGroups
- iterateModuleSubsections

Only these specific functions from DumpOutputStyle are moved to
the PDB library.

Reviewed By: aganea, dblaikie, rnk

Differential Revision: https://reviews.llvm.org/D122226

Added: 
    llvm/include/llvm/DebugInfo/PDB/Native/FormatUtil.h
    llvm/include/llvm/DebugInfo/PDB/Native/InputFile.h
    llvm/include/llvm/DebugInfo/PDB/Native/LinePrinter.h
    llvm/lib/DebugInfo/PDB/Native/FormatUtil.cpp
    llvm/lib/DebugInfo/PDB/Native/InputFile.cpp
    llvm/lib/DebugInfo/PDB/Native/LinePrinter.cpp

Modified: 
    llvm/lib/DebugInfo/PDB/CMakeLists.txt
    llvm/tools/llvm-pdbutil/BytesOutputStyle.cpp
    llvm/tools/llvm-pdbutil/BytesOutputStyle.h
    llvm/tools/llvm-pdbutil/CMakeLists.txt
    llvm/tools/llvm-pdbutil/DumpOutputStyle.cpp
    llvm/tools/llvm-pdbutil/DumpOutputStyle.h
    llvm/tools/llvm-pdbutil/ExplainOutputStyle.cpp
    llvm/tools/llvm-pdbutil/ExplainOutputStyle.h
    llvm/tools/llvm-pdbutil/MinimalSymbolDumper.cpp
    llvm/tools/llvm-pdbutil/MinimalTypeDumper.cpp
    llvm/tools/llvm-pdbutil/PrettyBuiltinDumper.cpp
    llvm/tools/llvm-pdbutil/PrettyClassDefinitionDumper.cpp
    llvm/tools/llvm-pdbutil/PrettyClassLayoutGraphicalDumper.cpp
    llvm/tools/llvm-pdbutil/PrettyCompilandDumper.cpp
    llvm/tools/llvm-pdbutil/PrettyEnumDumper.cpp
    llvm/tools/llvm-pdbutil/PrettyExternalSymbolDumper.cpp
    llvm/tools/llvm-pdbutil/PrettyFunctionDumper.cpp
    llvm/tools/llvm-pdbutil/PrettyTypeDumper.cpp
    llvm/tools/llvm-pdbutil/PrettyTypedefDumper.cpp
    llvm/tools/llvm-pdbutil/PrettyVariableDumper.cpp
    llvm/tools/llvm-pdbutil/StreamUtil.cpp
    llvm/tools/llvm-pdbutil/TypeReferenceTracker.cpp
    llvm/tools/llvm-pdbutil/TypeReferenceTracker.h
    llvm/tools/llvm-pdbutil/llvm-pdbutil.cpp
    llvm/tools/llvm-pdbutil/llvm-pdbutil.h

Removed: 
    llvm/tools/llvm-pdbutil/FormatUtil.cpp
    llvm/tools/llvm-pdbutil/FormatUtil.h
    llvm/tools/llvm-pdbutil/InputFile.cpp
    llvm/tools/llvm-pdbutil/InputFile.h
    llvm/tools/llvm-pdbutil/LinePrinter.cpp
    llvm/tools/llvm-pdbutil/LinePrinter.h


################################################################################
diff  --git a/llvm/tools/llvm-pdbutil/FormatUtil.h b/llvm/include/llvm/DebugInfo/PDB/Native/FormatUtil.h
similarity index 97%
rename from llvm/tools/llvm-pdbutil/FormatUtil.h
rename to llvm/include/llvm/DebugInfo/PDB/Native/FormatUtil.h
index b99ccec215b56..ed86537e6b93c 100644
--- a/llvm/tools/llvm-pdbutil/FormatUtil.h
+++ b/llvm/include/llvm/DebugInfo/PDB/Native/FormatUtil.h
@@ -6,8 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef LLVM_TOOLS_LLVMPDBUTIL_FORMAT_UTIL_H
-#define LLVM_TOOLS_LLVMPDBUTIL_FORMAT_UTIL_H
+#ifndef LLVM_DEBUGINFO_PDB_NATIVE_FORMATUTIL_H
+#define LLVM_DEBUGINFO_PDB_NATIVE_FORMATUTIL_H
 
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/StringRef.h"
@@ -136,6 +136,6 @@ fmtle(support::detail::packed_endian_specific_integral<T, support::little,
           Value) {
   return detail::EndianAdapter<T>(std::move(Value));
 }
-}
+} // namespace pdb
 } // namespace llvm
 #endif

diff  --git a/llvm/tools/llvm-pdbutil/InputFile.h b/llvm/include/llvm/DebugInfo/PDB/Native/InputFile.h
similarity index 60%
rename from llvm/tools/llvm-pdbutil/InputFile.h
rename to llvm/include/llvm/DebugInfo/PDB/Native/InputFile.h
index 633ab34a54d44..d0dd570f0e056 100644
--- a/llvm/tools/llvm-pdbutil/InputFile.h
+++ b/llvm/include/llvm/DebugInfo/PDB/Native/InputFile.h
@@ -6,8 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef LLVM_TOOLS_LLVMPDBDUMP_INPUTFILE_H
-#define LLVM_TOOLS_LLVMPDBDUMP_INPUTFILE_H
+#ifndef LLVM_DEBUGINFO_PDB_NATIVE_INPUTFILE_H
+#define LLVM_DEBUGINFO_PDB_NATIVE_INPUTFILE_H
 
 #include "llvm/ADT/Optional.h"
 #include "llvm/ADT/PointerUnion.h"
@@ -15,6 +15,7 @@
 #include "llvm/ADT/iterator.h"
 #include "llvm/DebugInfo/CodeView/DebugChecksumsSubsection.h"
 #include "llvm/DebugInfo/CodeView/StringsAndChecksums.h"
+#include "llvm/DebugInfo/PDB/Native/LinePrinter.h"
 #include "llvm/DebugInfo/PDB/Native/ModuleDebugStream.h"
 #include "llvm/Object/Binary.h"
 #include "llvm/Object/ObjectFile.h"
@@ -54,6 +55,9 @@ class InputFile {
   getOrCreateTypeCollection(TypeCollectionKind Kind);
 
 public:
+  InputFile(PDBFile *Pdb) { PdbOrObj = Pdb; }
+  InputFile(object::COFFObjectFile *Obj) { PdbOrObj = Obj; }
+  InputFile(MemoryBuffer *Buffer) { PdbOrObj = Buffer; }
   ~InputFile();
   InputFile(InputFile &&Other) = default;
 
@@ -91,6 +95,7 @@ class SymbolGroup {
   explicit SymbolGroup(InputFile *File, uint32_t GroupIndex = 0);
 
   Expected<StringRef> getNameFromStringTable(uint32_t Offset) const;
+  Expected<StringRef> getNameFromChecksums(uint32_t Offset) const;
 
   void formatFromFileName(LinePrinter &Printer, StringRef File,
                           bool Append = false) const;
@@ -148,6 +153,80 @@ class SymbolGroupIterator
   SymbolGroup Value;
 };
 
+Expected<ModuleDebugStreamRef>
+getModuleDebugStream(PDBFile &File, StringRef &ModuleName, uint32_t Index);
+Expected<ModuleDebugStreamRef> getModuleDebugStream(PDBFile &File,
+                                                    uint32_t Index);
+
+bool shouldDumpSymbolGroup(uint32_t Idx, const SymbolGroup &Group);
+
+// TODO: Change these callbacks to be function_refs (de-templatify them).
+template <typename CallbackT>
+Error iterateOneModule(InputFile &File, const Optional<PrintScope> &HeaderScope,
+                       const SymbolGroup &SG, uint32_t Modi,
+                       CallbackT Callback) {
+  if (HeaderScope) {
+    HeaderScope->P.formatLine(
+        "Mod {0:4} | `{1}`: ",
+        fmt_align(Modi, AlignStyle::Right, HeaderScope->LabelWidth), SG.name());
+  }
+
+  AutoIndent Indent(HeaderScope);
+  return Callback(Modi, SG);
+}
+
+template <typename CallbackT>
+Error iterateSymbolGroups(InputFile &Input,
+                          const Optional<PrintScope> &HeaderScope,
+                          CallbackT Callback) {
+  AutoIndent Indent(HeaderScope);
+
+  if (llvm::pdb::Filters.DumpModi > 0) {
+    assert(llvm::pdb::Filters.DumpModi == 1);
+    uint32_t Modi = llvm::pdb::Filters.DumpModi;
+    SymbolGroup SG(&Input, Modi);
+    return iterateOneModule(Input, withLabelWidth(HeaderScope, NumDigits(Modi)),
+                            SG, Modi, Callback);
+  }
+
+  uint32_t I = 0;
+
+  for (const auto &SG : Input.symbol_groups()) {
+    if (shouldDumpSymbolGroup(I, SG))
+      if (auto Err =
+              iterateOneModule(Input, withLabelWidth(HeaderScope, NumDigits(I)),
+                               SG, I, Callback))
+        return Err;
+
+    ++I;
+  }
+  return Error::success();
+}
+
+template <typename SubsectionT>
+Error iterateModuleSubsections(
+    InputFile &File, const Optional<PrintScope> &HeaderScope,
+    llvm::function_ref<Error(uint32_t, const SymbolGroup &, SubsectionT &)>
+        Callback) {
+
+  return iterateSymbolGroups(
+      File, HeaderScope, [&](uint32_t Modi, const SymbolGroup &SG) -> Error {
+        for (const auto &SS : SG.getDebugSubsections()) {
+          SubsectionT Subsection;
+
+          if (SS.kind() != Subsection.kind())
+            continue;
+
+          BinaryStreamReader Reader(SS.getRecordData());
+          if (auto Err = Subsection.initialize(Reader))
+            continue;
+          if (auto Err = Callback(Modi, SG, Subsection))
+            return Err;
+        }
+        return Error::success();
+      });
+}
+
 } // namespace pdb
 } // namespace llvm
 

diff  --git a/llvm/tools/llvm-pdbutil/LinePrinter.h b/llvm/include/llvm/DebugInfo/PDB/Native/LinePrinter.h
similarity index 84%
rename from llvm/tools/llvm-pdbutil/LinePrinter.h
rename to llvm/include/llvm/DebugInfo/PDB/Native/LinePrinter.h
index b6bb77280fd5c..38abf6635dcd3 100644
--- a/llvm/tools/llvm-pdbutil/LinePrinter.h
+++ b/llvm/include/llvm/DebugInfo/PDB/Native/LinePrinter.h
@@ -6,12 +6,13 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef LLVM_TOOLS_LLVMPDBDUMP_LINEPRINTER_H
-#define LLVM_TOOLS_LLVMPDBDUMP_LINEPRINTER_H
+#ifndef LLVM_DEBUGINFO_PDB_NATIVE_LINEPRINTER_H
+#define LLVM_DEBUGINFO_PDB_NATIVE_LINEPRINTER_H
 
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/Twine.h"
+#include "llvm/DebugInfo/PDB/Native/FormatUtil.h"
 #include "llvm/Support/BinaryStreamRef.h"
 #include "llvm/Support/FormatVariadic.h"
 #include "llvm/Support/Regex.h"
@@ -19,12 +20,28 @@
 
 #include <list>
 
+// Container for filter options to control which elements will be printed.
+struct FilterOptions {
+  std::list<std::string> ExcludeTypes;
+  std::list<std::string> ExcludeSymbols;
+  std::list<std::string> ExcludeCompilands;
+  std::list<std::string> IncludeTypes;
+  std::list<std::string> IncludeSymbols;
+  std::list<std::string> IncludeCompilands;
+  uint32_t PaddingThreshold;
+  uint32_t SizeThreshold;
+  uint32_t DumpModi;
+  bool JustMyCode;
+};
+
 namespace llvm {
 namespace msf {
 class MSFStreamLayout;
 } // namespace msf
 namespace pdb {
 
+extern FilterOptions Filters;
+
 class ClassLayout;
 class PDBFile;
 
@@ -32,7 +49,8 @@ class LinePrinter {
   friend class WithColor;
 
 public:
-  LinePrinter(int Indent, bool UseColor, raw_ostream &Stream);
+  LinePrinter(int Indent, bool UseColor, raw_ostream &Stream,
+              FilterOptions &Filters);
 
   void Indent(uint32_t Amount = 0);
   void Unindent(uint32_t Amount = 0);
@@ -40,10 +58,10 @@ class LinePrinter {
 
   void printLine(const Twine &T);
   void print(const Twine &T);
-  template <typename... Ts> void formatLine(const char *Fmt, Ts &&... Items) {
+  template <typename... Ts> void formatLine(const char *Fmt, Ts &&...Items) {
     printLine(formatv(Fmt, std::forward<Ts>(Items)...));
   }
-  template <typename... Ts> void format(const char *Fmt, Ts &&... Items) {
+  template <typename... Ts> void format(const char *Fmt, Ts &&...Items) {
     print(formatv(Fmt, std::forward<Ts>(Items)...));
   }
 
@@ -161,7 +179,7 @@ class WithColor {
   raw_ostream &OS;
   bool UseColor;
 };
-}
-}
+} // namespace pdb
+} // namespace llvm
 
 #endif

diff  --git a/llvm/lib/DebugInfo/PDB/CMakeLists.txt b/llvm/lib/DebugInfo/PDB/CMakeLists.txt
index 851c5c3dc03c4..b42fae41992e9 100644
--- a/llvm/lib/DebugInfo/PDB/CMakeLists.txt
+++ b/llvm/lib/DebugInfo/PDB/CMakeLists.txt
@@ -47,12 +47,15 @@ add_pdb_impl_folder(Native
   Native/DbiStream.cpp
   Native/DbiStreamBuilder.cpp
   Native/EnumTables.cpp
+  Native/FormatUtil.cpp
   Native/GlobalsStream.cpp
   Native/Hash.cpp
   Native/HashTable.cpp
   Native/InfoStream.cpp
   Native/InfoStreamBuilder.cpp
   Native/InjectedSourceStream.cpp
+  Native/InputFile.cpp
+  Native/LinePrinter.cpp
   Native/ModuleDebugStream.cpp
   Native/NativeCompilandSymbol.cpp
   Native/NativeEnumGlobals.cpp

diff  --git a/llvm/tools/llvm-pdbutil/FormatUtil.cpp b/llvm/lib/DebugInfo/PDB/Native/FormatUtil.cpp
similarity index 99%
rename from llvm/tools/llvm-pdbutil/FormatUtil.cpp
rename to llvm/lib/DebugInfo/PDB/Native/FormatUtil.cpp
index b4837398f1d0d..53de70b6f7aba 100644
--- a/llvm/tools/llvm-pdbutil/FormatUtil.cpp
+++ b/llvm/lib/DebugInfo/PDB/Native/FormatUtil.cpp
@@ -6,7 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "FormatUtil.h"
+#include "llvm/DebugInfo/PDB/Native/FormatUtil.h"
+
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/BinaryFormat/COFF.h"

diff  --git a/llvm/tools/llvm-pdbutil/InputFile.cpp b/llvm/lib/DebugInfo/PDB/Native/InputFile.cpp
similarity index 84%
rename from llvm/tools/llvm-pdbutil/InputFile.cpp
rename to llvm/lib/DebugInfo/PDB/Native/InputFile.cpp
index fe378cb2632d0..74d7d9b2711b1 100644
--- a/llvm/tools/llvm-pdbutil/InputFile.cpp
+++ b/llvm/lib/DebugInfo/PDB/Native/InputFile.cpp
@@ -6,10 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "InputFile.h"
-
-#include "FormatUtil.h"
-#include "LinePrinter.h"
+#include "llvm/DebugInfo/PDB/Native/InputFile.h"
 
 #include "llvm/BinaryFormat/Magic.h"
 #include "llvm/DebugInfo/CodeView/CodeView.h"
@@ -17,6 +14,8 @@
 #include "llvm/DebugInfo/CodeView/StringsAndChecksums.h"
 #include "llvm/DebugInfo/MSF/MappedBlockStream.h"
 #include "llvm/DebugInfo/PDB/Native/DbiStream.h"
+#include "llvm/DebugInfo/PDB/Native/FormatUtil.h"
+#include "llvm/DebugInfo/PDB/Native/LinePrinter.h"
 #include "llvm/DebugInfo/PDB/Native/NativeSession.h"
 #include "llvm/DebugInfo/PDB/Native/PDBFile.h"
 #include "llvm/DebugInfo/PDB/Native/PDBStringTable.h"
@@ -35,8 +34,9 @@ using namespace llvm::pdb;
 InputFile::InputFile() {}
 InputFile::~InputFile() {}
 
-static Expected<ModuleDebugStreamRef>
-getModuleDebugStream(PDBFile &File, StringRef &ModuleName, uint32_t Index) {
+Expected<ModuleDebugStreamRef>
+llvm::pdb::getModuleDebugStream(PDBFile &File, StringRef &ModuleName,
+                                uint32_t Index) {
   Expected<DbiStream &> DbiOrErr = File.getPDBDbiStream();
   if (!DbiOrErr)
     return DbiOrErr.takeError();
@@ -65,6 +65,30 @@ getModuleDebugStream(PDBFile &File, StringRef &ModuleName, uint32_t Index) {
   return std::move(ModS);
 }
 
+Expected<ModuleDebugStreamRef> llvm::pdb::getModuleDebugStream(PDBFile &File,
+                                                               uint32_t Index) {
+  Expected<DbiStream &> DbiOrErr = File.getPDBDbiStream();
+  if (!DbiOrErr)
+    return DbiOrErr.takeError();
+  DbiStream &Dbi = *DbiOrErr;
+  const auto &Modules = Dbi.modules();
+  auto Modi = Modules.getModuleDescriptor(Index);
+
+  uint16_t ModiStream = Modi.getModuleStreamIndex();
+  if (ModiStream == kInvalidStreamIndex)
+    return make_error<RawError>(raw_error_code::no_stream,
+                                "Module stream not present");
+
+  auto ModStreamData = File.createIndexedStream(ModiStream);
+
+  ModuleDebugStreamRef ModS(Modi, std::move(ModStreamData));
+  if (Error Err = ModS.reload())
+    return make_error<RawError>(raw_error_code::corrupt_file,
+                                "Invalid module stream");
+
+  return std::move(ModS);
+}
+
 static inline bool isCodeViewDebugSubsection(object::SectionRef Section,
                                              StringRef Name,
                                              BinaryStreamReader &Reader) {
@@ -122,7 +146,7 @@ static std::string formatChecksumKind(FileChecksumKind Kind) {
 }
 
 template <typename... Args>
-static void formatInternal(LinePrinter &Printer, bool Append, Args &&... args) {
+static void formatInternal(LinePrinter &Printer, bool Append, Args &&...args) {
   if (Append)
     Printer.format(std::forward<Args>(args)...);
   else
@@ -211,6 +235,26 @@ Expected<StringRef> SymbolGroup::getNameFromStringTable(uint32_t Offset) const {
   return SC.strings().getString(Offset);
 }
 
+Expected<StringRef> SymbolGroup::getNameFromChecksums(uint32_t Offset) const {
+  StringRef Name;
+  if (!SC.hasChecksums()) {
+    return std::move(Name);
+  }
+
+  auto Iter = SC.checksums().getArray().at(Offset);
+  if (Iter == SC.checksums().getArray().end()) {
+    return std::move(Name);
+  }
+
+  uint32_t FO = Iter->FileNameOffset;
+  auto ExpectedFile = getNameFromStringTable(FO);
+  if (!ExpectedFile) {
+    return std::move(Name);
+  }
+
+  return *ExpectedFile;
+}
+
 void SymbolGroup::formatFromFileName(LinePrinter &Printer, StringRef File,
                                      bool Append) const {
   auto FC = ChecksumsByFile.find(File);
@@ -510,3 +554,33 @@ bool SymbolGroupIterator::isEnd() const {
   assert(SectionIter.hasValue());
   return *SectionIter == Value.File->obj().section_end();
 }
+
+static bool isMyCode(const SymbolGroup &Group) {
+  if (Group.getFile().isObj())
+    return true;
+
+  StringRef Name = Group.name();
+  if (Name.startswith("Import:"))
+    return false;
+  if (Name.endswith_insensitive(".dll"))
+    return false;
+  if (Name.equals_insensitive("* linker *"))
+    return false;
+  if (Name.startswith_insensitive("f:\\binaries\\Intermediate\\vctools"))
+    return false;
+  if (Name.startswith_insensitive("f:\\dd\\vctools\\crt"))
+    return false;
+  return true;
+}
+
+bool llvm::pdb::shouldDumpSymbolGroup(uint32_t Idx, const SymbolGroup &Group) {
+  if (llvm::pdb::Filters.JustMyCode && !isMyCode(Group))
+    return false;
+
+  // If the arg was not specified on the command line, always dump all modules.
+  if (llvm::pdb::Filters.DumpModi == 0)
+    return true;
+
+  // Otherwise, only dump if this is the same module specified.
+  return (llvm::pdb::Filters.DumpModi == Idx);
+}

diff  --git a/llvm/tools/llvm-pdbutil/LinePrinter.cpp b/llvm/lib/DebugInfo/PDB/Native/LinePrinter.cpp
similarity index 88%
rename from llvm/tools/llvm-pdbutil/LinePrinter.cpp
rename to llvm/lib/DebugInfo/PDB/Native/LinePrinter.cpp
index 6e32105b157af..2c4ec80334b52 100644
--- a/llvm/tools/llvm-pdbutil/LinePrinter.cpp
+++ b/llvm/lib/DebugInfo/PDB/Native/LinePrinter.cpp
@@ -6,16 +6,18 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "LinePrinter.h"
-
-#include "llvm-pdbutil.h"
+#include "llvm/DebugInfo/PDB/Native/LinePrinter.h"
 
 #include "llvm/ADT/STLExtras.h"
+#include "llvm/DebugInfo/CodeView/LazyRandomTypeCollection.h"
 #include "llvm/DebugInfo/MSF/MSFCommon.h"
 #include "llvm/DebugInfo/MSF/MappedBlockStream.h"
 #include "llvm/DebugInfo/PDB/IPDBLineNumber.h"
+#include "llvm/DebugInfo/PDB/Native/InputFile.h"
+#include "llvm/DebugInfo/PDB/Native/NativeSession.h"
 #include "llvm/DebugInfo/PDB/Native/PDBFile.h"
 #include "llvm/DebugInfo/PDB/UDTLayout.h"
+#include "llvm/Object/COFF.h"
 #include "llvm/Support/BinaryStreamReader.h"
 #include "llvm/Support/Format.h"
 #include "llvm/Support/FormatAdapters.h"
@@ -28,6 +30,10 @@ using namespace llvm;
 using namespace llvm::msf;
 using namespace llvm::pdb;
 
+// TODO: Move this Filters state inside the LinePrinter class and pass it by
+// reference to the iterate* functions.
+FilterOptions llvm::pdb::Filters;
+
 namespace {
 bool IsItemExcluded(llvm::StringRef Item,
                     std::list<llvm::Regex> &IncludeFilters,
@@ -47,25 +53,27 @@ bool IsItemExcluded(llvm::StringRef Item,
 
   return false;
 }
-}
+} // namespace
 
 using namespace llvm;
 
-LinePrinter::LinePrinter(int Indent, bool UseColor, llvm::raw_ostream &Stream)
+LinePrinter::LinePrinter(int Indent, bool UseColor, llvm::raw_ostream &Stream,
+                         FilterOptions &Filters)
     : OS(Stream), IndentSpaces(Indent), CurrentIndent(0), UseColor(UseColor) {
-  SetFilters(ExcludeTypeFilters, opts::pretty::ExcludeTypes.begin(),
-             opts::pretty::ExcludeTypes.end());
-  SetFilters(ExcludeSymbolFilters, opts::pretty::ExcludeSymbols.begin(),
-             opts::pretty::ExcludeSymbols.end());
-  SetFilters(ExcludeCompilandFilters, opts::pretty::ExcludeCompilands.begin(),
-             opts::pretty::ExcludeCompilands.end());
-
-  SetFilters(IncludeTypeFilters, opts::pretty::IncludeTypes.begin(),
-             opts::pretty::IncludeTypes.end());
-  SetFilters(IncludeSymbolFilters, opts::pretty::IncludeSymbols.begin(),
-             opts::pretty::IncludeSymbols.end());
-  SetFilters(IncludeCompilandFilters, opts::pretty::IncludeCompilands.begin(),
-             opts::pretty::IncludeCompilands.end());
+  llvm::pdb::Filters = Filters;
+  SetFilters(ExcludeTypeFilters, Filters.ExcludeTypes.begin(),
+             Filters.ExcludeTypes.end());
+  SetFilters(ExcludeSymbolFilters, Filters.ExcludeSymbols.begin(),
+             Filters.ExcludeSymbols.end());
+  SetFilters(ExcludeCompilandFilters, Filters.ExcludeCompilands.begin(),
+             Filters.ExcludeCompilands.end());
+
+  SetFilters(IncludeTypeFilters, Filters.IncludeTypes.begin(),
+             Filters.IncludeTypes.end());
+  SetFilters(IncludeSymbolFilters, Filters.IncludeSymbols.begin(),
+             Filters.IncludeSymbols.end());
+  SetFilters(IncludeCompilandFilters, Filters.IncludeCompilands.begin(),
+             Filters.IncludeCompilands.end());
 }
 
 void LinePrinter::Indent(uint32_t Amount) {
@@ -95,7 +103,7 @@ void LinePrinter::printLine(const Twine &T) {
 bool LinePrinter::IsClassExcluded(const ClassLayout &Class) {
   if (IsTypeExcluded(Class.getName(), Class.getSize()))
     return true;
-  if (Class.deepPaddingSize() < opts::pretty::PaddingThreshold)
+  if (Class.deepPaddingSize() < Filters.PaddingThreshold)
     return true;
   return false;
 }
@@ -273,7 +281,7 @@ void LinePrinter::formatMsfStreamBlocks(
 bool LinePrinter::IsTypeExcluded(llvm::StringRef TypeName, uint64_t Size) {
   if (IsItemExcluded(TypeName, IncludeTypeFilters, ExcludeTypeFilters))
     return true;
-  if (Size < opts::pretty::SizeThreshold)
+  if (Size < Filters.SizeThreshold)
     return true;
   return false;
 }

diff  --git a/llvm/tools/llvm-pdbutil/BytesOutputStyle.cpp b/llvm/tools/llvm-pdbutil/BytesOutputStyle.cpp
index ffc907e09f11b..eba3a4a3198e3 100644
--- a/llvm/tools/llvm-pdbutil/BytesOutputStyle.cpp
+++ b/llvm/tools/llvm-pdbutil/BytesOutputStyle.cpp
@@ -8,7 +8,6 @@
 
 #include "BytesOutputStyle.h"
 
-#include "FormatUtil.h"
 #include "StreamUtil.h"
 #include "llvm-pdbutil.h"
 
@@ -17,6 +16,7 @@
 #include "llvm/DebugInfo/MSF/MSFCommon.h"
 #include "llvm/DebugInfo/MSF/MappedBlockStream.h"
 #include "llvm/DebugInfo/PDB/Native/DbiStream.h"
+#include "llvm/DebugInfo/PDB/Native/FormatUtil.h"
 #include "llvm/DebugInfo/PDB/Native/InfoStream.h"
 #include "llvm/DebugInfo/PDB/Native/ModuleDebugStream.h"
 #include "llvm/DebugInfo/PDB/Native/PDBFile.h"
@@ -83,7 +83,7 @@ static void printHeader(LinePrinter &P, const Twine &S) {
 }
 
 BytesOutputStyle::BytesOutputStyle(PDBFile &File)
-    : File(File), P(2, false, outs()) {}
+    : File(File), P(2, false, outs(), opts::Filters) {}
 
 Error BytesOutputStyle::dump() {
 

diff  --git a/llvm/tools/llvm-pdbutil/BytesOutputStyle.h b/llvm/tools/llvm-pdbutil/BytesOutputStyle.h
index d3aceb47679e8..cd28032fe7cdf 100644
--- a/llvm/tools/llvm-pdbutil/BytesOutputStyle.h
+++ b/llvm/tools/llvm-pdbutil/BytesOutputStyle.h
@@ -9,10 +9,10 @@
 #ifndef LLVM_TOOLS_LLVMPDBDUMP_BYTESOUTPUTSTYLE_H
 #define LLVM_TOOLS_LLVMPDBDUMP_BYTESOUTPUTSTYLE_H
 
-#include "LinePrinter.h"
 #include "OutputStyle.h"
 #include "StreamUtil.h"
 
+#include "llvm/DebugInfo/PDB/Native/LinePrinter.h"
 #include "llvm/Support/Error.h"
 
 namespace llvm {

diff  --git a/llvm/tools/llvm-pdbutil/CMakeLists.txt b/llvm/tools/llvm-pdbutil/CMakeLists.txt
index 56b9e19926d78..e834755bdf483 100644
--- a/llvm/tools/llvm-pdbutil/CMakeLists.txt
+++ b/llvm/tools/llvm-pdbutil/CMakeLists.txt
@@ -12,10 +12,7 @@ add_llvm_tool(llvm-pdbutil
   BytesOutputStyle.cpp
   DumpOutputStyle.cpp
   ExplainOutputStyle.cpp
-  InputFile.cpp
   llvm-pdbutil.cpp
-  FormatUtil.cpp
-  LinePrinter.cpp
   MinimalSymbolDumper.cpp
   MinimalTypeDumper.cpp
   PdbYaml.cpp

diff  --git a/llvm/tools/llvm-pdbutil/DumpOutputStyle.cpp b/llvm/tools/llvm-pdbutil/DumpOutputStyle.cpp
index 8e66b7bb73982..c3d95c836aa73 100644
--- a/llvm/tools/llvm-pdbutil/DumpOutputStyle.cpp
+++ b/llvm/tools/llvm-pdbutil/DumpOutputStyle.cpp
@@ -8,8 +8,6 @@
 
 #include "DumpOutputStyle.h"
 
-#include "FormatUtil.h"
-#include "InputFile.h"
 #include "MinimalSymbolDumper.h"
 #include "MinimalTypeDumper.h"
 #include "StreamUtil.h"
@@ -38,10 +36,13 @@
 #include "llvm/DebugInfo/MSF/MappedBlockStream.h"
 #include "llvm/DebugInfo/PDB/Native/DbiModuleDescriptor.h"
 #include "llvm/DebugInfo/PDB/Native/DbiStream.h"
+#include "llvm/DebugInfo/PDB/Native/FormatUtil.h"
 #include "llvm/DebugInfo/PDB/Native/GlobalsStream.h"
 #include "llvm/DebugInfo/PDB/Native/ISectionContribVisitor.h"
 #include "llvm/DebugInfo/PDB/Native/InfoStream.h"
+#include "llvm/DebugInfo/PDB/Native/InputFile.h"
 #include "llvm/DebugInfo/PDB/Native/ModuleDebugStream.h"
+#include "llvm/DebugInfo/PDB/Native/NativeSession.h"
 #include "llvm/DebugInfo/PDB/Native/PDBFile.h"
 #include "llvm/DebugInfo/PDB/Native/PublicsStream.h"
 #include "llvm/DebugInfo/PDB/Native/RawError.h"
@@ -61,7 +62,7 @@ using namespace llvm::msf;
 using namespace llvm::pdb;
 
 DumpOutputStyle::DumpOutputStyle(InputFile &File)
-    : File(File), P(2, false, outs()) {
+    : File(File), P(2, false, outs(), opts::Filters) {
   if (opts::dump::DumpTypeRefStats)
     RefTracker.reset(new TypeReferenceTracker(File));
 }
@@ -342,36 +343,6 @@ static void printModuleDetailStats(LinePrinter &P, StringRef Label,
   }
 }
 
-static bool isMyCode(const SymbolGroup &Group) {
-  if (Group.getFile().isObj())
-    return true;
-
-  StringRef Name = Group.name();
-  if (Name.startswith("Import:"))
-    return false;
-  if (Name.endswith_insensitive(".dll"))
-    return false;
-  if (Name.equals_insensitive("* linker *"))
-    return false;
-  if (Name.startswith_insensitive("f:\\binaries\\Intermediate\\vctools"))
-    return false;
-  if (Name.startswith_insensitive("f:\\dd\\vctools\\crt"))
-    return false;
-  return true;
-}
-
-static bool shouldDumpSymbolGroup(uint32_t Idx, const SymbolGroup &Group) {
-  if (opts::dump::JustMyCode && !isMyCode(Group))
-    return false;
-
-  // If the arg was not specified on the command line, always dump all modules.
-  if (opts::dump::DumpModi.getNumOccurrences() == 0)
-    return true;
-
-  // Otherwise, only dump if this is the same module specified.
-  return (opts::dump::DumpModi == Idx);
-}
-
 Error DumpOutputStyle::dumpStreamSummary() {
   printHeader(P, "Streams");
 
@@ -408,96 +379,6 @@ Error DumpOutputStyle::dumpStreamSummary() {
   return Error::success();
 }
 
-static Expected<ModuleDebugStreamRef> getModuleDebugStream(PDBFile &File,
-                                                           uint32_t Index) {
-  Expected<DbiStream &> DbiOrErr = File.getPDBDbiStream();
-  if (!DbiOrErr)
-    return DbiOrErr.takeError();
-  DbiStream &Dbi = *DbiOrErr;
-  const auto &Modules = Dbi.modules();
-  auto Modi = Modules.getModuleDescriptor(Index);
-
-  uint16_t ModiStream = Modi.getModuleStreamIndex();
-  if (ModiStream == kInvalidStreamIndex)
-    return make_error<RawError>(raw_error_code::no_stream,
-                                "Module stream not present");
-
-  auto ModStreamData = File.createIndexedStream(ModiStream);
-
-  ModuleDebugStreamRef ModS(Modi, std::move(ModStreamData));
-  if (auto EC = ModS.reload())
-    return make_error<RawError>(raw_error_code::corrupt_file,
-                                "Invalid module stream");
-
-  return std::move(ModS);
-}
-
-template <typename CallbackT>
-static Error
-iterateOneModule(InputFile &File, const Optional<PrintScope> &HeaderScope,
-                 const SymbolGroup &SG, uint32_t Modi, CallbackT Callback) {
-  if (HeaderScope) {
-    HeaderScope->P.formatLine(
-        "Mod {0:4} | `{1}`: ",
-        fmt_align(Modi, AlignStyle::Right, HeaderScope->LabelWidth), SG.name());
-  }
-
-  AutoIndent Indent(HeaderScope);
-  return Callback(Modi, SG);
-}
-
-template <typename CallbackT>
-static Error iterateSymbolGroups(InputFile &Input,
-                                 const Optional<PrintScope> &HeaderScope,
-                                 CallbackT Callback) {
-  AutoIndent Indent(HeaderScope);
-
-  if (opts::dump::DumpModi.getNumOccurrences() > 0) {
-    assert(opts::dump::DumpModi.getNumOccurrences() == 1);
-    uint32_t Modi = opts::dump::DumpModi;
-    SymbolGroup SG(&Input, Modi);
-    return iterateOneModule(Input, withLabelWidth(HeaderScope, NumDigits(Modi)),
-                            SG, Modi, Callback);
-  }
-
-  uint32_t I = 0;
-
-  for (const auto &SG : Input.symbol_groups()) {
-    if (shouldDumpSymbolGroup(I, SG))
-      if (auto Err =
-              iterateOneModule(Input, withLabelWidth(HeaderScope, NumDigits(I)),
-                               SG, I, Callback))
-        return Err;
-
-    ++I;
-  }
-  return Error::success();
-}
-
-template <typename SubsectionT>
-static Error iterateModuleSubsections(
-    InputFile &File, const Optional<PrintScope> &HeaderScope,
-    llvm::function_ref<Error(uint32_t, const SymbolGroup &, SubsectionT &)>
-        Callback) {
-
-  return iterateSymbolGroups(
-      File, HeaderScope, [&](uint32_t Modi, const SymbolGroup &SG) -> Error {
-        for (const auto &SS : SG.getDebugSubsections()) {
-          SubsectionT Subsection;
-
-          if (SS.kind() != Subsection.kind())
-            continue;
-
-          BinaryStreamReader Reader(SS.getRecordData());
-          if (auto Err = Subsection.initialize(Reader))
-            continue;
-          if (auto Err = Callback(Modi, SG, Subsection))
-            return Err;
-        }
-        return Error::success();
-      });
-}
-
 static Expected<std::pair<std::unique_ptr<MappedBlockStream>,
                           ArrayRef<llvm::object::coff_section>>>
 loadSectionHeaders(PDBFile &File, DbgHeaderType Type) {

diff  --git a/llvm/tools/llvm-pdbutil/DumpOutputStyle.h b/llvm/tools/llvm-pdbutil/DumpOutputStyle.h
index 041fb93a18a52..217d25d66d8bd 100644
--- a/llvm/tools/llvm-pdbutil/DumpOutputStyle.h
+++ b/llvm/tools/llvm-pdbutil/DumpOutputStyle.h
@@ -9,13 +9,13 @@
 #ifndef LLVM_TOOLS_LLVMPDBDUMP_DUMPOUTPUTSTYLE_H
 #define LLVM_TOOLS_LLVMPDBDUMP_DUMPOUTPUTSTYLE_H
 
-#include "LinePrinter.h"
 #include "OutputStyle.h"
 #include "StreamUtil.h"
 
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/Optional.h"
 #include "llvm/ADT/SmallVector.h"
+#include "llvm/DebugInfo/PDB/Native/LinePrinter.h"
 #include "llvm/DebugInfo/PDB/Native/RawConstants.h"
 
 #include <string>

diff  --git a/llvm/tools/llvm-pdbutil/ExplainOutputStyle.cpp b/llvm/tools/llvm-pdbutil/ExplainOutputStyle.cpp
index b631bdf8f2b1c..13a5f6ea6fe73 100644
--- a/llvm/tools/llvm-pdbutil/ExplainOutputStyle.cpp
+++ b/llvm/tools/llvm-pdbutil/ExplainOutputStyle.cpp
@@ -8,17 +8,20 @@
 
 #include "ExplainOutputStyle.h"
 
-#include "FormatUtil.h"
-#include "InputFile.h"
 #include "StreamUtil.h"
 #include "llvm-pdbutil.h"
 
 #include "llvm/DebugInfo/CodeView/Formatters.h"
+#include "llvm/DebugInfo/CodeView/LazyRandomTypeCollection.h"
 #include "llvm/DebugInfo/MSF/MappedBlockStream.h"
 #include "llvm/DebugInfo/PDB/Native/DbiStream.h"
+#include "llvm/DebugInfo/PDB/Native/FormatUtil.h"
 #include "llvm/DebugInfo/PDB/Native/InfoStream.h"
+#include "llvm/DebugInfo/PDB/Native/InputFile.h"
+#include "llvm/DebugInfo/PDB/Native/NativeSession.h"
 #include "llvm/DebugInfo/PDB/Native/PDBFile.h"
 #include "llvm/DebugInfo/PDB/Native/RawTypes.h"
+#include "llvm/Object/COFF.h"
 #include "llvm/Support/BinaryByteStream.h"
 #include "llvm/Support/BinaryStreamArray.h"
 #include "llvm/Support/Error.h"
@@ -29,7 +32,7 @@ using namespace llvm::msf;
 using namespace llvm::pdb;
 
 ExplainOutputStyle::ExplainOutputStyle(InputFile &File, uint64_t FileOffset)
-    : File(File), FileOffset(FileOffset), P(2, false, outs()) {}
+    : File(File), FileOffset(FileOffset), P(2, false, outs(), opts::Filters) {}
 
 Error ExplainOutputStyle::dump() {
   P.formatLine("Explaining file offset {0} of file '{1}'.", FileOffset,

diff  --git a/llvm/tools/llvm-pdbutil/ExplainOutputStyle.h b/llvm/tools/llvm-pdbutil/ExplainOutputStyle.h
index f405cf615e924..e3d19f25a9eac 100644
--- a/llvm/tools/llvm-pdbutil/ExplainOutputStyle.h
+++ b/llvm/tools/llvm-pdbutil/ExplainOutputStyle.h
@@ -9,9 +9,10 @@
 #ifndef LLVM_TOOLS_LLVMPDBDUMP_EXPLAINOUTPUTSTYLE_H
 #define LLVM_TOOLS_LLVMPDBDUMP_EXPLAINOUTPUTSTYLE_H
 
-#include "LinePrinter.h"
 #include "OutputStyle.h"
 
+#include "llvm/DebugInfo/PDB/Native/LinePrinter.h"
+
 #include <string>
 
 namespace llvm {

diff  --git a/llvm/tools/llvm-pdbutil/MinimalSymbolDumper.cpp b/llvm/tools/llvm-pdbutil/MinimalSymbolDumper.cpp
index e6b5d21f36e5f..8e17284871a9a 100644
--- a/llvm/tools/llvm-pdbutil/MinimalSymbolDumper.cpp
+++ b/llvm/tools/llvm-pdbutil/MinimalSymbolDumper.cpp
@@ -8,17 +8,19 @@
 
 #include "MinimalSymbolDumper.h"
 
-#include "FormatUtil.h"
-#include "InputFile.h"
-#include "LinePrinter.h"
-
 #include "llvm/DebugInfo/CodeView/CVRecord.h"
 #include "llvm/DebugInfo/CodeView/CodeView.h"
 #include "llvm/DebugInfo/CodeView/Formatters.h"
 #include "llvm/DebugInfo/CodeView/LazyRandomTypeCollection.h"
 #include "llvm/DebugInfo/CodeView/SymbolRecord.h"
 #include "llvm/DebugInfo/CodeView/TypeRecord.h"
+#include "llvm/DebugInfo/PDB/Native/FormatUtil.h"
+#include "llvm/DebugInfo/PDB/Native/InputFile.h"
+#include "llvm/DebugInfo/PDB/Native/LinePrinter.h"
+#include "llvm/DebugInfo/PDB/Native/NativeSession.h"
+#include "llvm/DebugInfo/PDB/Native/PDBFile.h"
 #include "llvm/DebugInfo/PDB/Native/PDBStringTable.h"
+#include "llvm/Object/COFF.h"
 #include "llvm/Support/FormatVariadic.h"
 
 using namespace llvm;

diff  --git a/llvm/tools/llvm-pdbutil/MinimalTypeDumper.cpp b/llvm/tools/llvm-pdbutil/MinimalTypeDumper.cpp
index 08006e9c62d42..be7e487673fbc 100644
--- a/llvm/tools/llvm-pdbutil/MinimalTypeDumper.cpp
+++ b/llvm/tools/llvm-pdbutil/MinimalTypeDumper.cpp
@@ -8,8 +8,6 @@
 
 #include "MinimalTypeDumper.h"
 
-#include "FormatUtil.h"
-#include "LinePrinter.h"
 #include "TypeReferenceTracker.h"
 
 #include "llvm-pdbutil.h"
@@ -19,8 +17,13 @@
 #include "llvm/DebugInfo/CodeView/Formatters.h"
 #include "llvm/DebugInfo/CodeView/LazyRandomTypeCollection.h"
 #include "llvm/DebugInfo/CodeView/TypeRecord.h"
+#include "llvm/DebugInfo/PDB/Native/FormatUtil.h"
+#include "llvm/DebugInfo/PDB/Native/LinePrinter.h"
+#include "llvm/DebugInfo/PDB/Native/NativeSession.h"
+#include "llvm/DebugInfo/PDB/Native/PDBFile.h"
 #include "llvm/DebugInfo/PDB/Native/TpiHashing.h"
 #include "llvm/DebugInfo/PDB/Native/TpiStream.h"
+#include "llvm/Object/COFF.h"
 #include "llvm/Support/FormatVariadic.h"
 #include "llvm/Support/MathExtras.h"
 

diff  --git a/llvm/tools/llvm-pdbutil/PrettyBuiltinDumper.cpp b/llvm/tools/llvm-pdbutil/PrettyBuiltinDumper.cpp
index a33c033cd83de..895066146a9d1 100644
--- a/llvm/tools/llvm-pdbutil/PrettyBuiltinDumper.cpp
+++ b/llvm/tools/llvm-pdbutil/PrettyBuiltinDumper.cpp
@@ -7,8 +7,8 @@
 //===----------------------------------------------------------------------===//
 
 #include "PrettyBuiltinDumper.h"
-#include "LinePrinter.h"
 
+#include "llvm/DebugInfo/PDB/Native/LinePrinter.h"
 #include "llvm/DebugInfo/PDB/PDBSymbolTypeBuiltin.h"
 
 using namespace llvm;

diff  --git a/llvm/tools/llvm-pdbutil/PrettyClassDefinitionDumper.cpp b/llvm/tools/llvm-pdbutil/PrettyClassDefinitionDumper.cpp
index 37b3fc9706429..2285ed16d2a59 100644
--- a/llvm/tools/llvm-pdbutil/PrettyClassDefinitionDumper.cpp
+++ b/llvm/tools/llvm-pdbutil/PrettyClassDefinitionDumper.cpp
@@ -8,7 +8,6 @@
 
 #include "PrettyClassDefinitionDumper.h"
 
-#include "LinePrinter.h"
 #include "PrettyClassLayoutGraphicalDumper.h"
 #include "llvm-pdbutil.h"
 

diff  --git a/llvm/tools/llvm-pdbutil/PrettyClassLayoutGraphicalDumper.cpp b/llvm/tools/llvm-pdbutil/PrettyClassLayoutGraphicalDumper.cpp
index 364fd3ff7b54b..1ade7f3970308 100644
--- a/llvm/tools/llvm-pdbutil/PrettyClassLayoutGraphicalDumper.cpp
+++ b/llvm/tools/llvm-pdbutil/PrettyClassLayoutGraphicalDumper.cpp
@@ -8,7 +8,6 @@
 
 #include "PrettyClassLayoutGraphicalDumper.h"
 
-#include "LinePrinter.h"
 #include "PrettyClassDefinitionDumper.h"
 #include "PrettyEnumDumper.h"
 #include "PrettyFunctionDumper.h"

diff  --git a/llvm/tools/llvm-pdbutil/PrettyCompilandDumper.cpp b/llvm/tools/llvm-pdbutil/PrettyCompilandDumper.cpp
index cf769ff66472b..591bd4f937025 100644
--- a/llvm/tools/llvm-pdbutil/PrettyCompilandDumper.cpp
+++ b/llvm/tools/llvm-pdbutil/PrettyCompilandDumper.cpp
@@ -8,7 +8,6 @@
 
 #include "PrettyCompilandDumper.h"
 
-#include "LinePrinter.h"
 #include "PrettyFunctionDumper.h"
 #include "llvm-pdbutil.h"
 

diff  --git a/llvm/tools/llvm-pdbutil/PrettyEnumDumper.cpp b/llvm/tools/llvm-pdbutil/PrettyEnumDumper.cpp
index cb96b55c4a833..64557ff09c72c 100644
--- a/llvm/tools/llvm-pdbutil/PrettyEnumDumper.cpp
+++ b/llvm/tools/llvm-pdbutil/PrettyEnumDumper.cpp
@@ -8,7 +8,6 @@
 
 #include "PrettyEnumDumper.h"
 
-#include "LinePrinter.h"
 #include "PrettyBuiltinDumper.h"
 #include "llvm-pdbutil.h"
 

diff  --git a/llvm/tools/llvm-pdbutil/PrettyExternalSymbolDumper.cpp b/llvm/tools/llvm-pdbutil/PrettyExternalSymbolDumper.cpp
index 14f241264e2f4..34436c572c8aa 100644
--- a/llvm/tools/llvm-pdbutil/PrettyExternalSymbolDumper.cpp
+++ b/llvm/tools/llvm-pdbutil/PrettyExternalSymbolDumper.cpp
@@ -7,9 +7,9 @@
 //===----------------------------------------------------------------------===//
 
 #include "PrettyExternalSymbolDumper.h"
-#include "LinePrinter.h"
 
 #include "llvm/DebugInfo/PDB/ConcreteSymbolEnumerator.h"
+#include "llvm/DebugInfo/PDB/Native/LinePrinter.h"
 #include "llvm/DebugInfo/PDB/PDBSymbolExe.h"
 #include "llvm/DebugInfo/PDB/PDBSymbolPublicSymbol.h"
 #include "llvm/Support/Format.h"

diff  --git a/llvm/tools/llvm-pdbutil/PrettyFunctionDumper.cpp b/llvm/tools/llvm-pdbutil/PrettyFunctionDumper.cpp
index f9a5a801c28f4..83cf4d9183227 100644
--- a/llvm/tools/llvm-pdbutil/PrettyFunctionDumper.cpp
+++ b/llvm/tools/llvm-pdbutil/PrettyFunctionDumper.cpp
@@ -7,12 +7,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "PrettyFunctionDumper.h"
-#include "LinePrinter.h"
 #include "PrettyBuiltinDumper.h"
 
 #include "llvm/DebugInfo/PDB/ConcreteSymbolEnumerator.h"
 #include "llvm/DebugInfo/PDB/IPDBLineNumber.h"
 #include "llvm/DebugInfo/PDB/IPDBSession.h"
+#include "llvm/DebugInfo/PDB/Native/LinePrinter.h"
 #include "llvm/DebugInfo/PDB/PDBExtras.h"
 #include "llvm/DebugInfo/PDB/PDBSymbolData.h"
 #include "llvm/DebugInfo/PDB/PDBSymbolFunc.h"

diff  --git a/llvm/tools/llvm-pdbutil/PrettyTypeDumper.cpp b/llvm/tools/llvm-pdbutil/PrettyTypeDumper.cpp
index 5730a0c494de2..9547d4e4ed356 100644
--- a/llvm/tools/llvm-pdbutil/PrettyTypeDumper.cpp
+++ b/llvm/tools/llvm-pdbutil/PrettyTypeDumper.cpp
@@ -8,7 +8,6 @@
 
 #include "PrettyTypeDumper.h"
 
-#include "LinePrinter.h"
 #include "PrettyBuiltinDumper.h"
 #include "PrettyClassDefinitionDumper.h"
 #include "PrettyEnumDumper.h"

diff  --git a/llvm/tools/llvm-pdbutil/PrettyTypedefDumper.cpp b/llvm/tools/llvm-pdbutil/PrettyTypedefDumper.cpp
index 09c591015c56b..197aa07299d12 100644
--- a/llvm/tools/llvm-pdbutil/PrettyTypedefDumper.cpp
+++ b/llvm/tools/llvm-pdbutil/PrettyTypedefDumper.cpp
@@ -8,13 +8,13 @@
 
 #include "PrettyTypedefDumper.h"
 
-#include "LinePrinter.h"
 #include "PrettyBuiltinDumper.h"
 #include "PrettyFunctionDumper.h"
 #include "PrettyTypeDumper.h"
 
 #include "llvm/DebugInfo/PDB/IPDBLineNumber.h"
 #include "llvm/DebugInfo/PDB/IPDBSession.h"
+#include "llvm/DebugInfo/PDB/Native/LinePrinter.h"
 #include "llvm/DebugInfo/PDB/PDBExtras.h"
 #include "llvm/DebugInfo/PDB/PDBSymbolTypeBuiltin.h"
 #include "llvm/DebugInfo/PDB/PDBSymbolTypeEnum.h"

diff  --git a/llvm/tools/llvm-pdbutil/PrettyVariableDumper.cpp b/llvm/tools/llvm-pdbutil/PrettyVariableDumper.cpp
index 60fb0d2ae0bdb..e9ac6984356ca 100644
--- a/llvm/tools/llvm-pdbutil/PrettyVariableDumper.cpp
+++ b/llvm/tools/llvm-pdbutil/PrettyVariableDumper.cpp
@@ -8,7 +8,6 @@
 
 #include "PrettyVariableDumper.h"
 
-#include "LinePrinter.h"
 #include "PrettyBuiltinDumper.h"
 #include "PrettyFunctionDumper.h"
 #include "llvm-pdbutil.h"

diff  --git a/llvm/tools/llvm-pdbutil/StreamUtil.cpp b/llvm/tools/llvm-pdbutil/StreamUtil.cpp
index de906f9064f47..878fb77353fa6 100644
--- a/llvm/tools/llvm-pdbutil/StreamUtil.cpp
+++ b/llvm/tools/llvm-pdbutil/StreamUtil.cpp
@@ -7,13 +7,13 @@
 //===----------------------------------------------------------------------===//
 
 #include "StreamUtil.h"
-#include "FormatUtil.h"
 
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/DenseMapInfo.h"
 #include "llvm/DebugInfo/PDB/Native/DbiModuleDescriptor.h"
 #include "llvm/DebugInfo/PDB/Native/DbiModuleList.h"
 #include "llvm/DebugInfo/PDB/Native/DbiStream.h"
+#include "llvm/DebugInfo/PDB/Native/FormatUtil.h"
 #include "llvm/DebugInfo/PDB/Native/InfoStream.h"
 #include "llvm/DebugInfo/PDB/Native/PDBFile.h"
 #include "llvm/DebugInfo/PDB/Native/TpiStream.h"

diff  --git a/llvm/tools/llvm-pdbutil/TypeReferenceTracker.cpp b/llvm/tools/llvm-pdbutil/TypeReferenceTracker.cpp
index f184f02e01ee3..d813bc22a93cb 100644
--- a/llvm/tools/llvm-pdbutil/TypeReferenceTracker.cpp
+++ b/llvm/tools/llvm-pdbutil/TypeReferenceTracker.cpp
@@ -9,10 +9,12 @@
 #include "TypeReferenceTracker.h"
 
 #include "llvm/DebugInfo/CodeView/LazyRandomTypeCollection.h"
-#include "llvm/DebugInfo/PDB/Native/PDBFile.h"
-#include "llvm/DebugInfo/PDB/Native/TpiStream.h"
 #include "llvm/DebugInfo/PDB/Native/GlobalsStream.h"
+#include "llvm/DebugInfo/PDB/Native/NativeSession.h"
+#include "llvm/DebugInfo/PDB/Native/PDBFile.h"
 #include "llvm/DebugInfo/PDB/Native/SymbolStream.h"
+#include "llvm/DebugInfo/PDB/Native/TpiStream.h"
+#include "llvm/Object/COFF.h"
 
 using namespace llvm;
 using namespace llvm::pdb;

diff  --git a/llvm/tools/llvm-pdbutil/TypeReferenceTracker.h b/llvm/tools/llvm-pdbutil/TypeReferenceTracker.h
index 8861731ab6ee8..c586f6523c57b 100644
--- a/llvm/tools/llvm-pdbutil/TypeReferenceTracker.h
+++ b/llvm/tools/llvm-pdbutil/TypeReferenceTracker.h
@@ -9,14 +9,13 @@
 #ifndef LLVM_TOOLS_LLVMPDBDUMP_TYPEREFERENCETRACKER_H
 #define LLVM_TOOLS_LLVMPDBDUMP_TYPEREFERENCETRACKER_H
 
-#include "InputFile.h"
-
 #include "llvm/ADT/BitVector.h"
 #include "llvm/ADT/Optional.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/DebugInfo/CodeView/CVRecord.h"
 #include "llvm/DebugInfo/CodeView/TypeIndex.h"
 #include "llvm/DebugInfo/CodeView/TypeIndexDiscovery.h"
+#include "llvm/DebugInfo/PDB/Native/InputFile.h"
 #include "llvm/Support/Error.h"
 
 namespace llvm {

diff  --git a/llvm/tools/llvm-pdbutil/llvm-pdbutil.cpp b/llvm/tools/llvm-pdbutil/llvm-pdbutil.cpp
index f1180d8532026..ff7e1dd738ac5 100644
--- a/llvm/tools/llvm-pdbutil/llvm-pdbutil.cpp
+++ b/llvm/tools/llvm-pdbutil/llvm-pdbutil.cpp
@@ -15,8 +15,6 @@
 #include "BytesOutputStyle.h"
 #include "DumpOutputStyle.h"
 #include "ExplainOutputStyle.h"
-#include "InputFile.h"
-#include "LinePrinter.h"
 #include "OutputStyle.h"
 #include "PrettyClassDefinitionDumper.h"
 #include "PrettyCompilandDumper.h"
@@ -55,6 +53,7 @@
 #include "llvm/DebugInfo/PDB/Native/DbiStreamBuilder.h"
 #include "llvm/DebugInfo/PDB/Native/InfoStream.h"
 #include "llvm/DebugInfo/PDB/Native/InfoStreamBuilder.h"
+#include "llvm/DebugInfo/PDB/Native/InputFile.h"
 #include "llvm/DebugInfo/PDB/Native/NativeSession.h"
 #include "llvm/DebugInfo/PDB/Native/PDBFile.h"
 #include "llvm/DebugInfo/PDB/Native/PDBFileBuilder.h"
@@ -199,6 +198,8 @@ static cl::opt<bool> Typedefs("typedefs", cl::desc("Dump typedefs"),
                               cl::sub(DiaDumpSubcommand));
 } // namespace diadump
 
+FilterOptions Filters;
+
 namespace pretty {
 cl::list<std::string> InputFilenames(cl::Positional,
                                      cl::desc("<input PDB files>"),
@@ -1072,7 +1073,7 @@ static void dumpPretty(StringRef Path) {
   const bool UseColor = opts::pretty::ColorOutput == cl::BOU_UNSET
                             ? Stream.has_colors()
                             : opts::pretty::ColorOutput == cl::BOU_TRUE;
-  LinePrinter Printer(2, UseColor, Stream);
+  LinePrinter Printer(2, UseColor, Stream, opts::Filters);
 
   auto GlobalScope(Session->getGlobalScope());
   if (!GlobalScope)
@@ -1510,6 +1511,25 @@ int main(int Argc, const char **Argv) {
 
   llvm::sys::InitializeCOMRAII COM(llvm::sys::COMThreadingMode::MultiThreaded);
 
+  // Initialize the filters for LinePrinter.
+  auto propagate = [&](auto &Target, auto &Reference) {
+    for (std::string &Option : Reference)
+      Target.push_back(Option);
+  };
+
+  propagate(opts::Filters.ExcludeTypes, opts::pretty::ExcludeTypes);
+  propagate(opts::Filters.ExcludeTypes, opts::pretty::ExcludeTypes);
+  propagate(opts::Filters.ExcludeSymbols, opts::pretty::ExcludeSymbols);
+  propagate(opts::Filters.ExcludeCompilands, opts::pretty::ExcludeCompilands);
+  propagate(opts::Filters.IncludeTypes, opts::pretty::IncludeTypes);
+  propagate(opts::Filters.IncludeSymbols, opts::pretty::IncludeSymbols);
+  propagate(opts::Filters.IncludeCompilands, opts::pretty::IncludeCompilands);
+  opts::Filters.PaddingThreshold = opts::pretty::PaddingThreshold;
+  opts::Filters.SizeThreshold = opts::pretty::SizeThreshold;
+  opts::Filters.JustMyCode = opts::dump::JustMyCode;
+  if (opts::dump::DumpModi.getNumOccurrences())
+    opts::Filters.DumpModi = opts::dump::DumpModi;
+
   if (opts::PdbToYamlSubcommand) {
     pdb2Yaml(opts::pdb2yaml::InputFilename.front());
   } else if (opts::YamlToPdbSubcommand) {
@@ -1548,14 +1568,14 @@ int main(int Argc, const char **Argv) {
     // it needs to be escaped again in the C++.  So matching a single \ in the
     // input requires 4 \es in the C++.
     if (opts::pretty::ExcludeCompilerGenerated) {
-      opts::pretty::ExcludeTypes.push_back("__vc_attributes");
-      opts::pretty::ExcludeCompilands.push_back("\\* Linker \\*");
+      opts::Filters.ExcludeTypes.push_back("__vc_attributes");
+      opts::Filters.ExcludeCompilands.push_back("\\* Linker \\*");
     }
     if (opts::pretty::ExcludeSystemLibraries) {
-      opts::pretty::ExcludeCompilands.push_back(
+      opts::Filters.ExcludeCompilands.push_back(
           "f:\\\\binaries\\\\Intermediate\\\\vctools\\\\crt_bld");
-      opts::pretty::ExcludeCompilands.push_back("f:\\\\dd\\\\vctools\\\\crt");
-      opts::pretty::ExcludeCompilands.push_back(
+      opts::Filters.ExcludeCompilands.push_back("f:\\\\dd\\\\vctools\\\\crt");
+      opts::Filters.ExcludeCompilands.push_back(
           "d:\\\\th.obj.x86fre\\\\minkernel");
     }
     llvm::for_each(opts::pretty::InputFilenames, dumpPretty);

diff  --git a/llvm/tools/llvm-pdbutil/llvm-pdbutil.h b/llvm/tools/llvm-pdbutil/llvm-pdbutil.h
index 9fe92c2c9d75e..455fe5f281915 100644
--- a/llvm/tools/llvm-pdbutil/llvm-pdbutil.h
+++ b/llvm/tools/llvm-pdbutil/llvm-pdbutil.h
@@ -12,6 +12,7 @@
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/Optional.h"
 #include "llvm/ADT/PointerUnion.h"
+#include "llvm/DebugInfo/PDB/Native/LinePrinter.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/raw_ostream.h"
 
@@ -50,6 +51,8 @@ enum class ModuleSubsection {
   All
 };
 
+extern FilterOptions Filters;
+
 namespace pretty {
 
 enum class ClassDefinitionFormat { None, Layout, All };


        


More information about the llvm-commits mailing list