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
16 class WatchpointIgnoreCountTestCase(TestBase):
18 mydir = TestBase.compute_mydir(__file__)
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 @add_test_categories(['pyapi'])
29 @expectedFailureAndroid(archs=['arm', 'aarch64']) # Watchpoints not supported
30 @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24446: WINDOWS XFAIL TRIAGE - Watchpoints not supported on Windows")
31 @expectedFailureAll(archs=['s390x']) # Read-write watchpoints not supported on SystemZ
32 def test_set_watch_ignore_count(self):
33 """Test SBWatchpoint.SetIgnoreCount() API."""
35 exe = os.path.join(os.getcwd(), "a.out")
37 # Create a target by the debugger.
38 target = self.dbg.CreateTarget(exe)
39 self.assertTrue(target, VALID_TARGET)
41 # Create a breakpoint on main.c in order to set our watchpoint later.
42 breakpoint = target.BreakpointCreateByLocation(self.source, self.line)
43 self.assertTrue(breakpoint and
44 breakpoint.GetNumLocations() == 1,
47 # Now launch the process, and do not stop at the entry point.
48 process = target.LaunchSimple (None, None, self.get_process_working_directory())
50 # We should be stopped due to the breakpoint. Get frame #0.
51 process = target.GetProcess()
52 self.assertTrue(process.GetState() == lldb.eStateStopped,
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)
61 self.assertTrue(value and watchpoint,
62 "Successfully found the variable and set a watchpoint")
63 self.DebugSBValue(value)
65 # Hide stdout if not running with '-t' option.
66 if not self.TraceOn():
69 # There should be only 1 watchpoint location under the target.
70 self.assertTrue(target.GetNumWatchpoints() == 1)
71 watchpoint = target.GetWatchpointAtIndex(0)
72 self.assertTrue(watchpoint.IsEnabled())
73 self.assertTrue(watchpoint.GetIgnoreCount() == 0)
74 watch_id = watchpoint.GetID()
75 self.assertTrue(watch_id != 0)
78 # Now immediately set the ignore count to 2. When we continue, expect the
79 # inferior to run to its completion without stopping due to watchpoint.
80 watchpoint.SetIgnoreCount(2)
84 # At this point, the inferior process should have exited.
85 self.assertTrue(process.GetState() == lldb.eStateExited, PROCESS_EXITED)
87 # Verify some vital statistics.
88 self.assertTrue(watchpoint)
89 self.assertTrue(watchpoint.GetWatchSize() == 4)
90 self.assertTrue(watchpoint.GetHitCount() == 2)