PowerAda Conditional Execution of Debugger Commands

From OC Systems Wiki!
Jump to: navigation, search

The debugger provides several structured statements, patterned after Ada statements, for conditional execution of debugger commands. They are:

In addition to these statements, you can use the EXIT and NULL commands in structured statements. EXIT allows an exit from a LOOP or WHILE statement; the NULL command allows the debugger to "do nothing". The syntax is described fully below.

Within the structured statements, you can have one or more debugger commands or structured statements. These are referred to, collectively, as a StatementList.

The debugger imposes three restrictions on the syntax of structured statements:

  1. You cannot abbreviate structured-statement keywords, such as END, LOOP, and THEN.

  2. Delayed substitution is not allowed for keywords or expressions in structured statements. For example, you cannot use a delayed substitution of a debugger variable ERROR_COUNT within an IF statement. The debugger will not allow you to complete the following sequence:

    declare otherwise;
    otherwise := "else"
    break 45 then
    if $error_count > 1 then
    -- ''No expression substitution
    '' step_mac
    otherwise -- ''No keyword substitution
    '' source $next_break
    -- ''Delayed substitution OK
    '' end if
  3. You cannot dereference a macro parameter in a nested macro or a BREAK..THEN compound command. For example, the following sequence does not execute as intended:

    Debug 14> macro stop_and_show(location,object) is
    stop_and_show> break $location then
    break> ? $object
    -- Executed when the breakpoint is hit
    stop_and_show> end stop_and_show

The debugger does not attempt to dereference $object until the breakpoint is reached. At that point the macro and the values of its parameters can no longer be referenced.

The same situation applies to nested macros. For example, the following sequence does not execute as intended:

Debug 18> macro watch(location,steps) is
watch> break $location then
break> begin
1 begin break> stepmac($steps)
   -- Executed when the breakpoint is hit
1 begin break> end
watch> end watch

If an error occurs during evaluation of an IF, ELSIF, or WHILE expression (for example, the expression contains a reference to an undefined variable), the statement terminates immediately without executing any commands. Guidelines for using expressions appear in "Using Expressions".

When a structured statement begins, the debugger adds, to the left of the prompt, information about the level of nesting of the control structures. In the example above, the begin/end pair is listed as being at level 1, while the IF/ELSE combination is listed as being at level 2. This information appears during an interactive session but, like the debugger prompt, it does not appear in a log file.


begin StatementList end

The BEGIN command groups a series of statements (the StatementList) together into a single compound statement. Use BEGIN in macros and in breakpoints with action clauses. Here are some examples of BEGIN:

break 17,sec/test then begin ? foo; ? x; continue; end


begin StatementList end

if expression then StatementList else StatementList end if
loop StatementList end loop

The END command ends the BEGIN, IF, and LOOP commands.


if expression then StatementList
[elsif expression then StatementList]
[else StatementList] end if

The IF command implements the Ada IF/THEN/ELSE structure within the debugger. The debugger evaluates each expression in turn and executes the StatementList associated with the first expression that evaluates to true. If all expressions evaluate to false, the debugger executes the StatementList associated with the ELSE, if one exists. Each expression must evaluate to a boolean value. For example:

if foo = 10 then ? x else ? y end if

You can use the EXIT command to exit the IF/THEN/ELSE structure. = See "Ending a Debugging Session: EXIT" for more information on the EXIT command.


loop StatementList end loop

The LOOP command specifies a debugger command loop; the debugger repeatedly executes StatementList until it encounters an EXIT.

Be sure to include an EXIT command in your loop, since the debugger provides no way for you to interrupt infinite loops. = See "Ending a Debugging Session: EXIT" for more information on the EXIT command.

Here is an example of LOOP:

  ? x; ? y
  exit when x = y
end loop


The NULL command does nothing. It is most often used within a structured statement:


For example:

if count = 10 then null else item := item + 1 end if


The WHILE command implements the Ada WHILE loop within the debugger:

while Expression loop StatementList end loop

The debugger repeatedly evaluates Expression and executes StatementList as long as it evaluates to true, stopping if it encounters an EXIT.

Here is an example of WHILE:

while x = 4 loop
  ? y
end loop