From unknown Fri Jun 20 07:29:20 2025 X-Loop: help-debbugs@gnu.org Subject: bug#11279: 24.0.95; GDB scripting doesn't work in "M-x gdb" Resent-From: Eli Zaretskii Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 19 Apr 2012 16:05:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 11279 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: To: 11279@debbugs.gnu.org X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Reply-To: Eli Zaretskii Received: via spool by submit@debbugs.gnu.org id=B.133485148211484 (code B ref -1); Thu, 19 Apr 2012 16:05:01 +0000 Received: (at submit) by debbugs.gnu.org; 19 Apr 2012 16:04:42 +0000 Received: from localhost ([127.0.0.1]:42008 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1SKtqb-0002zA-Om for submit@debbugs.gnu.org; Thu, 19 Apr 2012 12:04:42 -0400 Received: from eggs.gnu.org ([208.118.235.92]:41079) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1SKtqZ-0002yy-EG for submit@debbugs.gnu.org; Thu, 19 Apr 2012 12:04:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SKtq8-0006Ry-6y for submit@debbugs.gnu.org; Thu, 19 Apr 2012 12:04:14 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD autolearn=unavailable version=3.3.2 Received: from lists.gnu.org ([208.118.235.17]:33375) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SKtq8-0006Rs-3L for submit@debbugs.gnu.org; Thu, 19 Apr 2012 12:04:12 -0400 Received: from eggs.gnu.org ([208.118.235.92]:48260) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SKtq5-00029G-Jn for bug-gnu-emacs@gnu.org; Thu, 19 Apr 2012 12:04:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SKtpx-0006Q1-Q0 for bug-gnu-emacs@gnu.org; Thu, 19 Apr 2012 12:04:09 -0400 Received: from mtaout22.012.net.il ([80.179.55.172]:38878) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SKtpx-0006PW-1N for bug-gnu-emacs@gnu.org; Thu, 19 Apr 2012 12:04:01 -0400 Received: from conversion-daemon.a-mtaout22.012.net.il by a-mtaout22.012.net.il (HyperSendmail v2007.08) id <0M2Q00K00HVW7400@a-mtaout22.012.net.il> for bug-gnu-emacs@gnu.org; Thu, 19 Apr 2012 19:03:59 +0300 (IDT) Received: from HOME-C4E4A596F7 ([84.228.105.225]) by a-mtaout22.012.net.il (HyperSendmail v2007.08) with ESMTPA id <0M2Q00IIKHYMNUP0@a-mtaout22.012.net.il> for bug-gnu-emacs@gnu.org; Thu, 19 Apr 2012 19:03:59 +0300 (IDT) Date: Thu, 19 Apr 2012 19:03:59 +0300 From: Eli Zaretskii X-012-Sender: halo1@inter.net.il Message-id: <83ty0fiu8g.fsf@gnu.org> X-detected-operating-system: by eggs.gnu.org: Solaris 10 (beta) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 208.118.235.17 X-Spam-Score: -6.9 (------) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -6.9 (------) I guess no one (including myself ;-) uses "M-x gdb" in Emacs 24, because otherwise I can't believe this bug would go unnoticed for so long. To reproduce: emacs -Q M-x gdb RET /path/to/emacs RET break Fredraw_display RET commands end That "end" should have ended the entry of breakpoint commands and returned you to the "(gdb)" prompt, but it doesn't. What happens is that when you type "end" (or any other command after typing "commands"), gdb-mi sends to GDB the following MI command: -interpreter-exec console "end"\n But when GDB saw the initial "commands" command, it entered an internal reading loop in the CLI interpreter, which does not expect to see "-interpreter-exec". It expects to see an unadorned "end". So from GDB's perspective, the breakpoint commands never end. The bottom line is that you simply _cannot_ define breakpoint commands in "M-x gdb". The same problem happens with other commands that read blocks of commands terminated by "end", like "if", "while", "python", etc. This is a bad regression wrt Emacs 23.4 (which didn't use GDB/MI, and thus was free of this problem). The patch below fixes this for me. But because I know almost nothing about comint, please someone who does eyeball the patch closely, because it should go to the emacs-24 branch. After applying this patch, there's still one annoyance, which only shows on Posix hosts (not on Windows): the ">" prompts for more commands don't show. This happens because that's how GDB/MI seems to behave: when its standard output is a console, it does not respond with the ">" prompts. In fact, it doesn't respond at all until it sees "end". (On Windows, where the connection between GDB and Emacs uses pipes, GDB doesn't behave as if it were talking to a console.) This may be a GDB bug or misfeature, but I think it's a separate issue anyway. Perhaps people who know this stuff in more depth could look into this. Here's the patch I propose to install on the emacs-24 branch: ------------------------------------------------------------ --- lisp/progmodes/gdb-mi.el~0 2012-03-14 08:25:30.000000000 +0200 +++ lisp/progmodes/gdb-mi.el 2012-04-19 14:33:24.673836800 +0300 @@ -604,6 +604,8 @@ (set (make-local-variable 'gud-marker-filter) #'gud-gdb-marker-filter)) (funcall filter proc string)))) +(defvar gdb-control-level 0) + ;;;###autoload (defun gdb (command-line) "Run gdb on program FILE in buffer *gud-FILE*. @@ -678,6 +680,7 @@ (set-process-filter proc #'gdb--check-interpreter)) (set (make-local-variable 'gud-minor-mode) 'gdbmi) + (set (make-local-variable 'gdb-control-level) 0) (setq comint-input-sender 'gdb-send) (when (ring-empty-p comint-input-ring) ; cf shell-mode (let ((hfile (expand-file-name (or (getenv "GDBHISTFILE") @@ -1663,6 +1666,15 @@ :group 'gdb) +(defvar gdb-control-commands-regexp + (concat + "^\\(" + "commands\\|if\\|while\\|define\\|document\\|python\\|" + "while-stepping\\|stepping\\|ws\\|actions" + "\\)\\([[:blank:]]+.*\\)?$") + "Regexp matching GDB commands that enter a recursive reading loop which +does not expect commands to be prefixed by \"-interpreter-exec console\".") + (defun gdb-send (proc string) "A comint send filter for gdb." (with-current-buffer gud-comint-buffer @@ -1672,11 +1684,15 @@ (if (not (string= "" string)) (setq gdb-last-command string) (if gdb-last-command (setq string gdb-last-command))) - (if (string-match "^-" string) - ;; MI command + (if (or (string-match "^-" string) + (> gdb-control-level 0)) + ;; Either MI command or we are feeding GDB's recursive reading loop. (progn (setq gdb-first-done-or-error t) - (process-send-string proc (concat string "\n"))) + (process-send-string proc (concat string "\n")) + (if (and (string-match "^end$" string) + (> gdb-control-level 0)) + (setq gdb-control-level (1- gdb-control-level)))) ;; CLI command (if (string-match "\\\\$" string) (setq gdb-continuation (concat gdb-continuation string "\n")) @@ -1687,7 +1703,12 @@ (if gdb-enable-debug (push (cons 'mi-send to-send) gdb-debug-log)) (process-send-string proc to-send)) - (setq gdb-continuation nil)))) + (if (and (string-match "^end$" string) + (> gdb-control-level 0)) + (setq gdb-control-level (1- gdb-control-level))) + (setq gdb-continuation nil))) + (if (string-match gdb-control-commands-regexp string) + (setq gdb-control-level (1+ gdb-control-level)))) (defun gdb-mi-quote (string) "Return STRING quoted properly as an MI argument. ------------------------------------------------------------ In GNU Emacs 24.0.95.1 (i386-mingw-nt5.1.2600) of 2012-04-02 on HOME-C4E4A596F7 Windowing system distributor `Microsoft Corp.', version 5.1.2600 Configured using: `configure --with-gcc (3.4)' Important settings: value of $LC_ALL: nil value of $LC_COLLATE: nil value of $LC_CTYPE: nil value of $LC_MESSAGES: nil value of $LC_MONETARY: nil value of $LC_NUMERIC: nil value of $LC_TIME: nil value of $LANG: ENU value of $XMODIFIERS: nil locale-coding-system: cp1255 default enable-multibyte-characters: t Major mode: Mail Minor modes in effect: diff-auto-refine-mode: t flyspell-mode: t desktop-save-mode: t show-paren-mode: t display-time-mode: t tooltip-mode: t mouse-wheel-mode: t tool-bar-mode: t menu-bar-mode: t file-name-shadow-mode: t global-font-lock-mode: t font-lock-mode: t blink-cursor-mode: t auto-composition-mode: t auto-encryption-mode: t auto-compression-mode: t temp-buffer-resize-mode: t line-number-mode: t abbrev-mode: t Recent input: SPC p i t f a l l s SPC a l o n g SPC t h i s SPC r o u t e . ) M-q SPC SPC T I A C-t SPC b e t w e e n SPC E m a c s SPC a n d M-d M-q , SPC a n d SPC a l s o SPC r e a r s SPC i t s SPC u g l y SPC h e a d SPC i n SPC o t h e r SPC s i t u a t i o n s M-q f o r c e M-d SPC ( w e SPC a l r e a d y SPC h a v e SPC a SPC s i m i l a r SPC h a c k SPC f o r SPC I n s i g h t ) M-q C-c C-s M-x r e p o r t - e m a c s - b u g Recent messages: Auto-saving...done Auto-saving...done Auto-saving...done Auto-saving...done Mark set [3 times] Sending... Added to d:/usr/eli/rmail/SENT.MAIL Sending email Sending email done Sending...done Load-path shadows: None found. Features: (shadow emacsbug multi-isearch dabbrev network-stream starttls tls smtpmail auth-source eieio assoc gnus-util password-cache mailalias sendmail rmailout dired-x dired tcl nxml-uchnm rng-xsd xsd-regexp rng-cmpct rng-nxml rng-valid rng-loc rng-uri rng-parse nxml-parse rng-match rng-dt rng-util rng-pttrn nxml-ns nxml-mode nxml-outln nxml-rap nxml-util nxml-glyph nxml-enc xmltok sgml-mode face-remap org-wl org-w3m org-vm org-rmail org-mhe org-mew org-irc org-jsinfo org-infojs org-html org-exp ob-exp org-exp-blocks find-func org-agenda org-info org-gnus org-docview org-bibtex bibtex org-bbdb org byte-opt warnings bytecomp byte-compile cconv macroexp advice help-fns advice-preload ob-emacs-lisp ob-tangle ob-ref ob-lob ob-table org-footnote org-src ob-comint ob-keys ob ob-eval org-pcomplete pcomplete org-list org-faces org-compat org-entities org-macs cal-menu calendar cal-loaddefs noutline outline arc-mode archive-mode diff-mode conf-mode newcomment parse-time sh-script executable generic jka-compr make-mode gud easy-mmode comint ansi-color ring texinfo vc-cvs ld-script flyspell info autorevert vc-bzr cc-mode cc-fonts cc-guess cc-menus cc-cmds cc-styles cc-align cc-engine cc-vars cc-defs regexp-opt qp rmailsum rmailmm message format-spec rfc822 mml mml-sec mm-decode mm-bodies mm-encode mailabbrev gmm-utils mailheader mail-parse rfc2231 rmail rfc2047 rfc2045 ietf-drums mm-util mail-prsvr mail-utils desktop server filecache mairix cus-edit easymenu cus-start cus-load wid-edit saveplace midnight ispell generic-x paren battery time time-date tooltip ediff-hook vc-hooks lisp-float-type mwheel dos-w32 disp-table ls-lisp w32-win w32-vars tool-bar dnd fontset image fringe lisp-mode register page menu-bar rfn-eshadow timer select scroll-bar mouse jit-lock font-lock syntax facemenu font-core frame cham georgian utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao korean japanese hebrew greek romanian slovak czech european ethiopic indian cyrillic chinese case-table epa-hook jka-cmpr-hook help simple abbrev minibuffer loaddefs button faces cus-face files text-properties overlay sha1 md5 base64 format env code-pages mule custom widget hashtable-print-readable backquote make-network-process multi-tty emacs) From unknown Fri Jun 20 07:29:20 2025 X-Loop: help-debbugs@gnu.org Subject: bug#11279: 24.0.95; GDB scripting doesn't work in "M-x gdb" Resent-From: Eli Zaretskii Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 19 Apr 2012 16:57:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 11279 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: To: 11279@debbugs.gnu.org Reply-To: Eli Zaretskii Received: via spool by 11279-submit@debbugs.gnu.org id=B11279.133485459116570 (code B ref 11279); Thu, 19 Apr 2012 16:57:01 +0000 Received: (at 11279) by debbugs.gnu.org; 19 Apr 2012 16:56:31 +0000 Received: from localhost ([127.0.0.1]:42090 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1SKueh-0004J7-7w for submit@debbugs.gnu.org; Thu, 19 Apr 2012 12:56:31 -0400 Received: from mtaout23.012.net.il ([80.179.55.175]:48675) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1SKueb-0004Ir-L2 for 11279@debbugs.gnu.org; Thu, 19 Apr 2012 12:56:25 -0400 Received: from conversion-daemon.a-mtaout23.012.net.il by a-mtaout23.012.net.il (HyperSendmail v2007.08) id <0M2Q00100KASQW00@a-mtaout23.012.net.il> for 11279@debbugs.gnu.org; Thu, 19 Apr 2012 19:55:38 +0300 (IDT) Received: from HOME-C4E4A596F7 ([84.228.105.225]) by a-mtaout23.012.net.il (HyperSendmail v2007.08) with ESMTPA id <0M2Q001FJKCPLNB0@a-mtaout23.012.net.il> for 11279@debbugs.gnu.org; Thu, 19 Apr 2012 19:55:38 +0300 (IDT) Date: Thu, 19 Apr 2012 19:55:38 +0300 From: Eli Zaretskii In-reply-to: <83ty0fiu8g.fsf@gnu.org> X-012-Sender: halo1@inter.net.il Message-id: <83pqb3irud.fsf@gnu.org> References: <83ty0fiu8g.fsf@gnu.org> X-Spam-Score: -1.2 (-) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -1.2 (-) > Date: Thu, 19 Apr 2012 19:03:59 +0300 > From: Eli Zaretskii > > After applying this patch, there's still one annoyance, which only > shows on Posix hosts (not on Windows): the ">" prompts for more > commands don't show. This happens because that's how GDB/MI seems to > behave: when its standard output is a console, it does not respond > with the ">" prompts. In fact, it doesn't respond at all until it > sees "end". As pointed out to me on the GDB list, this can be fixed by sending "set interactive-mode off" to GDB at session start. From unknown Fri Jun 20 07:29:20 2025 X-Loop: help-debbugs@gnu.org Subject: bug#11279: 24.0.95; GDB scripting doesn't work in "M-x gdb" 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 07:28:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 11279 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: To: Eli Zaretskii Cc: 11279@debbugs.gnu.org Received: via spool by 11279-submit@debbugs.gnu.org id=B11279.133490685914628 (code B ref 11279); Fri, 20 Apr 2012 07:28:01 +0000 Received: (at 11279) by debbugs.gnu.org; 20 Apr 2012 07:27:39 +0000 Received: from localhost ([127.0.0.1]:43378 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1SL8Fn-0003ns-13 for submit@debbugs.gnu.org; Fri, 20 Apr 2012 03:27:39 -0400 Received: from fencepost.gnu.org ([208.118.235.10]:49202 ident=Debian-exim) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1SL8Fl-0003nl-7o for 11279@debbugs.gnu.org; Fri, 20 Apr 2012 03:27:38 -0400 Received: from [155.69.18.143] (port=50391 helo=ulysses) by fencepost.gnu.org with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1SL8FM-0005Bq-DT; Fri, 20 Apr 2012 03:27:13 -0400 From: Chong Yidong References: <83ty0fiu8g.fsf@gnu.org> Date: Fri, 20 Apr 2012 15:27:04 +0800 In-Reply-To: <83ty0fiu8g.fsf@gnu.org> (Eli Zaretskii's message of "Thu, 19 Apr 2012 19:03:59 +0300") Message-ID: <87y5pqeud3.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.95 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -6.9 (------) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -6.9 (------) Eli Zaretskii writes: > The patch below fixes this for me. But because I know almost nothing > about comint, please someone who does eyeball the patch closely, > because it should go to the emacs-24 branch. I eyeballed it and see no problems (aside from the docstring of `gdb-control-commands-regexp', which should have a leading complete sentence). If your testing turns up no problems, please go ahead and commit. And thanks. From unknown Fri Jun 20 07:29:20 2025 MIME-Version: 1.0 X-Mailer: MIME-tools 5.428 (Entity 5.428) X-Loop: help-debbugs@gnu.org From: help-debbugs@gnu.org (GNU bug Tracking System) To: Eli Zaretskii Subject: bug#11279: closed (Re: bug#11279: 24.0.95; GDB scripting doesn't work in "M-x gdb") Message-ID: References: <83bommiugl.fsf@gnu.org> <83ty0fiu8g.fsf@gnu.org> X-Gnu-PR-Message: they-closed 11279 X-Gnu-PR-Package: emacs Reply-To: 11279@debbugs.gnu.org Date: Fri, 20 Apr 2012 10:12:02 +0000 Content-Type: multipart/mixed; boundary="----------=_1334916722-6759-1" This is a multi-part message in MIME format... ------------=_1334916722-6759-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Your bug report #11279: 24.0.95; GDB scripting doesn't work in "M-x gdb" which was filed against the emacs package, has been closed. The explanation is attached below, along with your original report. If you require more details, please reply to 11279@debbugs.gnu.org. --=20 11279: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D11279 GNU Bug Tracking System Contact help-debbugs@gnu.org with problems ------------=_1334916722-6759-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at 11279-done) by debbugs.gnu.org; 20 Apr 2012 10:11:53 +0000 Received: from localhost ([127.0.0.1]:43569 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1SLAoi-0001ke-Pg for submit@debbugs.gnu.org; Fri, 20 Apr 2012 06:11:53 -0400 Received: from mtaout22.012.net.il ([80.179.55.172]:57950) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1SLAof-0001kQ-R1 for 11279-done@debbugs.gnu.org; Fri, 20 Apr 2012 06:11:51 -0400 Received: from conversion-daemon.a-mtaout22.012.net.il by a-mtaout22.012.net.il (HyperSendmail v2007.08) id <0M2R00500VY90G00@a-mtaout22.012.net.il> for 11279-done@debbugs.gnu.org; Fri, 20 Apr 2012 13:11:19 +0300 (IDT) Received: from HOME-C4E4A596F7 ([84.229.172.156]) by a-mtaout22.012.net.il (HyperSendmail v2007.08) with ESMTPA id <0M2R005FGWAU1D10@a-mtaout22.012.net.il>; Fri, 20 Apr 2012 13:11:19 +0300 (IDT) Date: Fri, 20 Apr 2012 13:11:22 +0300 From: Eli Zaretskii Subject: Re: bug#11279: 24.0.95; GDB scripting doesn't work in "M-x gdb" In-reply-to: <87y5pqeud3.fsf@gnu.org> X-012-Sender: halo1@inter.net.il To: Chong Yidong Message-id: <83bommiugl.fsf@gnu.org> References: <83ty0fiu8g.fsf@gnu.org> <87y5pqeud3.fsf@gnu.org> X-Spam-Score: -1.2 (-) X-Debbugs-Envelope-To: 11279-done Cc: 11279-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list Reply-To: Eli Zaretskii List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -1.2 (-) > From: Chong Yidong > Cc: 11279@debbugs.gnu.org > Date: Fri, 20 Apr 2012 15:27:04 +0800 > > Eli Zaretskii writes: > > > The patch below fixes this for me. But because I know almost nothing > > about comint, please someone who does eyeball the patch closely, > > because it should go to the emacs-24 branch. > > I eyeballed it and see no problems (aside from the docstring of > `gdb-control-commands-regexp', which should have a leading complete > sentence). I fixed the doc string, thanks for the review. > If your testing turns up no problems, please go ahead and > commit. Done, as revision 107872 on the emacs-24 branch. ------------=_1334916722-6759-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at submit) by debbugs.gnu.org; 19 Apr 2012 16:04:42 +0000 Received: from localhost ([127.0.0.1]:42008 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1SKtqb-0002zA-Om for submit@debbugs.gnu.org; Thu, 19 Apr 2012 12:04:42 -0400 Received: from eggs.gnu.org ([208.118.235.92]:41079) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1SKtqZ-0002yy-EG for submit@debbugs.gnu.org; Thu, 19 Apr 2012 12:04:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SKtq8-0006Ry-6y for submit@debbugs.gnu.org; Thu, 19 Apr 2012 12:04:14 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD autolearn=unavailable version=3.3.2 Received: from lists.gnu.org ([208.118.235.17]:33375) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SKtq8-0006Rs-3L for submit@debbugs.gnu.org; Thu, 19 Apr 2012 12:04:12 -0400 Received: from eggs.gnu.org ([208.118.235.92]:48260) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SKtq5-00029G-Jn for bug-gnu-emacs@gnu.org; Thu, 19 Apr 2012 12:04:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SKtpx-0006Q1-Q0 for bug-gnu-emacs@gnu.org; Thu, 19 Apr 2012 12:04:09 -0400 Received: from mtaout22.012.net.il ([80.179.55.172]:38878) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SKtpx-0006PW-1N for bug-gnu-emacs@gnu.org; Thu, 19 Apr 2012 12:04:01 -0400 Received: from conversion-daemon.a-mtaout22.012.net.il by a-mtaout22.012.net.il (HyperSendmail v2007.08) id <0M2Q00K00HVW7400@a-mtaout22.012.net.il> for bug-gnu-emacs@gnu.org; Thu, 19 Apr 2012 19:03:59 +0300 (IDT) Received: from HOME-C4E4A596F7 ([84.228.105.225]) by a-mtaout22.012.net.il (HyperSendmail v2007.08) with ESMTPA id <0M2Q00IIKHYMNUP0@a-mtaout22.012.net.il> for bug-gnu-emacs@gnu.org; Thu, 19 Apr 2012 19:03:59 +0300 (IDT) Date: Thu, 19 Apr 2012 19:03:59 +0300 From: Eli Zaretskii Subject: 24.0.95; GDB scripting doesn't work in "M-x gdb" X-012-Sender: halo1@inter.net.il To: bug-gnu-emacs@gnu.org Message-id: <83ty0fiu8g.fsf@gnu.org> X-detected-operating-system: by eggs.gnu.org: Solaris 10 (beta) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 208.118.235.17 X-Spam-Score: -6.9 (------) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list Reply-To: Eli Zaretskii List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -6.9 (------) I guess no one (including myself ;-) uses "M-x gdb" in Emacs 24, because otherwise I can't believe this bug would go unnoticed for so long. To reproduce: emacs -Q M-x gdb RET /path/to/emacs RET break Fredraw_display RET commands end That "end" should have ended the entry of breakpoint commands and returned you to the "(gdb)" prompt, but it doesn't. What happens is that when you type "end" (or any other command after typing "commands"), gdb-mi sends to GDB the following MI command: -interpreter-exec console "end"\n But when GDB saw the initial "commands" command, it entered an internal reading loop in the CLI interpreter, which does not expect to see "-interpreter-exec". It expects to see an unadorned "end". So from GDB's perspective, the breakpoint commands never end. The bottom line is that you simply _cannot_ define breakpoint commands in "M-x gdb". The same problem happens with other commands that read blocks of commands terminated by "end", like "if", "while", "python", etc. This is a bad regression wrt Emacs 23.4 (which didn't use GDB/MI, and thus was free of this problem). The patch below fixes this for me. But because I know almost nothing about comint, please someone who does eyeball the patch closely, because it should go to the emacs-24 branch. After applying this patch, there's still one annoyance, which only shows on Posix hosts (not on Windows): the ">" prompts for more commands don't show. This happens because that's how GDB/MI seems to behave: when its standard output is a console, it does not respond with the ">" prompts. In fact, it doesn't respond at all until it sees "end". (On Windows, where the connection between GDB and Emacs uses pipes, GDB doesn't behave as if it were talking to a console.) This may be a GDB bug or misfeature, but I think it's a separate issue anyway. Perhaps people who know this stuff in more depth could look into this. Here's the patch I propose to install on the emacs-24 branch: ------------------------------------------------------------ --- lisp/progmodes/gdb-mi.el~0 2012-03-14 08:25:30.000000000 +0200 +++ lisp/progmodes/gdb-mi.el 2012-04-19 14:33:24.673836800 +0300 @@ -604,6 +604,8 @@ (set (make-local-variable 'gud-marker-filter) #'gud-gdb-marker-filter)) (funcall filter proc string)))) +(defvar gdb-control-level 0) + ;;;###autoload (defun gdb (command-line) "Run gdb on program FILE in buffer *gud-FILE*. @@ -678,6 +680,7 @@ (set-process-filter proc #'gdb--check-interpreter)) (set (make-local-variable 'gud-minor-mode) 'gdbmi) + (set (make-local-variable 'gdb-control-level) 0) (setq comint-input-sender 'gdb-send) (when (ring-empty-p comint-input-ring) ; cf shell-mode (let ((hfile (expand-file-name (or (getenv "GDBHISTFILE") @@ -1663,6 +1666,15 @@ :group 'gdb) +(defvar gdb-control-commands-regexp + (concat + "^\\(" + "commands\\|if\\|while\\|define\\|document\\|python\\|" + "while-stepping\\|stepping\\|ws\\|actions" + "\\)\\([[:blank:]]+.*\\)?$") + "Regexp matching GDB commands that enter a recursive reading loop which +does not expect commands to be prefixed by \"-interpreter-exec console\".") + (defun gdb-send (proc string) "A comint send filter for gdb." (with-current-buffer gud-comint-buffer @@ -1672,11 +1684,15 @@ (if (not (string= "" string)) (setq gdb-last-command string) (if gdb-last-command (setq string gdb-last-command))) - (if (string-match "^-" string) - ;; MI command + (if (or (string-match "^-" string) + (> gdb-control-level 0)) + ;; Either MI command or we are feeding GDB's recursive reading loop. (progn (setq gdb-first-done-or-error t) - (process-send-string proc (concat string "\n"))) + (process-send-string proc (concat string "\n")) + (if (and (string-match "^end$" string) + (> gdb-control-level 0)) + (setq gdb-control-level (1- gdb-control-level)))) ;; CLI command (if (string-match "\\\\$" string) (setq gdb-continuation (concat gdb-continuation string "\n")) @@ -1687,7 +1703,12 @@ (if gdb-enable-debug (push (cons 'mi-send to-send) gdb-debug-log)) (process-send-string proc to-send)) - (setq gdb-continuation nil)))) + (if (and (string-match "^end$" string) + (> gdb-control-level 0)) + (setq gdb-control-level (1- gdb-control-level))) + (setq gdb-continuation nil))) + (if (string-match gdb-control-commands-regexp string) + (setq gdb-control-level (1+ gdb-control-level)))) (defun gdb-mi-quote (string) "Return STRING quoted properly as an MI argument. ------------------------------------------------------------ In GNU Emacs 24.0.95.1 (i386-mingw-nt5.1.2600) of 2012-04-02 on HOME-C4E4A596F7 Windowing system distributor `Microsoft Corp.', version 5.1.2600 Configured using: `configure --with-gcc (3.4)' Important settings: value of $LC_ALL: nil value of $LC_COLLATE: nil value of $LC_CTYPE: nil value of $LC_MESSAGES: nil value of $LC_MONETARY: nil value of $LC_NUMERIC: nil value of $LC_TIME: nil value of $LANG: ENU value of $XMODIFIERS: nil locale-coding-system: cp1255 default enable-multibyte-characters: t Major mode: Mail Minor modes in effect: diff-auto-refine-mode: t flyspell-mode: t desktop-save-mode: t show-paren-mode: t display-time-mode: t tooltip-mode: t mouse-wheel-mode: t tool-bar-mode: t menu-bar-mode: t file-name-shadow-mode: t global-font-lock-mode: t font-lock-mode: t blink-cursor-mode: t auto-composition-mode: t auto-encryption-mode: t auto-compression-mode: t temp-buffer-resize-mode: t line-number-mode: t abbrev-mode: t Recent input: SPC p i t f a l l s SPC a l o n g SPC t h i s SPC r o u t e . ) M-q SPC SPC T I A C-t SPC b e t w e e n SPC E m a c s SPC a n d M-d M-q , SPC a n d SPC a l s o SPC r e a r s SPC i t s SPC u g l y SPC h e a d SPC i n SPC o t h e r SPC s i t u a t i o n s M-q f o r c e M-d SPC ( w e SPC a l r e a d y SPC h a v e SPC a SPC s i m i l a r SPC h a c k SPC f o r SPC I n s i g h t ) M-q C-c C-s M-x r e p o r t - e m a c s - b u g Recent messages: Auto-saving...done Auto-saving...done Auto-saving...done Auto-saving...done Mark set [3 times] Sending... Added to d:/usr/eli/rmail/SENT.MAIL Sending email Sending email done Sending...done Load-path shadows: None found. Features: (shadow emacsbug multi-isearch dabbrev network-stream starttls tls smtpmail auth-source eieio assoc gnus-util password-cache mailalias sendmail rmailout dired-x dired tcl nxml-uchnm rng-xsd xsd-regexp rng-cmpct rng-nxml rng-valid rng-loc rng-uri rng-parse nxml-parse rng-match rng-dt rng-util rng-pttrn nxml-ns nxml-mode nxml-outln nxml-rap nxml-util nxml-glyph nxml-enc xmltok sgml-mode face-remap org-wl org-w3m org-vm org-rmail org-mhe org-mew org-irc org-jsinfo org-infojs org-html org-exp ob-exp org-exp-blocks find-func org-agenda org-info org-gnus org-docview org-bibtex bibtex org-bbdb org byte-opt warnings bytecomp byte-compile cconv macroexp advice help-fns advice-preload ob-emacs-lisp ob-tangle ob-ref ob-lob ob-table org-footnote org-src ob-comint ob-keys ob ob-eval org-pcomplete pcomplete org-list org-faces org-compat org-entities org-macs cal-menu calendar cal-loaddefs noutline outline arc-mode archive-mode diff-mode conf-mode newcomment parse-time sh-script executable generic jka-compr make-mode gud easy-mmode comint ansi-color ring texinfo vc-cvs ld-script flyspell info autorevert vc-bzr cc-mode cc-fonts cc-guess cc-menus cc-cmds cc-styles cc-align cc-engine cc-vars cc-defs regexp-opt qp rmailsum rmailmm message format-spec rfc822 mml mml-sec mm-decode mm-bodies mm-encode mailabbrev gmm-utils mailheader mail-parse rfc2231 rmail rfc2047 rfc2045 ietf-drums mm-util mail-prsvr mail-utils desktop server filecache mairix cus-edit easymenu cus-start cus-load wid-edit saveplace midnight ispell generic-x paren battery time time-date tooltip ediff-hook vc-hooks lisp-float-type mwheel dos-w32 disp-table ls-lisp w32-win w32-vars tool-bar dnd fontset image fringe lisp-mode register page menu-bar rfn-eshadow timer select scroll-bar mouse jit-lock font-lock syntax facemenu font-core frame cham georgian utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao korean japanese hebrew greek romanian slovak czech european ethiopic indian cyrillic chinese case-table epa-hook jka-cmpr-hook help simple abbrev minibuffer loaddefs button faces cus-face files text-properties overlay sha1 md5 base64 format env code-pages mule custom widget hashtable-print-readable backquote make-network-process multi-tty emacs) ------------=_1334916722-6759-1--