Index: llvm/test/tools/llvm-objdump/ELF/ARM/debug-vars-dwarf4.s =================================================================== --- llvm/test/tools/llvm-objdump/ELF/ARM/debug-vars-dwarf4.s +++ llvm/test/tools/llvm-objdump/ELF/ARM/debug-vars-dwarf4.s @@ -45,6 +45,8 @@ # RUN: llvm-mc -triple armv8a--none-eabi < %s -filetype=obj | \ # RUN: llvm-objdump - -d --debug-vars=ascii | \ # RUN: FileCheck %s --check-prefix=ASCII --strict-whitespace +# RUN: not llvm-objdump - -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 +148,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" Index: llvm/test/tools/llvm-objdump/dwarf_invalid.yaml =================================================================== --- /dev/null +++ llvm/test/tools/llvm-objdump/dwarf_invalid.yaml @@ -0,0 +1,16 @@ +## Test parsing of --dwarf=frames + +# RUN: yaml2obj %s -o %t +# RUN: llvm-objdump --dwarf=frames %t | FileCheck %s +# CHECK: .debug_frame contents: +# CHECK: .eh_frame contents: + +# 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 Index: llvm/tools/llvm-objdump/llvm-objdump.h =================================================================== --- llvm/tools/llvm-objdump/llvm-objdump.h +++ 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; Index: llvm/tools/llvm-objdump/llvm-objdump.cpp =================================================================== --- llvm/tools/llvm-objdump/llvm-objdump.cpp +++ 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);