Member-only story
Neovim for Beginners — Terminal Debugger
In this article, we will learn how to use the built-in terminal debugging plugin to debug Rust applications with gdb
and rust-gdb
.
This article is part of the Neovim for Beginners series.
The Neovim configuration files can be found in this repository.
Getting Started
The terminal debugging plugin (:h terminal-debug
) can be used to debug a program with gdb
and view the source code in a Vim window. This is completely contained inside Vim and also works remotely over an ssh connection.
This plugin needs to be loaded explicitly using the following command.
:packadd termdebug
Alternatively, we can load the plugin when we start Neovim.
gdb
Depending on the operating system, the GNU debugger can be installed easily.
For macOS, if you encounter the following error, refer to this link to give gdb
permission to control other processes.
Starting program: /x/y/foo
Unable to find Mach task port for process-id 28885: (os/kern) failure (0x5).
(please check gdb is codesigned - see taskgated(8))
Additionally, to prevent gdb
from using a shell to start the program to be debugged, we can use the following command for this inside gdb
.
set startup-with-shell off
We can also put this command in a file called .gdbinit in the home directory, in which case it will be applied automatically every time we start gdb
.
rust-gdb
rust-gdb
is a wrapper that loads external Python pretty-printing scripts into gdb
. It is a prebuilt binary that comes with the Rust installation.