[AMDGPU] Add True16 register classes.
[llvm-project.git] / lldb / test / API / python_api / watchpoint / condition / TestWatchpointConditionAPI.py
blob5de75834e73b69c68d44f2bda5190236fc7f3049
1 """
2 Test watchpoint condition API.
3 """
5 import lldb
6 from lldbsuite.test.decorators import *
7 from lldbsuite.test.lldbtest import *
8 from lldbsuite.test import lldbutil
11 class WatchpointConditionAPITestCase(TestBase):
12 NO_DEBUG_INFO_TESTCASE = True
14 def setUp(self):
15 # Call super's setUp().
16 TestBase.setUp(self)
17 # Our simple source filename.
18 self.source = "main.cpp"
19 # Find the line number to break inside main().
20 self.line = line_number(self.source, "// Set break point at this line.")
21 # And the watchpoint variable declaration line number.
22 self.decl = line_number(self.source, "// Watchpoint variable declaration.")
23 # Build dictionary to have unique executable names for each test
24 # method.
25 self.exe_name = self.testMethodName
26 self.d = {"CXX_SOURCES": self.source, "EXE": self.exe_name}
28 def test_watchpoint_cond_api(self):
29 """Test watchpoint condition API."""
30 self.build(dictionary=self.d)
31 self.setTearDownCleanup(dictionary=self.d)
32 exe = self.getBuildArtifact(self.exe_name)
34 # Create a target by the debugger.
35 target = self.dbg.CreateTarget(exe)
36 self.assertTrue(target, VALID_TARGET)
38 # Now create a breakpoint on main.c.
39 breakpoint = target.BreakpointCreateByLocation(self.source, self.line)
40 self.assertTrue(
41 breakpoint and breakpoint.GetNumLocations() == 1, VALID_BREAKPOINT
44 # Now launch the process, and do not stop at the entry point.
45 process = target.LaunchSimple(None, None, self.get_process_working_directory())
47 # We should be stopped due to the breakpoint. Get frame #0.
48 process = target.GetProcess()
49 self.assertState(process.GetState(), lldb.eStateStopped, PROCESS_STOPPED)
50 thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint)
51 frame0 = thread.GetFrameAtIndex(0)
53 # Watch 'global' for write.
54 value = frame0.FindValue("global", lldb.eValueTypeVariableGlobal)
55 error = lldb.SBError()
56 watchpoint = value.Watch(True, False, True, error)
57 self.assertTrue(
58 value and watchpoint, "Successfully found the variable and set a watchpoint"
60 self.DebugSBValue(value)
62 # Now set the condition as "global==5".
63 watchpoint.SetCondition("global==5")
64 self.expect(watchpoint.GetCondition(), exe=False, startstr="global==5")
66 # Hide stdout if not running with '-t' option.
67 if not self.TraceOn():
68 self.HideStdout()
70 print(watchpoint)
72 # Continue. Expect the program to stop due to the variable being
73 # written to.
74 process.Continue()
76 if self.TraceOn():
77 lldbutil.print_stacktraces(process)
79 thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonWatchpoint)
80 self.assertTrue(thread, "The thread stopped due to watchpoint")
81 self.DebugSBValue(value)
83 # Verify that the condition is met.
84 self.assertEqual(value.GetValueAsUnsigned(), 5)