]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - packages/Python/lldbsuite/test/python_api/watchpoint/TestWatchpointIgnoreCount.py
Vendor import of lldb trunk r351319 (just before the release_80 branch
[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 import os
9 import 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
17 class WatchpointIgnoreCountTestCase(TestBase):
18
19     mydir = TestBase.compute_mydir(__file__)
20
21     def setUp(self):
22         # Call super's setUp().
23         TestBase.setUp(self)
24         # Our simple source filename.
25         self.source = 'main.c'
26         # Find the line number to break inside main().
27         self.line = line_number(
28             self.source, '// Set break point at this line.')
29
30     @add_test_categories(['pyapi'])
31     @expectedFailureAll(
32         oslist=["windows"],
33         bugnumber="llvm.org/pr24446: WINDOWS XFAIL TRIAGE - Watchpoints not supported on Windows")
34     # Read-write watchpoints not supported on SystemZ
35     @expectedFailureAll(archs=['s390x'])
36     def test_set_watch_ignore_count(self):
37         """Test SBWatchpoint.SetIgnoreCount() API."""
38         self.build()
39         exe = self.getBuildArtifact("a.out")
40
41         # Create a target by the debugger.
42         target = self.dbg.CreateTarget(exe)
43         self.assertTrue(target, VALID_TARGET)
44
45         # Create a breakpoint on main.c in order to set our watchpoint later.
46         breakpoint = target.BreakpointCreateByLocation(self.source, self.line)
47         self.assertTrue(breakpoint and
48                         breakpoint.GetNumLocations() == 1,
49                         VALID_BREAKPOINT)
50
51         # Now launch the process, and do not stop at the entry point.
52         process = target.LaunchSimple(
53             None, None, self.get_process_working_directory())
54
55         # We should be stopped due to the breakpoint.  Get frame #0.
56         process = target.GetProcess()
57         self.assertEqual(process.GetState(), lldb.eStateStopped,
58                         PROCESS_STOPPED)
59         thread = lldbutil.get_stopped_thread(
60             process, lldb.eStopReasonBreakpoint)
61         frame0 = thread.GetFrameAtIndex(0)
62
63         # Watch 'global' for read and write.
64         value = frame0.FindValue('global', lldb.eValueTypeVariableGlobal)
65         error = lldb.SBError()
66         watchpoint = value.Watch(True, True, True, error)
67         self.assertTrue(value and watchpoint,
68                         "Successfully found the variable and set a watchpoint")
69         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.
76         self.assertEqual(target.GetNumWatchpoints(), 1)
77         watchpoint = target.GetWatchpointAtIndex(0)
78         self.assertTrue(watchpoint.IsEnabled())
79         self.assertEqual(watchpoint.GetIgnoreCount(), 0)
80         watch_id = watchpoint.GetID()
81         self.assertNotEqual(watch_id, 0)
82         print(watchpoint)
83
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.
86         watchpoint.SetIgnoreCount(2)
87         print(watchpoint)
88         process.Continue()
89
90         # At this point, the inferior process should have exited.
91         self.assertEqual(process.GetState(), lldb.eStateExited, PROCESS_EXITED)
92
93         # Verify some vital statistics.
94         self.assertTrue(watchpoint)
95         self.assertEqual(watchpoint.GetWatchSize(), 4)
96         self.assertEqual(watchpoint.GetHitCount(), 2)
97         print(watchpoint)