|
1 | | -*terminal.txt* For Vim version 9.1. Last change: 2025 Sep 15 |
| 1 | +*terminal.txt* For Vim version 9.1. Last change: 2025 Oct 08 |
2 | 2 |
|
3 | 3 |
|
4 | 4 | VIM REFERENCE MANUAL by Bram Moolenaar |
@@ -44,6 +44,7 @@ If the result is "1" you have it. |
44 | 44 | Prompt mode |termdebug-prompt| |
45 | 45 | Mappings |termdebug-mappings| |
46 | 46 | Communication |termdebug-communication| |
| 47 | + Remote Debugging |termdebug-remote| |
47 | 48 | Customizing |termdebug-customizing| |
48 | 49 |
|
49 | 50 | {only available when compiled with the |+terminal| feature} |
@@ -1635,26 +1636,125 @@ interrupt the running program. But after using the MI command |
1635 | 1636 | communication channel. |
1636 | 1637 |
|
1637 | 1638 |
|
| 1639 | +Remote debugging ~ |
| 1640 | + *termdebug-remote* |
| 1641 | +One of the main issues of remote debugging is the access to the debuggee's |
| 1642 | +source files. The plugin can profit from system and vim's networking |
| 1643 | +capabilities to workaround this. |
| 1644 | + *termdebug-remote-example* |
| 1645 | +The |termdebug-example| can be replicated by running the `gdb` debugger to |
| 1646 | +debug Vim on a remote Linux machine accessible via `ssh`. |
| 1647 | + |
| 1648 | +- Build Vim as explained in the local example. |
| 1649 | + |
| 1650 | +- If "socat" is not available in the remote machine 'terminal' mode will not |
| 1651 | + work properly. Fall back to |termdebug_use_prompt|: > |
| 1652 | + :let g:termdebug_config = {} |
| 1653 | + :let g:termdebug_config['use_prompt'] = v:true |
| 1654 | +
|
| 1655 | +- Specify the command line to run the remote `gdb` instance: > |
| 1656 | + :let g:termdebug_config['command'] = ['ssh', 'hostname', 'gdb'] |
| 1657 | +< Explaining `ssh` is beyond the scope of this example, but notice the |
| 1658 | + command line can be greatly simplified by specifying the user, keys and |
| 1659 | + other options into the `$HOME/.ssh/config` file. |
| 1660 | + |
| 1661 | +- Provide a hint for translating remote paths into |netrw| paths: > |
| 1662 | + :let g:termdebug_config['substitute_path'] = { '/': 'scp://hostname//' } |
| 1663 | +
|
| 1664 | +- Load the termdebug plugin and start debugging Vim: > |
| 1665 | + :packadd termdebug |
| 1666 | + :Termdebug vim |
| 1667 | +
|
| 1668 | +You now have the same three windows of the local example and can follow the |
| 1669 | +very same steps. The only difference is that the source windows displays a |
| 1670 | +netrw buffer instead of a local one. |
| 1671 | + |
| 1672 | + *termdebug-substitute-path* |
| 1673 | +Use the `g:termdebug_config['substitute_path']` entry to map remote to local |
| 1674 | +files using the same strategy that gdb's `substitute-path` command uses. |
| 1675 | +For example: |
| 1676 | +- Use |netrw| to access files remoting via ssh: > |
| 1677 | + let g:termdebug_config['command'] = ['ssh', 'hostname', 'gdb'] |
| 1678 | + let g:termdebug_config['substitute_path'] = { '/': 'scp://hostname//' } |
| 1679 | +< Note: that the key specifies the remote machine root path and the value |
| 1680 | + the local one. |
| 1681 | +- Use Windows' `UNC` paths to access `WSL2` sources: > |
| 1682 | + let g:termdebug_config['command'] = ['wsl', 'gdb'] |
| 1683 | + let g:termdebug_config['substitute_path'] = { |
| 1684 | + \ '/': '\\wsl.localhost\Ubuntu-22.04\', |
| 1685 | + \ '/mnt/c/': 'C:/' } |
| 1686 | +< Note: that several mappings are required: one for each drive unit |
| 1687 | + and one for the linux filesystem (queried via `wslpath`). |
| 1688 | + |
| 1689 | +In this mode any `ssh` or `wsl` command would be detected and a similar |
| 1690 | +command would be used to launch `socat` in a remote `tty` terminal session |
| 1691 | +and connect it to `gdb`. |
| 1692 | +If `socat` is not available a plain remote terminal would be used as |
| 1693 | +fallback. |
| 1694 | +The next session shows how to override this default behaviour. |
| 1695 | + |
| 1696 | + *termdebug-remote-window* |
| 1697 | +In order to use another remote terminal client, set "remote_window" entry |
| 1698 | +in `g:termdebug_config` variable before invoking `:Termdebug`. For example: |
| 1699 | +- Debugging inside a docker container using "prompt" mode: > |
| 1700 | + let g:termdebug_config['use_prompt'] = v:true |
| 1701 | + let g:termdebug_config['command'] = ['docker', 'run', '-i', |
| 1702 | + \ '--rm', '--name', 'container-name', 'image-name', 'gdb'] |
| 1703 | + let g:termdebug_config['remote_window'] = |
| 1704 | + \ ['docker', 'exec', '-ti', 'container-name' |
| 1705 | + \ ,'socat', '-dd', '-', 'PTY,raw,echo=0'] |
| 1706 | +
|
| 1707 | +- Debugging inside a docker container using a "terminal buffer". |
| 1708 | + The container should be already running because unlike the previous |
| 1709 | + case for `terminal mode` "program" and "communication" ptys are created |
| 1710 | + before the gdb one: > |
| 1711 | + $ docker run -ti --rm --name container-name immage-name |
| 1712 | +
|
| 1713 | +< Then, launch the debugger: > |
| 1714 | + let g:termdebug_config['use_prompt'] = v:false " default |
| 1715 | + let g:termdebug_config['command'] = |
| 1716 | + \ ['docker', 'exec', '-ti', 'container-name', 'gdb'] |
| 1717 | + let g:termdebug_config['remote_window'] = |
| 1718 | + \ ['docker', 'exec', '-ti', 'container-name' |
| 1719 | + \ ,'socat', '-dd', '-', 'PTY,raw,echo=0'] |
| 1720 | +
|
| 1721 | +Note: "command" cannot use `-t` on |termdebug-prompt| mode because prompt |
| 1722 | +buffers cannot handle `tty` connections. |
| 1723 | +The "remote_window" command must use `-t` because otherwise it will lack |
| 1724 | +a `pty slave device` for gdb to connect. |
| 1725 | +Note: "socat" must be available in the remote machine on "terminal" mode. |
| 1726 | +Note: docker container sources can be accessible combining `volumes` |
| 1727 | +with mappings (see |termdebug-substitute-path|). |
| 1728 | + |
1638 | 1729 | GDB command ~ |
1639 | 1730 | *g:termdebugger* |
1640 | 1731 | To change the name of the gdb command, set "debugger" entry in |
1641 | 1732 | g:termdebug_config or the "g:termdebugger" variable before invoking |
1642 | 1733 | `:Termdebug`: > |
1643 | 1734 | let g:termdebug_config['command'] = "mygdb" |
| 1735 | +
|
1644 | 1736 | If there is no g:termdebug_config you can use: > |
1645 | 1737 | let g:termdebugger = "mygdb" |
1646 | 1738 |
|
1647 | 1739 | However, the latter form will be deprecated in future releases. |
1648 | 1740 |
|
1649 | 1741 | If the command needs an argument use a List: > |
1650 | 1742 | let g:termdebug_config['command'] = ['rr', 'replay', '--'] |
| 1743 | +
|
1651 | 1744 | If there is no g:termdebug_config you can use: > |
1652 | 1745 | let g:termdebugger = ['rr', 'replay', '--'] |
1653 | 1746 |
|
1654 | 1747 | Several arguments will be added to make gdb work well for the debugger. |
1655 | 1748 | If you want to modify them, add a function to filter the argument list: > |
1656 | 1749 | let g:termdebug_config['command_filter'] = MyDebugFilter |
1657 | 1750 |
|
| 1751 | +A "command_filter" scenario is solving escaping issues on remote debugging |
| 1752 | +over "ssh". For convenience a default filter is provided for escaping |
| 1753 | +whitespaces inside the arguments. It is automatically configured for "ssh", |
| 1754 | +but can be employed in other use cases like this: > |
| 1755 | + let g:termdebug_config['command_filter'] = |
| 1756 | + / function('g:Termdebug_escape_whitespace') |
| 1757 | +
|
1658 | 1758 | If you do not want the arguments to be added, but you do need to set the |
1659 | 1759 | "pty", use a function to add the necessary arguments: > |
1660 | 1760 | let g:termdebug_config['command_add_args'] = MyAddArguments |
@@ -1717,7 +1817,8 @@ than 99 will be displayed as "9+". |
1717 | 1817 | If you want to customize the breakpoint signs to show `>>` in the signcolumn: > |
1718 | 1818 | let g:termdebug_config['sign'] = '>>' |
1719 | 1819 | You can also specify individual signs for the first several breakpoints: > |
1720 | | - let g:termdebug_config['signs'] = ['>1', '>2', '>3', '>4', '>5', '>6', '>7', '>8', '>9'] |
| 1820 | + let g:termdebug_config['signs'] = ['>1', '>2', '>3', '>4', '>5', |
| 1821 | + \ '>6', '>7', '>8', '>9'] |
1721 | 1822 | let g:termdebug_config['sign'] = '>>' |
1722 | 1823 | If you would like to use decimal (base 10) breakpoint signs: > |
1723 | 1824 | let g:termdebug_config['sign_decimal'] = 1 |
|
0 commit comments