0

If an assertion fails, I get the following output:

raised SYSTEM.ASSERTIONS.ASSERT_FAILURE : Dynamic_Predicate failed at file.adb:36

Can I get any more details? For example what the input was, or maybe a stack trace, or anything else that might help me in determining why the assertion failed?

rid
  • 61,078
  • 31
  • 152
  • 193

1 Answers1

5

You may catch System.Assertions.Assert_Failure to print stack trace using GNAT.Traceback (if you use GNAT) package or print values.

Something like here

pragma Assertion_Policy(CHECK);

with Ada.Text_IO; use Ada.Text_IO;
with GNAT.Traceback;
with System.Assertions;
with GNAT.Traceback.Symbolic;
procedure Main is
   procedure Call_Stack is
      Trace  : GNAT.Traceback.Tracebacks_Array (1..1_000);
      Length : Natural;
   begin
      GNAT.Traceback.Call_Chain (Trace, Length);
      Put_Line (GNAT.Traceback.Symbolic.Symbolic_Traceback (Trace (1..Length)));
   end Call_Stack; 
   type Day is new String (1 .. 10);
   type Message is record
      Sent     : Day;
      Received : Day;
   end record with
     Dynamic_Predicate => Message.Sent <= Message.Received;
   M : Message;
begin
   M  := (Received => "1776-07-04", Sent => "1783-09-03");
exception
   when System.Assertions.Assert_Failure =>
      Call_Stack;
      Put_Line(String(M.Sent));
      Put_Line(String(M.Received));
end Main;

Or you may debug your program as I mentioned in comment enter image description here

rid
  • 61,078
  • 31
  • 152
  • 193
Timur Samkharadze
  • 1,737
  • 1
  • 17
  • 33