[Lldb-commits] [lldb] 3a870bf - [lldb] Add missing space in C string format memory read warning
David Spickett via lldb-commits
lldb-commits at lists.llvm.org
Wed Dec 8 03:20:31 PST 2021
Author: David Spickett
Date: 2021-12-08T11:20:25Z
New Revision: 3a870bffb108516bc1c09818538466db4f1a505d
URL: https://github.com/llvm/llvm-project/commit/3a870bffb108516bc1c09818538466db4f1a505d
DIFF: https://github.com/llvm/llvm-project/commit/3a870bffb108516bc1c09818538466db4f1a505d.diff
LOG: [lldb] Add missing space in C string format memory read warning
Also add tests to check that we print the warning in the right
circumstances.
Reviewed By: labath
Differential Revision: https://reviews.llvm.org/D114877
Added:
lldb/test/API/commands/memory/read/Makefile
lldb/test/API/commands/memory/read/TestMemoryRead.py
lldb/test/API/commands/memory/read/main.c
Modified:
lldb/source/Commands/CommandObjectMemory.cpp
Removed:
################################################################################
diff --git a/lldb/source/Commands/CommandObjectMemory.cpp b/lldb/source/Commands/CommandObjectMemory.cpp
index 094ce6f8558f..9df42f36fafd 100644
--- a/lldb/source/Commands/CommandObjectMemory.cpp
+++ b/lldb/source/Commands/CommandObjectMemory.cpp
@@ -716,7 +716,7 @@ class CommandObjectMemoryRead : public CommandObjectParsed {
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;
diff --git a/lldb/test/API/commands/memory/read/Makefile b/lldb/test/API/commands/memory/read/Makefile
new file mode 100644
index 000000000000..10495940055b
--- /dev/null
+++ b/lldb/test/API/commands/memory/read/Makefile
@@ -0,0 +1,3 @@
+C_SOURCES := main.c
+
+include Makefile.rules
diff --git a/lldb/test/API/commands/memory/read/TestMemoryRead.py b/lldb/test/API/commands/memory/read/TestMemoryRead.py
new file mode 100644
index 000000000000..fe735ec61c89
--- /dev/null
+++ b/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.")
diff --git a/lldb/test/API/commands/memory/read/main.c b/lldb/test/API/commands/memory/read/main.c
new file mode 100644
index 000000000000..9dcf34ee3ed4
--- /dev/null
+++ b/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.
+}
More information about the lldb-commits
mailing list