]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - packages/Python/lldbsuite/test/functionalities/watchpoint/watchpoint_set_command/TestWatchLocationWithWatchSet.py
Vendor import of lldb trunk r290819:
[FreeBSD/FreeBSD.git] / packages / Python / lldbsuite / test / functionalities / watchpoint / watchpoint_set_command / TestWatchLocationWithWatchSet.py
1 """
2 Test lldb watchpoint that uses 'watchpoint set -w write -s size' to watch a pointed location with size.
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 WatchLocationUsingWatchpointSetTestCase(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         # This is for verifying that watch location works.
29         self.violating_func = "do_bad_thing_with_location"
30         # Build dictionary to have unique executable names for each test
31         # method.
32
33     # Watchpoints not supported
34     @expectedFailureAndroid(archs=['arm', 'aarch64'])
35     @expectedFailureAll(
36         oslist=["linux"],
37         archs=[
38             'aarch64',
39             'arm'],
40         bugnumber="llvm.org/pr26031")
41     @expectedFailureAll(
42         oslist=["windows"],
43         bugnumber="llvm.org/pr24446: WINDOWS XFAIL TRIAGE - Watchpoints not supported on Windows")
44     def test_watchlocation_using_watchpoint_set(self):
45         """Test watching a location with 'watchpoint set expression -w write -s size' option."""
46         self.build()
47         self.setTearDownCleanup()
48
49         exe = os.path.join(os.getcwd(), 'a.out')
50         self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
51
52         # Add a breakpoint to set a watchpoint when stopped on the breakpoint.
53         lldbutil.run_break_set_by_file_and_line(
54             self, None, self.line, num_expected_locations=1)
55
56         # Run the program.
57         self.runCmd("run", RUN_SUCCEEDED)
58
59         # We should be stopped again due to the breakpoint.
60         # The stop reason of the thread should be breakpoint.
61         self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
62                     substrs=['stopped',
63                              'stop reason = breakpoint'])
64
65         # Now let's set a write-type watchpoint pointed to by 'g_char_ptr' and
66         # with offset as 7.
67         # The main.cpp, by design, misbehaves by not following the agreed upon
68         # protocol of only accessing the allowable index range of [0, 6].
69         self.expect(
70             "watchpoint set expression -w write -s 1 -- g_char_ptr + 7",
71             WATCHPOINT_CREATED,
72             substrs=[
73                 'Watchpoint created',
74                 'size = 1',
75                 'type = w'])
76         self.runCmd("expr unsigned val = g_char_ptr[7]; val")
77         self.expect(self.res.GetOutput().splitlines()[0], exe=False,
78                     endstr=' = 0')
79
80         # Use the '-v' option to do verbose listing of the watchpoint.
81         # The hit count should be 0 initially.
82         self.expect("watchpoint list -v",
83                     substrs=['hit_count = 0'])
84
85         self.runCmd("process continue")
86
87         # We should be stopped again due to the watchpoint (write type), but
88         # only once.  The stop reason of the thread should be watchpoint.
89         self.expect("thread list", STOPPED_DUE_TO_WATCHPOINT,
90                     substrs=['stopped',
91                              'stop reason = watchpoint',
92                              self.violating_func])
93
94         # Switch to the thread stopped due to watchpoint and issue some
95         # commands.
96         self.switch_to_thread_with_stop_reason(lldb.eStopReasonWatchpoint)
97         self.runCmd("thread backtrace")
98         self.runCmd("expr unsigned val = g_char_ptr[7]; val")
99         self.expect(self.res.GetOutput().splitlines()[0], exe=False,
100                     endstr=' = 99')
101
102         # Use the '-v' option to do verbose listing of the watchpoint.
103         # The hit count should now be the same as the number of threads that
104         # stopped on a watchpoint.
105         threads = lldbutil.get_stopped_threads(
106             self.process(), lldb.eStopReasonWatchpoint)
107         self.expect("watchpoint list -v",
108                     substrs=['hit_count = %d' % len(threads)])
109
110         self.runCmd("thread backtrace all")