diff --git a/llvm/include/llvm/DebugInfo/PDB/Native/InputFile.h b/llvm/include/llvm/DebugInfo/PDB/Native/InputFile.h --- a/llvm/include/llvm/DebugInfo/PDB/Native/InputFile.h +++ b/llvm/include/llvm/DebugInfo/PDB/Native/InputFile.h @@ -180,10 +180,8 @@ 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 --- a/llvm/include/llvm/DebugInfo/PDB/Native/LinePrinter.h +++ b/llvm/include/llvm/DebugInfo/PDB/Native/LinePrinter.h @@ -31,6 +31,7 @@ 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 --- a/llvm/lib/DebugInfo/PDB/Native/InputFile.cpp +++ b/llvm/lib/DebugInfo/PDB/Native/InputFile.cpp @@ -579,7 +579,7 @@ 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 --- /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 --- a/llvm/tools/llvm-pdbutil/llvm-pdbutil.cpp +++ b/llvm/tools/llvm-pdbutil/llvm-pdbutil.cpp @@ -1527,8 +1527,15 @@ 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());