2 Use lldb Python SBWatchpoint API to set the ignore count.
5 from __future__ import print_function
12 from lldbsuite.test.decorators import *
13 from lldbsuite.test.lldbtest import *
14 from lldbsuite.test import lldbutil
17 class WatchpointIgnoreCountTestCase(TestBase):
19 mydir = TestBase.compute_mydir(__file__)
22 # Call super's setUp().
24 # Our simple source filename.
25 self.source = 'main.c'
26 # Find the line number to break inside main().
27 self.line = line_number(
28 self.source, '// Set break point at this line.')
30 @add_test_categories(['pyapi'])
33 bugnumber="llvm.org/pr24446: WINDOWS XFAIL TRIAGE - Watchpoints not supported on Windows")
34 # Read-write watchpoints not supported on SystemZ
35 @expectedFailureAll(archs=['s390x'])
36 def test_set_watch_ignore_count(self):
37 """Test SBWatchpoint.SetIgnoreCount() API."""
39 exe = self.getBuildArtifact("a.out")
41 # Create a target by the debugger.
42 target = self.dbg.CreateTarget(exe)
43 self.assertTrue(target, VALID_TARGET)
45 # Create a breakpoint on main.c in order to set our watchpoint later.
46 breakpoint = target.BreakpointCreateByLocation(self.source, self.line)
47 self.assertTrue(breakpoint and
48 breakpoint.GetNumLocations() == 1,
51 # Now launch the process, and do not stop at the entry point.
52 process = target.LaunchSimple(
53 None, None, self.get_process_working_directory())
55 # We should be stopped due to the breakpoint. Get frame #0.
56 process = target.GetProcess()
57 self.assertEqual(process.GetState(), lldb.eStateStopped,
59 thread = lldbutil.get_stopped_thread(
60 process, lldb.eStopReasonBreakpoint)
61 frame0 = thread.GetFrameAtIndex(0)
63 # Watch 'global' for read and write.
64 value = frame0.FindValue('global', lldb.eValueTypeVariableGlobal)
65 error = lldb.SBError()
66 watchpoint = value.Watch(True, True, True, error)
67 self.assertTrue(value and watchpoint,
68 "Successfully found the variable and set a watchpoint")
69 self.DebugSBValue(value)
71 # Hide stdout if not running with '-t' option.
72 if not self.TraceOn():
75 # There should be only 1 watchpoint location under the target.
76 self.assertEqual(target.GetNumWatchpoints(), 1)
77 watchpoint = target.GetWatchpointAtIndex(0)
78 self.assertTrue(watchpoint.IsEnabled())
79 self.assertEqual(watchpoint.GetIgnoreCount(), 0)
80 watch_id = watchpoint.GetID()
81 self.assertNotEqual(watch_id, 0)
84 # Now immediately set the ignore count to 2. When we continue, expect the
85 # inferior to run to its completion without stopping due to watchpoint.
86 watchpoint.SetIgnoreCount(2)
90 # At this point, the inferior process should have exited.
91 self.assertEqual(process.GetState(), lldb.eStateExited, PROCESS_EXITED)
93 # Verify some vital statistics.
94 self.assertTrue(watchpoint)
95 self.assertEqual(watchpoint.GetWatchSize(), 4)
96 self.assertEqual(watchpoint.GetHitCount(), 2)