[Lldb-commits] [lldb] r140398 - in /lldb/trunk/test/functionalities/watchpoint/watchpoint_commands: ./ Makefile TestWatchpointCommands.py main.c

Johnny Chen johnny.chen at apple.com
Fri Sep 23 11:42:28 PDT 2011


Author: johnny
Date: Fri Sep 23 13:42:28 2011
New Revision: 140398

URL: http://llvm.org/viewvc/llvm-project?rev=140398&view=rev
Log:
Add test cases for watchpoint list, enable, disable, and delete commands.

Added:
    lldb/trunk/test/functionalities/watchpoint/watchpoint_commands/
    lldb/trunk/test/functionalities/watchpoint/watchpoint_commands/Makefile
    lldb/trunk/test/functionalities/watchpoint/watchpoint_commands/TestWatchpointCommands.py
    lldb/trunk/test/functionalities/watchpoint/watchpoint_commands/main.c

Added: lldb/trunk/test/functionalities/watchpoint/watchpoint_commands/Makefile
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/watchpoint/watchpoint_commands/Makefile?rev=140398&view=auto
==============================================================================
--- lldb/trunk/test/functionalities/watchpoint/watchpoint_commands/Makefile (added)
+++ lldb/trunk/test/functionalities/watchpoint/watchpoint_commands/Makefile Fri Sep 23 13:42:28 2011
@@ -0,0 +1,5 @@
+LEVEL = ../../../make
+
+C_SOURCES := main.c
+
+include $(LEVEL)/Makefile.rules

