TestWatchpointConditionCmd.py revision 9351b4ff5bd824856dd9894d2005b29a020dfdd8
11e8a14af674e2761f257440c46c8aca34f53b951Johnny Chen"""
21e8a14af674e2761f257440c46c8aca34f53b951Johnny ChenTest watchpoint modify command to set condition on a watchpoint.
31e8a14af674e2761f257440c46c8aca34f53b951Johnny Chen"""
41e8a14af674e2761f257440c46c8aca34f53b951Johnny Chen
51e8a14af674e2761f257440c46c8aca34f53b951Johnny Chenimport os, time
61e8a14af674e2761f257440c46c8aca34f53b951Johnny Chenimport unittest2
71e8a14af674e2761f257440c46c8aca34f53b951Johnny Chenimport lldb
81e8a14af674e2761f257440c46c8aca34f53b951Johnny Chenfrom lldbtest import *
91e8a14af674e2761f257440c46c8aca34f53b951Johnny Chen
101e8a14af674e2761f257440c46c8aca34f53b951Johnny Chenclass WatchpointConditionCmdTestCase(TestBase):
111e8a14af674e2761f257440c46c8aca34f53b951Johnny Chen
121e8a14af674e2761f257440c46c8aca34f53b951Johnny Chen    mydir = os.path.join("functionalities", "watchpoint", "watchpoint_commands", "condition")
131e8a14af674e2761f257440c46c8aca34f53b951Johnny Chen
141e8a14af674e2761f257440c46c8aca34f53b951Johnny Chen    def setUp(self):
151e8a14af674e2761f257440c46c8aca34f53b951Johnny Chen        # Call super's setUp().
161e8a14af674e2761f257440c46c8aca34f53b951Johnny Chen        TestBase.setUp(self)
171e8a14af674e2761f257440c46c8aca34f53b951Johnny Chen        # Our simple source filename.
181e8a14af674e2761f257440c46c8aca34f53b951Johnny Chen        self.source = 'main.cpp'
191e8a14af674e2761f257440c46c8aca34f53b951Johnny Chen        # Find the line number to break inside main().
201e8a14af674e2761f257440c46c8aca34f53b951Johnny Chen        self.line = line_number(self.source, '// Set break point at this line.')
211e8a14af674e2761f257440c46c8aca34f53b951Johnny Chen        # And the watchpoint variable declaration line number.
221e8a14af674e2761f257440c46c8aca34f53b951Johnny Chen        self.decl = line_number(self.source, '// Watchpoint variable declaration.')
231e8a14af674e2761f257440c46c8aca34f53b951Johnny Chen        # Build dictionary to have unique executable names for each test method.
241e8a14af674e2761f257440c46c8aca34f53b951Johnny Chen        self.exe_name = self.testMethodName
251e8a14af674e2761f257440c46c8aca34f53b951Johnny Chen        self.d = {'CXX_SOURCES': self.source, 'EXE': self.exe_name}
261e8a14af674e2761f257440c46c8aca34f53b951Johnny Chen
271e8a14af674e2761f257440c46c8aca34f53b951Johnny Chen    @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
281e8a14af674e2761f257440c46c8aca34f53b951Johnny Chen    def test_watchpoint_cond_with_dsym(self):
291e8a14af674e2761f257440c46c8aca34f53b951Johnny Chen        """Test watchpoint condition."""
301e8a14af674e2761f257440c46c8aca34f53b951Johnny Chen        self.buildDsym(dictionary=self.d)
311e8a14af674e2761f257440c46c8aca34f53b951Johnny Chen        self.setTearDownCleanup(dictionary=self.d)
321e8a14af674e2761f257440c46c8aca34f53b951Johnny Chen        self.watchpoint_condition()
331e8a14af674e2761f257440c46c8aca34f53b951Johnny Chen
341e8a14af674e2761f257440c46c8aca34f53b951Johnny Chen    def test_watchpoint_cond_with_dwarf(self):
351e8a14af674e2761f257440c46c8aca34f53b951Johnny Chen        """Test watchpoint condition."""
361e8a14af674e2761f257440c46c8aca34f53b951Johnny Chen        self.buildDwarf(dictionary=self.d)
371e8a14af674e2761f257440c46c8aca34f53b951Johnny Chen        self.setTearDownCleanup(dictionary=self.d)
381e8a14af674e2761f257440c46c8aca34f53b951Johnny Chen        self.watchpoint_condition()
391e8a14af674e2761f257440c46c8aca34f53b951Johnny Chen
401e8a14af674e2761f257440c46c8aca34f53b951Johnny Chen    def watchpoint_condition(self):
411e8a14af674e2761f257440c46c8aca34f53b951Johnny Chen        """Do watchpoint condition 'global==5'."""
421e8a14af674e2761f257440c46c8aca34f53b951Johnny Chen        exe = os.path.join(os.getcwd(), self.exe_name)
431e8a14af674e2761f257440c46c8aca34f53b951Johnny Chen        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
441e8a14af674e2761f257440c46c8aca34f53b951Johnny Chen
451e8a14af674e2761f257440c46c8aca34f53b951Johnny Chen        # Add a breakpoint to set a watchpoint when stopped on the breakpoint.
461e8a14af674e2761f257440c46c8aca34f53b951Johnny Chen        self.expect("breakpoint set -l %d" % self.line, BREAKPOINT_CREATED,
471e8a14af674e2761f257440c46c8aca34f53b951Johnny Chen            startstr = "Breakpoint created: 1: file ='%s', line = %d, locations = 1" %
481e8a14af674e2761f257440c46c8aca34f53b951Johnny Chen                       (self.source, self.line))
491e8a14af674e2761f257440c46c8aca34f53b951Johnny Chen
501e8a14af674e2761f257440c46c8aca34f53b951Johnny Chen        # Run the program.
511e8a14af674e2761f257440c46c8aca34f53b951Johnny Chen        self.runCmd("run", RUN_SUCCEEDED)
521e8a14af674e2761f257440c46c8aca34f53b951Johnny Chen
531e8a14af674e2761f257440c46c8aca34f53b951Johnny Chen        # We should be stopped again due to the breakpoint.
541e8a14af674e2761f257440c46c8aca34f53b951Johnny Chen        # The stop reason of the thread should be breakpoint.
551e8a14af674e2761f257440c46c8aca34f53b951Johnny Chen        self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
561e8a14af674e2761f257440c46c8aca34f53b951Johnny Chen            substrs = ['stopped',
571e8a14af674e2761f257440c46c8aca34f53b951Johnny Chen                       'stop reason = breakpoint'])
581e8a14af674e2761f257440c46c8aca34f53b951Johnny Chen
591e8a14af674e2761f257440c46c8aca34f53b951Johnny Chen        # Now let's set a write-type watchpoint for 'global'.
601e8a14af674e2761f257440c46c8aca34f53b951Johnny Chen        # With a condition of 'global==5'.
611e8a14af674e2761f257440c46c8aca34f53b951Johnny Chen        self.expect("frame variable -w write -g -L global", WATCHPOINT_CREATED,
621e8a14af674e2761f257440c46c8aca34f53b951Johnny Chen            substrs = ['Watchpoint created', 'size = 4', 'type = w',
639351b4ff5bd824856dd9894d2005b29a020dfdd8Johnny Chen                       '%s:%d' % (self.source, self.decl)])
641e8a14af674e2761f257440c46c8aca34f53b951Johnny Chen
651e8a14af674e2761f257440c46c8aca34f53b951Johnny Chen        self.runCmd("watchpoint modify -c 'global==5'")
661e8a14af674e2761f257440c46c8aca34f53b951Johnny Chen
671e8a14af674e2761f257440c46c8aca34f53b951Johnny Chen        # Use the '-v' option to do verbose listing of the watchpoint.
681e8a14af674e2761f257440c46c8aca34f53b951Johnny Chen        # The hit count should be 0 initially.
691e8a14af674e2761f257440c46c8aca34f53b951Johnny Chen        self.expect("watchpoint list -v",
701e8a14af674e2761f257440c46c8aca34f53b951Johnny Chen            substrs = ['hit_count = 0', 'global==5'])
711e8a14af674e2761f257440c46c8aca34f53b951Johnny Chen
721e8a14af674e2761f257440c46c8aca34f53b951Johnny Chen        self.runCmd("process continue")
731e8a14af674e2761f257440c46c8aca34f53b951Johnny Chen
741e8a14af674e2761f257440c46c8aca34f53b951Johnny Chen        # We should be stopped again due to the watchpoint (write type).
751e8a14af674e2761f257440c46c8aca34f53b951Johnny Chen        # The stop reason of the thread should be watchpoint.
761e8a14af674e2761f257440c46c8aca34f53b951Johnny Chen        self.expect("thread backtrace", STOPPED_DUE_TO_WATCHPOINT,
771e8a14af674e2761f257440c46c8aca34f53b951Johnny Chen            substrs = ['stop reason = watchpoint'])
781e8a14af674e2761f257440c46c8aca34f53b951Johnny Chen        self.expect("frame variable -g global",
791e8a14af674e2761f257440c46c8aca34f53b951Johnny Chen            substrs = ['(int32_t)', 'global = 5'])
801e8a14af674e2761f257440c46c8aca34f53b951Johnny Chen
811e8a14af674e2761f257440c46c8aca34f53b951Johnny Chen        # Use the '-v' option to do verbose listing of the watchpoint.
821e8a14af674e2761f257440c46c8aca34f53b951Johnny Chen        # The hit count should now be 2.
831e8a14af674e2761f257440c46c8aca34f53b951Johnny Chen        self.expect("watchpoint list -v",
841e8a14af674e2761f257440c46c8aca34f53b951Johnny Chen            substrs = ['hit_count = 5'])
851e8a14af674e2761f257440c46c8aca34f53b951Johnny Chen
861e8a14af674e2761f257440c46c8aca34f53b951Johnny Chen
871e8a14af674e2761f257440c46c8aca34f53b951Johnny Chenif __name__ == '__main__':
881e8a14af674e2761f257440c46c8aca34f53b951Johnny Chen    import atexit
891e8a14af674e2761f257440c46c8aca34f53b951Johnny Chen    lldb.SBDebugger.Initialize()
901e8a14af674e2761f257440c46c8aca34f53b951Johnny Chen    atexit.register(lambda: lldb.SBDebugger.Terminate())
911e8a14af674e2761f257440c46c8aca34f53b951Johnny Chen    unittest2.main()
92