Debugging with Mozilla rr
Mozilla rr records program execution so you can replay it in the debugger and investigate the same sequence of events more than once.
To debug a recording, wait for the application to exit or click stop the recording in the Debug tool window. You can then inspect the recorded execution and move forward or backward between breakpoints.
Debug code with Mozilla rr
Install Mozilla rr. For installation instructions, refer to the Building And Installing.
In IntelliJ IDEA, set a breakpoint. To set a breakpoint, click the gutter near the code line where you want the debugger to stop code execution. For more information about breakpoints, refer to Debug code and Breakpoints.
Click the Run icon (
) in the gutter and select Record and Debug <configuration_name>. After recording finishes, inspect variables and goroutines in the Debug tool window.
Navigate through the recorded trace
Navigate to .
In the Trace directory field, specify a path to the trace directory.
Click OK.
In the Debug tool window, click Resume Program to move forward to the next breakpoint, or Rewind to move backward to the previous breakpoint.
Collecting Mozilla rr traces
In the application directory, build an executable with optimizations and inlining disabled:
go build -gcflags="all=-N -l" -o myAppKeep the debug information in the executable. Do not use linker flags such as
-wor-sthat remove information needed by the debugger.Open the terminal and run the following Mozilla rr command:
rr record <path_to_the_application_executable>As a result, the Mozilla rr trace files appear in the following folder: ~/.local/share/rr/<executable_name>
Remote debugging with Mozilla rr
On the remote machine, collect the Mozilla rr trace.
On the remote machine, start Delve with a loopback listener:
dlv --headless --api-version=2 --listen=127.0.0.1:2345 replay /path/to/trace/dirReplace /path/to/trace/dir with the recorded trace directory.
On your local machine, forward the debugger port through SSH:
ssh -N -L 2345:127.0.0.1:2345 user@remote-hostReplace
userandremote-hostwith your SSH username and the remote computer's address. Keep the connection open while debugging. Delve connections are not authenticated; keep the debugger port private.On the local machine, create the Go Remote run/debug configuration. Set Host to
127.0.0.1and Port to2345. For more information about creating run/debug configurations, refer to Create a run/debug configuration.On the local machine, ensure that the Go Remote run/debug configuration is selected from the list of configurations.
On the local machine, click . Alternatively, press Shift+F9.