Debugging a Program With dbx

Saving and Restoring a Debugging Run

dbx provides three commands for saving all or part of a debugging run and replaying it later:

save

The save command saves to a file all debugging commands issued from the last run, rerun, or debug command up to the save command. This segment of a debugging session is called a debugging run.

The save command saves more than the list of debugging commands issued. It saves debugging information associated with the state of the program at the start of the run -- breakpoints, display lists, and the like. When you restore a saved run, dbx uses the information in the save-file.

You can save part of a debugging run; that is, the whole run minus a specified number of commands from the last one entered. Example A shows a complete saved run. Example B shows the same run saved, minus the last two steps:

 A.   B. 
   debug     debug
   stop at line     stop at line
    run    run
   next    next
 Saving a Complete Run  next  Saving a Run Minus the Last Two Steps  next
  stop at line   stop at line
  continue   continue
   next    next
   next    next
   step    step
   next     next
    save    save-2

If you are not sure where you want to end the run you are saving, use the history command to see a list of the debugging commands issued since the beginning of the session.

To save all of a debugging run up to the save command:


(dbx) save

To save part of a debugging run


(dbx) save number

where number is the number of commands back from the save command that you do not want saved.

Saving a Series of Debugging Runs as Checkpoints

If you save a debugging run without specifying a filename, dbx writes the information to a special save-file. Each time you save, dbx overwrites this save-file. However, by giving the save command a filename argument, you can save a debugging run to a file that you can restore later, even if you have saved other debugging runs since the one saved to filename.

Saving a series of runs gives you a set of checkpoints, each one starting farther back in the session. You can restore any one of these saved runs, continue, then reset dbx back to the program location and state saved in an earlier run.

To save a debugging run to a file other than the default save-file:


(dbx) save filename

Restoring a Saved Run

After saving a run, you can restore the run using the restore command. dbx uses the information in the save-file. When you restore a run, dbx first resets the internal state to how it was at the start of the run, then reissues each of the debugging commands in the saved run.


Note -

The source command also reissues a set of commands stored in a file, but it does not reset the state of dbx; it merely reissues the list of commands from the current program location.


Prerequisites for An Exact Restoration of a Saved Run

For exact restoration of a saved debugging run, all of the inputs to the run must be exactly the same: arguments to a run-type command, manual inputs, and file inputs.


Note -

If you save a segment and then issue a run, rerun, or debug command before you do a restore, restore uses the arguments to the second, post-save run, rerun, or debug command. If those arguments are different, you may not get an exact restoration.


To restore a saved debugging run:


(dbx) restore

To restore a debugging run saved to a file other than the default save-file:


(dbx) restore filename

Saving and Restoring Using replay

The replay command is a combination command, equivalent to issuing a save -1 followed immediately by a restore. The replay command takes a negative number_of_ commands argument, which it passes to the save portion of the command. By default, the value of -number is -1, so replay works as an undo command, restoring the last run up until but not including the last command issued.

To replay the current debugging run, minus the last debugging command issued:


(dbx) replay

To replay the current debugging run and stop the run before the second to last command, use the dbx replay command where number is the number of commands back from the last debugging command:


(dbx) replay -number