[PATCH] D112183: [llvm-objdump] Fix the Assertion failure when providing invalid --debug-vars or --dwarf values
Owen Reynolds via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 2 04:08:20 PDT 2021
gbreynoo updated this revision to Diff 384035.
gbreynoo added a comment.
Fixed comment and added input to llvm-objdump call as suggested by James.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D112183/new/
https://reviews.llvm.org/D112183
Files:
llvm/test/tools/llvm-objdump/ELF/ARM/debug-vars-dwarf4.s
llvm/test/tools/llvm-objdump/dwarf_invalid.yaml
llvm/tools/llvm-objdump/llvm-objdump.cpp
llvm/tools/llvm-objdump/llvm-objdump.h
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<std::string>
commaSeparatedValues(const llvm::opt::InputArgList &InputArgs, int ID) {
std::vector<std::string> 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<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 @@
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);
Index: llvm/test/tools/llvm-objdump/dwarf_invalid.yaml
===================================================================
--- /dev/null
+++ 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
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,9 @@
# 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: llvm-mc -triple armv8a--none-eabi < %s -filetype=obj | \
+# 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 +149,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"
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D112183.384035.patch
Type: text/x-patch
Size: 3859 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211102/411533c3/attachment.bin>
More information about the llvm-commits
mailing list