-
Notifications
You must be signed in to change notification settings - Fork 585
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
- Install Visual Studio Code
- 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
Use at CLion version 2017.1 or greater, with rr version 5.0 or greater.
-
After you install rr, run the following to save a copy of the gdb initialization script for rr to your home directory. You should also re-run this after installing a new rr release.
$ rr gdbinit > ~/.rr_gdbinit
-
Add the following to the
.gdbinit
file in your home directory. Create a new one if it does not exist.# get around CLion/QtCreator not supporting target extended-remote define target remote target extended-remote $arg0 end define target hook-extended-remote source ~/.rr_gdbinit end # optional: prevent gdb asking for confirmation # when invoking the run command in gdb set confirm off set remotetimeout 100000
-
Record an rr trace from command line as usual. (You could perhaps add a Run configuration in CLion if you are doing this often.)
-
Enter CLion.
-
Open
Run
->Edit Configurations
-
Click the green
+
sign, and add aEmbedded GDB Server
configuration -
Fill in the executable binary with the project binary from the dropdown.
-
Make the debugger "Bundled GDB".
-
Under "Download executable" select "Never".
-
Under
target remote args
, enter:50505
, or another port of your choice -
Under "GDB Server", enter the path to the
rr
binary -
Under "GDB Server args", enter
replay -s 50505 -k
. -
Set a breakpoint in your program.
-
Start debugging in CLion by clicking the debug button, making sure your new debug configuration is selected. If the first try fails with "writing to memory outside diversion session", just try clicking the debug button again.
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 Port
to50505
andOverride sever address
tolocalhost
. - 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
main
and 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 --fullname
orgdb -i=mi
), replacegdb
withrr 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
- 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/RR-and-Seer
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.