Using rr in an IDE

Chad Smith edited this page Jan 11, 2018 · 13 revisions

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:

  • Visual Studio Code
  • CLion
  • QtCreator
  • Eclipse
  • emacs GUD/gdb-mi
  • gdbgui

Setting up CLion/QtCreator

Use at CLion version 2017.1 or greater, with rr version (strictly) greater than 4.5.0 (until 4.6.0 is released, you will have to build rr from the latest source).

The buttons for the reverse-step gdb commands can be added to CLion by installing UndoDB's plugin for CLion.

  1. 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
  2. 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
    
  3. Record an rr trace from command line as usual. (You could perhaps add a Run configuration in CLion if you are doing this often.)

In CLion:

  1. Open Run -> Edit Configurations

  2. Click the green + sign, and add a GDB Remote Debug configuration

  3. Under target remote args, enter :50505, or another port of your choice

  4. For the symbol file, point CLion to 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
  5. Invoke rr:

    $ rr replay -s 50505 -k
  6. Start debugging in CLion by clicking the debug button. Make sure that the GDB remote configuration is selected.

In QtCreator:

  1. Invoke rr:

    $ rr replay -s 50505 -k
  2. Open Debug -> Start Debugging -> Attach to Running Debug Server...

  3. Set the field Server Port to 50505 and Override sever address to localhost.

  4. 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
  5. Start debugging by clicking the "Ok" button.

Setting up Eclipse

  1. Install the Eclipse CDT as usual.
  2. Install rr master or >= 4.6.0.
  3. Create a script somewhere like so, calling it e.g. rrgdb:
    #!/bin/bash
    exec rr replay -- "$@"
  4. Record something using rr.
  5. Create a debugging configuration specifying the debugger as rrgdb. Don't enable Eclipse's reverse debugging, it doesn't work with rr.
  6. Launch the debugging configuration. It should work. You may need to manually set a breakpoint at main and then continue to it.
  7. 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 or gdb -i=mi), replace gdb with rr replay

Setting up Visual Studio Code

  1. Install Visual Studio Code
  2. Install the C/C++ extension (https://code.visualstudio.com/docs/languages/cpp)
  3. Open the directory where your source code reside.
  4. 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"
        }
    }
  1. Install rr master or >= 4.6.0.
  2. Record something using rr.
  3. Start rr with rr replay -s 50505 -k
  4. Launch the rr debugging configuration in VS code
  5. 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
  6. 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 gdbgui

  1. Install gdbgui
  2. Install rr master or >= 5.1.0 (not tested with earlier versions, but may work)
  3. Record something using rr
  4. Replay: gdbgui --rr. Optionally specify the directory of the recording: gdbgui DIRECTORY --rr

View demo on YouTube.

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.