From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Chong Yidong Newsgroups: gmane.emacs.bugs Subject: bug#11273: 24.0.94; quitting gdb Date: Fri, 20 Apr 2012 10:50:52 +0800 Message-ID: <87397zw1yr.fsf@gnu.org> References: <87y5ps99xp.fsf@gnu.org> <87mx68yvlm.fsf@gnu.org> <87k41bhdn6.fsf@gnu.org> <20368.22528.385744.874377@gargle.gargle.HOWL> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: dough.gmane.org 1334890309 29390 80.91.229.3 (20 Apr 2012 02:51:49 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Fri, 20 Apr 2012 02:51:49 +0000 (UTC) Cc: sds@gnu.org, 11273@debbugs.gnu.org To: Troels Nielsen Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri Apr 20 04:51:47 2012 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1SL3wp-0007gK-DN for geb-bug-gnu-emacs@m.gmane.org; Fri, 20 Apr 2012 04:51:47 +0200 Original-Received: from localhost ([::1]:33800 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SL3wo-0007fo-RP for geb-bug-gnu-emacs@m.gmane.org; Thu, 19 Apr 2012 22:51:46 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:60879) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SL3wk-0007fd-ND for bug-gnu-emacs@gnu.org; Thu, 19 Apr 2012 22:51:44 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SL3wi-0006I2-FS for bug-gnu-emacs@gnu.org; Thu, 19 Apr 2012 22:51:42 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:42025) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SL3wi-0006Hw-C5 for bug-gnu-emacs@gnu.org; Thu, 19 Apr 2012 22:51:40 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.72) (envelope-from ) id 1SL3x3-00029o-R1 for bug-gnu-emacs@gnu.org; Thu, 19 Apr 2012 22:52:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Chong Yidong Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 20 Apr 2012 02:52:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 11273 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 11273-submit@debbugs.gnu.org id=B11273.13348902898250 (code B ref 11273); Fri, 20 Apr 2012 02:52:01 +0000 Original-Received: (at 11273) by debbugs.gnu.org; 20 Apr 2012 02:51:29 +0000 Original-Received: from localhost ([127.0.0.1]:43059 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1SL3wW-000290-ME for submit@debbugs.gnu.org; Thu, 19 Apr 2012 22:51:29 -0400 Original-Received: from fencepost.gnu.org ([208.118.235.10]:41922 ident=Debian-exim) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1SL3wU-00028r-Az for 11273@debbugs.gnu.org; Thu, 19 Apr 2012 22:51:27 -0400 Original-Received: from bb116-14-12-6.singnet.com.sg ([116.14.12.6]:35603 helo=ulysses) by fencepost.gnu.org with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1SL3w4-0005cy-IL; Thu, 19 Apr 2012 22:51:01 -0400 In-Reply-To: <20368.22528.385744.874377@gargle.gargle.HOWL> (Troels Nielsen's message of "Thu, 19 Apr 2012 20:22:56 +0200") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.95 (gnu/linux) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:59287 Archived-At: Troels Nielsen writes: > I've looked into the issue more deeply and I think my suggested patch > is most certainly wrong. The PTY somehow continously will tell select > it has data available, but when emacs_read tries to read it nothing > but an error and errno=IO is returned. Yes, apparently we have no choice but to stop reading from the pty on receiving EIO, otherwise Emacs will spin trying to read from it (that's probably the reason for the gdb-mi causing 100% CPU someone reported). I propose the following patch. On getting EIO, Emacs sets up the pty process object so that it runs its sentinel, with the `failed' process status. Then gdb-mi applies a sentinel to the inferior-io pty, and that sentinel is responsible for allocating a new pty and hooking it to gdb. If there are no objections, I will commit this shortly. === modified file 'lisp/progmodes/gdb-mi.el' *** lisp/progmodes/gdb-mi.el 2012-04-19 08:09:30 +0000 --- lisp/progmodes/gdb-mi.el 2012-04-20 02:48:54 +0000 *************** *** 817,827 **** nil 'local) (local-set-key "\C-i" 'completion-at-point) - ;; FIXME: Under some circumstances, `gud-sentinel' apparently does - ;; not get called when the gdb process is killed (Bug#11273). - (add-hook 'post-command-hook 'gdb-inferior-io--maybe-delete-pty - nil t) - (setq gdb-first-prompt t) (setq gud-running nil) --- 817,822 ---- *************** *** 863,877 **** (gdb-get-buffer-create 'gdb-inferior-io) (gdb-clear-inferior-io) ! (set-process-filter (get-process "gdb-inferior") 'gdb-inferior-filter) ! (gdb-input ! ;; Needs GDB 6.4 onwards ! (concat "-inferior-tty-set " ! (or ! ;; The process can run on a remote host. ! (process-get (get-process "gdb-inferior") 'remote-tty) ! (process-tty-name (get-process "gdb-inferior")))) ! 'ignore) (if (eq window-system 'w32) (gdb-input "-gdb-set new-console off" 'ignore)) (gdb-input "-gdb-set height 0" 'ignore) --- 858,865 ---- (gdb-get-buffer-create 'gdb-inferior-io) (gdb-clear-inferior-io) ! (gdb-inferior-io--init-proc (get-process "gdb-inferior")) ! (if (eq window-system 'w32) (gdb-input "-gdb-set new-console off" 'ignore)) (gdb-input "-gdb-set height 0" 'ignore) *************** *** 1522,1527 **** --- 1510,1537 ---- inf-pty (delete-process inf-pty)))) + (defun gdb-inferior-io--init-proc (proc) + ;; Set up inferior I/O. Needs GDB 6.4 onwards. + (set-process-filter proc 'gdb-inferior-filter) + (set-process-sentinel proc 'gdb-inferior-io-sentinel) + (gdb-input + (concat "-inferior-tty-set " + ;; The process can run on a remote host. + (or (process-get proc 'remote-tty) + (process-tty-name proc))) + 'ignore)) + + (defun gdb-inferior-io-sentinel (proc str) + (when (eq (process-status proc) 'failed) + ;; When the debugged process exits, Emacs gets an EIO on read from + ;; the pty. We must remove the pty now (otherwise select() keeps + ;; triggering on this pty due to the EIO, and Emacs loops trying + ;; to read from it), and set up a new one. + (let ((buffer (process-buffer proc))) + ;; `comint-exec' deletes the original process as a side effect. + (comint-exec buffer "gdb-inferior" nil nil nil) + (gdb-inferior-io--init-proc (get-buffer-process buffer))))) + (defconst gdb-frame-parameters '((height . 14) (width . 80) (unsplittable . t) === modified file 'src/process.c' *** src/process.c 2012-04-18 07:21:18 +0000 --- src/process.c 2012-04-20 02:30:22 +0000 *************** *** 4893,4908 **** It can't hurt. */ else if (nread == -1 && errno == EIO) { ! /* Don't do anything if only a pty, with no associated ! process (bug#10933). */ ! if (XPROCESS (proc)->pid != -2) { ! /* Clear the descriptor now, so we only raise the signal ! once. */ ! FD_CLR (channel, &input_wait_mask); ! FD_CLR (channel, &non_keyboard_wait_mask); ! ! kill (getpid (), SIGCHLD); ! } } #endif /* HAVE_PTYS */ /* If we can detect process termination, don't consider the --- 4893,4915 ---- It can't hurt. */ else if (nread == -1 && errno == EIO) { ! struct Lisp_Process *p = XPROCESS (proc); ! ! /* Clear the descriptor now, so we only raise the ! signal once. */ ! FD_CLR (channel, &input_wait_mask); ! FD_CLR (channel, &non_keyboard_wait_mask); ! ! if (p->pid == -2) ! { ! /* If the EIO occurs on a pty, sigchld_handler's ! wait3 will not find the process object to ! mark for deletion. Do that here. */ ! p->tick = ++process_tick; ! p->status = Qfailed; ! } ! else ! kill (getpid (), SIGCHLD); } #endif /* HAVE_PTYS */ /* If we can detect process termination, don't consider the