2 Test my first lldb watchpoint.
8 from lldbsuite.test.decorators import *
9 from lldbsuite.test.lldbtest import *
10 from lldbsuite.test import lldbutil
13 class HelloWatchpointTestCase(TestBase):
15 mydir = TestBase.compute_mydir(__file__)
16 NO_DEBUG_INFO_TESTCASE = True
19 # Call super's setUp().
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}
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)
38 exe = self.getBuildArtifact(self.exe_name)
39 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
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)
46 self.runCmd("run", RUN_SUCCEEDED)
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,
52 'stop reason = breakpoint'])
54 # Now let's set a write-type watchpoint for 'global'.
55 # There should be only one watchpoint hit (see main.c).
57 "watchpoint set variable -w write global",
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'])
72 self.runCmd("process continue")
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,
78 'stop reason = watchpoint'])
80 self.runCmd("process continue")
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:
86 lldbutil.get_stopped_thread(
87 process, lldb.eStopReasonWatchpoint))
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'])