Time travel debugging in IntelliJ

Setup

If you’re replaying a recording, use the lr4j_replay tool.

Or if you’re debugging remotely, launch your application on the remote machine supplying the LiveRecorder agents on the Java command-line.

Consider adding breakpoints and/or watchpoints before starting the debugger session since your application or recording will start running as soon as you press the Debug button.

Start the debugger session

Choose a Run/Debug configuration from the Run/Debug Configurations dialog and press the Debug button to start debugging.

_images/rundebug.png

Note

Refer to Replaying a recording or Live Debugging if you haven’t already created a LiveRecorder Run/Debug configuration.

While your application is running, you can’t interact with it or examine application state. You can only Pause, Stop or Rerun your application. See IntelliJ tips for more info.

_images/running.png

Once your application is suspended due to hitting a breakpoint or watchpoint, you can examine variables and the contents of the stack and evaluate arbitrary expressions. Refer to the IntelliJ documentation for details. You can’t alter variables while time-travel debugging, since doing so would likely change the future execution of the application and cause the timelines to diverge.

Forward and reverse execution

You can use the familiar Step Over, Step Into, Force Step Into, Step Out and Run to Cursor buttons to step the application forwards, or the Resume button to run the application forwards until it hits a breakpoint or watchpoint.

_images/forward.png

LiveRecorder for Java adds the Reverse Step Out, Reverse Step Into and Reverse Step Over buttons, which you can use to step the application backwards, and the Resume Back button to run your application backwards until it hits a breakpoint or watchpoint.

_images/undo_buttons.png

Other methods of navigation

Use the Undo button to undo the effects of the last button that changed the time in your application’s execution history.

Log Jump

Use the Log Jump button to jump to a wall-clock time in your application’s execution history. This is useful when you’ve identified a line of interest in a log file: in this case copy the timestamp from the log file and paste it into the Log Jump dialog to jump directly to the point in time in your application’s execution history where it emitted that log line. (The Log Viewer window is an alternative way of doing the same thing)

Timestamps should ideally have millisecond accuracy but even these are only approximate so you might find that the resulting stack is just somewhere in the code that emitted the log line.

_images/logjump.png

Note

The Log Jump feature recognises timestamps in many standard time formats produced by common logging frameworks including Log4j, Logback and java.util.logging. You can add other time formats under Settings › Tools › LiveRecorder › Timestamp patterns. If the timezone is not specified in the timestamp it defaults to the local timezone.

Step Across

Use the Step Across and Step Across Back buttons to step between two of the services that comprise a microservice-based application. Step Across jumps to the point in time in another service’s execution history when it received the next API call made by this service. Step Across Back jumps to the point in time in another service’s execution history when it last made an API call to this service. Refer to Microservices for more information.

Bookmarks

LiveRecorder for Java allows you to set bookmarks in a recording to which you can later return. They are displayed in the TimeTravelBookmarks tool window (View › Tool Windows › TimeTravelBookmarks) as shown below:

_images/bookmarks.png

Use the START and END bookmarks to jump to the beginning or end of your application’s execution history.

Use the Add Bookmark button to add a bookmark at the current point in time in your application’s execution history. You can return to this point in time by clicking on the bookmark.

Bookmarks are automatically ordered by their place in the execution history and display the location as well as the bbcount.

Bookmarks are not persistent and only exist for the lifetime of the session.

If you press the control key and then hover over the bbcount cell, the bbcount will be copied to the clipboard. This can be useful when examining the same recording using udb.

Log Viewer

As an alternative to the Log Jump window you can also open a log file in the LogViewer window (View › Tool Windows › LogViewer). If the log file contains a timestamp at the start of each line in one of the recognised formats, just clicking on that line will take you to the approximate location.

_images/logviewer.png