GNU bug report logs - #14847
24.1; gdb-mi.el does not handle backslashes as quotes

Previous Next

Package: emacs;

Reported by: Sergio Durigan Junior <sergiodj <at> riseup.net>

Date: Fri, 12 Jul 2013 03:52:02 UTC

Severity: normal

Found in version 24.1

Done: Eli Zaretskii <eliz <at> gnu.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 14847 in the body.
You can then email your comments to 14847 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#14847; Package emacs. (Fri, 12 Jul 2013 03:52:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Sergio Durigan Junior <sergiodj <at> riseup.net>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Fri, 12 Jul 2013 03:52:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Sergio Durigan Junior <sergiodj <at> riseup.net>
To: bug-gnu-emacs <at> gnu.org
Subject: 24.1; gdb-mi.el does not handle backslashes as quotes
Date: Fri, 12 Jul 2013 00:51:20 -0300
If you start gdb-mi.el (on Emacs 24.1), and try to use backslashes to
quote/break long lines, it is not handled correctly.  For example,
suppose your program being debugged inside GDB takes 3 arguments.  You
could run it with:

    (gdb) file myprogram
    Reading symbols from myprogram...done.
    (gdb) run \
    first_arg \
    second_arg \
    third_arg

GDB should correctly run the binary using the 3 args.  However, inside
Emacs, you receive an error:

    Undefined command: "third_arg".  Try "help".

This is because gdb-mi.el is not handling the backslashes correctly.
The error is specifically on the function `gdb_send', and the patch
inlined in this message fixes this.  The patch can also be seen on:

<https://lists.gnu.org/archive/html/emacs-devel/2013-07/msg00423.html>

And there is also a GDB bug related to this issue:

<http://sourceware.org/bugzilla/show_bug.cgi?id=15596>

Thanks.

lisp/ChangeLog:
2013-07-12  Sergio Durigan Junior  <sergiodj <at> riseup.net>

	* progmodes/gdb-mi.el (gdb-strip-string-backslash): New function.
	(gdb-send): Correctly handle continuation strings with
	backslashes, and properly set the last command typed.

diff --git a/lisp/progmodes/gdb-mi.el b/lisp/progmodes/gdb-mi.el
index 2c4d6a0..87c5f98 100644
--- a/lisp/progmodes/gdb-mi.el
+++ b/lisp/progmodes/gdb-mi.el
@@ -1759,6 +1759,9 @@ static char *magick[] = {
 As long as GDB is in the recursive reading loop, it does not expect
 commands to be prefixed by \"-interpreter-exec console\".")
 
+(defun gdb-strip-string-backslash (string)
+  (replace-regexp-in-string "\\\\$" "" string))
+
 (defun gdb-send (proc string)
   "A comint send filter for gdb."
   (with-current-buffer gud-comint-buffer
@@ -1766,8 +1769,13 @@ commands to be prefixed by \"-interpreter-exec console\".")
       (remove-text-properties (point-min) (point-max) '(face))))
   ;; mimic <RET> key to repeat previous command in GDB
   (if (not (string= "" string))
-      (setq gdb-last-command string)
-    (if gdb-last-command (setq string gdb-last-command)))
+      (if gdb-continuation
+	  (setq gdb-last-command (concat gdb-continuation
+					 (gdb-strip-string-backslash string)
+					 " "))
+	(setq gdb-last-command (gdb-strip-string-backslash string)))
+    (if gdb-last-command (setq string gdb-last-command))
+    (setq gdb-continuation nil))
   (if (or (string-match "^-" string)
 	  (> gdb-control-level 0))
       ;; Either MI command or we are feeding GDB's recursive reading loop.
@@ -1779,10 +1787,13 @@ commands to be prefixed by \"-interpreter-exec console\".")
 	    (setq gdb-control-level (1- gdb-control-level))))
     ;; CLI command
     (if (string-match "\\\\$" string)
-	(setq gdb-continuation (concat gdb-continuation string "\n"))
+	(setq gdb-continuation
+	      (concat gdb-continuation (gdb-strip-string-backslash
+					string)
+		      " "))
       (setq gdb-first-done-or-error t)
       (let ((to-send (concat "-interpreter-exec console "
-                             (gdb-mi-quote string)
+                             (gdb-mi-quote (concat gdb-continuation string " "))
                              "\n")))
         (if gdb-enable-debug
             (push (cons 'mi-send to-send) gdb-debug-log))




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#14847; Package emacs. (Fri, 12 Jul 2013 08:52:02 GMT) Full text and rfc822 format available.

Message #8 received at 14847 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Sergio Durigan Junior <sergiodj <at> riseup.net>
Cc: 14847 <at> debbugs.gnu.org
Subject: Re: bug#14847: 24.1; gdb-mi.el does not handle backslashes as quotes
Date: Fri, 12 Jul 2013 11:50:33 +0300
> From: Sergio Durigan Junior <sergiodj <at> riseup.net>
> Date: Fri, 12 Jul 2013 00:51:20 -0300
> 
> If you start gdb-mi.el (on Emacs 24.1), and try to use backslashes to
> quote/break long lines, it is not handled correctly.  For example,
> suppose your program being debugged inside GDB takes 3 arguments.  You
> could run it with:
> 
>     (gdb) file myprogram
>     Reading symbols from myprogram...done.
>     (gdb) run \
>     first_arg \
>     second_arg \
>     third_arg
> 
> GDB should correctly run the binary using the 3 args.  However, inside
> Emacs, you receive an error:
> 
>     Undefined command: "third_arg".  Try "help".
> 
> This is because gdb-mi.el is not handling the backslashes correctly.
> The error is specifically on the function `gdb_send', and the patch
> inlined in this message fixes this.  The patch can also be seen on:
> 
> <https://lists.gnu.org/archive/html/emacs-devel/2013-07/msg00423.html>
> 
> And there is also a GDB bug related to this issue:
> 
> <http://sourceware.org/bugzilla/show_bug.cgi?id=15596>

