91 lines · python
1"""2Test my first lldb watchpoint.3"""4 5 6import lldb7from lldbsuite.test.decorators import *8from lldbsuite.test.lldbtest import *9from lldbsuite.test import lldbutil10 11 12class HelloWatchpointTestCase(TestBase):13 NO_DEBUG_INFO_TESTCASE = True14 15 def setUp(self):16 # Call super's setUp().17 TestBase.setUp(self)18 # Our simple source filename.19 self.source = "main.c"20 # Find the line number to break inside main().21 self.line = line_number(self.source, "// Set break point at this line.")22 # And the watchpoint variable declaration line number.23 self.decl = line_number(self.source, "// Watchpoint variable declaration.")24 self.exe_name = self.getBuildArtifact("a.out")25 self.d = {"C_SOURCES": self.source, "EXE": self.exe_name}26 27 @add_test_categories(["basic_process"])28 def test_hello_watchpoint_using_watchpoint_set(self):29 """Test a simple sequence of watchpoint creation and watchpoint hit."""30 self.build(dictionary=self.d)31 self.setTearDownCleanup(dictionary=self.d)32 33 exe = self.getBuildArtifact(self.exe_name)34 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)35 36 # Add a breakpoint to set a watchpoint when stopped on the breakpoint.37 lldbutil.run_break_set_by_file_and_line(38 self, None, self.line, num_expected_locations=139 )40 41 # Run the program.42 self.runCmd("run", RUN_SUCCEEDED)43 44 # We should be stopped again due to the breakpoint.45 # The stop reason of the thread should be breakpoint.46 self.expect(47 "thread list",48 STOPPED_DUE_TO_BREAKPOINT,49 substrs=["stopped", "stop reason = breakpoint"],50 )51 52 # Now let's set a write-type watchpoint for 'global'.53 # There should be only one watchpoint hit (see main.c).54 self.expect(55 "watchpoint set variable -w write global",56 WATCHPOINT_CREATED,57 substrs=[58 "Watchpoint created",59 "size = 4",60 "type = w",61 "%s:%d" % (self.source, self.decl),62 ],63 )64 65 # Use the '-v' option to do verbose listing of the watchpoint.66 # The hit count should be 0 initially.67 self.expect("watchpoint list -v", substrs=["hit_count = 0"])68 69 self.runCmd("process continue")70 71 # We should be stopped again due to the watchpoint (write type), but72 # only once. The stop reason of the thread should be watchpoint.73 self.expect(74 "thread list",75 STOPPED_DUE_TO_WATCHPOINT,76 substrs=["stopped", "stop reason = watchpoint"],77 )78 79 self.runCmd("process continue")80 81 # Don't expect the read of 'global' to trigger a stop exception.82 process = self.dbg.GetSelectedTarget().GetProcess()83 if process.GetState() == lldb.eStateStopped:84 self.assertFalse(85 lldbutil.get_stopped_thread(process, lldb.eStopReasonWatchpoint)86 )87 88 # Use the '-v' option to do verbose listing of the watchpoint.89 # The hit count should now be 1.90 self.expect("watchpoint list -v", substrs=["hit_count = 1"])91