Subject: Re: bug#12829: 24.3.50; emacs_abort () called from w32proc.c:1128

From: Eli Zaretskii <[email-masked]>
Date: Fri, 09 Nov 2012 21:38:08 +0200

> Date: Fri, 09 Nov 2012 18:59:43 +0000
> From: Stephen Powell <[email-masked]>
> 
> > Did this problem happen again since the original report?  If it does
> > happen from time to time, I might ask you to run Emacs under GDB
> > with a couple of breakpoints in strategic places, because usually
> > when dead_child's handle is NULL, it is too late: the evidence of
> > the crime is already forgotten.
> 
> Sure. It happens frequently but not always.

OK.  There;s only 1 place where the handle of the process is set to
NULL.  Here:

  static void
  reap_subprocess (child_process *cp)
  {
    if (cp->procinfo.hProcess)
      {
	/* Reap the process */
  #ifdef FULL_DEBUG
	/* Process should have already died before we are called.  */
	if (WaitForSingleObject (cp->procinfo.hProcess, 0) != WAIT_OBJECT_0)
	  DebPrint (("reap_subprocess: child fpr fd %d has not died yet!", cp->fd));
  #endif
	CloseHandle (cp->procinfo.hProcess);   <<<<<<<<<<<<<<<<<<<<<<<
	cp->procinfo.hProcess = NULL;

(One other place is when the process is launched, but I don't think
this is our case.)

So please put a breakpoint on this line, like this:

  (gdb) break w32proc.c:1096
  (gdb) commands
  > bt 6
  > p cp->pid
  > continue
  > end

In addition, please put a breakpoint here:

  static bool
  process_status_retrieved (pid_t desired, pid_t have, int *status)
  {
    if (have < 0)
      {
	/* Invoke waitpid only with a known process ID; do not invoke
	   waitpid with a nonpositive argument.  Otherwise, Emacs might
	   reap an unwanted process by mistake.  For example, invoking
	   waitpid (-1, ...) can mess up glib by reaping glib's subprocesses,
	   so that another thread running glib won't find them.  */
	do
	  have = waitpid (desired, status, WNOHANG | WUNTRACED);
	while (have < 0 && errno == EINTR);
      }

    return have == desired;  <<<<<<<<<<<<<<<<<<<<<<<<<<
  }

Like this:

  (gdb) process.c:6278 if have != desired
  (gdb) commands
  > p have
  > p desired
  > p status
  > continue
  > end

Then run Emacs as you normally would, and tell if these breakpoints
ever break, and if so, what do you see there.  The breakpoint commands
arrange for GDB to continue Emacs after it reports the values as
specified in the breakpoint commands.

Thanks.

> > If that GDB session is still active, can you show the entire list in
> > deleted_pid_list?  The 'pp' command should be able to display it in
> > a human-readable format.
> 
> (gdb) pp deleted_pid_list
> (5144 5412)

Interesting.  I need to think...