PowerAda Debugging Shortcuts

From OC Systems Wiki!
Jump to: navigation, search

The debugger commands described in this section can be used individually or together to improve your productivity during a debugging session. For example, the LOG and SCRIPT commands can be used to record and repeat debugger commands; the HISTORY command can be used to quickly recall the last few debugger commands that were executed during a debugging session; and the MACRO command creates new debugger commands to be used in place of a sequence of commands.

Recalling Debugger Commands: HISTORY

The syntax for this command is:

history [N]

where Nis the number of commands you want the debugger to keep for later review. For instance, if you wanted to keep 30 commands in the history buffer, you would enter

history 30

By default, the debugger keeps the last 20 commands. If you enter HISTORY with no parameters, the debugger displays the commands in the history buffer.

Each command listed is preceded by a number. To repeat a command, enter the "!" character followed by the number of the command you want to repeat. The command will execute again.

For example, if you wanted to repeat the last SOURCE command you entered, you might do something like this:

Debug> hi 
  11 log open debug.log
  12 run
  13 source 52-56,example1
  14 break 55
  15 continue
Debug> !13

History entries can be used to construct new command lines, using the history reference indicator. For example, if history entry 10 is BREAK, all of the following are valid commands:

!10 1,sec/some_package
!10 sorter.sort:entry
un!10 sorter.sort:entry

Recording a Debugging Session: LOG

The syntax for this command is:

log [{create | open | append LogFileName} | close]

where LogFileName is the name of a file that you specify. No suffix is added to the LogFileName.

The LOG command creates, opens closes, appends, or displays the name of a debugger log file. When you enter LOG without a variable, the debugger displays information on whether a log file is open or not. If a log file is open, its name is displayed.

All user commands and debugger output are saved in the log file. Program I/O does not appear in the log file. The debugger output is saved as comments (preceded by "--"). This allows log files to be used as script files (see "Executing Pre-Recorded Commands: SCRIPT" for information about the SCRIPT command). You will probably want to edit the log file and remove the debugger's output before reusing the log file as a script. If a script is run while a log file is open and the script contains a LOG CLOSE command, the log file is closed.

The command:

log create LogFileName

creates a new LogFileName. If it already exists, there will be an error message.

The command:

log open LogFileName

opens LogFileName for logging. A log file contain information from only one log session. If you open an existing log file to begin a new session, the log file accumulates information from the new session and writes over the existing file.

The command:

log append LogFileName

opens an existing log file and appends new commands to it. The debugger issues an error message if LogFileName does not exist.

The command:

log close

closes an open log file and discontinues input and output logging.

Abbreviating Sequences of Debugger Commands: MACRO

This command allows you to define sequences of debugger commands as a single macro that you can invoke during your debugging session. Commands are provided to create new macros, and to change, delete, and display existing macros.

Creating a New Macro

macro MacroName [(Parameter[,...])] [Variable[,...]] is

creates a new macro for later execution, where:

is the name of the macro you want to create.
is a formal parameter to the macro; more than one parameter may be specified, provided each is separated by a comma. The parameter list must be enclosed in parentheses. When the macro is invoked, the debugger sets the value of each macro formal parameter to the corresponding actual parameter. The number of actual parameters must match the number in the macro declaration. Parameters are referenced within the macro by name.
is a local variable to the macro; more than one variable may be specified, provided each is separated by a comma. Each local variable is set to the null string. Within the body of the macro, you can access and change the values in these variables in the same manner as global variables. You cannot, however, remove the variables. When the macro finishes execution, the debugger automatically removes the local variables and parameters.

After you have entered the first line of a macro definition the debugger prompts you to enter more lines until the definition is finished. No syntax check is made to any line that contains a macro parameter.

The correctness of such a macro command line cannot be determined until the line is already executed. You indicate that the macro is complete by entering END MacroName, in response to the macro line prompt. For example:

Debug> macro my_macro(a_param) is
  my_macro : run
  my_macro : break $a_param
  my_macro : cont
  my_macro : end my_macro

Executing Macros:

To execute a macro, enter:

MacroSpec [(Parameter[,...])]

For example:


The debugger executes each command in sequence.

Deleting a Macro

macro delete MacroSpec

removes the definition for the previously created macro called MacroSpec. After you have deleted MacroSpec, you may no longer invoke that macro. This means that other macros that reference MacroSpec will no longer work.

Changing a Macro

macro edit MacroName

Calls the vi editor, allowing you to change the contents of a macro. With MACRO EDIT, the debugger does not check the syntax of lines until you end the editing session. At the end of a session, the debugger checks all changed lines and returns you to the editor if errors are detected.

Note: if a log file is open when you use MACRO EDIT, changes made during the editing session will not be put in the log.

Displaying Defined Macros

macro list [MacroSpec]

Displays the names and parameters of MacroSpec. If MacroSpec is not specified, it displays the names and parameters of all currently defined macros.

Renaming a Macro

macro rename MacroName NewName

Changes the name of the existing macro to NewName.

Displaying Definitions of Macros

macro show [MacroSpec]

Displays the definition of the macro MacroSpec. If no MacroSpec is specified, the definitions of all currently available macros are displayed.

Executing Pre-Recorded Commands: SCRIPT

This command reads a specified debugger script and runs the commands contained in it. You can use a log file from a previous debugging session as a script. The syntax of this command is:

script ScriptFileName

The debugger reads text contained in the file ScriptFileName as if it were typed at the keyboard. Lines beginning with "--" are comments and are ignored. Lines read from the file, and the output of commands, are echoed to the screen.

A debugger log file to be used as a script file may contain much output in the form of comment lines generated by the previous commands in the log file. You can delete these excess lines by editing the log file. If you do not edit a log file before you use it as a script file, the new output appears in the log file before the old output for a command. If a script is run while a log file is open and a LOG command has not been removed from the script, the log file is closed.

The script file can be used to repeat a set of previous debugging actions from a log file, so that you can break up your long debugging sessions and continue at a later time. Any time during a debugging session, the debugger can read one script file. Script files can contain calls to other script files.

The following is an example of a short script file:

br 64,part1
br 353,part2
unbr 64

A script can be useful for displaying the values of critical variables, such as A and B in the example above. Scripts also provide a convenient shorthand for catching values within a specific iteration of a loop. For instance, to catch a value in the 10th iteration of a loop, the script file can set a breakpoint at the critical variable within the loop and issue 10 CONTINUE commands before asking for a display of the value of the variable. (You can do the same thing by entering a BREAK command using a condition of COUNT 10.) If there are several locations of particular interest within your program, you might create a script file that sets breakpoints at those locations. You might want to run this script each time you debug this program. Or you can save the script with the program and give it to other users who may need to debug the program.