Debugging Generic Units (GNAT User’s Guide for Native Platforms)

#### 6.1.9 Debugging Generic Units ¶

GNAT always uses the code expansion mechanism for generic instantiation. This means that each time an instantiation occurs, the compiler makes a complete copy of the original code, with appropriate substitutions of formals by actuals.

You can’t refer to the original generic entities in `GDB`, but you can debug a particular instance of a generic by using the appropriate expanded names. For example, if we have

>     procedure g is

>        generic package k is
>           procedure kp (v1 : in out integer);
>        end k;

>        package body k is
>           procedure kp (v1 : in out integer) is
>           begin
>              v1 := v1 + 1;
>           end kp;
>        end k;

>        package k1 is new k;
>        package k2 is new k;

>        var : integer := 1;

>     begin
>        k1.kp (var);
>        k2.kp (var);
>        k1.kp (var);
>        k2.kp (var);
>     end;

Then to break on a call to procedure kp in the k2 instance, simply use the command:

>     (gdb) break g.k2.kp

When the breakpoint occurs, you can step through the code of the instance in the normal manner and examine the values of local variables, as you do for other units.