Index: llvm/test/tools/llvm-objdump/X86/debug-vars.yaml =================================================================== --- /dev/null +++ llvm/test/tools/llvm-objdump/X86/debug-vars.yaml @@ -0,0 +1,22 @@ +## Test parsing of --dwarf=frames + +# RUN: llvm-mc -filetype=obj -triple=x86_64 %S/disassemble-print-comments.s -o %t + +# RUN: llvm-objdump -d --no-show-raw-insn --debug-vars %t | FileCheck %s --check-prefix=UNICODE +# RUN: llvm-objdump -d --no-show-raw-insn --debug-vars=unicode %t | FileCheck %s --check-prefix=UNICODE + +# UNICODE: 0000000000000000 : +# UNICODE-NEXT: ┠─ bar = RDX +# UNICODE-NEXT: 0: nop ┃ +# UNICODE-NEXT: 1: cmpl $305419896, %eax # imm = 0x12345678 ┻ + +# RUN: llvm-objdump -d --no-show-raw-insn --debug-vars=ascii %t | FileCheck %s --check-prefix=ASCII + +# ASCII: 0000000000000000 : +# ASCII-NEXT: |- bar = RDX +# ASCII-NEXT: 0: nop | +# ASCII-NEXT: 1: cmpl $305419896, %eax # imm = 0x12345678 v + +# RUN: not llvm-objdump -d --no-show-raw-insn --debug-vars=bad_value %t 2>&1 | FileCheck %s --check-prefix=ERROR + +# ERROR: error: 'bad_value' is not a valid value for '--debug-vars=' Index: llvm/test/tools/llvm-objdump/X86/eh_frame.yaml =================================================================== --- /dev/null +++ llvm/test/tools/llvm-objdump/X86/eh_frame.yaml @@ -0,0 +1,17 @@ +## 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 + Machine: EM_X86_64 Index: llvm/tools/llvm-objdump/llvm-objdump.h =================================================================== --- llvm/tools/llvm-objdump/llvm-objdump.h +++ llvm/tools/llvm-objdump/llvm-objdump.h @@ -35,6 +35,7 @@ DVDisabled, DVUnicode, DVASCII, + DVInvalid }; extern bool ArchiveHeaders; 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);