Using rr in an IDE - rr-debugger/rr GitHub Wiki
Using rr in an IDE
rr implements the standard gdb server interface, and also can present the gdb command-line interface. This means it can be used in integrated development environments (IDEs) which support GUI debugging based on gdb/gdbserver.
Known to work:
If your IDE does not run on the same machine as the replay: see debugging from a different host.
Setting up Visual Studio Code
There's two ways to use RR with VSCode. Either use the C/C++ extension or Midas which was explicitly written for ease of use with RR.
- Install Visual Studio Code
Midas
- Install Midas extension
- The extension will ask you if you want it to manage the RR installation for you. If you answer yes, Midas will download and build RR and also notify you when you can build the newest version (by pulling it from github and building it). If you don't, make sure RR is on
$PATHand Midas will find RR. - Open launch.json and add
{
"type": "midas-rr",
"request": "attach",
"name": "Start RR replay",
"cwd": "${workspaceFolder}",
"setupCommands": [ "set sysroot /", "set debuginfod enabled off", "set auto-load safe-path /" ]
}
- Launch the configuration that we've called
Start RR replayhere. Midas will ask you to pick a trace to replay and start that one. - Midas does support normal debugging as well. But for RR debug sessions, extra UI elements are exposed, like
reverse-step,reverse-finish,run to event,set checkpoint,reverse-continue - To set hardware watchpoints, in the debug console type
watch -l mVar. All gdb commands are available via the debug console (no additional prefixes etc).
C/C++ Extension
- Install the C/C++ extension (https://code.visualstudio.com/docs/languages/cpp)
- Open the directory where your source code reside.
- Create a debugging configuration from Debug view (Ctrl+Shift+D) and add the following configuration (this was for debugging firefox, adjust as per your requirements)
{ "name": "rr", "type": "cppdbg", "request": "launch", "program": "${workspaceRoot}/../obj-ff-dbg/dist/bin/firefox", "args": [], "miDebuggerServerAddress": "localhost:50505", "stopAtEntry": false, "cwd": "${workspaceRoot}/../obj-ff-dbg/dist/bin", "environment": [], "externalConsole": true, "linux": { "MIMode": "gdb", "setupCommands": [ { "description": "Setup to resolve symbols", "text": "set sysroot /", "ignoreFailures": false } ] }, "osx": { "MIMode": "gdb" }, "windows": { "MIMode": "gdb" } }
- Install rr >= 5.0.
- Record something using rr.
- Start rr with
rr replay -s 50505 -k - Launch the rr debugging configuration in VS code
- To reverse-execute, open the Debugger Console tab (Shift+Ctrl+Y) and enter manual commands such as
-exec reverse-continue(-exec rc),-exec reverse-step(-exec rs), etc - When rewinding the code, the display isn't refreshed. Step-in in the code once will fix that.
You can set breakpoints like you would with a normal debugging session. To set hardware watchers, in the debug console enter the rr command preceded by -exec (like -exec watch -l mVar)
Setting up CLion
Try this extension.
Setting up QtCreator
Set up .gdbinit as for CLion, following steps 1-4 above. Then:
- Invoke rr:
$ rr replay -s 50505 -k - Enter QtCreator.
- Open
Debug->Start Debugging->Attach to Running Debug Server... - Set the field
Server Portto50505andOverride sever addresstolocalhost. - In the field named
Local Executable, select the executable that you are running (it is located in the build directory). You can also use the hard link in the rr trace directory, if it is there:~/.local/share/rr/latest-trace/mmap_hardlink_3_executable_name - Start debugging by clicking the "Ok" button.
Setting up Eclipse
- Install the Eclipse CDT as usual.
- Install rr >= 5.0.
- Create a script somewhere like so, calling it e.g.
rrgdb:#!/bin/bash exec rr replay -- "$@" - Record something using rr.
- Create a debugging configuration specifying the debugger as
rrgdb. Don't enable Eclipse's reverse debugging, it doesn't work with rr. - Launch the debugging configuration. It should work. You may need to manually set a breakpoint at
mainand then continue to it. - To reverse-execute, open the Debugger Console tab in the Console view and enter manual commands such as
reverse-continue(rc),reverse-step(rs), etc
Setting up emacs
See this blog post:
you simply take the suggested command (
gdb --fullnameorgdb -i=mi), replacegdbwithrr replay
Setting up gdbgui
- Install gdbgui
- Install rr master or >= 5.1.0 (not tested with earlier versions, but may work)
- Record something using rr
- Replay:
gdbgui --gdb-cmd "rr replay --". Optionally specify the directory of the recording:gdbgui DIRECTORY --gdb-cmd "rr replay --"
View demo on YouTube.
Setting up NeoVim
- Install neovim
- Install the neovim plugin jonboh/nvim-dap-rr
- Install rr master or >= 5.6.0
- Generate a recording with
rr record <path/to/binary> - Start rr with
rr replay -s 50505 -k - Attach to the session in NeoVim using DAP
- Debug as with any other DAP compatible debugger
Setting up NeoVim for Rust.
- Install neovim and Rust
- Install the neovim plugin vlopes11/rrust.nvim
- Install rr master or >= 5.6.0 (not tested with earlier versions, but may work)
- Record: Position on a test and run
:lua require('rrust').RustRRTestRecord() - Replay: Run
:lua require('rrust').RustRRTestReplay()
Setting up seer
- Install Seer
- Install rr master or >= 5.1.0 (not tested with earlier versions, but may work)
- Record something using rr
$ rr record -n --output-trace-dir=/path/to/rr/trace-directory myprog arg1 arg2
- Run Seer. It will internally run 'rr replay'.
$ seergdb --rr /path/to/rr/trace-directory
Check out Seer's RR Wiki.
https://github.com/epasveer/seer/wiki/Seer-and-RR
Debugging from a different host
As gdbserver binds to INADDR_ANY by default and rr binds to localhost by default, any debugging, including IDE based, by default only work from the same machine. To allow debugging from another machine follow the steps above, but start the replay with rr replay -h 0.0.0.0 (so other hosts may connect, too) and when attaching drop the sysroot part in the IDE. Note: GDB (on the local machine) will then read all binaries via the remote connection, which may take some time and network io.