1""" 2Use lldb Python SBWatchpoint API to set the ignore count. 3""" 4 5from __future__ import print_function 6 7 8import lldb 9from lldbsuite.test.decorators import * 10from lldbsuite.test.lldbtest import * 11from lldbsuite.test import lldbutil 12 13 14class WatchpointIgnoreCountTestCase(TestBase): 15 16 mydir = TestBase.compute_mydir(__file__) 17 NO_DEBUG_INFO_TESTCASE = True 18 19 def setUp(self): 20 # Call super's setUp(). 21 TestBase.setUp(self) 22 # Our simple source filename. 23 self.source = 'main.c' 24 # Find the line number to break inside main(). 25 self.line = line_number( 26 self.source, '// Set break point at this line.') 27 28 # Read-write watchpoints not supported on SystemZ 29 @expectedFailureAll(archs=['s390x']) 30 def test_set_watch_ignore_count(self): 31 """Test SBWatchpoint.SetIgnoreCount() API.""" 32 self.build() 33 exe = self.getBuildArtifact("a.out") 34 35 # Create a target by the debugger. 36 target = self.dbg.CreateTarget(exe) 37 self.assertTrue(target, VALID_TARGET) 38 39 # Create a breakpoint on main.c in order to set our watchpoint later. 40 breakpoint = target.BreakpointCreateByLocation(self.source, self.line) 41 self.assertTrue(breakpoint and 42 breakpoint.GetNumLocations() == 1, 43 VALID_BREAKPOINT) 44 45 # Now launch the process, and do not stop at the entry point. 46 process = target.LaunchSimple( 47 None, None, self.get_process_working_directory()) 48 49 # We should be stopped due to the breakpoint. Get frame #0. 50 process = target.GetProcess() 51 self.assertEqual(process.GetState(), lldb.eStateStopped, 52 PROCESS_STOPPED) 53 thread = lldbutil.get_stopped_thread( 54 process, lldb.eStopReasonBreakpoint) 55 frame0 = thread.GetFrameAtIndex(0) 56 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) 64 65 # Hide stdout if not running with '-t' option. 66 if not self.TraceOn(): 67 self.HideStdout() 68 69 # There should be only 1 watchpoint location under the target. 70 self.assertEqual(target.GetNumWatchpoints(), 1) 71 watchpoint = target.GetWatchpointAtIndex(0) 72 self.assertTrue(watchpoint.IsEnabled()) 73 self.assertEqual(watchpoint.GetIgnoreCount(), 0) 74 watch_id = watchpoint.GetID() 75 self.assertNotEqual(watch_id, 0) 76 print(watchpoint) 77 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) 81 print(watchpoint) 82 process.Continue() 83 84 # At this point, the inferior process should have exited. 85 self.assertEqual(process.GetState(), lldb.eStateExited, PROCESS_EXITED) 86 87 # Verify some vital statistics. 88 self.assertTrue(watchpoint) 89 self.assertEqual(watchpoint.GetWatchSize(), 4) 90 self.assertEqual(watchpoint.GetHitCount(), 2) 91 print(watchpoint) 92