2 Test my first lldb watchpoint.
5 from __future__ import print_function
11 from lldbsuite.test.decorators import *
12 from lldbsuite.test.lldbtest import *
13 from lldbsuite.test import lldbutil
16 class HelloWatchpointTestCase(TestBase):
18 def getCategories(self):
19 return ['basic_process']
21 mydir = TestBase.compute_mydir(__file__)
24 # Call super's setUp().
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}
37 # Watchpoints not supported
38 @expectedFailureAndroid(archs=['arm', 'aarch64'])
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)
47 exe = os.path.join(os.getcwd(), self.exe_name)
48 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
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)
55 self.runCmd("run", RUN_SUCCEEDED)
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,
61 'stop reason = breakpoint'])
63 # Now let's set a write-type watchpoint for 'global'.
64 # There should be only one watchpoint hit (see main.c).
66 "watchpoint set variable -w write global",
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'])
81 self.runCmd("process continue")
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,
87 'stop reason = watchpoint'])
89 self.runCmd("process continue")
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:
95 lldbutil.get_stopped_thread(
96 process, lldb.eStopReasonWatchpoint))
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'])