[Lldb-commits] [lldb] 4a43ee0 - Re-enable StepOverWatchpoint test, make it more focused

Jason Molenda via lldb-commits lldb-commits at lists.llvm.org
Fri Sep 22 18:11:44 PDT 2023


Author: Jason Molenda
Date: 2023-09-22T18:11:33-07:00
New Revision: 4a43ee08e73287c006a317b94a94e3f19dbcf957

URL: https://github.com/llvm/llvm-project/commit/4a43ee08e73287c006a317b94a94e3f19dbcf957
DIFF: https://github.com/llvm/llvm-project/commit/4a43ee08e73287c006a317b94a94e3f19dbcf957.diff

LOG: Re-enable StepOverWatchpoint test, make it more focused

This is my second recent change to TestStepOverWatchpoint.py,
the first was to change the two global variables it is watching
from 'char' to 'long' so they're more likely to be on separate
words/doublewords of memory that can be watched indepdently.

I believe this removes the need for the MIPS and S390X skips.

The test was testing a combination of read and write watchpoints,
stepping over a function that hits them, and then instruction stepping
over a source line which hits them.  But previously it was
always starting with the read watchpoint in both of them, it
didn't test the instruction-stepping for the read watchpoint.

I now have to tests in TestStepOverWatchpoint.py, one which
runs to the read-watchpoint function, sets that watchpoint,
steps over another function which reads from that global, then
instruction steps over a source line that reads from that global.

The second test runs to the write-watchpoint function, sets that
watchpoint.  Steps over another function which writes to that
global, then instruction steps over a source line that writes to
that global.

These are both xfailed on Darwin systems because watchpoints and
hardware breakpoints are currently disabled by the kernel when
instruction stepping.

Added: 
    

Modified: 
    lldb/test/API/commands/watchpoints/step_over_watchpoint/TestStepOverWatchpoint.py
    lldb/test/API/commands/watchpoints/step_over_watchpoint/main.c

Removed: 
    


################################################################################
diff  --git a/lldb/test/API/commands/watchpoints/step_over_watchpoint/TestStepOverWatchpoint.py b/lldb/test/API/commands/watchpoints/step_over_watchpoint/TestStepOverWatchpoint.py
index 7d4be91bb4fbdb1..17f753d6c890796 100644
--- a/lldb/test/API/commands/watchpoints/step_over_watchpoint/TestStepOverWatchpoint.py
+++ b/lldb/test/API/commands/watchpoints/step_over_watchpoint/TestStepOverWatchpoint.py
@@ -1,4 +1,4 @@
-"""Test stepping over watchpoints."""
+"""Test stepping over watchpoints and instruction stepping past watchpoints."""
 
 
 import lldb
@@ -11,11 +11,25 @@ class TestStepOverWatchpoint(TestBase):
     NO_DEBUG_INFO_TESTCASE = True
 
     def get_to_start(self, bkpt_text):
-        """Test stepping over watchpoints."""
+        """Test stepping over watchpoints and instruction stepping past watchpoints.."""
         self.build()
         target, process, thread, bkpt = lldbutil.run_to_source_breakpoint(
             self, bkpt_text, lldb.SBFileSpec("main.c")
         )
+        return (target, process, thread, frame, read_watchpoint)
+
+    @add_test_categories(["basic_process"])
+    @expectedFailureAll(
+        oslist=["ios", "watchos", "tvos", "bridgeos", "macosx"],
+        archs=["aarch64", "arm"],
+        bugnumber="<rdar://problem/106868647>",
+    )
+    def test_step_over_read_watchpoint(self):
+        self.build()
+        target, process, thread, bkpt = lldbutil.run_to_source_breakpoint(
+            self, "break here for read watchpoints", lldb.SBFileSpec("main.c")
+        )
+
         frame = thread.GetFrameAtIndex(0)
         self.assertTrue(frame.IsValid(), "Failed to get frame.")
 
@@ -33,14 +47,6 @@ def get_to_start(self, bkpt_text):
         # stepping off from the breakpoint:
         bkpt.SetEnabled(False)
 
-        return (target, process, thread, frame, read_watchpoint)
-
-    # Read-write watchpoints not supported on SystemZ
-    @expectedFailureAll(archs=["s390x"])
-    @add_test_categories(["basic_process"])
-    def test_step_over(self):
-        target, process, thread, frame, wp = self.get_to_start("Set a breakpoint here")
-
         thread.StepOver()
         self.assertStopReason(
             thread.GetStopReason(),
@@ -49,39 +55,42 @@ def test_step_over(self):
         )
         self.assertEquals(thread.GetStopDescription(20), "watchpoint 1")
 
