unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* issue with gdb-mi.el and Guile
@ 2017-06-02  1:37 David Boles
  2017-06-03  8:04 ` Eli Zaretskii
  0 siblings, 1 reply; 4+ messages in thread
From: David Boles @ 2017-06-02  1:37 UTC (permalink / raw)
  To: emacs-devel

When using the guile command at the gdb prompt within emacs, it is easy to end up in a state in which the behavior of repeating the previous gdb command when hitting return is disabled. Basically, the gdb-send function in gdb-mi.el thinks that if you’ve entered “guile” at the gdb command prompt, then you must be in guile mode until it sees you enter a “,q”, “,quit”, or “end”.

Most of the time I use the guile control command to execute single Guile expressions (otherwise, I’d enter the guile repl). The patch below modifies this behavior in gdb-mi.el. I am decidedly not a “real Emacs Lisp” developer so there may well be a better/cleaner way to accomplish the same task. Nevertheless, this patch greatly improves the experience of using Guile within gdb within Emacs. The diff below is against a fresh tree a few days old.

Thanks,

 - db

diff --git a/lisp/progmodes/gdb-mi.el b/lisp/progmodes/gdb-mi.el
index 1af520d..438fb75 100644
--- a/lisp/progmodes/gdb-mi.el
+++ b/lisp/progmodes/gdb-mi.el
@@ -1778,6 +1778,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\".")
 
+(defvar gdb-guile-command-non-empty-regexp "^[[:blank:]]*\\(guile\\)\\([[:blank:]]+[[:graph:]].*\\)$"
+  "Regexp matching a non-empty GDB guile command.")
+
 (defun gdb-strip-string-backslash (string)
   (replace-regexp-in-string "\\\\$" "" string))
 
@@ -1831,7 +1834,8 @@ commands to be prefixed by \"-interpreter-exec console\".")
               (> gdb-control-level 0))
          (setq gdb-control-level (1- gdb-control-level)))
       (setq gdb-continuation nil)))
-  (if (string-match gdb-control-commands-regexp string)
+  (if (and (string-match gdb-control-commands-regexp string)
+           (not (string-match gdb-guile-command-non-empty-regexp string)))
       (setq gdb-control-level (1+ gdb-control-level))))
 
 (defun gdb-mi-quote (string)




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

* Re: issue with gdb-mi.el and Guile
  2017-06-02  1:37 issue with gdb-mi.el and Guile David Boles
@ 2017-06-03  8:04 ` Eli Zaretskii
       [not found]   ` <512B3559-B3DD-46DE-9E8C-2D0A90260A4D@ieee.org>
  0 siblings, 1 reply; 4+ messages in thread
From: Eli Zaretskii @ 2017-06-03  8:04 UTC (permalink / raw)
  To: David Boles; +Cc: emacs-devel

> From: David Boles <boles@ieee.org>
> Date: Thu, 1 Jun 2017 20:37:46 -0500
> 
> When using the guile command at the gdb prompt within emacs, it is easy to end up in a state in which the behavior of repeating the previous gdb command when hitting return is disabled. Basically, the gdb-send function in gdb-mi.el thinks that if you’ve entered “guile” at the gdb command prompt, then you must be in guile mode until it sees you enter a “,q”, “,quit”, or “end”.
> 
> Most of the time I use the guile control command to execute single Guile expressions (otherwise, I’d enter the guile repl). The patch below modifies this behavior in gdb-mi.el. I am decidedly not a “real Emacs Lisp” developer so there may well be a better/cleaner way to accomplish the same task. Nevertheless, this patch greatly improves the experience of using Guile within gdb within Emacs. The diff below is against a fresh tree a few days old.

Thanks.  Can you try the following patch, after reverting your changes
to gdb-mi.el, and see if it gives good results?

diff --git a/lisp/progmodes/gdb-mi.el b/lisp/progmodes/gdb-mi.el
index 1af520d..cc9205c 100644
--- a/lisp/progmodes/gdb-mi.el
+++ b/lisp/progmodes/gdb-mi.el
@@ -1767,13 +1767,17 @@ breakpoint-disabled
   :group 'gdb)
 
 \f
+(defvar gdb-python-guile-commands-regexp
+  "python\\|python-interactive\\|pi\\|guile\\|guile-repl\\|gr"
+  "Regexp that matches Python and Guile commands supported by GDB.")
+
 (defvar gdb-control-commands-regexp
   (concat
    "^\\("
    "commands\\|if\\|while\\|define\\|document\\|"
-   "python\\|python-interactive\\|pi\\|guile\\|guile-repl\\|gr\\|"
-   "while-stepping\\|stepping\\|ws\\|actions"
-   "\\)\\([[:blank:]]+.*\\)?$")
+   gdb-python-guile-commands-regexp
+   "\\|while-stepping\\|stepping\\|ws\\|actions"
+   "\\)\\([[:blank:]]+\\([^[:blank:]]*\\)\\)?$")
   "Regexp matching GDB commands that enter a recursive reading loop.
 As long as GDB is in the recursive reading loop, it does not expect
 commands to be prefixed by \"-interpreter-exec console\".")
@@ -1831,8 +1835,17 @@ gdb-send
 	       (> 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))))
+  ;; Python and Guile commands that have an argument don't enter the
+  ;; recursive reading loop.
+  (let* ((control-command-p (string-match gdb-control-commands-regexp string))
+         (command-arg (match-string 3 string))
+         (python-or-guile-p (string-match gdb-python-guile-commands-regexp
+                                          string)))
+    (if (and control-command-p
+             (or (not python-or-guile-p)
+                 (null command-arg)
+                 (zerop (length command-arg))))
+        (setq gdb-control-level (1+ gdb-control-level)))))
 
 (defun gdb-mi-quote (string)
   "Return STRING quoted properly as an MI argument.



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

* Re: issue with gdb-mi.el and Guile
       [not found]   ` <512B3559-B3DD-46DE-9E8C-2D0A90260A4D@ieee.org>
