I want to debug a child process of Vim using a debugger like lldb. These
debuggers use ptrace. ptrace has the effect of reparenting the process.

This reparenting of Vim's child processes confuses Vim. mch_job_status
calls waitpid to detect whether the child process is alive or not, but
waitpid returns -1 (ECHILD) for these ptrace-reparented processes.

Teach Vim to check if the process is really alive using the kill
syscall with signal 0. If it is alive with another parent, treat the job
as still running.
---
 src/os_unix.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git src/os_unix.c src/os_unix.c
index 0dfbd4977..0d587d812 100644
--- src/os_unix.c
+++ src/os_unix.c
@@ -5863,10 +5863,18 @@ mch_job_status(job_T *job)
 # endif
     if (wait_pid == -1)
     {
+       int waitpid_error = errno;
+       if (mch_process_running(job->jv_pid))
+       {
+               // The process is alive, but it was reparented (for example by
+               // ptrace called by a debugger like lldb or gdb).
+               // HACK(strager): This assumes that process IDs are not reused.
+               return "run";
+       }
        // process must have exited
        if (job->jv_status < JOB_ENDED)
            ch_log(job->jv_channel, "Job no longer exists: %s",
-                                                             strerror(errno));
+                                                             
strerror(waitpid_error));
        goto return_dead;
     }
     if (wait_pid == 0)
-- 
2.33.1

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/aWPOU9xSPwy-SaIAy1zLY4kM1NnkWe-0K3RBBmEGS--AqJj2y_hzOGvgnvTvNpkdriCrDFI4gVEfYaPwRbe742JzjY2MTh5w1vLRnRGfdbI%3D%40strager.net.

Attachment: 0001-fix-mch_job_status-giving-wrong-answer-for-ptraced-p.patch
Description: Binary data

Raspunde prin e-mail lui