Subject: bug#79036: [PATCH] Fix pdb tracking for remote filenames

From: Liu Hui <[email-masked]>
Date: Thu, 17 Jul 2025 22:23:14 +0800

On Thu, Jul 17, 2025 at 9:45 PM Michael Albinus <[email-masked]> wrote:
>
> Liu Hui <[email-masked]> writes:
>
>  Hi,
>
> >> > Because file-name may be not the actual file. file-name is actually
> >> > extracted from the pdb output in the python shell, e.g.
> >> >
> >> >     >>> f()
> >> >     > /ssh:server:/tmp/test.py(3)f()
> >> >     (Pdb)
> >> >
> >> > Generally, pdb shows local file names. But if we send the code using
> >> > C-c C-c from python buffers (i.e. step 3), python-send-string passes
> >> > (buffer-file-name), which may be a remote file name, to python
> >> > process. Therefore, pdb may also shows remote file names.
> >>
> >> This is an error. python-send-string shall send (file-local-name (buffer-file-name)) .
> >
> > Why is it an error? In python-shell-send-string, (buffer-file-name) is
> > finally passed to python's compile function in __PYTHON_EL_eval or
> > __PYTHON_EL_eval_file, and is just used for run-time error messages
> > according to the docstring.
> >
> >    The filename argument should give the file from which the code was
> >    read; pass some recognizable value if it wasn’t read from a file
> >    ('<string>' is commonly used).
> >
> > I think it is suitable to use a remote filename or even buffer name as
> > long as it helps Emacs find the source.
>
> This bug report is about an inconsistenccy in pdb. Sometimes it shows
> absolute file names which should be interpreted as remote file
> names. Sometimes, the file names are already prefixed with the remote
> identification.
>
> If python-shell-send-string does not use remote file names, your patch
> isn't needed. The existing code
>
> --8<---------------cut here---------------start------------->8---
>   (let* ((file-name-prospect (concat (file-remote-p default-directory)
>                               file-name))
> --8<---------------cut here---------------end--------------->8---
>
> would be OK.

Yes, forcing python-shell-send-string to use local filenames would
also solve the original problem, but may cause other problems. For
example, when sending some codes in a remote file to the local python
process, without the remote indentation, pdbtrack cannot find the
remote file.

So I think using remote file names in python-shell-send-string is a
feature rather than a bug.