7a00244309af5ded83a57c6b91b8c82f2b905f31
[platform/upstream/llvm.git] /
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 lldb
9 from lldbsuite.test.decorators import *
10 from lldbsuite.test.lldbtest import *
11 from lldbsuite.test import lldbutil
12
13
14 class WatchLocationUsingWatchpointSetTestCase(TestBase):
15
16     mydir = TestBase.compute_mydir(__file__)
17
18     def setUp(self):
19         # Call super's setUp().
20         TestBase.setUp(self)
21         # Our simple source filename.
22         self.source = 'main.cpp'
23         # Find the line number to break inside main().
24         self.line = line_number(
25             self.source, '// Set break point at this line.')
26         # This is for verifying that watch location works.
27         self.violating_func = "do_bad_thing_with_location"
28         # Build dictionary to have unique executable names for each test
29         # method.
30
31     @expectedFailureAll(
32         oslist=["linux"],
33         archs=[
34             'aarch64',
35             'arm'],
36         bugnumber="llvm.org/pr26031")
37     @expectedFailureAll(
38         oslist=["windows"],
39         bugnumber="llvm.org/pr24446: WINDOWS XFAIL TRIAGE - Watchpoints not supported on Windows")
40     @expectedFailureNetBSD
41     def test_watchlocation_using_watchpoint_set(self):
42         """Test watching a location with 'watchpoint set expression -w write -s size' option."""
43         self.build()
44         self.setTearDownCleanup()
45
46         exe = self.getBuildArtifact("a.out")
47         self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
48
49         # Add a breakpoint to set a watchpoint when stopped on the breakpoint.
50         lldbutil.run_break_set_by_file_and_line(
51             self, None, self.line, num_expected_locations=1)
52
53         # Run the program.
54         self.runCmd("run", RUN_SUCCEEDED)
55
56         # We should be stopped again due to the breakpoint.
57         # The stop reason of the thread should be breakpoint.
58         self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
59                     substrs=['stopped',
60                              'stop reason = breakpoint'])
61
62         # Now let's set a write-type watchpoint pointed to by 'g_char_ptr' and
63         # with offset as 7.
64         # The main.cpp, by design, misbehaves by not following the agreed upon
65         # protocol of only accessing the allowable index range of [0, 6].
66         self.expect(
67             "watchpoint set expression -w write -s 1 -- g_char_ptr + 7",
68             WATCHPOINT_CREATED,
69             substrs=[
70                 'Watchpoint created',
71                 'size = 1',
72                 'type = w'])
73         self.runCmd("expr unsigned val = g_char_ptr[7]; val")
74         self.expect(self.res.GetOutput().splitlines()[0], exe=False,
75                     endstr=' = 0')
76
77         # Use the '-v' option to do verbose listing of the watchpoint.
78         # The hit count should be 0 initially.
79         self.expect("watchpoint list -v",
80                     substrs=['hit_count = 0'])
81
82         self.runCmd("process continue")
83
84         # We should be stopped again due to the watchpoint (write type), but
85         # only once.  The stop reason of the thread should be watchpoint.
86         self.expect("thread list", STOPPED_DUE_TO_WATCHPOINT,
87                     substrs=['stopped',
88                              'stop reason = watchpoint',
89                              self.violating_func])
90
91         # Switch to the thread stopped due to watchpoint and issue some
92         # commands.
93         self.switch_to_thread_with_stop_reason(lldb.eStopReasonWatchpoint)
94         self.runCmd("thread backtrace")
95         self.runCmd("expr unsigned val = g_char_ptr[7]; val")
96         self.expect(self.res.GetOutput().splitlines()[0], exe=False,
97                     endstr=' = 99')
98
99         # Use the '-v' option to do verbose listing of the watchpoint.
100         # The hit count should now be the same as the number of threads that
101         # stopped on a watchpoint.
102         threads = lldbutil.get_stopped_threads(
103             self.process(), lldb.eStopReasonWatchpoint)
104         self.expect("watchpoint list -v",
105                     substrs=['hit_count = %d' % len(threads)])
106
107         self.runCmd("thread backtrace all")