[resend, not sure if this got through the first time]

> 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)

I suppose this is useful.

I wonder if we should check if errno is ECHILD, just to be safe.
Ah, you added that in the second version of the patch.

-- 
hundred-and-one symptoms of being an internet addict:
220. Your wife asks for sex and you tell her where to find you on IRC.

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///                                                                      \\\
\\\        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
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/20230307155832.ECB5F1C0354%40moolenaar.net.

Raspunde prin e-mail lui