unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Timo Lilja <timo.lilja@iki.fi>
To: 39408@debbugs.gnu.org
Subject: bug#39408: Breakpoints don't work with M-x gdb under TRAMP
Date: Mon, 3 Feb 2020 21:07:05 +0200	[thread overview]
Message-ID: <CAFsu5Z2nPRXbedpT_6WJ+F6YYZ3WA2V304PpaiqsEGkm=PYwUg@mail.gmail.com> (raw)


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

             reply	other threads:[~2020-02-03 19:07 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-03 19:07 Timo Lilja [this message]
2020-08-21 11:48 ` bug#39408: Breakpoints don't work with M-x gdb under TRAMP Lars Ingebrigtsen
2020-08-21 14:08   ` Michael Albinus
2021-04-16  5:02 ` Jim Porter
2021-05-01  9:59   ` Michael Albinus

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAFsu5Z2nPRXbedpT_6WJ+F6YYZ3WA2V304PpaiqsEGkm=PYwUg@mail.gmail.com' \
    --to=timo.lilja@iki.fi \
    --cc=39408@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).