@ 2017-06-04 14:20     ` Eli Zaretskii
  2017-06-10  8:31       ` Eli Zaretskii
  0 siblings, 1 reply; 4+ messages in thread
From: Eli Zaretskii @ 2017-06-04 14:20 UTC (permalink / raw)
  To: David Boles; +Cc: emacs-devel

[Please keep the mailing-list address on the CC.]

> From: David Boles <boles@ieee.org>
> Date: Sat, 3 Jun 2017 16:20:51 -0500
> 
> > Thanks.  Can you try the following patch, after reverting your changes
> > to gdb-mi.el, and see if it gives good results?
> 
> For whatever reason the patch is deemed corrupt at line 13 (perhaps an error on my part). However, I applied the patch “by hand” to an up to date instance of master and it appears to work fine. Clearly it’s a better approach than my hack.
> 
> I will be applying the delta to all my emacs installations and will let you know if I see anything, but at the moment I don’t see any issues.

Thanks.

> Will you be merging this into the Emacs repo?

If you don't see any issues in a few days, I will install this change,
yes.

> Also, I don’t know whether this might be a fit for gdb-mi.el or not but I’ve found it very helpful to hook yank and rewrite paste’s of hex numbers from 0x1234 form to #x1234 lisp form when running a guile command or in the guile repl:
> 
> (defun gdb-guile-command-entry ()
>   (interactive)
>   (save-excursion
>     (let ((end-pos (point)))
>       (beginning-of-line)
>       (let* ((beg-pos (point))
>              (chunk (buffer-substring beg-pos end-pos)))
>         (if (string-match "guile" chunk)
>             t
>           nil)))))
> 
> (defun my-gdb-guile-yank-filter (args)
>   (interactive)
>   (let ((chunk (car args)))
>     (if (and (string-match "*gud-" (buffer-name))
>              (gdb-guile-command-entry)
>              (string-match "0x\\([0-9a-f]+\\)" chunk))
>         (list (concat "#x" (match-string 1 chunk)))
>       (list chunk))))
> 
> (advice-add 'insert-for-yank-1 :filter-args #'my-gdb-guile-yank-filter)

We try to avoid using advice in the Emacs sources, but patches are
welcome to implement a similar feature via other means.  Also, I think
we'd want this for multi-line Guile commands typed into GDB.  Maybe you
should file a feature request about this using "M-x report-emacs-bug".

Thanks.



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

* Re: issue with gdb-mi.el and Guile
  2017-06-04 14:20     ` Eli Zaretskii
@ 2017-06-10  8:31       ` Eli Zaretskii
  0 siblings, 0 replies; 4+ messages in thread
From: Eli Zaretskii @ 2017-06-10  8:31 UTC (permalink / raw)
  To: boles; +Cc: emacs-devel

> Date: Sun, 04 Jun 2017 17:20:22 +0300
> From: Eli Zaretskii <eliz@gnu.org>
> Cc: emacs-devel@gnu.org
> 
> If you don't see any issues in a few days, I will install this change,
> yes.

Now done.

Thanks.



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

end of thread, other threads:[~2017-06-10  8:31 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-06-02  1:37 issue with gdb-mi.el and Guile David Boles
2017-06-03  8:04 ` Eli Zaretskii
     [not found]   ` <512B3559-B3DD-46DE-9E8C-2D0A90260A4D@ieee.org>
2017-06-04 14:20     ` Eli Zaretskii
2017-06-10  8:31       ` Eli Zaretskii

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