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 it is not compiled 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
In the above example the
.\ syntax in the `gnatmake' command
is currently required by `addr2line' for files that are in
the current working directory.
Moreover, the exact sequence of linker options may vary from platform
The above `-largs' section is for Windows platforms. By contrast,
under Unix there is no need for the `-largs' section.
Differences across platforms are due to details of linker implementation.
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;