Johnny Chen | 6cc60e8 | 2011-10-05 21:35:46 +0000 | [diff] [blame] | 1 | """ |
| 2 | Use lldb Python SBWatchpointLocation API to set the ignore count. |
| 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 |
| 25 | def test_set_watch_loc_ignore_count_with_dsym(self): |
| 26 | """Test SBWatchpointLocation.SetIgnoreCount() API.""" |
| 27 | self.buildDsym() |
| 28 | self.do_watchpoint_location_ignore_count() |
| 29 | |
| 30 | @python_api_test |
| 31 | def test_set_watch_loc_ignore_count_with_dwarf(self): |
| 32 | """Test SBWatchpointLocation.SetIgnoreCount() API.""" |
| 33 | self.buildDwarf() |
| 34 | self.do_watchpoint_location_ignore_count() |
| 35 | |
| 36 | def do_watchpoint_location_ignore_count(self): |
| 37 | """Test SBWatchpointLocation.SetIgnoreCount() API.""" |
| 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. |
| 61 | value = frame0.WatchValue('global', |
| 62 | lldb.eValueTypeVariableGlobal, |
| 63 | lldb.LLDB_WATCH_TYPE_READ|lldb.LLDB_WATCH_TYPE_WRITE) |
| 64 | self.assertTrue(value, "Successfully found the variable and set a watchpoint") |
| 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. |
| 72 | self.assertTrue(target.GetNumWatchpointLocations() == 1) |
| 73 | wp_loc = target.GetWatchpointLocationAtIndex(0) |
| 74 | last_created = target.GetLastCreatedWatchpointLocation() |
| 75 | self.assertTrue(wp_loc == last_created) |
| 76 | self.assertTrue(wp_loc.IsEnabled()) |
| 77 | self.assertTrue(wp_loc.GetIgnoreCount() == 0) |
| 78 | watch_id = wp_loc.GetID() |
| 79 | self.assertTrue(watch_id != 0) |
| 80 | print wp_loc |
| 81 | |
| 82 | # Now immediately set the ignore count to 2. When we continue, expect the |
| 83 | # inferior to run to its completion without stopping due to watchpoint. |
| 84 | wp_loc.SetIgnoreCount(2) |
| 85 | print wp_loc |
| 86 | process.Continue() |
| 87 | |
| 88 | # At this point, the inferior process should have exited. |
| 89 | self.assertTrue(process.GetState() == lldb.eStateExited, PROCESS_EXITED) |
| 90 | |
| 91 | # Verify some vital statistics. |
| 92 | self.assertTrue(wp_loc) |
| 93 | self.assertTrue(wp_loc.GetWatchSize() == 4) |
| 94 | self.assertTrue(wp_loc.GetHitCount() == 2) |
| 95 | print wp_loc |
| 96 | |
| 97 | |
| 98 | if __name__ == '__main__': |
| 99 | import atexit |
| 100 | lldb.SBDebugger.Initialize() |
| 101 | atexit.register(lambda: lldb.SBDebugger.Terminate()) |
| 102 | unittest2.main() |