[llvm] e758b77 - [llvm-pdbutil] Fix broken '-modi' option after change D122226.

Carlos Alberto Enciso via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 11 22:31:45 PDT 2022


Author: Carlos Alberto Enciso
Date: 2022-04-12T06:31:12+01:00
New Revision: e758b77161a70d7e7260d8f52bf161a89d73af8a

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

LOG: [llvm-pdbutil] Fix broken '-modi' option after change D122226.

The change described by:

https://reviews.llvm.org/D122226

Moved some llvm-pdbutil functionality to the debug PDB library.

This patch addresses a broken '-modi' argument handling, which
causes an assertion if its value is other than '0' or '1'.

In addition, it moves the assertion for the number of occurrences
of the '-modi' argument from the PDB library into the llvm-pdbutil
driver.

Reviewed By: zequanwu

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

Added: 
    llvm/test/tools/llvm-pdbutil/modi.test

Modified: 
    llvm/include/llvm/DebugInfo/PDB/Native/InputFile.h
    llvm/include/llvm/DebugInfo/PDB/Native/LinePrinter.h
    llvm/lib/DebugInfo/PDB/Native/InputFile.cpp
    llvm/tools/llvm-pdbutil/llvm-pdbutil.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/DebugInfo/PDB/Native/InputFile.h b/llvm/include/llvm/DebugInfo/PDB/Native/InputFile.h
index eeb7c76d2bd87..5b0f433f118af 100644
--- a/llvm/include/llvm/DebugInfo/PDB/Native/InputFile.h
+++ b/llvm/include/llvm/DebugInfo/PDB/Native/InputFile.h
@@ -180,10 +180,8 @@ Error iterateSymbolGroups(InputFile &Input, const PrintScope &HeaderScope,
   AutoIndent Indent(HeaderScope);
 
   FilterOptions Filters = HeaderScope.P.getFilters();
-  uint32_t Modi = Filters.DumpModi;
-
-  if (Modi > 0) {
-    assert(Modi == 1);
+  if (Filters.NumOccurrences) {
+    uint32_t Modi = Filters.DumpModi;
     SymbolGroup SG(&Input, Modi);
     return iterateOneModule(Input, withLabelWidth(HeaderScope, NumDigits(Modi)),
                             SG, Modi, Callback);

diff  --git a/llvm/include/llvm/DebugInfo/PDB/Native/LinePrinter.h b/llvm/include/llvm/DebugInfo/PDB/Native/LinePrinter.h
index 773bf061fb7b1..e65bfc19fd206 100644
--- a/llvm/include/llvm/DebugInfo/PDB/Native/LinePrinter.h
+++ b/llvm/include/llvm/DebugInfo/PDB/Native/LinePrinter.h
@@ -31,6 +31,7 @@ struct FilterOptions {
   uint32_t PaddingThreshold;
   uint32_t SizeThreshold;
   uint32_t DumpModi;
+  uint32_t NumOccurrences;
   bool JustMyCode;
 };
 

diff  --git a/llvm/lib/DebugInfo/PDB/Native/InputFile.cpp b/llvm/lib/DebugInfo/PDB/Native/InputFile.cpp
index ebe410748b670..99dd1316dd8fe 100644
--- a/llvm/lib/DebugInfo/PDB/Native/InputFile.cpp
+++ b/llvm/lib/DebugInfo/PDB/Native/InputFile.cpp
@@ -579,7 +579,7 @@ bool llvm::pdb::shouldDumpSymbolGroup(uint32_t Idx, const SymbolGroup &Group,
     return false;
 
   // If the arg was not specified on the command line, always dump all modules.
-  if (Filters.DumpModi == 0)
+  if (Filters.NumOccurrences == 0)
     return true;
 
   // Otherwise, only dump if this is the same module specified.

diff  --git a/llvm/test/tools/llvm-pdbutil/modi.test b/llvm/test/tools/llvm-pdbutil/modi.test
new file mode 100644
index 0000000000000..0d159272679f8
--- /dev/null
+++ b/llvm/test/tools/llvm-pdbutil/modi.test
@@ -0,0 +1,36 @@
+; Using the existing PDB file (Stripped.pdb).
+;
+; -modi is specified more than once: command line error
+; RUN: not llvm-pdbutil dump --symbols -modi=1 -modi=1 %p/Inputs/Stripped.pdb > %t 2>&1
+; RUN: FileCheck -input-file=%t %s -check-prefix=TWICE
+; TWICE: argument '-modi' specified more than once.
+
+; -modi is not specified: process all modules
+; RUN: llvm-pdbutil dump --symbols %p/Inputs/Stripped.pdb > %t
+; RUN: FileCheck -input-file=%t %s -check-prefix=NONE
+
+; NONE: Symbols
+; NONE-CHECK: Mod 0000
+; NONE-CHECK: Mod 0001
+; NONE-CHECK: Mod 0002
+
+; -modi=0: process module with id=0
+; RUN: llvm-pdbutil dump --symbols -modi=0 %p/Inputs/Stripped.pdb > %t
+; RUN: FileCheck -input-file=%t %s -check-prefix=ZERO
+
+; ZERO: Symbols
+; ZERO-CHECK: Mod 0000
+
+; -modi=1: process module with id=1
+; RUN: llvm-pdbutil dump --symbols -modi=1 %p/Inputs/Stripped.pdb > %t
+; RUN: FileCheck -input-file=%t %s -check-prefix=ONE
+
+; ONE: Symbols
+; ONE-CHECK: Mod 0001
+
+; -modi=2: process module with id=2
+; RUN: llvm-pdbutil dump --symbols -modi=2 %p/Inputs/Stripped.pdb > %t
+; RUN: FileCheck -input-file=%t %s -check-prefix=TWO
+
+; TWO: Symbols
+; TWO-CHECK: Mod 0002

diff  --git a/llvm/tools/llvm-pdbutil/llvm-pdbutil.cpp b/llvm/tools/llvm-pdbutil/llvm-pdbutil.cpp
index ff7e1dd738ac5..7258a7f0ecd8d 100644
--- a/llvm/tools/llvm-pdbutil/llvm-pdbutil.cpp
+++ b/llvm/tools/llvm-pdbutil/llvm-pdbutil.cpp
@@ -1527,8 +1527,15 @@ int main(int Argc, const char **Argv) {
   opts::Filters.PaddingThreshold = opts::pretty::PaddingThreshold;
   opts::Filters.SizeThreshold = opts::pretty::SizeThreshold;
   opts::Filters.JustMyCode = opts::dump::JustMyCode;
-  if (opts::dump::DumpModi.getNumOccurrences())
+  if (opts::dump::DumpModi.getNumOccurrences() > 0) {
+    if (opts::dump::DumpModi.getNumOccurrences() != 1) {
+      errs() << "argument '-modi' specified more than once.\n";
+      errs().flush();
+      exit(1);
+    }
+    opts::Filters.NumOccurrences = opts::dump::DumpModi.getNumOccurrences();
     opts::Filters.DumpModi = opts::dump::DumpModi;
+  }
 
   if (opts::PdbToYamlSubcommand) {
     pdb2Yaml(opts::pdb2yaml::InputFilename.front());


        


More information about the llvm-commits mailing list