blob: e369ef54e69d41e8e54ac6c7f23e7d210d6b0b19 [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 Chen24086bc2012-04-06 19:54:10 +000025 @dsym_test
Johnny Chen01a67862011-10-14 00:42:25 +000026 def test_set_watch_ignore_count_with_dsym(self):
27 """Test SBWatchpoint.SetIgnoreCount() API."""
Johnny Chen6cc60e82011-10-05 21:35:46 +000028 self.buildDsym()
Johnny Chen01a67862011-10-14 00:42:25 +000029 self.do_watchpoint_ignore_count()
Johnny Chen6cc60e82011-10-05 21:35:46 +000030
Daniel Malea93aec0f2012-11-23 21:59:29 +000031 @expectedFailureLinux # bugzilla 14416
Johnny Chen6cc60e82011-10-05 21:35:46 +000032 @python_api_test
Johnny Chen24086bc2012-04-06 19:54:10 +000033 @dwarf_test
Johnny Chen01a67862011-10-14 00:42:25 +000034 def test_set_watch_ignore_count_with_dwarf(self):
35 """Test SBWatchpoint.SetIgnoreCount() API."""
Johnny Chen6cc60e82011-10-05 21:35:46 +000036 self.buildDwarf()
Johnny Chen01a67862011-10-14 00:42:25 +000037 self.do_watchpoint_ignore_count()
Johnny Chen6cc60e82011-10-05 21:35:46 +000038
Johnny Chen01a67862011-10-14 00:42:25 +000039 def do_watchpoint_ignore_count(self):
40 """Test SBWatchpoint.SetIgnoreCount() API."""
Johnny Chen6cc60e82011-10-05 21:35:46 +000041 exe = os.path.join(os.getcwd(), "a.out")
42
43 # Create a target by the debugger.
44 target = self.dbg.CreateTarget(exe)
45 self.assertTrue(target, VALID_TARGET)
46
47 # Create a breakpoint on main.c in order to set our watchpoint later.
48 breakpoint = target.BreakpointCreateByLocation(self.source, self.line)
49 self.assertTrue(breakpoint and
50 breakpoint.GetNumLocations() == 1,
51 VALID_BREAKPOINT)
52
53 # Now launch the process, and do not stop at the entry point.
54 process = target.LaunchSimple(None, None, os.getcwd())
55
56 # We should be stopped due to the breakpoint. Get frame #0.
57 process = target.GetProcess()
58 self.assertTrue(process.GetState() == lldb.eStateStopped,
59 PROCESS_STOPPED)
60 thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint)
61 frame0 = thread.GetFrameAtIndex(0)
62
63 # Watch 'global' for read and write.
Johnny Chen01a67862011-10-14 00:42:25 +000064 value = frame0.FindValue('global', lldb.eValueTypeVariableGlobal)
Johnny Chenb90827e2012-06-04 23:19:54 +000065 error = lldb.SBError();
66 watchpoint = value.Watch(True, True, True, error)
Johnny Chen01a67862011-10-14 00:42:25 +000067 self.assertTrue(value and watchpoint,
68 "Successfully found the variable and set a watchpoint")
Johnny Chen6cc60e82011-10-05 21:35:46 +000069 self.DebugSBValue(value)
70
71 # Hide stdout if not running with '-t' option.
72 if not self.TraceOn():
73 self.HideStdout()
74
75 # There should be only 1 watchpoint location under the target.
Johnny Chen01a67862011-10-14 00:42:25 +000076 self.assertTrue(target.GetNumWatchpoints() == 1)
77 watchpoint = target.GetWatchpointAtIndex(0)
78 self.assertTrue(watchpoint.IsEnabled())
79 self.assertTrue(watchpoint.GetIgnoreCount() == 0)
80 watch_id = watchpoint.GetID()
Johnny Chen6cc60e82011-10-05 21:35:46 +000081 self.assertTrue(watch_id != 0)
Johnny Chen01a67862011-10-14 00:42:25 +000082 print watchpoint
Johnny Chen6cc60e82011-10-05 21:35:46 +000083
84 # Now immediately set the ignore count to 2. When we continue, expect the
85 # inferior to run to its completion without stopping due to watchpoint.
Johnny Chen01a67862011-10-14 00:42:25 +000086 watchpoint.SetIgnoreCount(2)
87 print watchpoint
Johnny Chen6cc60e82011-10-05 21:35:46 +000088 process.Continue()
89
90 # At this point, the inferior process should have exited.
91 self.assertTrue(process.GetState() == lldb.eStateExited, PROCESS_EXITED)
92
93 # Verify some vital statistics.
Johnny Chen01a67862011-10-14 00:42:25 +000094 self.assertTrue(watchpoint)
95 self.assertTrue(watchpoint.GetWatchSize() == 4)
96 self.assertTrue(watchpoint.GetHitCount() == 2)
97 print watchpoint
Johnny Chen6cc60e82011-10-05 21:35:46 +000098
99
100if __name__ == '__main__':
101 import atexit
102 lldb.SBDebugger.Initialize()
103 atexit.register(lambda: lldb.SBDebugger.Terminate())
104 unittest2.main()