From: charles@aurox.ch (Charles A. Roelli)
To: Sung Ho Kim <sk6875@gmail.com>
Cc: 28544@debbugs.gnu.org
Subject: bug#28544: 26.0.50; emacs will consume 100% cpu after gdb debugee exits
Date: Sun, 26 Nov 2017 15:17:43 +0100 [thread overview]
Message-ID: <m2h8thdszc.fsf@aurox.ch> (raw)
In-Reply-To: <m27ewuqdfa.fsf@dana.local.i-did-not-set--mail-host-address--so-tickle-me> (message from Sung Ho Kim on Wed, 20 Sep 2017 12:03:37 +0900)
> From: Sung Ho Kim <sk6875@gmail.com>
> Date: Wed, 20 Sep 2017 12:03:37 +0900
>
> First time using the bug report system, so apologies in advance if the
> report feels muddled.
>
> The procedure I had used is as follows:
> 1) open emacs [-Q] [-nw]
> N.B. the option flags -Q -nw do not make any difference in the
> behavior described.
> 2) run gdb using M-x gdb ( I have tested gdb 7.12 and 8.0, 8.0.1 and
> even earlier versions but gdb version do not seem to make any difference)
> 3) open any executable binary for debugging.
> 4) continue, step, next or run until binary in step (3) finishes
> execution and exits (whether it exits normally or abnormally does not
> make a difference)
> 5) open top and watch emacs cpu usage.
>
> What I have noticed with a little bit of debugging and looking at the
> emacs source code is that in process.c in about line 5660 (thankfully
> process.c receives very little changes recently so the line number
> should be approximately accurate) you see the following code:
> -------------------------------------------------------------------
> /* If we can detect process termination, don't consider the
> process gone just because its pipe is closed. */
> else if (nread == 0 && !NETCONN_P (proc) && !SERIALCONN_P (proc)
> && !PIPECONN_P (proc))
> -------------------------------------------------------------------
> This if clause becomes true when the debugee exits in Mac OS Sierra
> (10.12.6, BuildVersion 16G29, Darwin Kernel Version 16.7.0) and since
> nothing is done about the read file descriptor (proc's infd, outfd,
> channel) this results in an infinite loop where thread_select keeps
> returning nfds = 1 but the subsequent read operation will not return an
> error (i.e. nread will never be < 0) and nread will always be 0. I feel
> this infinite loop is the cause of the 100% cpu usage behavior.
>
> To test this theory, I added the same code used in the
> (nread == -1 && errno == EIO) condition to the
> (nread == 0 && !NETCONN_P (proc) && !SERIALCONN_P (proc) && !PIPECONN_P(proc))
> condition to remove the target file descriptor when this condition is
> encountered as such:
>
> else if (nread == 0 && !NETCONN_P (proc) && !SERIALCONN_P (proc)
> && !PIPECONN_P (proc))
> #ifdef DARWIN_OS
> {
> struct Lisp_Process *p = XPROCESS (proc);
>
> /* Clear the descriptor now, so we only raise the
> signal once. */
> delete_read_fd (channel);
>
> if (p->pid == -2)
> {
> /* If the EIO occurs on a pty, the SIGCHLD handler's
> waitpid call will not find the process object to
> delete. Do it here. */
> p->tick = ++process_tick;
> pset_status (p, Qfailed);
> }
> }
> #else
> ;
> #endif /* DARWIN_OS */
>
> after rebuilding with the aforementioned change, the 100% cpu usage
> disappears. I have refrained from offering a patch because I am not
> fully knowledgeable with the code and its possible side effects.
>
> Thank you for your patience and your great work developing this great OS.
>
>
> In GNU Emacs 26.0.50 (build 2, x86_64-apple-darwin16.7.0)
> of 2017-09-20 built on dana.local
Thanks a lot for investigating this problem. It also happens on macOS
10.6, and your change fixes it. Not knowing much about this part of
Emacs myself, I hope somebody can review your change soon.
next prev parent reply other threads:[~2017-11-26 14:17 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-20 3:03 bug#28544: 26.0.50; emacs will consume 100% cpu after gdb debugee exits Sung Ho Kim
2017-11-26 14:17 ` Charles A. Roelli [this message]
2020-08-16 16:46 ` Lars Ingebrigtsen
2020-11-24 8:43 ` bug#28544: [macOS] " Lars Ingebrigtsen
[not found] <mailman.907.1506017889.14750.bug-gnu-emacs@gnu.org>
2017-10-28 14:10 ` bug#28544: 26.0.50; " sk6875
2017-10-28 17:02 ` Eli Zaretskii
[not found] ` <mailman.2406.1509210248.27995.bug-gnu-emacs@gnu.org>
2017-10-28 21:52 ` sk6875
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m2h8thdszc.fsf@aurox.ch \
--to=charles@aurox.ch \
--cc=28544@debbugs.gnu.org \
--cc=sk6875@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).