d51565b2b8474a56d6ac8540368b6e4d7fc020b7
[openbsd] /
1 """
2 Test my first lldb watchpoint.
3 """
4
5
6
7 import lldb
8 from lldbsuite.test.decorators import *
9 from lldbsuite.test.lldbtest import *
10 from lldbsuite.test import lldbutil
11
12
13 class HelloWatchpointTestCase(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.c'
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         self.exe_name = self.getBuildArtifact('a.out')
30         self.d = {'C_SOURCES': self.source, 'EXE': self.exe_name}
31
32     @add_test_categories(["basic_process"])
33     def test_hello_watchpoint_using_watchpoint_set(self):
34         """Test a simple sequence of watchpoint creation and watchpoint hit."""
35         self.build(dictionary=self.d)
36         self.setTearDownCleanup(dictionary=self.d)
37
38         exe = self.getBuildArtifact(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(
43             self, None, self.line, num_expected_locations=1)
44
45         # Run the program.
46         self.runCmd("run", RUN_SUCCEEDED)
47
48         # We should be stopped again due to the breakpoint.
49         # The stop reason of the thread should be breakpoint.
50         self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
51                     substrs=['stopped',
52                              'stop reason = breakpoint'])
53
54         # Now let's set a write-type watchpoint for 'global'.
55         # There should be only one watchpoint hit (see main.c).
56         self.expect(
57             "watchpoint set variable -w write global",
58             WATCHPOINT_CREATED,
59             substrs=[
60                 'Watchpoint created',
61                 'size = 4',
62                 'type = w',
63                 '%s:%d' %
64                 (self.source,
65                  self.decl)])
66
67         # Use the '-v' option to do verbose listing of the watchpoint.
68         # The hit count should be 0 initially.
69         self.expect("watchpoint list -v",
70                     substrs=['hit_count = 0'])
71
72         self.runCmd("process continue")
73
74         # We should be stopped again due to the watchpoint (write type), but
75         # only once.  The stop reason of the thread should be watchpoint.
76         self.expect("thread list", STOPPED_DUE_TO_WATCHPOINT,
77                     substrs=['stopped',
78                              'stop reason = watchpoint'])
79
80         self.runCmd("process continue")
81
82         # Don't expect the read of 'global' to trigger a stop exception.
83         process = self.dbg.GetSelectedTarget().GetProcess()
84         if process.GetState() == lldb.eStateStopped:
85             self.assertFalse(
86                 lldbutil.get_stopped_thread(
87                     process, lldb.eStopReasonWatchpoint))
88
89         # Use the '-v' option to do verbose listing of the watchpoint.
90         # The hit count should now be 1.
91         self.expect("watchpoint list -v",
92                     substrs=['hit_count = 1'])