Your patch doesn't seem to work for me.  I tried on GNU/Linux and on
MS-Windows, and in both cases I get the same error.  Here's the recipe
I tried (after applying your latest patch and rebuilding Emacs):

 emacs -Q
 M-x gdb RET
 gdb -i=mi ./src/emacs RET
 (gdb) break main
 (gdb) run \
 -Q

When I type RET after "-Q", I get an error:

  Undefined MI command: Q

What am I doing wrong?

Thanks.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#14847; Package emacs. (Fri, 12 Jul 2013 15:52:01 GMT) Full text and rfc822 format available.

Message #11 received at 14847 <at> debbugs.gnu.org (full text, mbox):

From: Sergio Durigan Junior <sergiodj <at> riseup.net>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 14847 <at> debbugs.gnu.org
Subject: Re: bug#14847: 24.1; gdb-mi.el does not handle backslashes as quotes
Date: Fri, 12 Jul 2013 12:51:24 -0300
On Friday, July 12 2013, Eli Zaretskii wrote:

> Your patch doesn't seem to work for me.  I tried on GNU/Linux and on
> MS-Windows, and in both cases I get the same error.  Here's the recipe
> I tried (after applying your latest patch and rebuilding Emacs):
>
>  emacs -Q
>  M-x gdb RET
>  gdb -i=mi ./src/emacs RET
>  (gdb) break main
>  (gdb) run \
>  -Q
>
> When I type RET after "-Q", I get an error:
>
>   Undefined MI command: Q
>
> What am I doing wrong?

Hi Eli,

Thanks for testing!  You're doing nothing wrong, the patch is the
culprit.  `gdb-send' checks for commands starting with "-", but this
check should be disabled when a command is being continued.

Could you please try the following version?

Thanks,

-- 
Sergio

diff --git a/lisp/progmodes/gdb-mi.el b/lisp/progmodes/gdb-mi.el
index 2c4d6a0..10472ec 100644
--- a/lisp/progmodes/gdb-mi.el
+++ b/lisp/progmodes/gdb-mi.el
@@ -1759,6 +1759,9 @@ static char *magick[] = {
 As long as GDB is in the recursive reading loop, it does not expect
 commands to be prefixed by \"-interpreter-exec console\".")
 
+(defun gdb-strip-string-backslash (string)
+  (replace-regexp-in-string "\\\\$" "" string))
+
 (defun gdb-send (proc string)
   "A comint send filter for gdb."
   (with-current-buffer gud-comint-buffer
@@ -1766,10 +1769,15 @@ commands to be prefixed by \"-interpreter-exec console\".")
       (remove-text-properties (point-min) (point-max) '(face))))
   ;; mimic <RET> key to repeat previous command in GDB
   (if (not (string= "" string))
-      (setq gdb-last-command string)
-    (if gdb-last-command (setq string gdb-last-command)))
-  (if (or (string-match "^-" string)
-	  (> gdb-control-level 0))
+      (if gdb-continuation
+	  (setq gdb-last-command (concat gdb-continuation
+					 (gdb-strip-string-backslash string)
+					 " "))
+	(setq gdb-last-command (gdb-strip-string-backslash string)))
+    (if gdb-last-command (setq string gdb-last-command))
+    (setq gdb-continuation nil))
+  (if (and (not gdb-continuation) (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)
@@ -1779,10 +1787,13 @@ commands to be prefixed by \"-interpreter-exec console\".")
 	    (setq gdb-control-level (1- gdb-control-level))))
     ;; CLI command
     (if (string-match "\\\\$" string)
-	(setq gdb-continuation (concat gdb-continuation string "\n"))
+	(setq gdb-continuation
+	      (concat gdb-continuation (gdb-strip-string-backslash
+					string)
+		      " "))
       (setq gdb-first-done-or-error t)
       (let ((to-send (concat "-interpreter-exec console "
-                             (gdb-mi-quote string)
+                             (gdb-mi-quote (concat gdb-continuation string " "))
                              "\n")))
         (if gdb-enable-debug
             (push (cons 'mi-send to-send) gdb-debug-log))




Reply sent to Eli Zaretskii <eliz <at> gnu.org>:
You have taken responsibility. (Fri, 12 Jul 2013 18:21:02 GMT) Full text and rfc822 format available.

Notification sent to Sergio Durigan Junior <sergiodj <at> riseup.net>:
bug acknowledged by developer. (Fri, 12 Jul 2013 18:21:02 GMT) Full text and rfc822 format available.

Message #16 received at 14847-done <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Sergio Durigan Junior <sergiodj <at> riseup.net>
Cc: 14847-done <at> debbugs.gnu.org
Subject: Re: bug#14847: 24.1; gdb-mi.el does not handle backslashes as quotes
Date: Fri, 12 Jul 2013 21:20:22 +0300
> From: Sergio Durigan Junior <sergiodj <at> riseup.net>
> Cc: 14847 <at> debbugs.gnu.org
> Date: Fri, 12 Jul 2013 12:51:24 -0300
> 
> Thanks for testing!  You're doing nothing wrong, the patch is the
> culprit.  `gdb-send' checks for commands starting with "-", but this
> check should be disabled when a command is being continued.
> 
> Could you please try the following version?

Thanks, this works, so I committed this version, and I'm closing the
bug.




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sat, 10 Aug 2013 11:24:02 GMT) Full text and rfc822 format available.

This bug report was last modified 10 years and 271 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.