unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* [PATCH] Fix gdb-mi.el to recognize backslashes as quotes
@ 2013-07-11  5:33 Sergio Durigan Junior
  2013-07-11  8:16 ` Andreas Schwab
  2013-07-11 23:35 ` Stefan Monnier
  0 siblings, 2 replies; 6+ messages in thread
From: Sergio Durigan Junior @ 2013-07-11  5:33 UTC (permalink / raw)
  To: emacs-devel

Hi there.

I've sent a message a while ago asking about this question, and in the
end I managed to figure it out.  You can read my question at:

    https://lists.gnu.org/archive/html/emacs-devel/2013-06/msg00482.html

There is also a GDB bug about it:

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

The fix is rather simple.  gdb-mi.el is not preserving the context and
saving the command being typed when it sees the backslash, and although
it has a "gdb-continuation" variable for that exact purpose, it is not
setting it properly.  All this patch does is to make sure that
gdb-continuation (and gdb-last-command, for that matter) gets set
correctly when it sees a backslash, or when the user presses RET without
nothing in the prompt (i.e., GDB's parlance for "repeat the last
command").  I chose to strip the last backslash, just like GDB does in
the CLI.

I've tested it with real simple examples, and it worked OK.

OK to apply?

lisp/ChangeLog:
2013-07-11  Sergio Durigan Junior  <sergiodj@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..789e7b4 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 (not (null 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))

--
Sergio




^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] Fix gdb-mi.el to recognize backslashes as quotes
  2013-07-11  5:33 [PATCH] Fix gdb-mi.el to recognize backslashes as quotes Sergio Durigan Junior
@ 2013-07-11  8:16 ` Andreas Schwab
  2013-07-12  3:41   ` Sergio Durigan Junior
  2013-07-11 23:35 ` Stefan Monnier
  1 sibling, 1 reply; 6+ messages in thread
From: Andreas Schwab @ 2013-07-11  8:16 UTC (permalink / raw)
  To: Sergio Durigan Junior; +Cc: emacs-devel

Sergio Durigan Junior <sergiodj@riseup.net> writes:

> +      (if (not (null gdb-continuation))

(not (null ...)) is a no-op in this context.

Andreas.

-- 
Andreas Schwab, SUSE Labs, schwab@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] Fix gdb-mi.el to recognize backslashes as quotes
  2013-07-11  5:33 [PATCH] Fix gdb-mi.el to recognize backslashes as quotes Sergio Durigan Junior
  2013-07-11  8:16 ` Andreas Schwab
@ 2013-07-11 23:35 ` Stefan Monnier
  2013-07-12  3:42   ` Sergio Durigan Junior
  1 sibling, 1 reply; 6+ messages in thread
From: Stefan Monnier @ 2013-07-11 23:35 UTC (permalink / raw)
  To: Sergio Durigan Junior; +Cc: emacs-devel

> I've sent a message a while ago asking about this question, and in the
> end I managed to figure it out.  You can read my question at:

Thanks for looking into it.  I'm on the road for another two weeks, so
I may not be able to check and/or install it before then, but it
looks promising.


        Stefan


PS: If you want to make sure we don't forget about it, you might send it
via M-x report-emacs-bug.



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] Fix gdb-mi.el to recognize backslashes as quotes
  2013-07-11  8:16 ` Andreas Schwab
@ 2013-07-12  3:41   ` Sergio Durigan Junior
  0 siblings, 0 replies; 6+ messages in thread
From: Sergio Durigan Junior @ 2013-07-12  3:41 UTC (permalink / raw)
  To: emacs-devel

On Thursday, July 11 2013, Andreas Schwab wrote:

> Sergio Durigan Junior <sergiodj@riseup.net> writes:
>
>> +      (if (not (null gdb-continuation))
>
> (not (null ...)) is a no-op in this context.

Ops, thanks.  Fixed in this version.

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))




^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] Fix gdb-mi.el to recognize backslashes as quotes
  2013-07-11 23:35 ` Stefan Monnier
@ 2013-07-12  3:42   ` Sergio Durigan Junior
  2013-07-12  5:10     ` Sergio Durigan Junior
  0 siblings, 1 reply; 6+ messages in thread
From: Sergio Durigan Junior @ 2013-07-12  3:42 UTC (permalink / raw)
  To: emacs-devel

On Thursday, July 11 2013, Stefan Monnier wrote:

>> I've sent a message a while ago asking about this question, and in the
>> end I managed to figure it out.  You can read my question at:
>
> Thanks for looking into it.  I'm on the road for another two weeks, so
> I may not be able to check and/or install it before then, but it
> looks promising.

Thank you!

> PS: If you want to make sure we don't forget about it, you might send it
> via M-x report-emacs-bug.

Fair enough, I will create the bug right away.

-- 
Sergio




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] Fix gdb-mi.el to recognize backslashes as quotes
  2013-07-12  3:42   ` Sergio Durigan Junior
@ 2013-07-12  5:10     ` Sergio Durigan Junior
  0 siblings, 0 replies; 6+ messages in thread
From: Sergio Durigan Junior @ 2013-07-12  5:10 UTC (permalink / raw)
  To: emacs-devel

On Friday, July 12 2013, I wrote:

>> PS: If you want to make sure we don't forget about it, you might send it
>> via M-x report-emacs-bug.
>
> Fair enough, I will create the bug right away.

<http://debbugs.gnu.org/cgi/bugreport.cgi?bug=14847> FWIW.

Thanks,

-- 
Sergio




^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2013-07-12  5:10 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-07-11  5:33 [PATCH] Fix gdb-mi.el to recognize backslashes as quotes Sergio Durigan Junior
2013-07-11  8:16 ` Andreas Schwab
2013-07-12  3:41   ` Sergio Durigan Junior
2013-07-11 23:35 ` Stefan Monnier
2013-07-12  3:42   ` Sergio Durigan Junior
2013-07-12  5:10     ` Sergio Durigan Junior

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).