]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - packages/Python/lldbsuite/test/functionalities/watchpoint/hello_watchpoint/TestMyFirstWatchpoint.py
Vendor import of lldb trunk r290819:
[FreeBSD/FreeBSD.git] / packages / Python / lldbsuite / test / functionalities / watchpoint / hello_watchpoint / TestMyFirstWatchpoint.py
1 """
2 Test my first lldb watchpoint.
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 HelloWatchpointTestCase(TestBase):
17
18     def getCategories(self):
19         return ['basic_process']
20
21     mydir = TestBase.compute_mydir(__file__)
22
23     def setUp(self):
24         # Call super's setUp().
25         TestBase.setUp(self)
26         # Our simple source filename.
27         self.source = 'main.c'
28         # Find the line number to break inside main().
29         self.line = line_number(
30             self.source, '// Set break point at this line.')
31         # And the watchpoint variable declaration line number.
32         self.decl = line_number(self.source,
33                                 '// Watchpoint variable declaration.')
34         self.exe_name = 'a.out'
35         self.d = {'C_SOURCES': self.source, 'EXE': self.exe_name}
36
37     # Watchpoints not supported
38     @expectedFailureAndroid(archs=['arm', 'aarch64'])
39     @expectedFailureAll(
40         oslist=["windows"],
41         bugnumber="llvm.org/pr24446: WINDOWS XFAIL TRIAGE - Watchpoints not supported on Windows")
42     def test_hello_watchpoint_using_watchpoint_set(self):
43         """Test a simple sequence of watchpoint creation and watchpoint hit."""
44         self.build(dictionary=self.d)
45         self.setTearDownCleanup(dictionary=self.d)
46
47         exe = os.path.join(os.getcwd(), self.exe_name)
48         self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
49
50         # Add a breakpoint to set a watchpoint when stopped on the breakpoint.
51         lldbutil.run_break_set_by_file_and_line(
52             self, None, self.line, num_expected_locations=1)
53
54         # Run the program.
55         self.runCmd("run", RUN_SUCCEEDED)
56
57         # We should be stopped again due to the breakpoint.
58         # The stop reason of the thread should be breakpoint.
59         self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
60                     substrs=['stopped',
61                              'stop reason = breakpoint'])
62
63         # Now let's set a write-type watchpoint for 'global'.
64         # There should be only one watchpoint hit (see main.c).
65         self.expect(
66             "watchpoint set variable -w write global",
67             WATCHPOINT_CREATED,
68             substrs=[
69                 'Watchpoint created',
70                 'size = 4',
71                 'type = w',
72                 '%s:%d' %
73                 (self.source,
74                  self.decl)])
75
76         # Use the '-v' option to do verbose listing of the watchpoint.
77         # The hit count should be 0 initially.
78         self.expect("watchpoint list -v",
79                     substrs=['hit_count = 0'])
80
81         self.runCmd("process continue")
82
83         # We should be stopped again due to the watchpoint (write type), but
84         # only once.  The stop reason of the thread should be watchpoint.
85         self.expect("thread list", STOPPED_DUE_TO_WATCHPOINT,
86                     substrs=['stopped',
87                              'stop reason = watchpoint'])
88
89         self.runCmd("process continue")
90
91         # Don't expect the read of 'global' to trigger a stop exception.
92         process = self.dbg.GetSelectedTarget().GetProcess()
93         if process.GetState() == lldb.eStateStopped:
94             self.assertFalse(
95                 lldbutil.get_stopped_thread(
96                     process, lldb.eStopReasonWatchpoint))
97
98         # Use the '-v' option to do verbose listing of the watchpoint.
99         # The hit count should now be 1.
100         self.expect("watchpoint list -v",
101                     substrs=['hit_count = 1'])