aboutsummaryrefslogtreecommitdiff
path: root/lldb/test/API/python_api
diff options
context:
space:
mode:
authorJim Ingham <jingham@apple.com>2023-02-28 17:14:46 -0800
committerJim Ingham <jingham@apple.com>2023-02-28 17:34:49 -0800
commita92f7832f35c6c4792d8693e724c19802da75b36 (patch)
tree5f5923b4d91e2be659aa6bf4ca739947dd6618ab /lldb/test/API/python_api
parent740e2e908ca49118a6e1f27e380dbb3665a99cc8 (diff)
downloadllvm-a92f7832f35c6c4792d8693e724c19802da75b36.zip
llvm-a92f7832f35c6c4792d8693e724c19802da75b36.tar.gz
llvm-a92f7832f35c6c4792d8693e724c19802da75b36.tar.bz2
Fix the run locker setting for async launches that don't stop at the
initial stop. The code was using PrivateResume when it should have used Resume. This was allowing expression evaluation while the target was running, and though that was caught a litle later on, we should never have gotten that far. To make sure that this is caught immediately I made an error SBValue when this happens, and test that we get this error. Differential Revision: https://reviews.llvm.org/D144665
Diffstat (limited to 'lldb/test/API/python_api')
-rw-r--r--lldb/test/API/python_api/run_locker/Makefile4
-rw-r--r--lldb/test/API/python_api/run_locker/TestRunLocker.py89
-rw-r--r--lldb/test/API/python_api/run_locker/main.c15
3 files changed, 108 insertions, 0 deletions
diff --git a/lldb/test/API/python_api/run_locker/Makefile b/lldb/test/API/python_api/run_locker/Makefile
new file mode 100644
index 0000000..695335e
--- /dev/null
+++ b/lldb/test/API/python_api/run_locker/Makefile
@@ -0,0 +1,4 @@
+C_SOURCES := main.c
+CFLAGS_EXTRAS := -std=c99
+
+include Makefile.rules
diff --git a/lldb/test/API/python_api/run_locker/TestRunLocker.py b/lldb/test/API/python_api/run_locker/TestRunLocker.py
new file mode 100644
index 0000000..191400d
--- /dev/null
+++ b/lldb/test/API/python_api/run_locker/TestRunLocker.py
@@ -0,0 +1,89 @@
+"""
+Test that the run locker really does work to keep
+us from running SB API that should only be run
+while stopped. This test is mostly concerned with
+what happens between launch and first stop.
+"""
+
+import lldb
+import lldbsuite.test.lldbutil as lldbutil
+from lldbsuite.test.lldbtest import *
+
+
+class TestRunLocker(TestBase):
+
+ NO_DEBUG_INFO_TESTCASE = True
+
+ def test_run_locker(self):
+ """Test that the run locker is set correctly when we launch"""
+ self.build()
+ self.runlocker_test(False)
+
+ def test_run_locker_stop_at_entry(self):
+ """Test that the run locker is set correctly when we launch"""
+ self.build()
+ self.runlocker_test(False)
+
+ def setUp(self):
+ # Call super's setUp().
+ TestBase.setUp(self)
+ self.main_source_file = lldb.SBFileSpec("main.c")
+
+ def runlocker_test(self, stop_at_entry):
+ """The code to stop at entry handles events slightly differently, so
+ we test both versions of process launch."""
+
+ target = lldbutil.run_to_breakpoint_make_target(self)
+
+ launch_info = target.GetLaunchInfo()
+ if stop_at_entry:
+ flags = launch_info.GetFlags()
+ launch_info.SetFlags(flags | lldb.eLaunchFlagStopAtEntry)
+
+ error = lldb.SBError()
+ # We are trying to do things when the process is running, so
+ # we have to run the debugger asynchronously.
+ self.dbg.SetAsync(True)
+
+ listener = lldb.SBListener("test-run-lock-listener")
+ launch_info.SetListener(listener)
+ process = target.Launch(launch_info, error)
+ self.assertSuccess(error, "Launched the process")
+
+ event = lldb.SBEvent()
+
+ event_result = listener.WaitForEvent(10, event)
+ self.assertTrue(event_result, "timed out waiting for launch")
+ state_type = lldb.SBProcess.GetStateFromEvent(event)
+ # We don't always see a launching...
+ if state_type == lldb.eStateLaunching:
+ event_result = listener.WaitForEvent(10, event)
+ self.assertTrue(event_result, "Timed out waiting for running after launching")
+ state_type = lldb.SBProcess.GetStateFromEvent(event)
+
+ self.assertState(state_type, lldb.eStateRunning, "Didn't get a running event")
+
+ # We aren't checking the entry state, but just making sure
+ # the running state is set properly if we continue in this state.
+
+ if stop_at_entry:
+ event_result = listener.WaitForEvent(10, event)
+ self.assertTrue(event_result, "Timed out waiting for stop at entry stop")
+ state_type = lldb.SBProcess.GetStateFromEvent(event)
+ self.assertState(state_type, eStateStopped, "Stop at entry stopped")
+ process.Continue()
+
+ # Okay, now the process is running, make sure we can't do things
+ # you aren't supposed to do while running, and that we get some
+ # actual error:
+ val = target.EvaluateExpression("SomethingToCall()")
+ error = val.GetError()
+ self.assertTrue(error.Fail(), "Failed to run expression")
+ print(f"Got Error: {error.GetCString()}")
+ self.assertIn("can't evaluate expressions when the process is running", error.GetCString(), "Stopped by stop locker")
+
+ # This should also fail if we try to use the script interpreter directly:
+ interp = self.dbg.GetCommandInterpreter()
+ result = lldb.SBCommandReturnObject()
+ ret = interp.HandleCommand("script var = lldb.frame.EvaluateExpression('SomethingToCall()'); var.GetError().GetCString()", result)
+ self.assertIn("can't evaluate expressions when the process is running", result.GetOutput())
diff --git a/lldb/test/API/python_api/run_locker/main.c b/lldb/test/API/python_api/run_locker/main.c
new file mode 100644
index 0000000..2cdb68c
--- /dev/null
+++ b/lldb/test/API/python_api/run_locker/main.c
@@ -0,0 +1,15 @@
+#include <unistd.h>
+
+int
+SomethingToCall() {
+ return 100;
+}
+
+int
+main()
+{
+ while (1) {
+ sleep(1);
+ }
+ return SomethingToCall();
+}