2 Test watchpoint condition API.
5 from __future__ import print_function
11 from lldbsuite.test.decorators import *
12 from lldbsuite.test.lldbtest import *
13 from lldbsuite.test import lldbutil
15 class WatchpointConditionAPITestCase(TestBase):
17 mydir = TestBase.compute_mydir(__file__)
20 # Call super's setUp().
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}
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)
41 # Create a target by the debugger.
42 target = self.dbg.CreateTarget(exe)
43 self.assertTrue(target, VALID_TARGET)
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,
51 # Now launch the process, and do not stop at the entry point.
52 process = target.LaunchSimple (None, None, self.get_process_working_directory())
54 # We should be stopped due to the breakpoint. Get frame #0.
55 process = target.GetProcess()
56 self.assertTrue(process.GetState() == lldb.eStateStopped,
58 thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint)
59 frame0 = thread.GetFrameAtIndex(0)
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)
69 # Now set the condition as "global==5".
70 watchpoint.SetCondition('global==5')
71 self.expect(watchpoint.GetCondition(), exe=False,
72 startstr = 'global==5')
74 # Hide stdout if not running with '-t' option.
75 if not self.TraceOn():
80 # Continue. Expect the program to stop due to the variable being written to.
84 lldbutil.print_stacktraces(process)
86 thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonWatchpoint)
87 self.assertTrue(thread, "The thread stopped due to watchpoint")
88 self.DebugSBValue(value)
90 # Verify that the condition is met.
91 self.assertTrue(value.GetValueAsUnsigned() == 5)