blob: 53b86bc97060230da29138121ee710e3946dda3a [file] [log] [blame]
Johnny Chen6cc60e82011-10-05 21:35:46 +00001"""
Johnny Chen01a67862011-10-14 00:42:25 +00002Use lldb Python SBWatchpoint API to set the ignore count.
Johnny Chen6cc60e82011-10-05 21:35:46 +00003"""
4
5import os, time
6import re
7import unittest2
8import lldb, lldbutil
9from lldbtest import *
10
11class 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 Chen01a67862011-10-14 00:42:25 +000025 def test_set_watch_ignore_count_with_dsym(self):
26 """Test SBWatchpoint.SetIgnoreCount() API."""
Johnny Chen6cc60e82011-10-05 21:35:46 +000027 self.buildDsym()
Johnny Chen01a67862011-10-14 00:42:25 +000028 self.do_watchpoint_ignore_count()
Johnny Chen6cc60e82011-10-05 21:35:46 +000029
30 @python_api_test
Johnny Chen01a67862011-10-14 00:42:25 +000031 def test_set_watch_ignore_count_with_dwarf(self):
32 """Test SBWatchpoint.SetIgnoreCount() API."""
Johnny Chen6cc60e82011-10-05 21:35:46 +000033 self.buildDwarf()
Johnny Chen01a67862011-10-14 00:42:25 +000034 self.do_watchpoint_ignore_count()
Johnny Chen6cc60e82011-10-05 21:35:46 +000035
Johnny Chen01a67862011-10-14 00:42:25 +000036 def do_watchpoint_ignore_count(self):
37 """Test SBWatchpoint.SetIgnoreCount() API."""
Johnny Chen6cc60e82011-10-05 21:35:46 +000038 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 Chen01a67862011-10-14 00:42:25 +000061 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 Chen6cc60e82011-10-05 21:35:46 +000065 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 Chen01a67862011-10-14 00:42:25 +000072 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 Chen6cc60e82011-10-05 21:35:46 +000077 self.assertTrue(watch_id != 0)
Johnny Chen01a67862011-10-14 00:42:25 +000078 print watchpoint
Johnny Chen6cc60e82011-10-05 21:35:46 +000079
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 Chen01a67862011-10-14 00:42:25 +000082 watchpoint.SetIgnoreCount(2)
83 print watchpoint
Johnny Chen6cc60e82011-10-05 21:35:46 +000084 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 Chen01a67862011-10-14 00:42:25 +000090 self.assertTrue(watchpoint)
91 self.assertTrue(watchpoint.GetWatchSize() == 4)
92 self.assertTrue(watchpoint.GetHitCount() == 2)
93 print watchpoint
Johnny Chen6cc60e82011-10-05 21:35:46 +000094
95
96if __name__ == '__main__':
97 import atexit
98 lldb.SBDebugger.Initialize()
99 atexit.register(lambda: lldb.SBDebugger.Terminate())
100 unittest2.main()