2 Use lldb Python SBTarget API to iterate on the watchpoint(s) for the target.
6 from lldbsuite
.test
.decorators
import *
7 from lldbsuite
.test
.lldbtest
import *
8 from lldbsuite
.test
import lldbutil
11 class WatchpointIteratorTestCase(TestBase
):
12 NO_DEBUG_INFO_TESTCASE
= True
14 # hardware watchpoints are not reported with a hardware index # on armv7 on ios devices
15 def affected_by_radar_34564183(self
):
17 self
.getArchitecture() in ["armv7", "armv7k", "arm64_32"]
18 ) and self
.platformIsDarwin()
21 # Call super's setUp().
23 # Our simple source filename.
24 self
.source
= "main.c"
25 # Find the line number to break inside main().
26 self
.line
= line_number(self
.source
, "// Set break point at this line.")
28 def test_watch_iter(self
):
29 """Exercise SBTarget.watchpoint_iter() API to iterate on the available watchpoints."""
31 exe
= self
.getBuildArtifact("a.out")
33 # Create a target by the debugger.
34 target
= self
.dbg
.CreateTarget(exe
)
35 self
.assertTrue(target
, VALID_TARGET
)
37 # Create a breakpoint on main.c in order to set our watchpoint later.
38 breakpoint
= target
.BreakpointCreateByLocation(self
.source
, self
.line
)
40 breakpoint
and breakpoint
.GetNumLocations() == 1, VALID_BREAKPOINT
43 # Now launch the process, and do not stop at the entry point.
44 process
= target
.LaunchSimple(None, None, self
.get_process_working_directory())
46 # We should be stopped due to the breakpoint. Get frame #0.
47 process
= target
.GetProcess()
48 self
.assertState(process
.GetState(), lldb
.eStateStopped
, PROCESS_STOPPED
)
49 thread
= lldbutil
.get_stopped_thread(process
, lldb
.eStopReasonBreakpoint
)
50 frame0
= thread
.GetFrameAtIndex(0)
52 # Watch 'global' for read and write.
53 value
= frame0
.FindValue("global", lldb
.eValueTypeVariableGlobal
)
54 error
= lldb
.SBError()
55 watchpoint
= value
.Watch(True, False, True, error
)
57 value
and watchpoint
, "Successfully found the variable and set a watchpoint"
59 self
.DebugSBValue(value
)
61 # Hide stdout if not running with '-t' option.
62 if not self
.TraceOn():
65 # There should be only 1 watchpoint location under the target.
66 self
.assertEqual(target
.GetNumWatchpoints(), 1)
67 self
.assertTrue(watchpoint
.IsEnabled())
68 watch_id
= watchpoint
.GetID()
69 self
.assertTrue(watch_id
!= 0)
71 # Continue. Expect the program to stop due to the variable being
75 # Hide stdout if not running with '-t' option.
76 if not self
.TraceOn():
79 # Print the stack traces.
80 lldbutil
.print_stacktraces(process
)
82 thread
= lldbutil
.get_stopped_thread(process
, lldb
.eStopReasonWatchpoint
)
83 self
.assertTrue(thread
, "The thread stopped due to watchpoint")
84 self
.DebugSBValue(value
)
86 # We currently only support hardware watchpoint. Verify that we have a
87 # meaningful hardware index at this point. Exercise the printed repr of
88 # SBWatchpointLocation.
90 if not self
.affected_by_radar_34564183():
91 self
.assertTrue(watchpoint
.GetHardwareIndex() != -1)
93 # SBWatchpoint.GetDescription() takes a description level arg.
94 print(lldbutil
.get_description(watchpoint
, lldb
.eDescriptionLevelFull
))
96 # Now disable the 'rw' watchpoint. The program won't stop when it reads
98 watchpoint
.SetEnabled(False)
99 self
.assertEqual(watchpoint
.GetHardwareIndex(), -1)
100 self
.assertFalse(watchpoint
.IsEnabled())
102 # Continue. The program does not stop again when the variable is being
103 # read from because the watchpoint location has been disabled.
106 # At this point, the inferior process should have exited.
107 self
.assertEqual(process
.GetState(), lldb
.eStateExited
, PROCESS_EXITED
)
109 # Verify some vital statistics and exercise the iterator API.
110 for watchpoint
in target
.watchpoint_iter():
111 self
.assertTrue(watchpoint
)
112 self
.assertEqual(watchpoint
.GetWatchSize(), 4)
113 self
.assertEqual(watchpoint
.GetHitCount(), 1)