2 Use lldb Python SBWatchpoint API to set the ignore count.
6 from lldbsuite
.test
.decorators
import *
7 from lldbsuite
.test
.lldbtest
import *
8 from lldbsuite
.test
import lldbutil
11 class WatchpointIgnoreCountTestCase(TestBase
):
12 NO_DEBUG_INFO_TESTCASE
= True
15 # Call super's setUp().
17 # Our simple source filename.
18 self
.source
= "main.c"
19 # Find the line number to break inside main().
20 self
.line
= line_number(self
.source
, "// Set break point at this line.")
22 # on arm64 targets, lldb has incorrect hit-count / ignore-counts
23 # for watchpoints when they are hit with multiple threads at
24 # the same time. Tracked as llvm.org/pr49433
25 # or rdar://93863107 inside Apple.
26 def affected_by_radar_93863107(self
):
28 self
.getArchitecture() in ["arm64", "arm64e"]
29 ) and self
.platformIsDarwin()
31 # Read-write watchpoints not supported on SystemZ
32 @expectedFailureAll(archs
=["s390x"])
33 def test_set_watch_ignore_count(self
):
34 """Test SBWatchpoint.SetIgnoreCount() API."""
36 exe
= self
.getBuildArtifact("a.out")
38 # Create a target by the debugger.
39 target
= self
.dbg
.CreateTarget(exe
)
40 self
.assertTrue(target
, VALID_TARGET
)
42 # Create a breakpoint on main.c in order to set our watchpoint later.
43 breakpoint
= target
.BreakpointCreateByLocation(self
.source
, self
.line
)
45 breakpoint
and breakpoint
.GetNumLocations() == 1, VALID_BREAKPOINT
48 # Now launch the process, and do not stop at the entry point.
49 process
= target
.LaunchSimple(None, None, self
.get_process_working_directory())
51 # We should be stopped due to the breakpoint. Get frame #0.
52 process
= target
.GetProcess()
53 self
.assertState(process
.GetState(), lldb
.eStateStopped
, PROCESS_STOPPED
)
54 thread
= lldbutil
.get_stopped_thread(process
, lldb
.eStopReasonBreakpoint
)
55 frame0
= thread
.GetFrameAtIndex(0)
57 # Watch 'global' for read and write.
58 value
= frame0
.FindValue("global", lldb
.eValueTypeVariableGlobal
)
59 error
= lldb
.SBError()
60 watchpoint
= value
.Watch(True, True, True, error
)
62 value
and watchpoint
, "Successfully found the variable and set a watchpoint"
64 self
.DebugSBValue(value
)
66 # Hide stdout if not running with '-t' option.
67 if not self
.TraceOn():
70 # There should be only 1 watchpoint location under the target.
71 self
.assertEqual(target
.GetNumWatchpoints(), 1)
72 watchpoint
= target
.GetWatchpointAtIndex(0)
73 self
.assertTrue(watchpoint
.IsEnabled())
74 self
.assertEqual(watchpoint
.GetIgnoreCount(), 0)
75 watch_id
= watchpoint
.GetID()
76 self
.assertNotEqual(watch_id
, 0)
79 # Now immediately set the ignore count to 2. When we continue, expect the
80 # inferior to run to its completion without stopping due to watchpoint.
81 watchpoint
.SetIgnoreCount(2)
85 # At this point, the inferior process should have exited.
86 self
.assertState(process
.GetState(), lldb
.eStateExited
, PROCESS_EXITED
)
88 # Verify some vital statistics.
89 self
.assertTrue(watchpoint
)
90 self
.assertEqual(watchpoint
.GetWatchSize(), 4)
91 if not self
.affected_by_radar_93863107():
92 self
.assertEqual(watchpoint
.GetHitCount(), 2)