]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - packages/Python/lldbsuite/test/functionalities/watchpoint/watchpoint_commands/command/TestWatchpointCommandLLDB.py
Vendor import of lldb trunk r290819:
[FreeBSD/FreeBSD.git] / packages / Python / lldbsuite / test / functionalities / watchpoint / watchpoint_commands / command / TestWatchpointCommandLLDB.py
1 """
2 Test 'watchpoint command'.
3 """
4
5 from __future__ import print_function
6
7
8 import os
9 import time
10 import lldb
11 from lldbsuite.test.decorators import *
12 from lldbsuite.test.lldbtest import *
13 from lldbsuite.test import lldbutil
14
15
16 class WatchpointLLDBCommandTestCase(TestBase):
17
18     mydir = TestBase.compute_mydir(__file__)
19
20     def setUp(self):
21         # Call super's setUp().
22         TestBase.setUp(self)
23         # Our simple source filename.
24         self.source = 'main.cpp'
25         # Find the line number to break inside main().
26         self.line = line_number(
27             self.source, '// Set break point at this line.')
28         # And the watchpoint variable declaration line number.
29         self.decl = line_number(self.source,
30                                 '// Watchpoint variable declaration.')
31         # Build dictionary to have unique executable names for each test
32         # method.
33         self.exe_name = 'a%d.out' % self.test_number
34         self.d = {'CXX_SOURCES': self.source, 'EXE': self.exe_name}
35
36     # Watchpoints not supported
37     @expectedFailureAndroid(archs=['arm', 'aarch64'])
38     @expectedFailureAll(
39         oslist=["linux"],
40         archs=["aarch64"],
41         bugnumber="llvm.org/pr27710")
42     @expectedFailureAll(
43         oslist=["windows"],
44         bugnumber="llvm.org/pr24446: WINDOWS XFAIL TRIAGE - Watchpoints not supported on Windows")
45     def test_watchpoint_command(self):
46         """Test 'watchpoint command'."""
47         self.build(dictionary=self.d)
48         self.setTearDownCleanup(dictionary=self.d)
49
50         exe = os.path.join(os.getcwd(), self.exe_name)
51         self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
52
53         # Add a breakpoint to set a watchpoint when stopped on the breakpoint.
54         lldbutil.run_break_set_by_file_and_line(
55             self, None, self.line, num_expected_locations=1)
56
57         # Run the program.
58         self.runCmd("run", RUN_SUCCEEDED)
59
60         # We should be stopped again due to the breakpoint.
61         # The stop reason of the thread should be breakpoint.
62         self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
63                     substrs=['stopped',
64                              'stop reason = breakpoint'])
65
66         # Now let's set a write-type watchpoint for 'global'.
67         self.expect(
68             "watchpoint set variable -w write global",
69             WATCHPOINT_CREATED,
70             substrs=[
71                 'Watchpoint created',
72                 'size = 4',
73                 'type = w',
74                 '%s:%d' %
75                 (self.source,
76                  self.decl)])
77
78         self.runCmd('watchpoint command add 1 -o "expr -- cookie = 777"')
79
80         # List the watchpoint command we just added.
81         self.expect("watchpoint command list 1",
82                     substrs=['expr -- cookie = 777'])
83
84         # Use the '-v' option to do verbose listing of the watchpoint.
85         # The hit count should be 0 initially.
86         self.expect("watchpoint list -v",
87                     substrs=['hit_count = 0'])
88
89         self.runCmd("process continue")
90
91         # We should be stopped again due to the watchpoint (write type).
92         # The stop reason of the thread should be watchpoint.
93         self.expect("thread backtrace", STOPPED_DUE_TO_WATCHPOINT,
94                     substrs=['stop reason = watchpoint'])
95
96         # Check that the watchpoint snapshoting mechanism is working.
97         self.expect("watchpoint list -v",
98                     substrs=['old value:', ' = 0',
99                              'new value:', ' = 1'])
100
101         # The watchpoint command "forced" our global variable 'cookie' to
102         # become 777.
103         self.expect("frame variable --show-globals cookie",
104                     substrs=['(int32_t)', 'cookie = 777'])
105
106     # Watchpoints not supported
107     @expectedFailureAndroid(archs=['arm', 'aarch64'])
108     @expectedFailureAll(
109         oslist=["linux"],
110         archs=["aarch64"],
111         bugnumber="llvm.org/pr27710")
112     @expectedFailureAll(
113         oslist=["windows"],
114         bugnumber="llvm.org/pr24446: WINDOWS XFAIL TRIAGE - Watchpoints not supported on Windows")
115     def test_watchpoint_command_can_disable_a_watchpoint(self):
116         """Test that 'watchpoint command' action can disable a watchpoint after it is triggered."""
117         self.build(dictionary=self.d)
118         self.setTearDownCleanup(dictionary=self.d)
119
120         exe = os.path.join(os.getcwd(), self.exe_name)
121         self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
122
123         # Add a breakpoint to set a watchpoint when stopped on the breakpoint.
124         lldbutil.run_break_set_by_file_and_line(
125             self, None, self.line, num_expected_locations=1)
126
127         # Run the program.
128         self.runCmd("run", RUN_SUCCEEDED)
129
130         # We should be stopped again due to the breakpoint.
131         # The stop reason of the thread should be breakpoint.
132         self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
133                     substrs=['stopped',
134                              'stop reason = breakpoint'])
135
136         # Now let's set a write-type watchpoint for 'global'.
137         self.expect(
138             "watchpoint set variable -w write global",
139             WATCHPOINT_CREATED,
140             substrs=[
141                 'Watchpoint created',
142                 'size = 4',
143                 'type = w',
144                 '%s:%d' %
145                 (self.source,
146                  self.decl)])
147
148         self.runCmd('watchpoint command add 1 -o "watchpoint disable 1"')
149
150         # List the watchpoint command we just added.
151         self.expect("watchpoint command list 1",
152                     substrs=['watchpoint disable 1'])
153
154         # Use the '-v' option to do verbose listing of the watchpoint.
155         # The hit count should be 0 initially.
156         self.expect("watchpoint list -v",
157                     substrs=['hit_count = 0'])
158
159         self.runCmd("process continue")
160
161         # We should be stopped again due to the watchpoint (write type).
162         # The stop reason of the thread should be watchpoint.
163         self.expect("thread backtrace", STOPPED_DUE_TO_WATCHPOINT,
164                     substrs=['stop reason = watchpoint'])
165
166         # Check that the watchpoint has been disabled.
167         self.expect("watchpoint list -v",
168                     substrs=['disabled'])
169
170         self.runCmd("process continue")
171
172         # There should be no more watchpoint hit and the process status should
173         # be 'exited'.
174         self.expect("process status",
175                     substrs=['exited'])