]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - packages/Python/lldbsuite/test/functionalities/watchpoint/watchpoint_commands/condition/TestWatchpointConditionCmd.py
Vendor import of lldb trunk r256945:
[FreeBSD/FreeBSD.git] / packages / Python / lldbsuite / test / functionalities / watchpoint / watchpoint_commands / condition / TestWatchpointConditionCmd.py
1 """
2 Test watchpoint modify command to set condition on a watchpoint.
3 """
4
5 from __future__ import print_function
6
7
8
9 import os, time
10 import lldb
11 from lldbsuite.test.lldbtest import *
12 import lldbsuite.test.lldbutil as lldbutil
13
14 class WatchpointConditionCmdTestCase(TestBase):
15
16     mydir = TestBase.compute_mydir(__file__)
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(self.source, '// Set break point at this line.')
25         # And the watchpoint variable declaration line number.
26         self.decl = line_number(self.source, '// Watchpoint variable declaration.')
27         # Build dictionary to have unique executable names for each test method.
28         self.exe_name = self.testMethodName
29         self.d = {'CXX_SOURCES': self.source, 'EXE': self.exe_name}
30
31     @expectedFailureAndroid(archs=['arm', 'aarch64']) # Watchpoints not supported
32     @expectedFailureWindows("llvm.org/pr24446") # WINDOWS XFAIL TRIAGE - Watchpoints not supported on Windows
33     def test_watchpoint_cond(self):
34         """Test watchpoint condition."""
35         self.build(dictionary=self.d)
36         self.setTearDownCleanup(dictionary=self.d)
37
38         exe = os.path.join(os.getcwd(), self.exe_name)
39         self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
40
41         # Add a breakpoint to set a watchpoint when stopped on the breakpoint.
42         lldbutil.run_break_set_by_file_and_line (self, None, self.line, num_expected_locations=1)
43
44         # Run the program.
45         self.runCmd("run", RUN_SUCCEEDED)
46
47         # We should be stopped again due to the breakpoint.
48         # The stop reason of the thread should be breakpoint.
49         self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
50             substrs = ['stopped',
51                        'stop reason = breakpoint'])
52
53         # Now let's set a write-type watchpoint for 'global'.
54         # With a condition of 'global==5'.
55         self.expect("watchpoint set variable -w write global", WATCHPOINT_CREATED,
56             substrs = ['Watchpoint created', 'size = 4', 'type = w',
57                        '%s:%d' % (self.source, self.decl)])
58
59         self.runCmd("watchpoint modify -c 'global==5'")
60
61         # Use the '-v' option to do verbose listing of the watchpoint.
62         # The hit count should be 0 initially.
63         self.expect("watchpoint list -v",
64             substrs = ['hit_count = 0', 'global==5'])
65
66         self.runCmd("process continue")
67
68         # We should be stopped again due to the watchpoint (write type).
69         # The stop reason of the thread should be watchpoint.
70         self.expect("thread backtrace", STOPPED_DUE_TO_WATCHPOINT,
71             substrs = ['stop reason = watchpoint'])
72         self.expect("frame variable --show-globals global",
73             substrs = ['(int32_t)', 'global = 5'])
74
75         # Use the '-v' option to do verbose listing of the watchpoint.
76         # The hit count should now be 2.
77         self.expect("watchpoint list -v",
78             substrs = ['hit_count = 5'])