rr

From Gentoo Wiki
Jump to:navigation Jump to:search

This article is a stub. Please help out by expanding it - how to get started.

rr, Record and Replay Framework, is a C/C++ debugging tool for Linux that aims to enhance GDB. It provides an efficient reverse execution under GDB, allowing for the replaying of recorded instructions.

Installation

USE flags

USE flags for dev-debug/rr Record and Replay Framework

multilib On 64bit systems, if you want to be able to compile 32bit and 64bit binaries
test Enable dependencies and/or preparations necessary to run tests (usually controlled by FEATURES=test but can be toggled independently)

Emerge

root #emerge --ask dev-debug/rr

Usage

Debugging a segmentation fault

Take the following C file for example:

CODE
#include <stdio.h>

int main() {
	int *val = NULL;
	*val = 5;
	printf("%d\n", *val);
}

Compile the file with the -g flag:

user $gcc -g main.c

Upon running this file after compilation, the following is output:

user $./a.out
Segmentation fault

To investigate the problem with rr, use rr record:

user $rr record ./a.out
rr: Saving execution to trace directory `/home/larry/.local/share/rr/a.out-0'.
Segmentation fault

Now replay the file using rr replay:

user $rr replay
GNU gdb (Gentoo 16.2 vanilla) 16.2
Copyright (C) 2024 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-pc-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://bugs.gentoo.org/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from /home/larry/.local/share/rr/a.out-0/mmap_clone_5_a.out...
Remote debugging using 127.0.0.1:15671
Reading symbols from /lib64/ld-linux-x86-64.so.2...
warning: BFD: warning: system-supplied DSO at 0x6fffd000 has a section extending past end of file
warning: Discarding section .replay.text which has an invalid size (27) [in module system-supplied DSO at 0x6fffd000]
0x00007fd7827acbc0 in _start () from /lib64/ld-linux-x86-64.so.2

Set a breakpoint at main:

(rr)break main
Breakpoint 1 at 0x558bbd0e9185: file main.c, line 7.

Continue until the breakpoint is hit:

(rr)continue
Continuing.

Breakpoint 1, main () at main.c:7
7		int *val = NULL;

And now step through the file until the Segmentation fault is reached:

(rr)step
9		*val = 5;
(rr)step

Program received signal SIGSEGV, Segmentation fault.
0x0000558bbd0e9191 in main () at main.c:9
9		*val = 5;

Egads! A NULL pointer was dereferenced!

See also

  • GDB — used to investigate runtime errors that normally involve memory corruption