The termdebug
plugin doesn't work with gdbserver
because is focus on tty
. This plugin allows launching gdb connecting it via tty
to the program windows.
This PR modifies it to allow using a remote tty device
by launching the program window terminal remotely too. It automatically detects remoting if g:termdebug_config['command']
uses ssh
or wsl
(vim can access the sources directly on that case).
For other use cases (like docker
) a g:termdebug_config['remote_windows']
allows customization.
This only works in prompt-buffer mode because termina-job mode
(default) specifically creates a local tty
window.
The PR provides g:termdebug_config['substitute_path']
entry to map remote to local files using the same strategy that gdb's substitute-path
command.
In this case the netrw builtin plugin retrieves the sources automatically from the remote machine.
let g:termdebug_config = {} let g:termdebug_config['use_prompt'] = v:true let g:termdebug_config['command'] = ['ssh', 'hostname', 'gdb'] let g:termdebug_config['substitute_path'] = { '/': 'scp://hostname//' }
In this case the Windows OS will use special UNC paths for the linux filesystem and mounts for the windows drives.
let g:termdebug_config = {} let g:termdebug_config['use_prompt'] = v:true let g:termdebug_config['command'] = ['wsl', 'gdb'] let g:termdebug_config['substitute_path'] = { \ '/': '\\wsl.localhost\Ubuntu-22.04\', \ '/mnt/c/': 'C:/' }
Note: the
UNC path
can be queried usingwslpath
tool.
https://github.com/vim/vim/pull/18429
(4 files)
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.
@MiguelBarro pushed 1 commit.
—
View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.
@MiguelBarro pushed 1 commit.
You are receiving this because you are subscribed to this thread.
@MiguelBarro pushed 5 commits.
You are receiving this because you are subscribed to this thread.
@MiguelBarro pushed 1 commit.
You are receiving this because you are subscribed to this thread.
@Copilot commented on this pull request.
This PR adds remote debugging capabilities to the termdebug plugin, enabling gdb debugging over remote connections like ssh, wsl, and docker. It automatically detects remote contexts and provides path substitution for mapping remote files to local ones.
Copilot reviewed 3 out of 4 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
src/testdir/test_plugin_termdebug.vim | Added comprehensive test for remote debugging functionality with path substitution |
runtime/doc/terminal.txt | Added documentation for remote debugging features including configuration examples |
runtime/doc/tags | Added new documentation tags for remote debugging help references |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
> +- Use Windows' `UNC` paths to access `WSL2` sources: > + let g:termdebug_config['command'] = ['wsl', 'gdb'] + let g:termdebug_config['substitute_path'] = { + \ '/': '\\wsl.localhost\Ubuntu-22.04\', + \ '/mnt/c/': 'C:/' } +< Note: that several mappings are required: one for each drive unit + and one for the linux filesystem (queried via `wslpath`). + +The plugin "program window" is linked to `gdb` using `pty slave devices`. +Those must be local to the `gdb` instance, thus remote debugging only works +on `prompt mode` (see |termdebug_use_prompt|). +In this mode any `ssh` or `wsl` command would be detected and a similar command +used to launch a remote `tty` terminal session and connect it to `gdb`. + + *termdebug-remote-window* +In order to use another remote terminal clients, set "remote_window" entry
Grammar error: 'clients' should be 'client' since it refers to a single client.
⬇️ Suggested change-In order to use another remote terminal clients, set "remote_window" entry +In order to use another remote terminal client, set "remote_window" entry
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.
@MiguelBarro commented on this pull request.
> +- Use Windows' `UNC` paths to access `WSL2` sources: > + let g:termdebug_config['command'] = ['wsl', 'gdb'] + let g:termdebug_config['substitute_path'] = { + \ '/': '\\wsl.localhost\Ubuntu-22.04\', + \ '/mnt/c/': 'C:/' } +< Note: that several mappings are required: one for each drive unit + and one for the linux filesystem (queried via `wslpath`). + +The plugin "program window" is linked to `gdb` using `pty slave devices`. +Those must be local to the `gdb` instance, thus remote debugging only works +on `prompt mode` (see |termdebug_use_prompt|). +In this mode any `ssh` or `wsl` command would be detected and a similar command +used to launch a remote `tty` terminal session and connect it to `gdb`. + + *termdebug-remote-window* +In order to use another remote terminal clients, set "remote_window" entry
If I were referencing a single client, e.g. telnet
, no extra option would be required. I would have included extra builtin management (like with ssh
or wsl
) 🤣.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.
@chrisbra commented on this pull request.
> @@ -1634,6 +1635,48 @@ interrupt the running program. But after using the MI command "continue" being used for the `:Continue` command, instead of using the communication channel. +Remote Debugging ~ + *termdebug-remote* +One of the main issues of remote debugging is the access to the debuggee's +source files. The plugin can profit from system and vim's networking +capabilities to workaround this. + *termdebug-substitute-path* +Use the `g:termdebug_config['substitute_path']` entry to map remote to local +files using the same strategy that gdb's `substitute-path` command.⬇️ Suggested change
-files using the same strategy that gdb's `substitute-path` command. +files using the same strategy that gdb's `substitute-path` command uses.
> @@ -1634,6 +1635,48 @@ interrupt the running program. But after using the MI command "continue" being used for the `:Continue` command, instead of using the communication channel. +Remote Debugging ~ + *termdebug-remote* +One of the main issues of remote debugging is the access to the debuggee's +source files. The plugin can profit from system and vim's networking +capabilities to workaround this. + *termdebug-substitute-path* +Use the `g:termdebug_config['substitute_path']` entry to map remote to local +files using the same strategy that gdb's `substitute-path` command. +For example: +- Use |netrw| to access files remoting via ssh: > + let g:termdebug_config['command'] = ['ssh', 'hostname', 'gdb'] + let g:termdebug_config['substitute_path'] = { '/': 'scp://hostname//' } +< Note: that first is specified the remote machine root path and later⬇️ Suggested change
-< Note: that first is specified the remote machine root path and later +< Note: that the key specifies the remote machine root path and the value
> + *termdebug-substitute-path* +Use the `g:termdebug_config['substitute_path']` entry to map remote to local +files using the same strategy that gdb's `substitute-path` command. +For example: +- Use |netrw| to access files remoting via ssh: > + let g:termdebug_config['command'] = ['ssh', 'hostname', 'gdb'] + let g:termdebug_config['substitute_path'] = { '/': 'scp://hostname//' } +< Note: that first is specified the remote machine root path and later + the local one. +- Use Windows' `UNC` paths to access `WSL2` sources: > + let g:termdebug_config['command'] = ['wsl', 'gdb'] + let g:termdebug_config['substitute_path'] = { + \ '/': '\\wsl.localhost\Ubuntu-22.04\', + \ '/mnt/c/': 'C:/' } +< Note: that several mappings are required: one for each drive unit + and one for the linux filesystem (queried via `wslpath`).
Do we always need to specify g:termdebug_config['command']
and also g:termdebug_config['substitute_path']
?
Can you please also give an example. Something along the lines of:
Assuming you want to debug a program on a remote server using ssh, you would need to run the following command: >
ssh user@hostname gdb args /opt/command
This needs to be translated into a command your local Vim can run: >
gdb args scp://user@hostname//opt/command
> +- Use Windows' `UNC` paths to access `WSL2` sources: > + let g:termdebug_config['command'] = ['wsl', 'gdb'] + let g:termdebug_config['substitute_path'] = { + \ '/': '\\wsl.localhost\Ubuntu-22.04\', + \ '/mnt/c/': 'C:/' } +< Note: that several mappings are required: one for each drive unit + and one for the linux filesystem (queried via `wslpath`). + +The plugin "program window" is linked to `gdb` using `pty slave devices`. +Those must be local to the `gdb` instance, thus remote debugging only works +on `prompt mode` (see |termdebug_use_prompt|). +In this mode any `ssh` or `wsl` command would be detected and a similar command +used to launch a remote `tty` terminal session and connect it to `gdb`. + + *termdebug-remote-window* +In order to use another remote terminal clients, set "remote_window" entry
-In order to use another remote terminal clients, set "remote_window" entry +In order to use another remote terminal client, set "remote_window" entry
In runtime/pack/dist/opt/termdebug/plugin/termdebug.vim:
> + # Check if the user provided a command to launch the program window + var term_cmd = null_list + if exists('g:termdebug_config') && has_key(g:termdebug_config, 'remote_window') + term_cmd = g:termdebug_config['remote_window'] + term_cmd = type(term_cmd) == v:t_list ? copy(term_cmd) : [term_cmd] + else + # Check if it is a remote gdb, the program terminal should be started + # on the remote machine. + const remote_pattern = '^\(ssh\|wsl\)' + if gdb_cmd[0] =~? remote_pattern + var gdb_pos = indexof(gdb_cmd, $'v:val =~? "^{GetCommand()[-1]}"') + if gdb_pos > 0 + # strip debugger call + term_cmd = gdb_cmd[0 : gdb_pos - 1] + # create a devoted tty slave device and link to stdin/stdout + term_cmd += ['socat', '-d', '-d', '-', 'PTY,raw,echo=0']
that socat
is required should be documented or even better checked
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.
@MiguelBarro pushed 1 commit.
You are receiving this because you are subscribed to this thread.
@MiguelBarro commented on this pull request.
In runtime/pack/dist/opt/termdebug/plugin/termdebug.vim:
> + # Check if the user provided a command to launch the program window + var term_cmd = null_list + if exists('g:termdebug_config') && has_key(g:termdebug_config, 'remote_window') + term_cmd = g:termdebug_config['remote_window'] + term_cmd = type(term_cmd) == v:t_list ? copy(term_cmd) : [term_cmd] + else + # Check if it is a remote gdb, the program terminal should be started + # on the remote machine. + const remote_pattern = '^\(ssh\|wsl\)' + if gdb_cmd[0] =~? remote_pattern + var gdb_pos = indexof(gdb_cmd, $'v:val =~? "^{GetCommand()[-1]}"') + if gdb_pos > 0 + # strip debugger call + term_cmd = gdb_cmd[0 : gdb_pos - 1] + # create a devoted tty slave device and link to stdin/stdout + term_cmd += ['socat', '-d', '-d', '-', 'PTY,raw,echo=0']
Let's check. I was afraid it might introduce a roundtrip that could slow down startup, but that doesn't seem to be the case.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.
@MiguelBarro commented on this pull request.
> + *termdebug-substitute-path* +Use the `g:termdebug_config['substitute_path']` entry to map remote to local +files using the same strategy that gdb's `substitute-path` command. +For example: +- Use |netrw| to access files remoting via ssh: > + let g:termdebug_config['command'] = ['ssh', 'hostname', 'gdb'] + let g:termdebug_config['substitute_path'] = { '/': 'scp://hostname//' } +< Note: that first is specified the remote machine root path and later + the local one. +- Use Windows' `UNC` paths to access `WSL2` sources: > + let g:termdebug_config['command'] = ['wsl', 'gdb'] + let g:termdebug_config['substitute_path'] = { + \ '/': '\\wsl.localhost\Ubuntu-22.04\', + \ '/mnt/c/': 'C:/' } +< Note: that several mappings are required: one for each drive unit + and one for the linux filesystem (queried via `wslpath`).
I have reproduced the session example as a remote session.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.
@MiguelBarro pushed 4 commits.
You are receiving this because you are subscribed to this thread.
@MiguelBarro pushed 1 commit.
You are receiving this because you are subscribed to this thread.
@MiguelBarro pushed 3 commits.
You are receiving this because you are subscribed to this thread.
@MiguelBarro pushed 1 commit.
You are receiving this because you are subscribed to this thread.
@MiguelBarro pushed 3 commits.
You are receiving this because you are subscribed to this thread.
@MiguelBarro pushed 1 commit.
You are receiving this because you are subscribed to this thread.