55bf929b25fcf0eea6a84b14920331d9f01d6113
[openbsd] /
1 """
2 Test lldb watchpoint that uses '-s size' to watch a pointed location with size.
3 """
4
5
6
7 import re
8 import lldb
9 from lldbsuite.test.decorators import *
10 from lldbsuite.test.lldbtest import *
11 from lldbsuite.test import lldbutil
12
13
14 class HelloWatchLocationTestCase(TestBase):
15
16     mydir = TestBase.compute_mydir(__file__)
17     NO_DEBUG_INFO_TESTCASE = True
18
19     def setUp(self):
20         # Call super's setUp().
21         TestBase.setUp(self)
22         # Our simple source filename.
23         self.source = 'main.cpp'
24         # Find the line number to break inside main().
25         self.line = line_number(
26             self.source, '// Set break point at this line.')
27         # This is for verifying that watch location works.
28         self.violating_func = "do_bad_thing_with_location"
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     # Most of the MIPS boards provide only one H/W watchpoints, and S/W
35     # watchpoints are not supported yet
36     @expectedFailureAll(triple=re.compile('^mips'))
37     # SystemZ and PowerPC also currently supports only one H/W watchpoint
38     @expectedFailureAll(archs=['powerpc64le', 's390x'])
39     @skipIfDarwin
40     def test_hello_watchlocation(self):
41         """Test watching a location with '-s size' option."""
42         self.build(dictionary=self.d)
43         self.setTearDownCleanup(dictionary=self.d)
44         exe = self.getBuildArtifact(self.exe_name)
45         self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
46
47         # Add a breakpoint to set a watchpoint when stopped on the breakpoint.
48         lldbutil.run_break_set_by_file_and_line(
49             self, None, self.line, num_expected_locations=1, loc_exact=False)
50
51         # Run the program.
52         self.runCmd("run", RUN_SUCCEEDED)
53
54         # We should be stopped again due to the breakpoint.
55         # The stop reason of the thread should be breakpoint.
56         self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
57                     substrs=['stopped',
58                              'stop reason = breakpoint'])
59
60         # Now let's set a write-type watchpoint pointed to by 'g_char_ptr'.
61         self.expect(
62             "watchpoint set expression -w write -s 1 -- g_char_ptr",
63             WATCHPOINT_CREATED,
64             substrs=[
65                 'Watchpoint created',
66                 'size = 1',
67                 'type = w'])
68         # Get a hold of the watchpoint id just created, it is used later on to
69         # match the watchpoint id which is expected to be fired.
70         match = re.match(
71             "Watchpoint created: Watchpoint (.*):",
72             self.res.GetOutput().splitlines()[0])
73         if match:
74             expected_wp_id = int(match.group(1), 0)
75         else:
76             self.fail("Grokking watchpoint id faailed!")
77
78         self.runCmd("expr unsigned val = *g_char_ptr; val")
79         self.expect(self.res.GetOutput().splitlines()[0], exe=False,
80                     endstr=' = 0')
81
82         self.runCmd("watchpoint set expression -w write -s 4 -- &threads[0]")
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), but
92         # only once.  The stop reason of the thread should be watchpoint.
93         self.expect("thread list", STOPPED_DUE_TO_WATCHPOINT,
94                     substrs=['stopped',
95                              'stop reason = watchpoint %d' % expected_wp_id])
96
97         # Switch to the thread stopped due to watchpoint and issue some
98         # commands.
99         self.switch_to_thread_with_stop_reason(lldb.eStopReasonWatchpoint)
100         self.runCmd("thread backtrace")
101         self.expect("frame info",
102                     substrs=[self.violating_func])
103
104         # Use the '-v' option to do verbose listing of the watchpoint.
105         # The hit count should now be 1.
106         self.expect("watchpoint list -v",
107                     substrs=['hit_count = 1'])
108
109         self.runCmd("thread backtrace all")