diff --git a/llvm/test/tools/llvm-objdump/ELF/ARM/debug-vars-dwarf4.s b/llvm/test/tools/llvm-objdump/ELF/ARM/debug-vars-dwarf4.s --- a/llvm/test/tools/llvm-objdump/ELF/ARM/debug-vars-dwarf4.s +++ b/llvm/test/tools/llvm-objdump/ELF/ARM/debug-vars-dwarf4.s @@ -8,26 +8,23 @@ ## Generated with this compile command, with the source code in Inputs/debug.c: ## clang --target=arm--none-eabi -march=armv7-a -c debug.c -O1 -gdwarf-4 -S -o - -# RUN: llvm-mc -triple armv8a--none-eabi < %s -filetype=obj | \ -# RUN: llvm-objdump - -d --debug-vars | \ +# RUN: llvm-mc -triple armv8a--none-eabi < %s -filetype=obj -o %t.o + +# RUN: llvm-objdump %t.o -d --debug-vars | \ # RUN: FileCheck %s --check-prefix=RAW --strict-whitespace ## Check that passing the default value for --debug-vars-indent (52) makes no ## change to the output. -# RUN: llvm-mc -triple armv8a--none-eabi < %s -filetype=obj | \ -# RUN: llvm-objdump - -d --debug-vars --debug-vars-indent=52 | \ +# RUN: llvm-objdump %t.o -d --debug-vars --debug-vars-indent=52 | \ # RUN: FileCheck %s --check-prefix=RAW --strict-whitespace -# RUN: llvm-mc -triple armv8a--none-eabi < %s -filetype=obj | \ -# RUN: llvm-objdump - -d --debug-vars --debug-vars-indent=30 | \ +# RUN: llvm-objdump %t.o -d --debug-vars --debug-vars-indent=30 | \ # RUN: FileCheck %s --check-prefix=INDENT --strict-whitespace -# RUN: llvm-mc -triple armv8a--none-eabi < %s -filetype=obj | \ -# RUN: llvm-objdump - -d --debug-vars --no-show-raw-insn | \ +# RUN: llvm-objdump %t.o -d --debug-vars --no-show-raw-insn | \ # RUN: FileCheck %s --check-prefix=NO-RAW --strict-whitespace -# RUN: llvm-mc -triple armv8a--none-eabi < %s -filetype=obj | \ -# RUN: llvm-objdump - -d --debug-vars --no-show-raw-insn --line-numbers | \ +# RUN: llvm-objdump %t.o -d --debug-vars --no-show-raw-insn --line-numbers | \ # RUN: FileCheck %s --check-prefix=LINE-NUMS --strict-whitespace # RUN: mkdir -p %t/a @@ -39,12 +36,12 @@ ## An optional argument to the --debug-vars= option can be used to switch ## between unicode and ascii output (with unicode being the default). -# RUN: llvm-mc -triple armv8a--none-eabi < %s -filetype=obj | \ -# RUN: llvm-objdump - -d --debug-vars=unicode | \ +# RUN: llvm-objdump %t.o -d --debug-vars=unicode | \ # RUN: FileCheck %s --check-prefix=RAW --strict-whitespace -# RUN: llvm-mc -triple armv8a--none-eabi < %s -filetype=obj | \ -# RUN: llvm-objdump - -d --debug-vars=ascii | \ +# RUN: llvm-objdump %t.o -d --debug-vars=ascii | \ # RUN: FileCheck %s --check-prefix=ASCII --strict-whitespace +# RUN: not llvm-objdump %t.o -d --debug-vars=bad_value 2>&1 | \ +# RUN: FileCheck %s --check-prefix=ERROR ## Note that llvm-objdump emits tab characters in the disassembly, assuming an ## 8-byte tab stop, so these might not look aligned in a text editor. @@ -146,6 +143,8 @@ # ASCII-NEXT: c: 01 00 80 e2 add r0, r0, #1 | # ASCII-NEXT: 10: 1e ff 2f e1 bx lr v +# ERROR: error: 'bad_value' is not a valid value for '--debug-vars=' + .text .syntax unified .eabi_attribute 67, "2.09" diff --git a/llvm/test/tools/llvm-objdump/dwarf_invalid.yaml b/llvm/test/tools/llvm-objdump/dwarf_invalid.yaml new file mode 100644 --- /dev/null +++ b/llvm/test/tools/llvm-objdump/dwarf_invalid.yaml @@ -0,0 +1,12 @@ +## Test invalid use of the --dwarf option. + +# RUN: yaml2obj %s -o %t +# RUN: not llvm-objdump --dwarf=bad_value %t 2>&1 | FileCheck %s --check-prefix=ERROR + +# ERROR: error: 'bad_value' is not a valid value for '--dwarf=' + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL diff --git a/llvm/tools/llvm-objdump/llvm-objdump.h b/llvm/tools/llvm-objdump/llvm-objdump.h --- a/llvm/tools/llvm-objdump/llvm-objdump.h +++ b/llvm/tools/llvm-objdump/llvm-objdump.h @@ -31,11 +31,7 @@ namespace objdump { -enum DebugVarsFormat { - DVDisabled, - DVUnicode, - DVASCII, -}; +enum DebugVarsFormat { DVDisabled, DVUnicode, DVASCII, DVInvalid }; extern bool ArchiveHeaders; extern int DbgIndent; diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp --- a/llvm/tools/llvm-objdump/llvm-objdump.cpp +++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp @@ -2500,6 +2500,11 @@ } } +static void invalidArgValue(const opt::Arg *A) { + reportCmdLineError("'" + StringRef(A->getValue()) + + "' is not a valid value for '" + A->getSpelling() + "'"); +} + static std::vector commaSeparatedValues(const llvm::opt::InputArgList &InputArgs, int ID) { std::vector Values; @@ -2573,8 +2578,11 @@ commaSeparatedValues(InputArgs, OBJDUMP_disassemble_symbols_EQ); DisassembleZeroes = InputArgs.hasArg(OBJDUMP_disassemble_zeroes); if (const opt::Arg *A = InputArgs.getLastArg(OBJDUMP_dwarf_EQ)) { - DwarfDumpType = - StringSwitch(A->getValue()).Case("frames", DIDT_DebugFrame); + DwarfDumpType = StringSwitch(A->getValue()) + .Case("frames", DIDT_DebugFrame) + .Default(DIDT_Null); + if (DwarfDumpType == DIDT_Null) + invalidArgValue(A); } DynamicRelocations = InputArgs.hasArg(OBJDUMP_dynamic_reloc); FaultMapSection = InputArgs.hasArg(OBJDUMP_fault_map_section); @@ -2611,7 +2619,10 @@ if (const opt::Arg *A = InputArgs.getLastArg(OBJDUMP_debug_vars_EQ)) { DbgVariables = StringSwitch(A->getValue()) .Case("ascii", DVASCII) - .Case("unicode", DVUnicode); + .Case("unicode", DVUnicode) + .Default(DVInvalid); + if (DbgVariables == DVInvalid) + invalidArgValue(A); } parseIntArg(InputArgs, OBJDUMP_debug_vars_indent_EQ, DbgIndent);