9.4. The Ada Mode

The Ada mode of the debugger supports a fairly large subset of Ada expression syntax, with some extensions. The philosophy behind the design of this subset is:

Thus, for brevity, the debugger acts as if there were implicit with and use clauses in effect for all user-written packages, making it unnecessary to fully qualify most names with their packages, regardless of context. Where this causes ambiguity, the debugger asks the user's intent.

The debugger will start in Ada mode if it detects an Ada main program. As for other languages, it will enter Ada mode when stopped in a program that was translated from an Ada source file.

While in Ada mode, you may use -- for comments. This is useful mostly for documenting command files. The standard debugger comment (#) still works at the beginning of a line in Ada mode, but not in the middle (to allow based literals).

The debugger supports limited overloading. Given a subprogram call in which the function symbol has multiple definitions, it will use the number of actual parameters and some information about their types to attempt to narrow the set of definitions. It also makes very limited use of context, preferring procedures to functions in the context of the call command, and functions to procedures elsewhere.

9.4.1. Omissions from Ada

Here are the notable omissions from the subset:

9.4.2. Additions to Ada

As it does for other languages, the debugger makes certain generic extensions to Ada: the operators "@", "::", and {type} addr convenience variables and machine registers.

In addition, it provides a few other shortcuts and outright additions specific to Ada:

9.4.3. Stopping at the Beginning

The main procedure in Ada has no fixed name, and attempts to break on main will position you before elaboration. Therefore, Ada mode provides a convenient way to begin execution of the program and to stop at the beginning.

begin

Does the equivalent of setting a temporary breakpoint at the beginning of the main procedure and then performing run. Since in general there is package elaboration code that runs before the main procedure begins, it is possible that the program will stop before reaching the main procedure. However, the temporary breakpoint will remain to halt execution.

9.4.4. Breaking on Ada Exceptions

In Ada mode, you can set breakpoints that trip when your program raises selected exceptions.

info exceptions, info exceptions regexp

The info exceptions command permits the user to examine all defined exceptions within Ada programs. With a regular expression, regexp, as argument, prints out only those exceptions whose name matches regexp.

9.4.5. Extensions for Ada Tasks

Support for Ada tasks is analogous to that for threads. When in Ada mode (that is, when the "current language" is Ada), the debugger allows the following task-related commands:

info tasks

This command shows a list of current Ada tasks, as in the following example:

Example 9-1. Output from info tasks


(gdb) info tasks
 TCB      Task Task        Base Actv   On     Ready  Wakeup Time     Deadline
 Address    Id State       Prio Prio Hold     Count    (seconds)    (seconds)
+--------+----+-----------+----+----+----+---------+------------+------------
*00010778    1 Running        0    0    0         3     0.000000     0.000000
 000107ba    2 At_Barrier     1    1    0         1     0.000000     0.000000
 00010ffa    3 Delayed       10   10    0        24     2.402170     0.000000
 0001183a    4 Delayed       10   10    0        24     2.402170     0.000000
+--------+----+-----------+----+----+----+---------+------------+------------

In this listing, the asterisk before the first task indicates it to be the currently running task.

info queues

This command lists any tasks that are queued in the ready queue, the delay queue and the deadline queue.

Example 9-2. Output from info queues


(gdb) info queues
The ready queue is empty
Delay queue: 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 
The deadline queue is empty

9.4.6. Debugging Generic Units

The compiler always uses code expansion for generic instantiation. This means that each time an instantiation occurs, a complete copy of the original code is made with appropriate substitutions.

It is not possible to refer to the original generic entities themselves in the debugger (there is no code to refer to), but it is certainly possible to debug a particular instance of a generic, simply by using the appropriate expanded names. For example, suppose that Gen is a generic package:

-- In file gen.ads:
generic package Gen is
   function F (v1 : in out INTEGER) return INTEGER;
end Gen;

-- In file gen.adb:
package body Gen is
   function F (v1 : in out INTEGER) return INTEGER is
   begin
      v1 := v1 + 1;
      return v1;         -- Line 5
   end F;
end Gen;

and we have the following expansions:

procedure G is
   package Gen1 is new Gen;
   package Gen2 is new Gen;
begin
   Gen1.F;
   Gen2.F;
   Gen1.F;
   Gen2.F;
end; 

Then to break on a call to procedure F in the Gen2 instance, simply use the command:

break G.Gen2.F 

To break at a particular line in a particular generic instance, say the return statement in G.Gen2, append the line specification to the file and function name:

break gen.adb:G.Gen2.F:5 

To break on this line line in all instances of Gen, use `*' as the function name:

break gen.adb:*:5 

This will set individual breakpoints at all instances; they are independent of each other and you may remove, conditionalize, or otherwise modify them individually.

When a breakpoint occurs, you can step through the code of the generic instance in the normal manner. You can also examine values of data in the normal manner, providing the appropriate generic package qualification to refer to non-local entities.

9.4.7. Set commands for Ada

Ada introduces one new set command.

set varsize-limit size

Limit the size of the types of objects when those sizes are computed from run-time quantities to size bytes. When this is set to 0, there is no limit. By default, it is about 65K.

show varsize-limit

Show the limit on types whose size is determined by run-time quantities.

9.4.8. Known Peculiarities of Ada Mode

Besides the omissions listed previously (see Section 9.4.1), we know of several problems with and limitations of Ada mode in the debugger, some of which will be fixed with planned future releases of the debugger and the Ada compiler.