Added: lldb/trunk/test/functionalities/watchpoint/watchpoint_commands/TestWatchpointCommands.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/watchpoint/watchpoint_commands/TestWatchpointCommands.py?rev=140398&view=auto
==============================================================================
--- lldb/trunk/test/functionalities/watchpoint/watchpoint_commands/TestWatchpointCommands.py (added)
+++ lldb/trunk/test/functionalities/watchpoint/watchpoint_commands/TestWatchpointCommands.py Fri Sep 23 13:42:28 2011
@@ -0,0 +1,308 @@
+"""
+Test watchpoint list, enable, disable, and delete commands.
+"""
+
+import os, time
+import unittest2
+import lldb
+from lldbtest import *
+
+class WatchpointCommandsTestCase(TestBase):
+
+    mydir = os.path.join("functionalities", "watchpoint", "watchpoint_commands")
+
+    def setUp(self):
+        # Call super's setUp().
+        TestBase.setUp(self)
+        # Our simple source filename.
+        self.source = 'main.c'
+        # Find the line number to break inside main().
+        self.line = line_number(self.source, '// Set break point at this line.')
+        self.line2 = line_number(self.source, '// Set 2nd break point for disable_then_enable test case.')
+        # And the watchpoint variable declaration line number.
+        self.decl = line_number(self.source, '// Watchpoint variable declaration.')
+        # Build dictionary to have unique executable names for each test method.
+        self.exe_name = self.testMethodName
+        self.d = {'C_SOURCES': self.source, 'EXE': self.exe_name}
+
+    @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
+    def test_rw_watchpoint_with_dsym(self):
+        """Test read_write watchpoint and expect to stop two times."""
+        self.buildDsym(dictionary=self.d)
+        self.setTearDownCleanup(dictionary=self.d)
+        self.normal_read_write_watchpoint()
+
+    def test_rw_watchpoint_with_dwarf(self):
+        """Test read_write watchpoint and expect to stop two times."""
+        self.buildDwarf(dictionary=self.d)
+        self.setTearDownCleanup(dictionary=self.d)
+        self.normal_read_write_watchpoint()
+
+    @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
+    def test_rw_watchpoint_delete_with_dsym(self):
+        """Test delete watchpoint and expect not to stop for watchpoint."""
+        self.buildDsym(dictionary=self.d)
+        self.setTearDownCleanup(dictionary=self.d)
+        self.delete_read_write_watchpoint()
+
+    def test_rw_watchpoint_delete_with_dwarf(self):
+        """Test delete watchpoint and expect not to stop for watchpoint."""
+        self.buildDwarf(dictionary=self.d)
+        self.setTearDownCleanup(dictionary=self.d)
+        self.delete_read_write_watchpoint()
+
+    @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
+    def test_rw_disable_after_first_stop_with_dsym(self):
+        """Test read_write watchpoint but disable it after the first stop."""
+        self.buildDsym(dictionary=self.d)
+        self.setTearDownCleanup(dictionary=self.d)
+        self.read_write_watchpoint_disable_after_first_stop()
+
+    def test_rw_disable_after_first_stop__with_dwarf(self):
+        """Test read_write watchpoint but disable it after the first stop."""
+        self.buildDwarf(dictionary=self.d)
+        self.setTearDownCleanup(dictionary=self.d)
+        self.read_write_watchpoint_disable_after_first_stop()
+
+    @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
+    def test_rw_disable_then_enable_with_dsym(self):
+        """Test read_write watchpoint, disable initially, then enable it."""
+        self.buildDsym(dictionary=self.d)
+        self.setTearDownCleanup(dictionary=self.d)
+        self.read_write_watchpoint_disable_then_enable()
+
+    def test_rw_disable_then_enable_with_dwarf(self):
+        """Test read_write watchpoint, disable initially, then enable it."""
+        self.buildDwarf(dictionary=self.d)
+        self.setTearDownCleanup(dictionary=self.d)
+        self.read_write_watchpoint_disable_then_enable()
+
+    def normal_read_write_watchpoint(self):
+        """Do read_write watchpoint and expect to stop two times."""
+        exe = os.path.join(os.getcwd(), self.exe_name)
+        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
+
+        # Add a breakpoint to set a watchpoint when stopped on the breakpoint.
+        self.expect("breakpoint set -l %d" % self.line, BREAKPOINT_CREATED,
+            startstr = "Breakpoint created: 1: file ='%s', line = %d, locations = 1" %
+                       (self.source, self.line))
+
+        # Run the program.
+        self.runCmd("run", RUN_SUCCEEDED)
+
+        # We should be stopped again due to the breakpoint.
+        # The stop reason of the thread should be breakpoint.
+        self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
+            substrs = ['stopped',
+                       'stop reason = breakpoint'])
+
+        # Now let's set a read_write-type watchpoint for 'global'.
+        # There should be two watchpoint hits (see main.c).
+        self.expect("frame variable -w read_write -g -L global", WATCHPOINT_CREATED,
+            substrs = ['Watchpoint created', 'size = 4', 'type = rw',
+                       '%s:%d' % (self.source, self.decl)])
+
+        # Use the '-v' option to do verbose listing of the watchpoint.
+        # The hit count should be 0 initially.
+        self.expect("watchpoint list -v",
+            substrs = ['hit_count = 0'])
+
+        self.runCmd("process continue")
+
+        # We should be stopped again due to the watchpoint (read_write type).
+        # The stop reason of the thread should be watchpoint.
+        self.expect("thread backtrace", STOPPED_DUE_TO_WATCHPOINT,
+            substrs = ['stop reason = watchpoint'])
+
+        self.runCmd("process continue")
+
+        # We should be stopped again due to the watchpoint (read_write type).
+        # The stop reason of the thread should be watchpoint.
+        self.expect("thread backtrace", STOPPED_DUE_TO_WATCHPOINT,
+            substrs = ['stop reason = watchpoint'])
+
+        self.runCmd("process continue")
+
+        # There should be no more watchpoint hit and the process status should
+        # be 'exited'.
+        self.expect("process status",
+            substrs = ['exited'])
+
+        # Use the '-v' option to do verbose listing of the watchpoint.
+        # The hit count should now be 2.
+        self.expect("watchpoint list -v",
+            substrs = ['hit_count = 2'])
+
+    def delete_read_write_watchpoint(self):
+        """Do delete watchpoint immediately and expect not to stop for watchpoint."""
+        exe = os.path.join(os.getcwd(), self.exe_name)
+        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
+
+        # Add a breakpoint to set a watchpoint when stopped on the breakpoint.
+        self.expect("breakpoint set -l %d" % self.line, BREAKPOINT_CREATED,
+            startstr = "Breakpoint created: 1: file ='%s', line = %d, locations = 1" %
+                       (self.source, self.line))
+
+        # Run the program.
+        self.runCmd("run", RUN_SUCCEEDED)
+
+        # We should be stopped again due to the breakpoint.
+        # The stop reason of the thread should be breakpoint.
+        self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
+            substrs = ['stopped',
+                       'stop reason = breakpoint'])
+
+        # Now let's set a read_write-type watchpoint for 'global'.
+        # There should be two watchpoint hits (see main.c).
+        self.expect("frame variable -w read_write -g -L global", WATCHPOINT_CREATED,
+            substrs = ['Watchpoint created', 'size = 4', 'type = rw',
+                       '%s:%d' % (self.source, self.decl)])
+
+        # Delete the watchpoint immediately, but set auto-confirm to true first.
+        self.runCmd("settings set auto-confirm true")
+        self.expect("watchpoint delete",
+            substrs = ['All watchpoints removed.'])
+        # Restore the original setting of auto-confirm.
+        self.runCmd("settings set -r auto-confirm")
+
+        # Use the '-v' option to do verbose listing of the watchpoint.
+        self.runCmd("watchpoint list -v")
+
+        self.runCmd("process continue")
+
+        # There should be no more watchpoint hit and the process status should
+        # be 'exited'.
+        self.expect("process status",
+            substrs = ['exited'])
+
+    def read_write_watchpoint_disable_after_first_stop(self):
+        """Do read_write watchpoint but disable it after the first stop."""
+        exe = os.path.join(os.getcwd(), self.exe_name)
+        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
+
+        # Add a breakpoint to set a watchpoint when stopped on the breakpoint.
+        self.expect("breakpoint set -l %d" % self.line, BREAKPOINT_CREATED,
+            startstr = "Breakpoint created: 1: file ='%s', line = %d, locations = 1" %
+                       (self.source, self.line))
+
+        # Run the program.
+        self.runCmd("run", RUN_SUCCEEDED)
+
+        # We should be stopped again due to the breakpoint.
+        # The stop reason of the thread should be breakpoint.
+        self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
+            substrs = ['stopped',
+                       'stop reason = breakpoint'])
+
+        # Now let's set a read_write-type watchpoint for 'global'.
+        # There should be two watchpoint hits (see main.c).
+        self.expect("frame variable -w read_write -g -L global", WATCHPOINT_CREATED,
+            substrs = ['Watchpoint created', 'size = 4', 'type = rw',
+                       '%s:%d' % (self.source, self.decl)])
+
+        # Use the '-v' option to do verbose listing of the watchpoint.
+        # The hit count should be 0 initially.
+        self.expect("watchpoint list -v",
+            substrs = ['state = enabled', 'hit_count = 0'])
+
+        self.runCmd("process continue")
+
+        # We should be stopped again due to the watchpoint (read_write type).
+        # The stop reason of the thread should be watchpoint.
+        self.expect("thread backtrace", STOPPED_DUE_TO_WATCHPOINT,
+            substrs = ['stop reason = watchpoint'])
+
+        # Before continuing, we'll disable the watchpoint, which means we won't
+        # stop agian after this.
+        self.runCmd("watchpoint disable")
+
+        self.expect("watchpoint list -v",
+            substrs = ['state = disabled', 'hit_count = 1'])
+
+        self.runCmd("process continue")
+
+        # There should be no more watchpoint hit and the process status should
+        # be 'exited'.
+        self.expect("process status",
+            substrs = ['exited'])
+
+        # Use the '-v' option to do verbose listing of the watchpoint.
+        # The hit count should be 1.
+        self.expect("watchpoint list -v",
+            substrs = ['hit_count = 1'])
+
+    def read_write_watchpoint_disable_then_enable(self):
+        """Do read_write watchpoint, disable initially, then enable it."""
+        exe = os.path.join(os.getcwd(), self.exe_name)
+        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
+
+        # Add a breakpoint to set a watchpoint when stopped on the breakpoint.
+        self.expect("breakpoint set -l %d" % self.line, BREAKPOINT_CREATED,
+            startstr = "Breakpoint created: 1: file ='%s', line = %d, locations = 1" %
+                       (self.source, self.line))
+        self.expect("breakpoint set -l %d" % self.line2, BREAKPOINT_CREATED,
+            startstr = "Breakpoint created: 2: file ='%s', line = %d, locations = 1" %
+                       (self.source, self.line2))
+
+        # Run the program.
+        self.runCmd("run", RUN_SUCCEEDED)
+
+        # We should be stopped again due to the breakpoint.
+        # The stop reason of the thread should be breakpoint.
+        self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
+            substrs = ['stopped',
+                       'stop reason = breakpoint'])
+
+        # Now let's set a read_write-type watchpoint for 'global'.
+        # There should be two watchpoint hits (see main.c).
+        self.expect("frame variable -w read_write -g -L global", WATCHPOINT_CREATED,
+            substrs = ['Watchpoint created', 'size = 4', 'type = rw',
+                       '%s:%d' % (self.source, self.decl)])
+
+        # Immediately, we disable the watchpoint.  We won't be stopping due to a
+        # watchpoint after this.
+        self.runCmd("watchpoint disable")
+
+        # Use the '-v' option to do verbose listing of the watchpoint.
+        # The hit count should be 0 initially.
+        self.expect("watchpoint list -v",
+            substrs = ['state = disabled', 'hit_count = 0'])
+
+        self.runCmd("process continue")
+
+        # We should be stopped again due to the breakpoint.
+        self.expect("thread backtrace", STOPPED_DUE_TO_BREAKPOINT,
+            substrs = ['stop reason = breakpoint'])
+
+        # Before continuing, we'll enable the watchpoint, which means we will
+        # stop agian after this.
+        self.runCmd("watchpoint enable")
+
+        self.expect("watchpoint list -v",
+            substrs = ['state = enabled', 'hit_count = 0'])
+
+        self.runCmd("process continue")
+
+        # We should be stopped again due to the watchpoint (read_write type).
+        # The stop reason of the thread should be watchpoint.
+        self.expect("thread backtrace", STOPPED_DUE_TO_WATCHPOINT,
+            substrs = ['stop reason = watchpoint'])
+
+        self.runCmd("process continue")
+
+        # There should be no more watchpoint hit and the process status should
+        # be 'exited'.
+        self.expect("process status",
+            substrs = ['exited'])
+
+        # Use the '-v' option to do verbose listing of the watchpoint.
+        # The hit count should be 1.
+        self.expect("watchpoint list -v",
+            substrs = ['hit_count = 1'])
+
+
+if __name__ == '__main__':
+    import atexit
+    lldb.SBDebugger.Initialize()
+    atexit.register(lambda: lldb.SBDebugger.Terminate())
+    unittest2.main()

Added: lldb/trunk/test/functionalities/watchpoint/watchpoint_commands/main.c
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/watchpoint/watchpoint_commands/main.c?rev=140398&view=auto
==============================================================================
--- lldb/trunk/test/functionalities/watchpoint/watchpoint_commands/main.c (added)
+++ lldb/trunk/test/functionalities/watchpoint/watchpoint_commands/main.c Fri Sep 23 13:42:28 2011
@@ -0,0 +1,24 @@
+//===-- main.c --------------------------------------------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+#include <stdio.h>
+#include <stdint.h>
+
+int32_t global = 10; // Watchpoint variable declaration.
+
+int main(int argc, char** argv) {
+    int local = 0;
+    printf("&global=%p\n", &global);
+    printf("about to write to 'global'...\n"); // Set break point at this line.
+                                               // When stopped, watch 'global' for write.
+    global = 20;
+    local += argc;
+    ++local; // Set 2nd break point for disable_then_enable test case.
+    printf("local: %d\n", local);
+    printf("global=%d\n", global);
+}





More information about the lldb-commits mailing list