Subject: Re: bug#14333: 24.3.50; Emacs hangs when trying to exit

From: Eli Zaretskii <[email-masked]>
Date: Thu, 09 May 2013 18:53:04 +0300

> Date: Thu, 9 May 2013 11:09:11 +0200
> From: Dani Moncayo <[email-masked]>
> Cc: [email-masked]
> 
> So, it seems it is not possible to attach gdb to the hanged Emacs
> session.   Is there another way of tracking down the problem?

I hope so.  See below.

> For example, I could add some sentences at the C level, which write
> information to some log file.  If this is a good idea, just send me
> the patch I should apply.

I don't know yet what to write and where.  We need more information
about the problem.

I can think about 2 methods to gain more info:

 1) Attach GDB before you exit Emacs, while Emacs still runs.
    Hopefully, it will attach cleanly.  Then:

     (gdb) break shut_down_emacs
     (gdb) continue

    Now exit Emacs as usual.  GDB will kick in and stop Emacs inside
    shut_down_emacs.  Step through that function (with "next") and see
    which call doesn't return.  Then try the same again in another
    session, but now step into the function that didn't return, and
    step through that, again looking for some sub-function that
    doesn't return.  Etc., etc., until you find which system call
    doesn't return, or maybe some Emacs code that infloops for some
    reason.

 2) Download and install the latest version of Process Explorer from
    SysInternals.

    Start Process Explorer and find the line showing the running Emacs
    (before you exit it).  Right-click on that line, and select
    "Properties".  In the window that pops up, click on the "Threads"
    tab.  You should see several threads that belong to Emacs.

    Now exit Emacs.  Every thread that exits should have its line
    highlighted by a red background.  Normally, they all exit, so they
    all become red.  I suspect that in your case, some of them will
    not exit.  If so, click on the line of that thread, and tell what
    is its State as shown below the thread list.

    Next, click the entry of the thread that didn't exit, and push the
    "Stack" button below the thread list.  This should pop up another
    window with the call stack addresses.  Press "Copy All" and then
    paste into some file.  Repeat this for every thread that did not
    exit.

    Now start GDB on the Emacs binary:

       gdb emacs.exe

    and translate the call stack addresses into source lines like
    this:

      (gdb) list *0xNNNNNNN

    where NNNNNNN is the address you see in the call stack after
    "emacs+", to which you need to add 0x1000000.  For example, if you
    see emacs+0x19f93, type

      (gdb) list *0x1019f93

    This should show a small number of source lines around the line
    that corresponds to the address.  The top-most address of the form
    emacs+0xNNNN that you find in the call stack of each thread that
    didn't exit is the most important one -- it tells where that
    thread is stuck.

    Alternatively, you can use addr2line to convert addresses to
    source line numbers; once again, you will need to add 0x1000000 to
    each address displayed by the Process Explorer.

I hope at least one of these 2 methods will allow us to determine why
Emacs hangs.