Download GNAT User's Guide
Transcript
GNAT User’s Guide Supplement for Cross Platforms
K.9 Non-Symbolic Traceback
A non-symbolic traceback is a list of addresses of call instructions. To enable
this feature you must use the ‘-E’ gnatbind’s option. With this option a stack
traceback is stored as part of the exception occurrence.
Here is a simple example:
with GNAT.IO;
with Ada.Exceptions.Traceback;
with GNAT.Debug_Utilities;
procedure STB is
procedure P1 is
K : Positive := 1;
begin
K := K - 1;
exception
when E : others =>
declare
Buffer : constant Ada.Exceptions.Traceback.Tracebacks_Array :=
Ada.Exceptions.Traceback.Tracebacks (E);
begin
GNAT.IO.Put_Line ("Call stack traceback locations:");
for J in Buffer’Range loop
GNAT.IO.Put (GNAT.Debug_Utilities.Image_C (Buffer (J)));
GNAT.IO.Put (" ");
end loop;
end;
end P1;
procedure P2 is
begin
P1;
end P2;
begin
P2;
end STB;
$ leon-elf-gnatmake -g stb -bargs -E
$ leon-elf-qemu stb
Call stack traceback locations:
0x4000194C 0x40001518 0x400014F4 0x400014C0 0x4000116C
The location of these call instructions can be inspected with standard binary
oriented tools, such as nm or objdump, or with the addr2line tool, that converts
addresses into file names and line numbers. It is also possible to use GDB with
132