]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - packages/Python/lldbsuite/test/python_api/watchpoint/TestWatchpointIter.py
Vendor import of lldb release_39 branch r276489:
[FreeBSD/FreeBSD.git] / packages / Python / lldbsuite / test / python_api / watchpoint / TestWatchpointIter.py
1 """
2 Use lldb Python SBTarget API to iterate on the watchpoint(s) for the target.
3 """
4
5 from __future__ import print_function
6
7
8
9 import os
10 import re
11 import time
12
13 import lldb
14 from lldbsuite.test.decorators import *
15 from lldbsuite.test.lldbtest import *
16 from lldbsuite.test import lldbutil
17
18 class WatchpointIteratorTestCase(TestBase):
19
20     mydir = TestBase.compute_mydir(__file__)
21
22     def setUp(self):
23         # Call super's setUp().
24         TestBase.setUp(self)
25         # Our simple source filename.
26         self.source = 'main.c'
27         # Find the line number to break inside main().
28         self.line = line_number(self.source, '// Set break point at this line.')
29
30     @add_test_categories(['pyapi'])
31     @expectedFailureAndroid(archs=['arm', 'aarch64']) # Watchpoints not supported
32     @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24446: WINDOWS XFAIL TRIAGE - Watchpoints not supported on Windows")
33     def test_watch_iter(self):
34         """Exercise SBTarget.watchpoint_iter() API to iterate on the available watchpoints."""
35         self.build()
36         exe = os.path.join(os.getcwd(), "a.out")
37
38         # Create a target by the debugger.
39         target = self.dbg.CreateTarget(exe)
40         self.assertTrue(target, VALID_TARGET)
41
42         # Create a breakpoint on main.c in order to set our watchpoint later.
43         breakpoint = target.BreakpointCreateByLocation(self.source, self.line)
44         self.assertTrue(breakpoint and
45                         breakpoint.GetNumLocations() == 1,
46                         VALID_BREAKPOINT)
47
48         # Now launch the process, and do not stop at the entry point.
49         process = target.LaunchSimple (None, None, self.get_process_working_directory())
50
51         # We should be stopped due to the breakpoint.  Get frame #0.
52         process = target.GetProcess()
53         self.assertTrue(process.GetState() == lldb.eStateStopped,
54                         PROCESS_STOPPED)
55         thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint)
56         frame0 = thread.GetFrameAtIndex(0)
57
58         # Watch 'global' for read and write.
59         value = frame0.FindValue('global', lldb.eValueTypeVariableGlobal)
60         error = lldb.SBError();
61         watchpoint = value.Watch(True, False, True, error)
62         self.assertTrue(value and watchpoint,
63                         "Successfully found the variable and set a watchpoint")
64         self.DebugSBValue(value)
65
66         # Hide stdout if not running with '-t' option.
67         if not self.TraceOn():
68             self.HideStdout()
69
70         # There should be only 1 watchpoint location under the target.
71         self.assertTrue(target.GetNumWatchpoints() == 1)
72         self.assertTrue(watchpoint.IsEnabled())
73         watch_id = watchpoint.GetID()
74         self.assertTrue(watch_id != 0)
75
76         # Continue.  Expect the program to stop due to the variable being written to.
77         process.Continue()
78
79         # Hide stdout if not running with '-t' option.
80         if not self.TraceOn():
81             self.HideStdout()
82
83         # Print the stack traces.
84         lldbutil.print_stacktraces(process)
85
86         thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonWatchpoint)
87         self.assertTrue(thread, "The thread stopped due to watchpoint")
88         self.DebugSBValue(value)
89
90         # We currently only support hardware watchpoint.  Verify that we have a
91         # meaningful hardware index at this point.  Exercise the printed repr of
92         # SBWatchpointLocation.
93         print(watchpoint)
94         self.assertTrue(watchpoint.GetHardwareIndex() != -1)
95
96         # SBWatchpoint.GetDescription() takes a description level arg.
97         print(lldbutil.get_description(watchpoint, lldb.eDescriptionLevelFull))
98
99         # Now disable the 'rw' watchpoint.  The program won't stop when it reads
100         # 'global' next.
101         watchpoint.SetEnabled(False)
102         self.assertTrue(watchpoint.GetHardwareIndex() == -1)
103         self.assertFalse(watchpoint.IsEnabled())
104
105         # Continue.  The program does not stop again when the variable is being
106         # read from because the watchpoint location has been disabled.
107         process.Continue()
108
109         # At this point, the inferior process should have exited.
110         self.assertTrue(process.GetState() == lldb.eStateExited, PROCESS_EXITED)
111
112         # Verify some vital statistics and exercise the iterator API.
113         for watchpoint in target.watchpoint_iter():
114             self.assertTrue(watchpoint)
115             self.assertTrue(watchpoint.GetWatchSize() == 4)
116             self.assertTrue(watchpoint.GetHitCount() == 1)
117             print(watchpoint)
118