[Lldb-commits] [lldb] Fix a bug with cancelling "attach -w" after you have run a process previously (PR #65822)
via lldb-commits
lldb-commits at lists.llvm.org
Fri Sep 8 17:11:23 PDT 2023
================
@@ -127,3 +128,61 @@ def tearDown(self):
# Call super's tearDown().
TestBase.tearDown(self)
+
+ def test_run_then_attach_wait_interrupt(self):
+ # Test that having run one process doesn't cause us to be unable
+ # to interrupt a subsequent attach attempt.
+ self.build()
+ exe = self.getBuildArtifact(exe_name)
+
+ target = lldbutil.run_to_breakpoint_make_target(self, exe_name, True)
+ launch_info = target.GetLaunchInfo()
+ launch_info.SetArguments(["q"], True)
+ error = lldb.SBError()
+ target.Launch(launch_info, error)
+ self.assertSuccess(error, "Launched a process")
+ self.assertState(target.process.state, lldb.eStateExited, "and it exited.")
+
+ # Okay now we've run a process, try to attach/wait to something
+ # and make sure that we can interrupt that.
+
+ options = lldb.SBCommandInterpreterRunOptions()
+ options.SetPrintResults(True)
+ options.SetEchoCommands(False)
+
+ self.stdin_path = self.getBuildArtifact("stdin.txt")
+
+ with open(self.stdin_path, "w") as input_handle:
+ input_handle.write("process attach -w -n noone_would_use_this_name\nquit")
+
+ # Python will close the file descriptor if all references
+ # to the filehandle object lapse, so we need to keep one
+ # around.
+ self.filehandle = open(self.stdin_path, "r")
+ self.dbg.SetInputFileHandle(self.filehandle, False)
+
+ # No need to track the output
+ self.stdout_path = self.getBuildArtifact("stdout.txt")
+ self.out_filehandle = open(self.stdout_path, "w")
+ self.dbg.SetOutputFileHandle(self.out_filehandle, False)
+ self.dbg.SetErrorFileHandle(self.out_filehandle, False)
+
+ n_errors, quit_req, crashed = self.dbg.RunCommandInterpreter(
+ True, True, options, 0, False, False)
+
+ time.sleep(5)
----------------
jimingham wrote:
I'm waiting for the "process attach -w -n no-such-process" to start running. There's really no external sign for that.
If all processes had to go through gdb-remote, I could turn on the gdb-remote log and wait till I saw `vAttach` come by? But otherwise there's no external sign the command has asked debugserver to wait for process launch, but nothing else has happened yet - the point of the test is that the attach is never going to succeed...
But all we're doing is starting up a debugserver and sending it a vAttach, so that shouldn't be all the variable in time.
https://github.com/llvm/llvm-project/pull/65822
More information about the lldb-commits
mailing list