[PATCH] D86998: [llvm-dwarfdump] Warn user when it encounters no null terminated strings.
Xing GUO via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 1 22:16:40 PDT 2020
Higuoxing updated this revision to Diff 289352.
Higuoxing marked an inline comment as done.
Higuoxing added a comment.
Address comment.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D86998/new/
https://reviews.llvm.org/D86998
Files:
llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
llvm/test/tools/llvm-dwarfdump/debug-str.yaml
Index: llvm/test/tools/llvm-dwarfdump/debug-str.yaml
===================================================================
--- llvm/test/tools/llvm-dwarfdump/debug-str.yaml
+++ llvm/test/tools/llvm-dwarfdump/debug-str.yaml
@@ -44,3 +44,16 @@
# ESCAPED-NEXT: 0x00000002: "\001"
# ESCAPED-NEXT: 0x00000004: "\\001"
# ESCAPED-EMPTY:
+
+## c) Test that llvm-dwarfdump emits a warning when it encounters a no null terminated string.
+
+## "abc\0" "abc"
+# RUN: yaml2obj -DCONTENT="61626300616263" %s -o %t3.o
+# RUN: llvm-dwarfdump --debug-str %t3.o 2>&1 | FileCheck %s --check-prefix=WARN
+
+# WARN: .debug_str contents:
+# WARN-NEXT: 0x00000000: "abc"
+# WARN-NEXT: warning: no null terminated string at offset 0x4
+# WARN: .debug_str.dwo contents:
+# WARN-NEXT: 0x00000000: "abc"
+# WARN-NEXT: warning: no null terminated string at offset 0x4
Index: llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
===================================================================
--- llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
+++ llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
@@ -528,9 +528,18 @@
auto DumpStrSection = [&](StringRef Section) {
DataExtractor StrData(Section, isLittleEndian(), 0);
+
+ Error Err = Error::success();
+ (void)!Err;
+
uint64_t Offset = 0;
uint64_t StrOffset = 0;
- while (const char *CStr = StrData.getCStr(&Offset)) {
+ while (StrData.isValidOffset(Offset)) {
+ const char *CStr = StrData.getCStr(&Offset, &Err);
+ if (Err) {
+ DumpOpts.WarningHandler(std::move(Err));
+ return;
+ }
OS << format("0x%8.8" PRIx64 ": \"", StrOffset);
OS.write_escaped(CStr);
OS << "\"\n";
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D86998.289352.patch
Type: text/x-patch
Size: 1693 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200902/95296896/attachment.bin>
More information about the llvm-commits
mailing list