11.2 Symbolic Debugging 12 Using Simics for Hardware Bring-Up and Firmware Development
Simics User's Guide  /  III Low-Level Debugging  /  11 Low-level Debugging with Simics  / 

11.3 Reverse Execution

Simics has the capability to run a simulation in reverse, which in many cases can greatly simplify the debugging of complicated software problems.

From a user perspective, there is little difference between running the simulation forwards and backwards; all the standard debugging tools like breakpoints and watchpoints can be used when the simulation is run in reverse. There are, however, some reverse execution specific issues, which are discussed in the following sections.

11.3.1 Using Reverse Execution

Before any reverse operations can be performed, there has to be at least one time bookmark; reverse operations are possible in the region following the first (oldest) bookmark. Depending upon how Simics is invoked (and various user preferences), a time bookmark denoted "start" is sometimes added automatically at the beginning of the simulation. Bookmarks can also be created by enabling reverse execution in an external debugger.

Bookmarks are managed through the commands

Note: From a performance and resource utilization perspective, it might be advantageous to put the first bookmark as close to the region of interest as possible.
Reverse execution support is disabled when all time bookmarks are deleted.

Once reverse execution has been enabled (by the creation of a time bookmark), it is possible to both run the simulation in reverse and to skip backwards in time. The Simics commands to do this are

The reverse and reverse-to commands run the simulation backwards until a breakpoint occurs or till the oldest time bookmark is reached. The skip-to command jumps to a particular point in time, ignoring intermediate breakpoints. It should be noted that skipping can be significantly faster than reversing.

The skip-to and reverse-to commands take either an absolute step count or a time bookmark as argument.

Most forward executing commands used for debugging has a corresponding reverse variant obtained by adding a reverse prefix. The reverse variant of step-instruction is for instance reverse-step-instruction.

Any external input (like a human typing on a virtual serial console) is replayed when the simulation is being run forward after a reversal; this guarantees that the simulation will follow the same path as it did originally. For the same reason, all external input is ignored until the point is reached where the first reverse operation was initiated. It is possible to override this behavior with the clear-recorder command. This command discards all recorded input and allows an alternate future to take place.

Some changes to the simulation from entities outside the simulation are not recorded by recorders, for example manual changes from the command line interfaces or the graphical user interface. Such changes can make reverse execution operate somewhat unpredictably. It is recommended that any time bookmarks before a non-replayable change of the simulation state is deleted explicitly.

11.3.2 Performance

The usage of time bookmarks has a certain impact on overall performance since it implicitly enables reverse execution support. Normal performance is always obtained if all time bookmarks are removed.

The reverse execution engine optimizes performance for certain reverse operations that are expected to be common. One example of this is that skipping to a bookmark (or to the region just after a bookmark) can be significantly faster than skipping to some other location.

It is possible to tune certain reverse execution parameters in order to optimize for a particular usage pattern (although the default settings should work well in most situations). Trade-offs exist between:

The rexec-limit command is the primary tool for adjusting the balance, e.g.

    simics> rexec-limit steps = 20000000 
    simics> rexec-limit size_mb = 200 

The steps limit indicate that the scope of interest is at most the specified number of steps. By imposing a steps limit, resources can be spent more effectively with the drawback that reversal past the limit may not be possible.

The size limit imposes a limit on the amount of memory reverse execution may use. If the limit is exceeded, reverse performance will be traded for less memory consumption.

11.2 Symbolic Debugging 12 Using Simics for Hardware Bring-Up and Firmware Development