Rewrite llvm-pdbdump in terms of LLVMDebugInfoPDB.

This makes llvm-pdbdump available on all platforms, although it
will currently fail to create a dumper if there is no PDB reader
implementation for the current platform.

It implements dumping of compilands and children, which is less
information than was previously available, but it has to be
rewritten from scratch using the new set of interfaces, so the
rest of the functionality will be added back in subsequent commits.

llvm-svn: 228755
diff --git a/llvm/lib/DebugInfo/PDB/PDBSymbolFunc.cpp b/llvm/lib/DebugInfo/PDB/PDBSymbolFunc.cpp
index 38959f1..fcd533c 100644
--- a/llvm/lib/DebugInfo/PDB/PDBSymbolFunc.cpp
+++ b/llvm/lib/DebugInfo/PDB/PDBSymbolFunc.cpp
@@ -9,13 +9,55 @@
 
 #include <utility>
 
+#include "llvm/DebugInfo/PDB/IPDBEnumChildren.h"
 #include "llvm/DebugInfo/PDB/PDBSymbol.h"
 #include "llvm/DebugInfo/PDB/PDBSymbolFunc.h"
+#include "llvm/DebugInfo/PDB/PDBSymbolFuncDebugEnd.h"
+#include "llvm/DebugInfo/PDB/PDBSymbolFuncDebugStart.h"
+
+#include "llvm/Support/Format.h"
 
 using namespace llvm;
-
 PDBSymbolFunc::PDBSymbolFunc(const IPDBSession &PDBSession,
                              std::unique_ptr<IPDBRawSymbol> Symbol)
     : PDBSymbol(PDBSession, std::move(Symbol)) {}
 
-void PDBSymbolFunc::dump(llvm::raw_ostream &OS) const {}
+void PDBSymbolFunc::dump(raw_ostream &OS, int Indent,
+                         PDB_DumpLevel Level) const {
+  bool doFullDump = false;
+  if (Level == PDB_DumpLevel::Compact) {
+    uint32_t FuncStart = getRelativeVirtualAddress();
+    uint32_t FuncEnd = FuncStart + getLength();
+    auto DebugEndSymbol = findChildren(PDB_SymType::FuncDebugEnd);
+    OS << stream_indent(Indent);
+    OS << "[" << format_hex(FuncStart, 8);
+    if (auto DebugStartEnum = findChildren(PDB_SymType::FuncDebugStart)) {
+      if (auto StartSym = DebugStartEnum->getNext()) {
+        auto DebugStart = dyn_cast<PDBSymbolFuncDebugStart>(StartSym.get());
+        OS << "+" << DebugStart->getRelativeVirtualAddress() - FuncStart;
+      }
+    }
+    OS << " - " << format_hex(FuncEnd, 8);
+    if (auto DebugEndEnum = findChildren(PDB_SymType::FuncDebugEnd)) {
+      if (auto DebugEndSym = DebugEndEnum->getNext()) {
+        auto DebugEnd = dyn_cast<PDBSymbolFuncDebugEnd>(DebugEndSym.get());
+        OS << "-" << FuncEnd - DebugEnd->getRelativeVirtualAddress();
+      }
+    }
+    OS << "] ";
+    PDB_RegisterId Reg = getLocalBasePointerRegisterId();
+    if (Reg == PDB_RegisterId::VFrame)
+      OS << "(VFrame)";
+    else if (hasFramePointer()) {
+      if (Reg == PDB_RegisterId::EBP)
+        OS << "(EBP)";
+      else
+        OS << "(" << (int)Reg << ")";
+    } else {
+      OS << "(FPO)";
+      doFullDump = true;
+    }
+    OS << " " << getName() << "\n";
+  }
+  OS.flush();
+}