[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
This commit is contained in:
Carlos Alberto Enciso 2022-04-12 05:31:26 +01:00
parent 3c9e09036c
commit e758b77161
5 changed files with 48 additions and 6 deletions

View File

@ -180,10 +180,8 @@ Error iterateSymbolGroups(InputFile &Input, const PrintScope &HeaderScope,
AutoIndent Indent(HeaderScope);
FilterOptions Filters = HeaderScope.P.getFilters();
if (Filters.NumOccurrences) {
uint32_t Modi = Filters.DumpModi;
if (Modi > 0) {
assert(Modi == 1);
SymbolGroup SG(&Input, Modi);
return iterateOneModule(Input, withLabelWidth(HeaderScope, NumDigits(Modi)),
SG, Modi, Callback);

View File

@ -31,6 +31,7 @@ struct FilterOptions {
uint32_t PaddingThreshold;
uint32_t SizeThreshold;
uint32_t DumpModi;
uint32_t NumOccurrences;
bool JustMyCode;
};

View File

@ -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.

View File

@ -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

View File

@ -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());