unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#39408: Breakpoints don't work with M-x gdb under TRAMP
@ 2020-02-03 19:07 Timo Lilja
  2020-08-21 11:48 ` Lars Ingebrigtsen
  2021-04-16  5:02 ` Jim Porter
  0 siblings, 2 replies; 5+ messages in thread
From: Timo Lilja @ 2020-02-03 19:07 UTC (permalink / raw)
  To: 39408


[-- Attachment #1.1: Type: text/plain, Size: 1893 bytes --]

*** Environment

- GNU Emacs 26.1 (build 2, x86_64-pc-linux-gnu, GTK+ Version 3.24.5) of
  2019-09-23, modified by Debian
- The code looks identical on the relevant parts in Emacs git master

*** Steps to reproduce

1. Run emacs
   $ emacs -q

2. Start remote debugging session
   M-x gdb RET gdb -i=mi /ssh:vagrant@debug:/vagrant/hello

3. Set a breakpoint in *gud-hello* buffer
   (gdb) break main
   Breakpoint 1 at 0x1149: file hello.c, line 6.

4. Run the program to the breakpoint
   (gdb) run

5. Switch back to source window
   C-x b hello.c RET

6. Add another breakpoint
   C-x C-a c-b

Emacs becomes unresponsive and the minibuffer is flooded with the
following error message:

~File /ssh:vagrant@debug:/vagrant/"/vagrant/hello.c" no longer exists!~

*** Fix

1. Apply patch gdb-tramp-fix.diff
   $ zcat /usr/share/emacs/26.1/lisp/progmodes/gdb-mi.el.gz >gdb-mi.el
   $ zcat /usr/share/emacs/26.1/lisp/progmodes/gud.el.gz >gud.el
   $ patch <gdb-tramp-fix.diff

2. run emacs with modified gdb-mi.el and gud.el
   $ emacs -q -l el/gdb-mi.el -l el/gud.el

3. Setting breakpoints with C-x C-a C-b should work now

The changes in ~gdb-mi.el~ fix the problem with the "no longer exist"
error message.

The change in ~gud.el~ makes the fringe mark work a bit better and also
the source buffer to pop up when a break point is hit.

The problem seems to be that not all filename information goes through
(gdb-jsonify-buffer) but gdb-mi.el and gud.el read them directly from
gdb's buffers. These patches check wheter a gdb buffer is remote, and
wrap the file names accordingly.

There is probably a better way to fix the problem, but my knowledge
of gdb-mi.el is limited.

Relates to bug #23608.

*** Affected functions
(gdb-place-breakpoints)
(gdb-get-location)
(gdb-goto-breakpoint)
(gdb-frame-handler)
(gud-file-name)

*** References
- https://debbugs.gnu.org/cgi/bugreport.cgi?bug=23608

[-- Attachment #1.2: Type: text/html, Size: 2313 bytes --]

[-- Attachment #2: gdb-tramp-fix.diff --]
[-- Type: text/x-patch, Size: 3583 bytes --]

--- gdb-mi.el.orig	2020-01-26 18:46:35.351741525 +0200
+++ gdb-mi.el	2020-01-22 09:58:01.445834007 +0200
@@ -2693,7 +2693,7 @@
     (let ((remote (file-remote-p default-directory)))
       (when remote
         (goto-char (point-min))
-        (while (re-search-forward "[\\[,]fullname=\"\\(.+\\)\"" nil t)
+        (while (re-search-forward ",fullname=\"\\(.+\\)\"" nil t)
           (replace-match (concat remote "\\1") nil nil nil 1))))
     (goto-char (point-min))
     (when fix-key
@@ -2967,6 +2967,13 @@
     (insert (gdb-table-string table " "))
     (gdb-place-breakpoints)))
 
+(defun fix-filename (filename)
+  (let ((remote (file-remote-p default-directory)))
+    (if (and remote filename (not (file-remote-p filename)))
+        (concat remote (replace-regexp-in-string "^\\\"\\(.+\\)\"" "\\1"
+                                                 filename nil))
+      filename)))
+
 ;; Put breakpoint icons in relevant margins (even those set in the GUD buffer).
 (defun gdb-place-breakpoints ()
   ;; Remove all breakpoint-icons in source buffers but not assembler buffer.
@@ -2980,7 +2987,7 @@
                                         ; an associative list
            (line (bindat-get-field breakpoint 'line)))
       (when line
-        (let ((file (bindat-get-field breakpoint 'fullname))
+        (let ((file (fix-filename (bindat-get-field breakpoint 'fullname)))
               (flag (bindat-get-field breakpoint 'enabled))
               (bptno (bindat-get-field breakpoint 'number)))
           (unless (and file (file-exists-p file))
@@ -3019,7 +3026,7 @@
 	(message-box "Cannot find source file for breakpoint location.
 Add directory to search path for source files using the GDB command, dir."))
       (throw 'file-not-found nil))
-    (with-current-buffer (find-file-noselect (match-string 1))
+    (with-current-buffer (find-file-noselect (fix-filename (match-string 1)))
       (gdb-init-buffer)
       ;; only want one breakpoint icon at each location
       (gdb-put-breakpoint-icon (eq flag ?y) bptno (string-to-number line)))))
@@ -3977,7 +3984,7 @@
     (let ((breakpoint (get-text-property (point) 'gdb-breakpoint)))
       (if breakpoint
           (let ((bptno (bindat-get-field breakpoint 'number))
-                (file  (bindat-get-field breakpoint 'fullname))
+                (file  (fix-filename (bindat-get-field breakpoint 'fullname)))
                 (line  (bindat-get-field breakpoint 'line)))
             (save-selected-window
               (let* ((buffer (find-file-noselect
@@ -4373,7 +4380,7 @@
   (let ((frame (bindat-get-field (gdb-json-partial-output) 'frame)))
     (when frame
       (setq gdb-selected-frame (bindat-get-field frame 'func))
-      (setq gdb-selected-file (bindat-get-field frame 'fullname))
+      (setq gdb-selected-file (fix-filename (bindat-get-field frame 'fullname)))
       (setq gdb-frame-number (bindat-get-field frame 'level))
       (setq gdb-frame-address (bindat-get-field frame 'addr))
       (let ((line (bindat-get-field frame 'line)))
--- gud.el.orig	2020-01-26 18:46:41.563789189 +0200
+++ gud.el	2020-01-26 22:29:38.053975346 +0200
@@ -301,7 +301,8 @@
   ;; remote part to f, which is the local file name.  Fortunately,
   ;; `file-remote-p' returns exactly this remote file name part (or
   ;; nil otherwise).
-  (setq f (concat (or (file-remote-p default-directory) "") f))
+  (unless (file-remote-p f)
+    (setq f (concat (or (file-remote-p default-directory) "") f)))
   (if (file-exists-p f) (expand-file-name f)
     (let ((directories (gud-val 'directories))
 	  (result nil))

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

* bug#39408: Breakpoints don't work with M-x gdb under TRAMP
  2020-02-03 19:07 bug#39408: Breakpoints don't work with M-x gdb under TRAMP Timo Lilja
@ 2020-08-21 11:48 ` Lars Ingebrigtsen
  2020-08-21 14:08   ` Michael Albinus
  2021-04-16  5:02 ` Jim Porter
  1 sibling, 1 reply; 5+ messages in thread
From: Lars Ingebrigtsen @ 2020-08-21 11:48 UTC (permalink / raw)
  To: Timo Lilja; +Cc: 39408, Michael Albinus

Timo Lilja <timo.lilja@iki.fi> writes:

[...]

> 5. Switch back to source window
>    C-x b hello.c RET
>
> 6. Add another breakpoint
>    C-x C-a c-b
>
> Emacs becomes unresponsive and the minibuffer is flooded with the
> following error message:
>
> ~File /ssh:vagrant@debug:/vagrant/"/vagrant/hello.c" no longer exists!~
>
> *** Fix
>
> 1. Apply patch gdb-tramp-fix.diff
>    $ zcat /usr/share/emacs/26.1/lisp/progmodes/gdb-mi.el.gz >gdb-mi.el
>    $ zcat /usr/share/emacs/26.1/lisp/progmodes/gud.el.gz >gud.el
>    $ patch <gdb-tramp-fix.diff

Michael, there's tramp-related patch for gdb-mi/gud in this bug report
that I think looks reasonable, if I'm reading it correctly.  Do you have
any opinions on this?

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





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

* bug#39408: Breakpoints don't work with M-x gdb under TRAMP
  2020-08-21 11:48 ` Lars Ingebrigtsen
@ 2020-08-21 14:08   ` Michael Albinus
  0 siblings, 0 replies; 5+ messages in thread
From: Michael Albinus @ 2020-08-21 14:08 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 39408, Timo Lilja

Lars Ingebrigtsen <larsi@gnus.org> writes:

Hi Lars,

> Michael, there's tramp-related patch for gdb-mi/gud in this bug report
> that I think looks reasonable, if I'm reading it correctly.  Do you have
> any opinions on this?

Somehow, I've missed that bug report :-(

I have no objection to apply the patch, but wouldn't it be better to
understand, why bindat-get-field returns file names like
/ssh:vagrant@debug:/vagrant/"/vagrant/hello.c" ? Just patching the
obscure result doesn't look error prone to me.

Furthermore,

-  (setq f (concat (or (file-remote-p default-directory) "") f))
+  (unless (file-remote-p f)
+    (setq f (concat (or (file-remote-p default-directory) "") f)))

could be simplified to

   (setq f (concat (file-remote-p default-directory) f))

Best regards, Michael.





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

* bug#39408: Breakpoints don't work with M-x gdb under TRAMP
  2020-02-03 19:07 bug#39408: Breakpoints don't work with M-x gdb under TRAMP Timo Lilja
  2020-08-21 11:48 ` Lars Ingebrigtsen
@ 2021-04-16  5:02 ` Jim Porter
  2021-05-01  9:59   ` Michael Albinus
  1 sibling, 1 reply; 5+ messages in thread
From: Jim Porter @ 2021-04-16  5:02 UTC (permalink / raw)
  To: 39408

[-- Attachment #1: Type: text/plain, Size: 720 bytes --]

This is already fixed in Emacs 28 thanks to bug#44173 (a78c614), which
replaces the old GDB/MI parser (that converted the data to JSON first)
with a more-robust parser. Attached is a patch to fix this under Emacs
27.

The problem is that in `gdb-jsonify-buffer', when replacing the
"fullname" with a Tramp path, the wildcard was greedy, resulting in
only one "fullname" being replaced in the buffer. This had the effect
of rendering it impossible to have more than one breakpoint, as all
but the first breakpoint would have unmodified "fullname"s.

(Note: I have a couple of patches in Tramp already that put me at the
limit for patches without copyright assignment paperwork. However,
I've already requested the form.)

[-- Attachment #2: 0001-Emacs-27-Fix-setting-breakpoints-in-M-x-gdb-for-remote-files.patch --]
[-- Type: application/octet-stream, Size: 1062 bytes --]

From 2ab1ecef679df32230705e37098c1d93c639c22f Mon Sep 17 00:00:00 2001
From: Jim Porter <jporterbugs@gmail.com>
Date: Thu, 15 Apr 2021 21:39:03 -0700
Subject: [PATCH 1/2] Fix setting breakpoints in M-x gdb for remote files

* lisp/progmodes/gdb-mi.el (gdb-jsonify-buffer): Fix modification of
GDB/MI "fullname" property for remote files
---
 lisp/progmodes/gdb-mi.el | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lisp/progmodes/gdb-mi.el b/lisp/progmodes/gdb-mi.el
index 65fe997341..1b2642fae7 100644
--- a/lisp/progmodes/gdb-mi.el
+++ b/lisp/progmodes/gdb-mi.el
@@ -2696,7 +2696,7 @@ If `default-directory' is remote, full file names are adapted accordingly."
     (let ((remote (file-remote-p default-directory)))
       (when remote
         (goto-char (point-min))
-        (while (re-search-forward "[\\[,]fullname=\"\\(.+\\)\"" nil t)
+        (while (re-search-forward "[\\[,]fullname=\"\\(.+?\\)\"" nil t)
           (replace-match (concat remote "\\1") nil nil nil 1))))
     (goto-char (point-min))
     (when fix-key
-- 
2.25.1


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

* bug#39408: Breakpoints don't work with M-x gdb under TRAMP
  2021-04-16  5:02 ` Jim Porter
@ 2021-05-01  9:59   ` Michael Albinus
  0 siblings, 0 replies; 5+ messages in thread
From: Michael Albinus @ 2021-05-01  9:59 UTC (permalink / raw)
  To: Jim Porter; +Cc: 39408-done

Version: 27.3

Jim Porter <jporterbugs@gmail.com> writes:

> This is already fixed in Emacs 28 thanks to bug#44173 (a78c614), which
> replaces the old GDB/MI parser (that converted the data to JSON first)
> with a more-robust parser. Attached is a patch to fix this under Emacs
> 27.
>
> The problem is that in `gdb-jsonify-buffer', when replacing the
> "fullname" with a Tramp path, the wildcard was greedy, resulting in
> only one "fullname" being replaced in the buffer. This had the effect
> of rendering it impossible to have more than one breakpoint, as all
> but the first breakpoint would have unmodified "fullname"s.

Pushed to the emacs-27 branch. Closing the bug.

Note: I don't know, whether there will be an Emacs 27.3. So the patch is
pushed just in case of.

Best regards, Michael.





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

end of thread, other threads:[~2021-05-01  9:59 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-03 19:07 bug#39408: Breakpoints don't work with M-x gdb under TRAMP Timo Lilja
2020-08-21 11:48 ` Lars Ingebrigtsen
2020-08-21 14:08   ` Michael Albinus
2021-04-16  5:02 ` Jim Porter
2021-05-01  9:59   ` Michael Albinus

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