Next: , Previous: Ada Tasks, Up: Ada


12.4.3.7 Debugging Generic Units

GNAT 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 GDB (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 : Integer) return Integer;
     end Gen;
     
     -- In file gen.adb:
     package body Gen is
        function F (v1 : Integer) return Integer is
        begin
           return v1+1;         -- Line 5
        end F;
     end Gen;

and we have the following expansions

     with Gen;
     procedure G is
        package Gen1 is new Gen;
        package Gen2 is new Gen;
     
        I : Integer := 0;
     begin
        I := Gen1.F (I);
        I := Gen2.F (I);
        I := Gen1.F (I);
        I := Gen2.F (I);
     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.