A symbolic traceback is a stack traceback in which procedure names are associated with each code location.
Note that this feature is not supported on all platforms. See
GNAT.Traceback.Symbolic
spec in g-trasym.ads
for a complete
list of currently supported platforms.
Note that the symbolic traceback requires that the program be compiled with debug information. If you do not compile it with debug information, only the non-symbolic information will be valid.
Here is an example:
with Ada.Text_IO; with GNAT.Traceback.Symbolic; procedure STB is procedure P1 is begin raise Constraint_Error; end P1; procedure P2 is begin P1; end P2; procedure P3 is begin P2; end P3; begin P3; exception when E : others => Ada.Text_IO.Put_Line (GNAT.Traceback.Symbolic.Symbolic_Traceback (E)); end STB;$ gnatmake -g stb -bargs -E $ stb 0040149F in stb.p1 at stb.adb:8 004014B7 in stb.p2 at stb.adb:13 004014CF in stb.p3 at stb.adb:18 004015DD in ada.stb at stb.adb:22 00401461 in main at b~stb.adb:168 004011C4 in __mingw_CRTStartup at crt1.c:200 004011F1 in mainCRTStartup at crt1.c:222 77E892A4 in ?? at ??:0
You can get a symbolic stack traceback
from anywhere in a program, just as you can for non-symbolic tracebacks.
The first step is to obtain a non-symbolic
traceback. 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;
You may also enable symbolic tracebacks by using
the -Es
switch to gnatbind (as in gprbuild -g ... -bargs -Es
).
This causes the Exception_Information to contain a symbolic
traceback, which will also be printed if an unhandled exception
terminates the program.