2 Test my first lldb watchpoint.
7 from lldbsuite
.test
.decorators
import *
8 from lldbsuite
.test
.lldbtest
import *
9 from lldbsuite
.test
import lldbutil
12 class HelloWatchpointTestCase(TestBase
):
13 NO_DEBUG_INFO_TESTCASE
= True
16 # Call super's setUp().
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
}
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
)
33 exe
= self
.getBuildArtifact(self
.exe_name
)
34 self
.runCmd("file " + exe
, CURRENT_EXECUTABLE_SET
)
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
=1
42 self
.runCmd("run", RUN_SUCCEEDED
)
44 # We should be stopped again due to the breakpoint.
45 # The stop reason of the thread should be breakpoint.
48 STOPPED_DUE_TO_BREAKPOINT
,
49 substrs
=["stopped", "stop reason = breakpoint"],
52 # Now let's set a write-type watchpoint for 'global'.
53 # There should be only one watchpoint hit (see main.c).
55 "watchpoint set variable -w write global",
61 "%s:%d" % (self
.source
, self
.decl
),
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"])
69 self
.runCmd("process continue")
71 # We should be stopped again due to the watchpoint (write type), but
72 # only once. The stop reason of the thread should be watchpoint.
75 STOPPED_DUE_TO_WATCHPOINT
,
76 substrs
=["stopped", "stop reason = watchpoint"],
79 self
.runCmd("process continue")
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
:
85 lldbutil
.get_stopped_thread(process
, lldb
.eStopReasonWatchpoint
)
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"])