1"""
2Test watchpoint modify command to set condition on a watchpoint.
3"""
4
5
6
7import lldb
8from lldbsuite.test.decorators import *
9from lldbsuite.test.lldbtest import *
10from lldbsuite.test import lldbutil
11
12
13class WatchpointConditionCmdTestCase(TestBase):
14
15    mydir = TestBase.compute_mydir(__file__)
16    NO_DEBUG_INFO_TESTCASE = True
17
18    def setUp(self):
19        # Call super's setUp().
20        TestBase.setUp(self)
21        # Our simple source filename.
22        self.source = 'main.cpp'
23        # Find the line number to break inside main().
24        self.line = line_number(
25            self.source, '// Set break point at this line.')
26        # And the watchpoint variable declaration line number.
27        self.decl = line_number(self.source,
28                                '// Watchpoint variable declaration.')
29        # Build dictionary to have unique executable names for each test
30        # method.
31        self.exe_name = self.testMethodName
32        self.d = {'CXX_SOURCES': self.source, 'EXE': self.exe_name}
33
34    def test_watchpoint_cond(self):
35        """Test watchpoint condition."""
36        self.build(dictionary=self.d)
37        self.setTearDownCleanup(dictionary=self.d)
38
39        exe = self.getBuildArtifact(self.exe_name)
40        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
41
42        # Add a breakpoint to set a watchpoint when stopped on the breakpoint.
43        lldbutil.run_break_set_by_file_and_line(
44            self, None, self.line, num_expected_locations=1)
45
46        # Run the program.
47        self.runCmd("run", RUN_SUCCEEDED)
48
49        # We should be stopped again due to the breakpoint.
50        # The stop reason of the thread should be breakpoint.
51        self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
52                    substrs=['stopped',
53                             'stop reason = breakpoint'])
54
55        # Now let's set a write-type watchpoint for 'global'.
56        # With a condition of 'global==5'.
57        self.expect(
58            "watchpoint set variable -w write global",
59            WATCHPOINT_CREATED,
60            substrs=[
61                'Watchpoint created',
62                'size = 4',
63                'type = w',
64                '%s:%d' %
65                (self.source,
66                 self.decl)])
67
68        self.runCmd("watchpoint modify -c 'global==5'")
69
70        # Use the '-v' option to do verbose listing of the watchpoint.
71        # The hit count should be 0 initially.
72        self.expect("watchpoint list -v",
73                    substrs=['global==5', 'hit_count = 0'])
74
75        self.runCmd("process continue")
76
77        # We should be stopped again due to the watchpoint (write type).
78        # The stop reason of the thread should be watchpoint.
79        self.expect("thread backtrace", STOPPED_DUE_TO_WATCHPOINT,
80                    substrs=['stop reason = watchpoint'])
81        self.expect("frame variable --show-globals global",
82                    substrs=['(int32_t)', 'global = 5'])
83
84        # Use the '-v' option to do verbose listing of the watchpoint.
85        # The hit count should now be 2.
86        self.expect("watchpoint list -v",
87                    substrs=['hit_count = 5'])
88