+        process.Continue()
+        self.assertState(process.GetState(), lldb.eStateStopped, PROCESS_STOPPED)
+        self.assertEquals(thread.GetStopDescription(20), "step over")
+
+        self.step_inst_for_watchpoint(1)
+
     # Skip everywhere while modify watchpoints are sorted out.
-    @skipTestIfFn(lambda : True)
     @expectedFailureAll(
         oslist=["freebsd", "linux"],
         archs=["aarch64", "arm"],
         bugnumber="llvm.org/pr26031",
     )
-    # Read-write watchpoints not supported on SystemZ
-    @expectedFailureAll(archs=["s390x"])
+    @add_test_categories(["basic_process"])
     @expectedFailureAll(
         oslist=["ios", "watchos", "tvos", "bridgeos", "macosx"],
         archs=["aarch64", "arm"],
-        bugnumber="<rdar://problem/34027183>",
+        bugnumber="<rdar://problem/106868647>",
     )
-    @add_test_categories(["basic_process"])
-    def test_step_instruction(self):
-        target, process, thread, frame, wp = self.get_to_start(
-            "Set breakpoint after call"
+    def test_step_over_write_watchpoint(self):
+        self.build()
+        target, process, thread, bkpt = lldbutil.run_to_source_breakpoint(
+            self, "break here for modify watchpoints", lldb.SBFileSpec("main.c")
         )
 
-        self.step_inst_for_watchpoint(1)
+        # Disable the breakpoint we hit so we don't muddy the waters with
+        # stepping off from the breakpoint:
+        bkpt.SetEnabled(False)
+
+        frame = thread.GetFrameAtIndex(0)
+        self.assertTrue(frame.IsValid(), "Failed to get frame.")
 
         write_value = frame.FindValue("g_watch_me_write", lldb.eValueTypeVariableGlobal)
         self.assertTrue(write_value, "Failed to find write value.")
 
-        # Most of the MIPS boards provide only one H/W watchpoints, and S/W
-        # watchpoints are not supported yet
-        arch = self.getArchitecture()
-        if re.match("^mips", arch) or re.match("powerpc64le", arch):
-            self.runCmd("watchpoint delete 1")
-
         error = lldb.SBError()
-        # resolve_location=True, read=False, write=True
+        # resolve_location=True, read=False, modify=True
         write_watchpoint = write_value.Watch(True, False, True, error)
         self.assertTrue(write_watchpoint, "Failed to set write watchpoint.")
         self.assertSuccess(error, "Error while setting watchpoint")
@@ -92,13 +101,13 @@ def test_step_instruction(self):
             lldb.eStopReasonWatchpoint,
             STOPPED_DUE_TO_WATCHPOINT,
         )
-        self.assertEquals(thread.GetStopDescription(20), "watchpoint 2")
+        self.assertEquals(thread.GetStopDescription(20), "watchpoint 1")
 
         process.Continue()
         self.assertState(process.GetState(), lldb.eStateStopped, PROCESS_STOPPED)
         self.assertEquals(thread.GetStopDescription(20), "step over")
 
-        self.step_inst_for_watchpoint(2)
+        self.step_inst_for_watchpoint(1)
 
     def step_inst_for_watchpoint(self, wp_id):
         watchpoint_hit = False

diff  --git a/lldb/test/API/commands/watchpoints/step_over_watchpoint/main.c b/lldb/test/API/commands/watchpoints/step_over_watchpoint/main.c
index f1831c5c5a18b66..09dd1f7a42509fe 100644
--- a/lldb/test/API/commands/watchpoints/step_over_watchpoint/main.c
+++ b/lldb/test/API/commands/watchpoints/step_over_watchpoint/main.c
@@ -6,14 +6,20 @@ void watch_read() {
     g_temp = g_watch_me_read;
 }
 
-void watch_write() {
-    g_watch_me_write = g_temp;
+void watch_write() { g_watch_me_write = g_temp++; }
+
+void read_watchpoint_testing() {
+  watch_read(); // break here for read watchpoints
+  g_temp = g_watch_me_read;
+}
+
+void watch_breakpoint_testing() {
+  watch_write(); // break here for modify watchpoints
+  g_watch_me_write = g_temp;
 }
 
 int main() {
-    watch_read(); // Set a breakpoint here
-    g_temp = g_watch_me_read; // Set breakpoint after call
-    watch_write();
-    g_watch_me_write = g_temp + 1;
-    return 0;
+  read_watchpoint_testing();
+  watch_breakpoint_testing();
+  return 0;
 }


        


More information about the lldb-commits mailing list