]> granicus.if.org Git - llvm/commitdiff
[llvm-pdbutil] Add support for dumping cross module imports/exports.
authorZachary Turner <zturner@google.com>
Fri, 16 Jun 2017 00:04:24 +0000 (00:04 +0000)
committerZachary Turner <zturner@google.com>
Fri, 16 Jun 2017 00:04:24 +0000 (00:04 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@305532 91177308-0d34-0410-b5e6-96231b3b80d8

tools/llvm-pdbutil/FormatUtil.cpp
tools/llvm-pdbutil/RawOutputStyle.cpp
tools/llvm-pdbutil/RawOutputStyle.h
tools/llvm-pdbutil/llvm-pdbutil.cpp
tools/llvm-pdbutil/llvm-pdbutil.h

index 007db9ee9f999443e6a81e269d1feda4599452dd..1bbe2724f0ab94683c9a00be33261e4ad91bf70d 100644 (file)
@@ -17,7 +17,7 @@ using namespace llvm;
 using namespace llvm::pdb;
 
 std::string llvm::pdb::typesetItemList(ArrayRef<std::string> Opts,
-                                       uint32_t GroupSize, uint32_t IndentLevel,
+                                       uint32_t IndentLevel, uint32_t GroupSize,
                                        StringRef Sep) {
   std::string Result;
   while (!Opts.empty()) {
index 053c10996adfe4a3786503264cdd0d9b41ab335b..b204a89ec317aefa9b593dd97c87cd0d6a9957f4 100644 (file)
@@ -119,6 +119,16 @@ Error RawOutputStyle::dump() {
       return EC;
   }
 
+  if (opts::raw::DumpXmi) {
+    if (auto EC = dumpXmi())
+      return EC;
+  }
+
+  if (opts::raw::DumpXme) {
+    if (auto EC = dumpXme())
+      return EC;
+  }
+
   if (opts::raw::DumpTypes || opts::raw::DumpTypeExtras) {
     if (auto EC = dumpTpiStream(StreamTPI))
       return EC;
@@ -566,7 +576,6 @@ static void typesetLinesAndColumns(PDBFile &File, LinePrinter &P,
 
 Error RawOutputStyle::dumpLines() {
   printHeader(P, "Lines");
-  ExitOnError Err("Unexpected error processing modules");
 
   uint32_t LastModi = UINT32_MAX;
   uint32_t LastNameIndex = UINT32_MAX;
@@ -603,7 +612,6 @@ Error RawOutputStyle::dumpLines() {
 
 Error RawOutputStyle::dumpInlineeLines() {
   printHeader(P, "Inlinee Lines");
-  ExitOnError Err("Unexpected error processing modules");
 
   iterateModuleSubsections<DebugInlineeLinesSubsectionRef>(
       File, P, 2,
@@ -621,6 +629,58 @@ Error RawOutputStyle::dumpInlineeLines() {
   return Error::success();
 }
 
+Error RawOutputStyle::dumpXmi() {
+  printHeader(P, "Cross Module Imports");
+  iterateModuleSubsections<DebugCrossModuleImportsSubsectionRef>(
+      File, P, 2,
+      [this](uint32_t Modi, StringsAndChecksumsPrinter &Strings,
+             DebugCrossModuleImportsSubsectionRef &Imports) {
+        P.formatLine("{0,=32} | {1}", "Imported Module", "Type IDs");
+
+        for (const auto &Xmi : Imports) {
+          auto ExpectedModule =
+              Strings.getNameFromStringTable(Xmi.Header->ModuleNameOffset);
+          StringRef Module;
+          SmallString<32> ModuleStorage;
+          if (!ExpectedModule) {
+            Module = "(unknown module)";
+            consumeError(ExpectedModule.takeError());
+          } else
+            Module = *ExpectedModule;
+          if (Module.size() > 32) {
+            ModuleStorage = "...";
+            ModuleStorage += Module.take_back(32 - 3);
+            Module = ModuleStorage;
+          }
+          std::vector<std::string> TIs;
+          for (const auto I : Xmi.Imports)
+            TIs.push_back(formatv("{0,+10:X+}", fmtle(I)));
+          std::string Result =
+              typesetItemList(TIs, P.getIndentLevel() + 35, 12, " ");
+          P.formatLine("{0,+32} | {1}", Module, Result);
+        }
+      });
+
+  return Error::success();
+}
+
+Error RawOutputStyle::dumpXme() {
+  printHeader(P, "Cross Module Exports");
+
+  iterateModuleSubsections<DebugCrossModuleExportsSubsectionRef>(
+      File, P, 2,
+      [this](uint32_t Modi, StringsAndChecksumsPrinter &Strings,
+             DebugCrossModuleExportsSubsectionRef &Exports) {
+        P.formatLine("{0,-10} | {1}", "Local ID", "Global ID");
+        for (const auto &Export : Exports) {
+          P.formatLine("{0,+10:X+} | {1}", TypeIndex(Export.Local),
+                       TypeIndex(Export.Global));
+        }
+      });
+
+  return Error::success();
+}
+
 Error RawOutputStyle::dumpStringTable() {
   printHeader(P, "String Table");
 
@@ -909,7 +969,7 @@ static std::string formatSectionCharacteristics(uint32_t IndentLevel,
   PUSH_FLAG(SC, IMAGE_SCN_MEM_EXECUTE, C, "IMAGE_SCN_MEM_EXECUTE");
   PUSH_FLAG(SC, IMAGE_SCN_MEM_READ, C, "IMAGE_SCN_MEM_READ");
   PUSH_FLAG(SC, IMAGE_SCN_MEM_WRITE, C, "IMAGE_SCN_MEM_WRITE");
-  return typesetItemList(Opts, 3, IndentLevel, " | ");
+  return typesetItemList(Opts, IndentLevel, 3, " | ");
 }
 
 static std::string formatSegMapDescriptorFlag(uint32_t IndentLevel,
@@ -925,7 +985,7 @@ static std::string formatSegMapDescriptorFlag(uint32_t IndentLevel,
   PUSH_FLAG(OMFSegDescFlags, IsSelector, Flags, "selector");
   PUSH_FLAG(OMFSegDescFlags, IsAbsoluteAddress, Flags, "absolute addr");
   PUSH_FLAG(OMFSegDescFlags, IsGroup, Flags, "group");
-  return typesetItemList(Opts, 4, IndentLevel, " | ");
+  return typesetItemList(Opts, IndentLevel, 4, " | ");
 }
 
 Error RawOutputStyle::dumpSectionContribs() {
index e9405fc2a92862b26c837fa5d0a3ab50ebdf40de..803f588961bb2514cd41146598177bc3cac2775f 100644 (file)
@@ -44,6 +44,8 @@ private:
   Error dumpStringTable();
   Error dumpLines();
   Error dumpInlineeLines();
+  Error dumpXmi();
+  Error dumpXme();
   Error dumpTpiStream(uint32_t StreamIdx);
   Error dumpModules();
   Error dumpModuleFiles();
index cbda8e6dbf545b3decfdfe5dfa92026d83a1e9dc..9088783876e0ce0b8ccbf746ff87d6e9f2ba5851 100644 (file)
@@ -344,6 +344,16 @@ cl::opt<bool> DumpInlineeLines(
     "il",
     cl::desc("dump inlinee line information (DEBUG_S_INLINEELINES subsection)"),
     cl::cat(FileOptions), cl::sub(RawSubcommand));
+cl::opt<bool> DumpXmi(
+    "xmi",
+    cl::desc(
+        "dump cross module imports (DEBUG_S_CROSSSCOPEIMPORTS subsection)"),
+    cl::cat(FileOptions), cl::sub(RawSubcommand));
+cl::opt<bool> DumpXme(
+    "xme",
+    cl::desc(
+        "dump cross module exports (DEBUG_S_CROSSSCOPEEXPORTS subsection)"),
+    cl::cat(FileOptions), cl::sub(RawSubcommand));
 
 // MISCELLANEOUS OPTIONS
 cl::opt<bool> DumpStringTable("string-table", cl::desc("dump PDB String Table"),
@@ -903,6 +913,8 @@ int main(int argc_, const char *argv_[]) {
     if (opts::raw::RawAll) {
       opts::raw::DumpLines = true;
       opts::raw::DumpInlineeLines = true;
+      opts::raw::DumpXme = true;
+      opts::raw::DumpXmi = true;
       opts::raw::DumpIds = true;
       opts::raw::DumpPublics = true;
       opts::raw::DumpSectionContribs = true;
index 422b92939814d9679ccc0dcf3b56b0d88dd92c3a..a41b032d2b1300d3508523a4e2c3a9de5a64c066 100644 (file)
@@ -105,6 +105,8 @@ extern llvm::cl::list<std::string> DumpStreamData;
 
 extern llvm::cl::opt<bool> DumpLines;
 extern llvm::cl::opt<bool> DumpInlineeLines;
+extern llvm::cl::opt<bool> DumpXmi;
+extern llvm::cl::opt<bool> DumpXme;
 extern llvm::cl::opt<bool> DumpStringTable;
 extern llvm::cl::opt<bool> DumpTypes;
 extern llvm::cl::opt<bool> DumpTypeData;