[llvm] ced9287 - [llvm-objdump] Fix the Assertion failure when providing invalid --debug-vars or --dwarf values
via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 4 04:04:04 PDT 2021
Author: gbreynoo
Date: 2021-11-04T11:01:32Z
New Revision: ced9287c2dfff254edf85e0a43ad80a2d6dcf7eb
URL: https://github.com/llvm/llvm-project/commit/ced9287c2dfff254edf85e0a43ad80a2d6dcf7eb
DIFF: https://github.com/llvm/llvm-project/commit/ced9287c2dfff254edf85e0a43ad80a2d6dcf7eb.diff
LOG: [llvm-objdump] Fix the Assertion failure when providing invalid --debug-vars or --dwarf values
As seen in https://bugs.llvm.org/show_bug.cgi?id=52213 llvm-objdump
asserts if either the --debug-vars or the --dwarf options are provided
with invalid values. As suggested, this fix adds use of a default value
to these options and errors when given bad input.
Differential Revision: https://reviews.llvm.org/D112183
Added:
llvm/test/tools/llvm-objdump/dwarf_invalid.yaml
Modified:
llvm/test/tools/llvm-objdump/ELF/ARM/debug-vars-dwarf4.s
llvm/tools/llvm-objdump/llvm-objdump.cpp
llvm/tools/llvm-objdump/llvm-objdump.h
Removed:
################################################################################
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
index 43a30aeaca6fb..9a8bc47b51774 100644
--- 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
index 0000000000000..531a4c7716542
--- /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.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp
index 163c1cffcefd9..ed605e65bbe83 100644
--- a/llvm/tools/llvm-objdump/llvm-objdump.cpp
+++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp
@@ -2500,6 +2500,11 @@ static void parseIntArg(const llvm::opt::InputArgList &InputArgs, int ID,
}
}
+static void invalidArgValue(const opt::Arg *A) {
+ reportCmdLineError("'" + StringRef(A->getValue()) +
+ "' is not a valid value for '" + A->getSpelling() + "'");
+}
+
static std::vector<std::string>
commaSeparatedValues(const llvm::opt::InputArgList &InputArgs, int ID) {
std::vector<std::string> Values;
@@ -2573,8 +2578,11 @@ static void parseObjdumpOptions(const llvm::opt::InputArgList &InputArgs) {
commaSeparatedValues(InputArgs, OBJDUMP_disassemble_symbols_EQ);
DisassembleZeroes = InputArgs.hasArg(OBJDUMP_disassemble_zeroes);
if (const opt::Arg *A = InputArgs.getLastArg(OBJDUMP_dwarf_EQ)) {
- DwarfDumpType =
- StringSwitch<DIDumpType>(A->getValue()).Case("frames", DIDT_DebugFrame);
+ DwarfDumpType = StringSwitch<DIDumpType>(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 @@ static void parseObjdumpOptions(const llvm::opt::InputArgList &InputArgs) {
if (const opt::Arg *A = InputArgs.getLastArg(OBJDUMP_debug_vars_EQ)) {
DbgVariables = StringSwitch<DebugVarsFormat>(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);
diff --git a/llvm/tools/llvm-objdump/llvm-objdump.h b/llvm/tools/llvm-objdump/llvm-objdump.h
index d9fc3bfe66a5d..864a9920efbef 100644
--- a/llvm/tools/llvm-objdump/llvm-objdump.h
+++ b/llvm/tools/llvm-objdump/llvm-objdump.h
@@ -31,11 +31,7 @@ struct VersionEntry;
namespace objdump {
-enum DebugVarsFormat {
- DVDisabled,
- DVUnicode,
- DVASCII,
-};
+enum DebugVarsFormat { DVDisabled, DVUnicode, DVASCII, DVInvalid };
extern bool ArchiveHeaders;
extern int DbgIndent;
More information about the llvm-commits
mailing list