[Lldb-commits] [PATCH] D114877: [lldb] Add missing space in C string format memory read warning
David Spickett via Phabricator via lldb-commits
lldb-commits at lists.llvm.org
Wed Dec 1 07:02:50 PST 2021
DavidSpickett updated this revision to Diff 391013.
DavidSpickett added a comment.
Put the command in a string and add in the size each time since that's all that changes.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D114877/new/
https://reviews.llvm.org/D114877
Files:
lldb/source/Commands/CommandObjectMemory.cpp
lldb/test/API/commands/memory/read/Makefile
lldb/test/API/commands/memory/read/TestMemoryRead.py
lldb/test/API/commands/memory/read/main.c
Index: lldb/test/API/commands/memory/read/main.c
===================================================================
--- /dev/null
+++ lldb/test/API/commands/memory/read/main.c
@@ -0,0 +1,4 @@
+int main() {
+ char the_string[] = {'a', 'b', 'c', 'd', 0};
+ return 0; // Set break point at this line.
+}
Index: lldb/test/API/commands/memory/read/TestMemoryRead.py
===================================================================
--- /dev/null
+++ lldb/test/API/commands/memory/read/TestMemoryRead.py
@@ -0,0 +1,64 @@
+"""
+Test the 'memory read' command.
+"""
+
+import lldb
+import lldbsuite.test.lldbutil as lldbutil
+
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+
+
+class MemoryWriteTestCase(TestBase):
+
+ mydir = TestBase.compute_mydir(__file__)
+
+ def setUp(self):
+ # Call super's setUp().
+ TestBase.setUp(self)
+ # Find the line number to break inside main().
+ self.line = line_number('main.c', '// Set break point at this line.')
+
+ def build_run_stop(self):
+ self.build()
+ exe = self.getBuildArtifact("a.out")
+ self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
+
+ # Break in main() after the variables are assigned values.
+ lldbutil.run_break_set_by_file_and_line(self,
+ "main.c",
+ self.line,
+ num_expected_locations=1,
+ loc_exact=True)
+
+ self.runCmd("run", RUN_SUCCEEDED)
+
+ # The stop reason of the thread should be breakpoint.
+ self.expect("thread list",
+ STOPPED_DUE_TO_BREAKPOINT,
+ substrs=['stopped', 'stop reason = breakpoint'])
+
+ # The breakpoint should have a hit count of 1.
+ lldbutil.check_breakpoint(self, bpno = 1, expected_hit_count = 1)
+
+ @no_debug_info_test
+ def test_memory_read_c_string(self):
+ """Test that reading memory as a c string respects the size limit given
+ and warns if the null terminator is missing."""
+ self.build_run_stop()
+
+ # The size here is the size in memory so it includes the null terminator.
+ cmd = "memory read --format \"c-string\" --size {} &the_string"
+
+ # Size matches the size of the array.
+ self.expect(cmd.format(5), substrs=['\"abcd\"'])
+
+ # If size would take us past the terminator we stop at the terminator.
+ self.expect(cmd.format(10), substrs=['\"abcd\"'])
+
+ # Size 3 means 2 chars and a terminator. So we print 2 chars but warn because
+ # the third isn't 0 as expected.
+ self.expect(cmd.format(3), substrs=['\"ab\"'])
+ self.assertRegex(self.res.GetError(),
+ "unable to find a NULL terminated string at 0x[0-9A-fa-f]+."
+ " Consider increasing the maximum read length.")
Index: lldb/test/API/commands/memory/read/Makefile
===================================================================
--- /dev/null
+++ lldb/test/API/commands/memory/read/Makefile
@@ -0,0 +1,3 @@
+C_SOURCES := main.c
+
+include Makefile.rules
Index: lldb/source/Commands/CommandObjectMemory.cpp
===================================================================
--- lldb/source/Commands/CommandObjectMemory.cpp
+++ lldb/source/Commands/CommandObjectMemory.cpp
@@ -716,7 +716,7 @@
if (item_byte_size == read) {
result.AppendWarningWithFormat(
"unable to find a NULL terminated string at 0x%" PRIx64
- ".Consider increasing the maximum read length.\n",
+ ". Consider increasing the maximum read length.\n",
data_addr);
--read;
break_on_no_NULL = true;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D114877.391013.patch
Type: text/x-patch
Size: 3825 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20211201/a85450ed/attachment.bin>
More information about the lldb-commits
mailing list