Skip to content

RR and Seer

Ernie Pasveer edited this page Sep 4, 2023 · 14 revisions

Introduction

RR is a popular time-travel debugger. While the gdb debugger itself has its method to debug forward or backwards, RR method is slightly different. RR can record a program's execution to a file. This is done once. This file can then be played back through gdb to debug the program, forward or backwards, as many times as you want.

More information on RR can be found here:

https://rr-project.org/
https://github.com/rr-debugger/rr/wiki/Usage

Install RR

Install RR using your distro's package manager. Otherwise, you will need to get RR from github and follow the build instructions.

I'd like to mention at this point, not all Linux hardware can support running RR. RR requires some kernel features and CPU features to work. Of the 3 linux boxes I have, only 1 worked. I suspect the other 2 have CPU chips that are older technology.

https://github.com/rr-debugger/rr/wiki/Will-rr-work-on-my-system

The error I got was:

$ rr record hellovalgrind |& c++filt 
[FATAL src/PerfCounters.cc:325:check_for_ioc_period_bug() errno: EINVAL] ioctl(PERF_EVENT_IOC_PERIOD) failed
=== Start rr backtrace:
rr(rr::dump_rr_stack()+0x28)[0x45b558]
rr(rr::notifying_abort()+0xe)[0x45f65e]
rr[0x44a090]
rr(rr::PerfCounters::reset(long)+0x67d)[0x54822d]
rr(rr::Task::resume_execution(rr::ResumeRequest, rr::WaitRequest, rr::TicksRequest, int)+0x15c)[0x48b1bc]
rr(rr::RecordSession::task_continue(rr::RecordSession::StepState const&)+0x3fe)[0x539f8e]
rr(rr::RecordSession::record_step()+0x2d0)[0x537270]
rr(rr::RecordCommand::run(std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, ...)+0xdc4)[0x53b284]
rr(main+0x179)[0x446149]
/lib64/libc.so.6(__libc_start_main+0xef)[0x7fca3ce3924d]
rr(_start+0x2a)[0x44639a]
=== End rr backtrace
$ 

Even after the suggested fix of:

sysctl kernel.perf_event_paranoid=1

Anyway, more of a problem with my suspected old hardware.

Using RR and Seer

Running RR record

The first thing to do is use RR to record a program's execution. My example here has an intentional SEGV error. RR will save the recording to a trace directory the replay session will load. Although RR has a method of automatically setting the trace directory, it's best to manually specify it. At least, Seer requires manually specifying the trace directory.

$ rr record -n --output-trace-dir=hellosegv.rr hellosegv one two three
rr: Saving execution to trace directory `hellosegv.rr'.
XX: 0 hellosegv
XX: 1 one
XX: 2 two
XX: 3 three
Hello, World!42
Segmentation fault
$ 

Now that the program's execution is recorded, it can now be debugged any number of times.

Using Seer to debug the replay session.

Seer has two ways to connect to the replay session. The first is from the command line:

$ seergdb --rr hellosegv.rr

The second is using Seer's debug dialog. Click on the RR tab and enter the path to the trace-directory previously entered during the 'rr record'.

image

Start debugging.

After clicking OK, you can now debug using RR. RR will initially stop the execution of the program in the "_start" function, which is just before the "main()" function. This gives you an opportunity to set breakpoints or change other gdb settings.

image

Create the breakpoint via Seer's gdb entry field, or by clicking on New Breakpoint button in the breakpoint tab.

image

Click on Continue or F8 to continue running the program. It will stop in "main()".

From this point on, you are debugging as usual. You can set more breakpoints, examine variables and memory, step through the program. The big difference is you are now able to use RR's big feature, debugging forward or backwards.

Seer show's the debugging direction prominently on Seer's main toolbar. The arrow can be clicked to toggle the debugging direction.

image

The arrow pointing right means you are debugging forwards. This affects step, next, continue, and finish commands. The arrow pointing left means you are debugging backwards.

The RR button just means you are, in fact, using RR.

One point to mention is you can show the assembly tab and you can step, forwards or backwards, one instruction at a time.

Have fun with RR!

RR Config Settings

Seer has a configuration dialog for some RR settings. Look under: Settings -> Configuration -> RR

image

Feedback.

Send me email or create a task for errors/suggestions/etc.