15 Using Debugger Scripts

This chapter describes the scripting features of the Digital Ladebug debugger. Using debugger script commands, you can specify a file to input as debugger commands, send debugger output to a file, or send a transcript of an entire debugging session to a file.

15.1 The Debugger Initialization File

When you start the debugger, it first searches for a file named .dbxinit in the current directory; if it is not there, it then searches for it in your home directory. If a .dbxinit file exists in either directory, the debugger interprets the contents of the file as a string of debugger commands. You can customize your debugger environment by adding commands to your .dbxinit file that set debugger aliases (using the alias command), debugger variables (using the set command), and source-code search paths (using the use command).

Ladebug processes the .dbxinit file using the language of the main program being debugged. Depending on the language of that program, there are some situations where the behavior of some .dbxinit commands may vary. If this is an issue, you can put a set $lang command in the file to ensure the expected behavior.

Example 15-1 shows a sample .dbxinit file.

Example 15-1 A Sample .dbxinit File

set $listwindow = 45
alias ls "sh ls -l"
stop in main; run

When you invoke the debugger, it executes the commands in the .dbxinit file without echoing the commands to the screen. Example 15-2 shows this process for the sample .dbxinit file.

Example 15-2 Debugger Startup Using a .dbxinit File

%  ladebug sample
Welcome to the Ladebug Debugger Version 4.0
------------------
object file name: sample
Reading symbolic information ...done
[#1: stop in main ]
[1] stopped at [main:4 0x1200001180]
      4     for (i=1 ; i<3 ; i++) {
(ladebug)

15.2 Recording Debugger Sessions

You can record both your debugger commands as well as the debugger's responses into a single file by using the record io command. The syntax for this command is as follows:

record io  filename

The debugger records all input and output starting with the command following the record io command.


Note
The record io command does not record the output from the program you are debugging.

To stop recording, you must exit the debugger. If a file already exists with the file name you specify, the debugger appends to the file.

You can record debugger responses to your commands using the record output command. The syntax for this command is as follows:

record output  filename

Use the record input command to create a file containing the commands you enter at the debugger prompt. The syntax for this command is as follows:

record input  filename

Use the record input command to create a debugger script. After creating a file containing a list of debugger commands, you can request that the debugger execute the commands in the file using the source command. You can also use an editor (such as vi or emacs ) to edit the commands listed in the file. Example 15-3 shows how to use the record input command to record a series of debugger commands in a file named myscript.

Example 15-3 Recording a Debugger Script

(ladebug) record input myscript

(ladebug) stop in main
[#1: stop in main ]

(ladebug) run
[1] stopped at [main:4 0x120000b14]
      4     for (i=1 ; i<3 ; i++) {

(ladebug) next
stopped at [main:5 0x120000b1c]
      5         f = factorial(i);

(ladebug) step
stopped at [factorial:13 0x120000bb8]
     13     if (i<=1)

(ladebug) where
>0  0x120000bb8 in factorial(i=1) sample.c:13
#1  0x120000b28 in main() sample.c:5

(ladebug) cont
1! = 1
2! = 2
Thread has finished executing

(ladebug) quit

% cat myscript
stop in main
run
next
step
where
cont
quit

%

15.3 Playing Back a Command Script

With the source or playback input commands, you can read in and execute a file containing debugger commands. You can create such a file manually using an editor or automatically using the record input command. The syntax of the command to read in a file of debugger commands is as follows:

source  filename

playback input  filename

The file corresponding to the filename argument must be in the current directory or be preceded by a path specification. When the debugger executes a script file, the $pimode debugger variable determines whether the commands are echoed to the display as they are executed, as follows:

Example 15-4 shows how to execute a debugger script. Because $pimode is set to 0, only the command output, and not the commands themselves, echoes to the display.

Example 15-4 Executing a Debugger Script

(ladebug) source myscript
[#1: stop in main ]
[1] stopped at [main:4 0x120000b14]
      4     for (i=1 ; i<3 ; i++) {
stopped at [main:5 0x4001d4]
      5         f = factorial(i);
stopped at [factorial:13 0x120000b1c]
     13     if (i<=1)
>0  0x120000bb8 in factorial(i=1) sample.c:13
#1  0x120000b28 in main() sample.c:5
1! = 1
2! = 2
Thread has finished executing
%