]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - packages/Python/lldbsuite/test/python_api/watchpoint/TestWatchpointIgnoreCount.py
Vendor import of lldb release_39 branch r276489:
[FreeBSD/FreeBSD.git] / packages / Python / lldbsuite / test / python_api / watchpoint / TestWatchpointIgnoreCount.py
1 """
2 Use lldb Python SBWatchpoint API to set the ignore count.
3 """
4
5 from __future__ import print_function
6
7
8
9 import os, time
10 import re
11 import lldb
12 from lldbsuite.test.decorators import *
13 from lldbsuite.test.lldbtest import *
14 from lldbsuite.test import lldbutil
15
16 class WatchpointIgnoreCountTestCase(TestBase):
17
18     mydir = TestBase.compute_mydir(__file__)
19
20     def setUp(self):
21         # Call super's setUp().
22         TestBase.setUp(self)
23         # Our simple source filename.
24         self.source = 'main.c'
25         # Find the line number to break inside main().
26         self.line = line_number(self.source, '// Set break point at this line.')
27
28     @add_test_categories(['pyapi'])
29     @expectedFailureAndroid(archs=['arm', 'aarch64']) # Watchpoints not supported
30     @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24446: WINDOWS XFAIL TRIAGE - Watchpoints not supported on Windows")
31     @expectedFailureAll(archs=['s390x']) # Read-write watchpoints not supported on SystemZ
32     def test_set_watch_ignore_count(self):
33         """Test SBWatchpoint.SetIgnoreCount() API."""
34         self.build()
35         exe = os.path.join(os.getcwd(), "a.out")
36
37         # Create a target by the debugger.
38         target = self.dbg.CreateTarget(exe)
39         self.assertTrue(target, VALID_TARGET)
40
41         # Create a breakpoint on main.c in order to set our watchpoint later.
42         breakpoint = target.BreakpointCreateByLocation(self.source, self.line)
43         self.assertTrue(breakpoint and
44                         breakpoint.GetNumLocations() == 1,
45                         VALID_BREAKPOINT)
46
47         # Now launch the process, and do not stop at the entry point.
48         process = target.LaunchSimple (None, None, self.get_process_working_directory())
49
50         # We should be stopped due to the breakpoint.  Get frame #0.
51         process = target.GetProcess()
52         self.assertTrue(process.GetState() == lldb.eStateStopped,
53                         PROCESS_STOPPED)
54         thread = lldbutil.get_stopped_thread(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.assertTrue(target.GetNumWatchpoints() == 1)
71         watchpoint = target.GetWatchpointAtIndex(0)
72         self.assertTrue(watchpoint.IsEnabled())
73         self.assertTrue(watchpoint.GetIgnoreCount() == 0)
74         watch_id = watchpoint.GetID()
75         self.assertTrue(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.assertTrue(process.GetState() == lldb.eStateExited, PROCESS_EXITED)
86
87         # Verify some vital statistics.
88         self.assertTrue(watchpoint)
89         self.assertTrue(watchpoint.GetWatchSize() == 4)
90         self.assertTrue(watchpoint.GetHitCount() == 2)
91         print(watchpoint)