Previous: Tracebacks From Exception Occurrences (symbolic), Up: Symbolic Traceback


29.14.2.2 Tracebacks From Anywhere in a Program

It is possible to get a symbolic stack traceback from anywhere in a program, just as for non-symbolic tracebacks. The first step is to obtain a non-symbolic traceback, and then call Symbolic_Traceback to compute the symbolic information. Here is an example:

     with Ada.Text_IO;
     with GNAT.Traceback;
     with GNAT.Traceback.Symbolic;
     
     procedure STB is
     
        use Ada;
        use GNAT.Traceback;
        use GNAT.Traceback.Symbolic;
     
        procedure P1 is
           TB  : Tracebacks_Array (1 .. 10);
           --  We are asking for a maximum of 10 stack frames.
           Len : Natural;
           --  Len will receive the actual number of stack frames returned.
        begin
           Call_Chain (TB, Len);
           Text_IO.Put_Line (Symbolic_Traceback (TB (1 .. Len)));
        end P1;
     
        procedure P2 is
        begin
           P1;
        end P2;
     
     begin
        P2;
     end STB;