2 Test watchpoint condition API.
5 from __future__ import print_function
9 from lldbsuite.test.decorators import *
10 from lldbsuite.test.lldbtest import *
11 from lldbsuite.test import lldbutil
14 class WatchpointConditionAPITestCase(TestBase):
16 mydir = TestBase.compute_mydir(__file__)
17 NO_DEBUG_INFO_TESTCASE = True
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(
26 self.source, '// Set break point at this line.')
27 # And the watchpoint variable declaration line number.
28 self.decl = line_number(self.source,
29 '// Watchpoint variable declaration.')
30 # Build dictionary to have unique executable names for each test
32 self.exe_name = self.testMethodName
33 self.d = {'CXX_SOURCES': self.source, 'EXE': self.exe_name}
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 = self.getBuildArtifact(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(
53 None, None, self.get_process_working_directory())
55 # We should be stopped due to the breakpoint. Get frame #0.
56 process = target.GetProcess()
57 self.assertTrue(process.GetState() == lldb.eStateStopped,
59 thread = lldbutil.get_stopped_thread(
60 process, lldb.eStopReasonBreakpoint)
61 frame0 = thread.GetFrameAtIndex(0)
63 # Watch 'global' for write.
64 value = frame0.FindValue('global', lldb.eValueTypeVariableGlobal)
65 error = lldb.SBError()
66 watchpoint = value.Watch(True, False, True, error)
67 self.assertTrue(value and watchpoint,
68 "Successfully found the variable and set a watchpoint")
69 self.DebugSBValue(value)
71 # Now set the condition as "global==5".
72 watchpoint.SetCondition('global==5')
73 self.expect(watchpoint.GetCondition(), exe=False,
76 # Hide stdout if not running with '-t' option.
77 if not self.TraceOn():
82 # Continue. Expect the program to stop due to the variable being
87 lldbutil.print_stacktraces(process)
89 thread = lldbutil.get_stopped_thread(
90 process, lldb.eStopReasonWatchpoint)
91 self.assertTrue(thread, "The thread stopped due to watchpoint")
92 self.DebugSBValue(value)
94 # Verify that the condition is met.
95 self.assertTrue(value.GetValueAsUnsigned() == 5)