]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - packages/Python/lldbsuite/test/python_api/watchpoint/condition/TestWatchpointConditionAPI.py
Vendor import of lldb release_39 branch r276489:
[FreeBSD/FreeBSD.git] / packages / Python / lldbsuite / test / python_api / watchpoint / condition / TestWatchpointConditionAPI.py
1 """
2 Test watchpoint condition API.
3 """
4
5 from __future__ import print_function
6
7
8
9 import os, time
10 import lldb
11 from lldbsuite.test.decorators import *
12 from lldbsuite.test.lldbtest import *
13 from lldbsuite.test import lldbutil
14
15 class WatchpointConditionAPITestCase(TestBase):
16
17     mydir = TestBase.compute_mydir(__file__)
18
19     def setUp(self):
20         # Call super's setUp().
21         TestBase.setUp(self)
22         # Our simple source filename.
23         self.source = 'main.cpp'
24         # Find the line number to break inside main().
25         self.line = line_number(self.source, '// Set break point at this line.')
26         # And the watchpoint variable declaration line number.
27         self.decl = line_number(self.source, '// Watchpoint variable declaration.')
28         # Build dictionary to have unique executable names for each test method.
29         self.exe_name = self.testMethodName
30         self.d = {'CXX_SOURCES': self.source, 'EXE': self.exe_name}
31
32     @expectedFailureAndroid(archs=['arm', 'aarch64']) # Watchpoints not supported
33     @expectedFailureAll(oslist=["linux"], archs=["aarch64"], bugnumber="llvm.org/pr27710")
34     @skipIfWindows # Watchpoints not supported on Windows, and this test hangs
35     def test_watchpoint_cond_api(self):
36         """Test watchpoint condition API."""
37         self.build(dictionary=self.d)
38         self.setTearDownCleanup(dictionary=self.d)
39         exe = os.path.join(os.getcwd(), self.exe_name)
40
41         # Create a target by the debugger.
42         target = self.dbg.CreateTarget(exe)
43         self.assertTrue(target, VALID_TARGET)
44
45         # Now create a breakpoint on main.c.
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 (None, None, self.get_process_working_directory())
53
54         # We should be stopped due to the breakpoint.  Get frame #0.
55         process = target.GetProcess()
56         self.assertTrue(process.GetState() == lldb.eStateStopped,
57                         PROCESS_STOPPED)
58         thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint)
59         frame0 = thread.GetFrameAtIndex(0)
60
61         # Watch 'global' for write.
62         value = frame0.FindValue('global', lldb.eValueTypeVariableGlobal)
63         error = lldb.SBError();
64         watchpoint = value.Watch(True, False, True, error)
65         self.assertTrue(value and watchpoint,
66                         "Successfully found the variable and set a watchpoint")
67         self.DebugSBValue(value)
68
69         # Now set the condition as "global==5".
70         watchpoint.SetCondition('global==5')
71         self.expect(watchpoint.GetCondition(), exe=False,
72             startstr = 'global==5')
73
74         # Hide stdout if not running with '-t' option.
75         if not self.TraceOn():
76             self.HideStdout()
77
78         print(watchpoint)
79
80         # Continue.  Expect the program to stop due to the variable being written to.
81         process.Continue()
82
83         if (self.TraceOn()):
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         # Verify that the condition is met.
91         self.assertTrue(value.GetValueAsUnsigned() == 5)