GNAT symbolic traceback of Ada exceptions is not working on macOS
because macOS doesn't support addr2line.
Hopefully, Xcode brings a similar tool: atos.
This library calls atos with exception information and returns
the symbolic traceback.
This workaround is compatible with other OS.
Thus, in case of an other OS, it simply returns the original Symbolic_Traceback functions from GNAT.
In your own Alire project, add exsytrawo dependency:
% alr with exsytrawo
Then, you can import the Ada exsytrawo package in your programs.
Your program must compile with -g switch and bind with -E switch.
You can use it like that:
with Ada.Text_IO; use Ada.Text_IO;
-- with GNAT.Traceback.Symbolic; use GNAT.Traceback.Symbolic;
with Excep_Sym_Trace_Workaround; use Excep_Sym_Trace_Workaround;
procedure STBGA is
procedure P1 is
begin
raise Constraint_Error;
end P1;
procedure P2 is
begin
P1;
end P2;
begin
P2;
exception
when E : others =>
Put_Line ("----------------------------");
Put_Line (Symbolic_Traceback (E));
Put_Line ("----------------------------");
end STBGA;or:
with GNAT.Exception_Traces;
with Excep_Sym_Trace_Workaround;
procedure STBH is
procedure P1 is
begin
raise Constraint_Error;
exception
when others =>
null;
end P1;
procedure P2 is
begin
P1;
raise Storage_Error;
end P2;
begin
GNAT.Exception_Traces.Trace_On (GNAT.Exception_Traces.Every_Raise);
GNAT.Exception_Traces.Set_Trace_Decorator
(Excep_Sym_Trace_Workaround.Symbolic_Traceback'Access);
P2;
end STBH;All files are provided under terms of the CeCILL-C licence.
Pascal Pignard, February-August 2025.