Johnny Chen | 6cc60e8 | 2011-10-05 21:35:46 +0000 | [diff] [blame] | 1 | """ |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 +0000 | [diff] [blame^] | 2 | Use lldb Python SBWatchpoint API to set the ignore count. |
Johnny Chen | 6cc60e8 | 2011-10-05 21:35:46 +0000 | [diff] [blame] | 3 | """ |
| 4 | |
| 5 | import os, time |
| 6 | import re |
| 7 | import unittest2 |
| 8 | import lldb, lldbutil |
| 9 | from lldbtest import * |
| 10 | |
| 11 | class WatchpointIgnoreCountTestCase(TestBase): |
| 12 | |
| 13 | mydir = os.path.join("python_api", "watchpoint") |
| 14 | |
| 15 | def setUp(self): |
| 16 | # Call super's setUp(). |
| 17 | TestBase.setUp(self) |
| 18 | # Our simple source filename. |
| 19 | self.source = 'main.c' |
| 20 | # Find the line number to break inside main(). |
| 21 | self.line = line_number(self.source, '// Set break point at this line.') |
| 22 | |
| 23 | @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin") |
| 24 | @python_api_test |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 +0000 | [diff] [blame^] | 25 | def test_set_watch_ignore_count_with_dsym(self): |
| 26 | """Test SBWatchpoint.SetIgnoreCount() API.""" |
Johnny Chen | 6cc60e8 | 2011-10-05 21:35:46 +0000 | [diff] [blame] | 27 | self.buildDsym() |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 +0000 | [diff] [blame^] | 28 | self.do_watchpoint_ignore_count() |
Johnny Chen | 6cc60e8 | 2011-10-05 21:35:46 +0000 | [diff] [blame] | 29 | |
| 30 | @python_api_test |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 +0000 | [diff] [blame^] | 31 | def test_set_watch_ignore_count_with_dwarf(self): |
| 32 | """Test SBWatchpoint.SetIgnoreCount() API.""" |
Johnny Chen | 6cc60e8 | 2011-10-05 21:35:46 +0000 | [diff] [blame] | 33 | self.buildDwarf() |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 +0000 | [diff] [blame^] | 34 | self.do_watchpoint_ignore_count() |
Johnny Chen | 6cc60e8 | 2011-10-05 21:35:46 +0000 | [diff] [blame] | 35 | |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 +0000 | [diff] [blame^] | 36 | def do_watchpoint_ignore_count(self): |
| 37 | """Test SBWatchpoint.SetIgnoreCount() API.""" |
Johnny Chen | 6cc60e8 | 2011-10-05 21:35:46 +0000 | [diff] [blame] | 38 | exe = os.path.join(os.getcwd(), "a.out") |
| 39 | |
| 40 | # Create a target by the debugger. |
| 41 | target = self.dbg.CreateTarget(exe) |
| 42 | self.assertTrue(target, VALID_TARGET) |
| 43 | |
| 44 | # Create a breakpoint on main.c in order to set our watchpoint later. |
| 45 | breakpoint = target.BreakpointCreateByLocation(self.source, self.line) |
| 46 | self.assertTrue(breakpoint and |
| 47 | breakpoint.GetNumLocations() == 1, |
| 48 | VALID_BREAKPOINT) |
| 49 | |
| 50 | # Now launch the process, and do not stop at the entry point. |
| 51 | process = target.LaunchSimple(None, None, os.getcwd()) |
| 52 | |
| 53 | # We should be stopped due to the breakpoint. Get frame #0. |
| 54 | process = target.GetProcess() |
| 55 | self.assertTrue(process.GetState() == lldb.eStateStopped, |
| 56 | PROCESS_STOPPED) |
| 57 | thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint) |
| 58 | frame0 = thread.GetFrameAtIndex(0) |
| 59 | |
| 60 | # Watch 'global' for read and write. |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 +0000 | [diff] [blame^] | 61 | value = frame0.FindValue('global', lldb.eValueTypeVariableGlobal) |
| 62 | watchpoint = value.Watch(True, True, True) |
| 63 | self.assertTrue(value and watchpoint, |
| 64 | "Successfully found the variable and set a watchpoint") |
Johnny Chen | 6cc60e8 | 2011-10-05 21:35:46 +0000 | [diff] [blame] | 65 | self.DebugSBValue(value) |
| 66 | |
| 67 | # Hide stdout if not running with '-t' option. |
| 68 | if not self.TraceOn(): |
| 69 | self.HideStdout() |
| 70 | |
| 71 | # There should be only 1 watchpoint location under the target. |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 +0000 | [diff] [blame^] | 72 | self.assertTrue(target.GetNumWatchpoints() == 1) |
| 73 | watchpoint = target.GetWatchpointAtIndex(0) |
| 74 | self.assertTrue(watchpoint.IsEnabled()) |
| 75 | self.assertTrue(watchpoint.GetIgnoreCount() == 0) |
| 76 | watch_id = watchpoint.GetID() |
Johnny Chen | 6cc60e8 | 2011-10-05 21:35:46 +0000 | [diff] [blame] | 77 | self.assertTrue(watch_id != 0) |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 +0000 | [diff] [blame^] | 78 | print watchpoint |
Johnny Chen | 6cc60e8 | 2011-10-05 21:35:46 +0000 | [diff] [blame] | 79 | |
| 80 | # Now immediately set the ignore count to 2. When we continue, expect the |
| 81 | # inferior to run to its completion without stopping due to watchpoint. |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 +0000 | [diff] [blame^] | 82 | watchpoint.SetIgnoreCount(2) |
| 83 | print watchpoint |
Johnny Chen | 6cc60e8 | 2011-10-05 21:35:46 +0000 | [diff] [blame] | 84 | process.Continue() |
| 85 | |
| 86 | # At this point, the inferior process should have exited. |
| 87 | self.assertTrue(process.GetState() == lldb.eStateExited, PROCESS_EXITED) |
| 88 | |
| 89 | # Verify some vital statistics. |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 +0000 | [diff] [blame^] | 90 | self.assertTrue(watchpoint) |
| 91 | self.assertTrue(watchpoint.GetWatchSize() == 4) |
| 92 | self.assertTrue(watchpoint.GetHitCount() == 2) |
| 93 | print watchpoint |
Johnny Chen | 6cc60e8 | 2011-10-05 21:35:46 +0000 | [diff] [blame] | 94 | |
| 95 | |
| 96 | if __name__ == '__main__': |
| 97 | import atexit |
| 98 | lldb.SBDebugger.Initialize() |
| 99 | atexit.register(lambda: lldb.SBDebugger.Terminate()) |
| 100 | unittest2.main() |