• Extra information in the message string of exceptions.

    From Rod Kay@21:1/5 to All on Mon Jun 6 22:59:19 2022
    Hi all,

    Any thoughts on pro's/con's of having the Ada standard packages
    runtime provide extra information in the message string of exceptions ?

    For instance, a Constraint_Error message might provide details on
    the variable name, the legal range and the erroneous value which caused
    the exception.


    Regards.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Fabien Chouteau@21:1/5 to roda...@gmail.com on Mon Jun 6 06:40:36 2022
    On Monday, June 6, 2022 at 3:02:25 PM UTC+2, roda...@gmail.com wrote:
    For instance, a Constraint_Error message might provide details on
    the variable name, the legal range and the erroneous value which caused
    the exception.

    That's a really good idea I would say. Extremely useful during development where I often start the debugger just to know what value triggered a Constraint_Error.

    I guess the drawback is performance as formatting string with extra information will have a cost.
    But this feature could be activated with a switch only when needed.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Gautier write-only address@21:1/5 to All on Mon Jun 6 07:31:07 2022
    Any thoughts on pro's/con's of having the Ada standard packages
    runtime provide extra information in the message string of exceptions ?

    It depends on the compiler. And of course it is advantage to provide more details.
    For instance HAC issues for...

    procedure CE_2 is
    i : Positive;
    j : Integer := 1;
    begin
    i := -j;
    end CE_2;

    the message:
    hac ce_2.adb
    HAC VM: raised Constraint_Error
    Out of range: pos, -1, is below (sub)type's lower bound, 1
    Trace-back: approximate location
    ce_2.adb: CE_2 at line 5

    Of for...

    procedure CE_3 is
    a : array (1 .. 5) of Integer;
    begin
    a (7) := 2;
    end CE_3;

    hac ce_3.adb
    HAC VM: raised Constraint_Error
    Out of range: index (pos: 7) is above upper bound (pos: 5)
    Trace-back: approximate location
    ce_3.adb: CE_3 at line 4

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From G.B.@21:1/5 to Fabien Chouteau on Mon Jun 6 20:40:57 2022
    On 06.06.22 15:40, Fabien Chouteau wrote:
    On Monday, June 6, 2022 at 3:02:25 PM UTC+2, roda...@gmail.com wrote:
    For instance, a Constraint_Error message might provide details on
    the variable name, the legal range and the erroneous value which caused
    the exception.

    That's a really good idea I would say. Extremely useful during development where I often start the debugger just to know what value triggered a Constraint_Error.

    I guess the drawback is performance as formatting string with extra information will have a cost.
    But this feature could be activated with a switch only when needed.

    Will it help to have a standard object taking just the data?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Dmitry A. Kazakov@21:1/5 to G.B. on Mon Jun 6 21:24:27 2022
    On 2022-06-06 20:40, G.B. wrote:
    On 06.06.22 15:40, Fabien Chouteau wrote:
    On Monday, June 6, 2022 at 3:02:25 PM UTC+2, roda...@gmail.com wrote:
    For instance, a Constraint_Error message might provide details on
    the variable name, the legal range and the erroneous value which caused
    the exception.

    That's a really good idea I would say. Extremely useful during
    development where I often start the debugger just to know what value
    triggered a Constraint_Error.

    I guess the drawback is performance as formatting string with extra
    information will have a cost.
    But this feature could be activated with a switch only when needed.

    Will it help to have a standard object taking just the data?

    Besides problems with finalization and touching memory pools, an
    exception from a rendezvous is propagated in two tasks. Will the object
    be shared, copied?

    ------------------
    Though you can always serialize an object into a string stream and use
    the result. One could consider some syntax sugar like:

    raise E with X;

    would mean

    declare
    S : aliased String_Stream (200);
    begin
    T'Output (S'Access, X); -- T is the subtype of X
    raise E with S.Get;
    end;

    and

    function Stream (X : Exception_Occurrence)
    return not null access Root_Stream_Type'Class;

    So, in the handler:

    when Error : E =>
    declare
    X : T'Class := T'Class'Input (Error'Stream);
    begin
    ...
    end;

    without the sugar:

    when Error : E =>
    declare
    S : aliased String_Stream (200);
    begin
    S.Set (Exception_Message (S));
    declare
    X : T'Class := T'Class'Input (S'Access);
    begin
    ...
    end;
    end;

    --
    Regards,
    Dmitry A. Kazakov
    http://www.dmitry-kazakov.de

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Luke A. Guest@21:1/5 to Rod Kay on Mon Jun 6 21:14:26 2022
    On 06/06/2022 13:59, Rod Kay wrote:
    Hi all,

       Any thoughts on pro's/con's of having the Ada standard packages
    runtime provide extra information in the message string of exceptions ?

       For instance, a Constraint_Error message might provide details on
    the variable name, the legal range and the erroneous value which caused
    the exception.

    This is something which could be added to either the language or the
    compiler. GNAT does have a dump backtrace call you could use.

    Luke.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From DrPi@21:1/5 to All on Mon Jun 6 22:49:03 2022
    Le 06/06/2022 à 14:59, Rod Kay a écrit :
    Hi all,

       Any thoughts on pro's/con's of having the Ada standard packages
    runtime provide extra information in the message string of exceptions ?

       For instance, a Constraint_Error message might provide details on
    the variable name, the legal range and the erroneous value which caused
    the exception.


    +1


    Regards.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Jerry@21:1/5 to DrPi on Mon Jun 6 16:17:37 2022
    On Monday, June 6, 2022 at 1:49:08 PM UTC-7, DrPi wrote:
    Le 06/06/2022 à 14:59, Rod Kay a écrit :
    Hi all,

    Any thoughts on pro's/con's of having the Ada standard packages
    runtime provide extra information in the message string of exceptions ?

    For instance, a Constraint_Error message might provide details on
    the variable name, the legal range and the erroneous value which caused the exception.

    +1


    Regards.

    This is not responsive to the OP but here is a bit of code that I find extremely useful to get a symbolic traceback for unhandled exceptions. Here is an example:

    with Common; use Common;
    with Ada.Exceptions;

    procedure CE_2 is
    i : Positive;
    j : Integer := 1;

    procedure A_Subroutine is
    begin
    i := -j;
    end A_Subroutine;

    begin
    A_Subroutine;

    -- Print a traceback for all unhandled exceptions.
    -- See http://www.adacore.com/adaanswers/gems/gem-142-exceptions/.
    exception
    when Error : others =>
    Common.Print_Traceback_For_Unhandled_Exception(Error);
    end CE_2;

    It provides this output:

    ==========================================================
    Exception name: CONSTRAINT_ERROR
    Message: ce_2.adb:10 range check failed
    Load address: 0x100000000
    Call stack traceback locations:
    0x1000013ac 0x1000013cd 0x100001c36
    <<<<<< Symbolic Traceback >>>>>>
    If incomplete, compile with -O0.
    ce_2__a_subroutine.3035 (in run) (ce_2.adb:10)
    _ada_ce_2 (in run) (ce_2.adb:14)
    main (in run) (b__ce_2.adb:354) ==========================================================

    I can post the code that does this if anyone is interested. The gist is calling Ada.Exceptions.Exception_Information, massaging that information, and calling atos. (Is atos macOS-specific?)

    Jerry

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Gautier write-only address@21:1/5 to All on Mon Jun 6 18:53:31 2022
    GNAT provides an integrated symbolic trace-back through the -Es switch. Doesn't it work on your Mac setup?
    Anyway, it's much trouble for a feature which should be activated by default...

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Randy Brukardt@21:1/5 to All on Mon Jun 6 21:35:45 2022
    "Gautier write-only address" <gautier_niouzes@hotmail.com> wrote in message news:cd0452bc-1330-4754-b88a-9c000707f098n@googlegroups.com...
    GNAT provides an integrated symbolic trace-back through the -Es switch. Doesn't it work on your Mac setup?
    Anyway, it's much trouble for a feature which should be activated by default...

    And I think it is in every other Ada compiler I've ever used. Ergo, don't
    blame the language, blame the implementation. ::-)

    Randy.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Randy Brukardt@21:1/5 to All on Mon Jun 6 21:33:44 2022
    "Gautier write-only address" <gautier_niouzes@hotmail.com> wrote in message news:1353f387-bb5a-4dc5-853f-a74d40f9237dn@googlegroups.com...
    Any thoughts on pro's/con's of having the Ada standard packages
    runtime provide extra information in the message string of exceptions ?

    It depends on the compiler. And of course it is advantage to provide more details.
    For instance HAC issues for...

    procedure CE_2 is
    i : Positive;
    j : Integer := 1;
    begin
    i := -j;
    end CE_2;

    the message:
    hac ce_2.adb
    HAC VM: raised Constraint_Error
    Out of range: pos, -1, is below (sub)type's lower bound, 1
    Trace-back: approximate location
    ce_2.adb: CE_2 at line 5

    Janus/Ada has *always* done this (going all the way back to the original
    Z-80 CP/M compiler). This particular case is not very expensive, since one
    can use the fact that the out-of-range value is certainly in a register to
    be tested in order to construct the message. And no real program cares about the performance of raising Constraint_Error -- the main issue is one of
    space (making the program larger).

    For example, from a recent bug report:

    ** Unhandled CONSTRAINT_ERROR
    Index or Subtype out of bounds - Pos of Error Value = 197807
    On Line Number 37 In XCB_MAIN.DETERMINE_FILE_SIZE
    Called from line number 40 In XCB_MAIN

    It's possible to turn this off, but there hasn't been much need to do so
    this century.

    Randy.

    P.S. I'd quibble with the OP, in that the vast majority of Constraint_Errors have nothing to do with the standard library; their checks are compiled directly into the code of your application; the only use of a library is to raise an exception. We use special library calls for specific checks (like
    the discrete range error discussed here); no strings are created in the user code. An implementation would certainly have to do that as the alternative would be to duplicate lots of complex code for each failed check -- but in
    the absence of such information, the implementation probably uses the same library call to raise all exceptions. Ergo, such a change probably isn't
    easy for any implementation that doesn't do something like it already.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Simon Wright@21:1/5 to Gautier on Tue Jun 7 09:07:18 2022
    Gautier write-only address <gautier_niouzes@hotmail.com> writes:

    GNAT provides an integrated symbolic trace-back through the -Es
    switch. Doesn't it work on your Mac setup?

    No. atos is a macOS utility.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Rod Kay@21:1/5 to Fabien Chouteau on Tue Jun 7 21:26:35 2022
    On 6/6/22 23:40, Fabien Chouteau wrote:

    That's a really good idea I would say. Extremely useful during development where I often start the debugger just to know what value triggered a Constraint_Error.

    Starting gdb and adding 'put_Line's often is what prompted the
    thought :) .


    I guess the drawback is performance as formatting string with extra information will have a cost.
    But this feature could be activated with a switch only when needed.

    A compiler switch to be used during development and debugging sounds
    ideal.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Rod Kay@21:1/5 to Randy Brukardt on Tue Jun 7 21:47:38 2022
    On 7/6/22 12:33, Randy Brukardt wrote:

    Janus/Ada has *always* done this (going all the way back to the original
    Z-80 CP/M compiler).

    Very nice !

    This particular case is not very expensive, since one
    can use the fact that the out-of-range value is certainly in a register to
    be tested in order to construct the message. And no real program cares about the performance of raising Constraint_Error

    I didn't think that there would be too much impact on performance.


    -- the main issue is one of
    space (making the program larger).

    I hadn't really considered the extra space required. For a desktop/workstation/server, I expect the extra space would not be a huge consideration. For embedded systems and such, I guess it might be,
    though if the feature could be switched off for production releases
    perhaps not such a big problem.



    P.S. I'd quibble with the OP, in that the vast majority of Constraint_Errors have nothing to do with the standard library; their checks are compiled directly into the code of your application.

    Quite right. I should simply have said the standard exceptions,
    wherever they are raised.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Rod Kay@21:1/5 to Gautier on Tue Jun 7 21:29:52 2022
    On 7/6/22 00:31, Gautier write-only address wrote:

    hac ce_2.adb
    HAC VM: raised Constraint_Error
    Out of range: pos, -1, is below (sub)type's lower bound, 1
    Trace-back: approximate location
    ce_2.adb: CE_2 at line 5

    Of for...


    ... and ...

    hac ce_3.adb
    HAC VM: raised Constraint_Error
    Out of range: index (pos: 7) is above upper bound (pos: 5)
    Trace-back: approximate location
    ce_3.adb: CE_3 at line 4


    ... are very much what i'd like to see.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Rod Kay@21:1/5 to Luke A. Guest on Tue Jun 7 21:51:33 2022
    On 7/6/22 06:14, Luke A. Guest wrote:

    This is something which could be added to either the language or the compiler.

    I'd prefer to see it in the standard (for the usual reasons).


    GNAT does have a dump backtrace call you could use.


    Ah, does it show more info than just the call stack ?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Fabien Chouteau@21:1/5 to Fabien Chouteau on Tue Jun 7 08:55:58 2022
    On Monday, June 6, 2022 at 3:40:38 PM UTC+2, Fabien Chouteau wrote:
    But this feature could be activated with a switch only when needed.

    Well, it turns our this is already implemented in GNAT ^^

    Example here: https://godbolt.org/z/fcTEaq3xP

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Anh Vo@21:1/5 to Fabien Chouteau on Tue Jun 7 09:41:06 2022
    On Tuesday, June 7, 2022 at 8:56:00 AM UTC-7, Fabien Chouteau wrote:
    On Monday, June 6, 2022 at 3:40:38 PM UTC+2, Fabien Chouteau wrote:
    But this feature could be activated with a switch only when needed.
    Well, it turns our this is already implemented in GNAT ^^

    Example here: https://godbolt.org/z/fcTEaq3xP
    Very nice. I love some thing like this.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Luke A. Guest@21:1/5 to Rod Kay on Tue Jun 7 22:06:05 2022
    On 07/06/2022 12:51, Rod Kay wrote:
    On 7/6/22 06:14, Luke A. Guest wrote:

    This is something which could be added to either the language or the
    compiler.

       I'd prefer to see it in the standard (for the usual reasons).

    Yeah, fair enough, just saying it could be added no problems (probably).

    GNAT does have a dump backtrace call you could use.


       Ah, does it show more info than just the call stack ?

    That I'm not sure of, been a while since I looked at it.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Jerry@21:1/5 to All on Wed Jun 8 00:14:55 2022
    On Monday, June 6, 2022 at 6:53:32 PM UTC-7, wrote:
    GNAT provides an integrated symbolic trace-back through the -Es switch. Doesn't it work on your Mac setup?
    Anyway, it's much trouble for a feature which should be activated by default...
    It does not work. My compiler reports "unrecognized command line option '-Es'". Maybe it's a new feature. My GNAT is a few years old.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Jerry@21:1/5 to Fabien Chouteau on Wed Jun 8 00:31:12 2022
    On Tuesday, June 7, 2022 at 8:56:00 AM UTC-7, Fabien Chouteau wrote:
    On Monday, June 6, 2022 at 3:40:38 PM UTC+2, Fabien Chouteau wrote:
    But this feature could be activated with a switch only when needed.
    Well, it turns our this is already implemented in GNAT ^^

    Example here: https://godbolt.org/z/fcTEaq3xP
    Indeed. The switch is -GNATeE. It provides additional information for the program at that page,

    procedure Main is
    procedure Test (A : Integer) is
    type T is range 0 .. 42;
    begin
    Ada.Text_IO.Put_Line (T (A)'Img);
    end;
    begin
    Test (-1);
    end Main;

    But has no effect on this program;

    procedure CE_2 is
    i : Positive;
    j : Integer := 1;
    begin
    i := -j;
    end CE_2;

    Jerry

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Dmitry A. Kazakov@21:1/5 to Jerry on Wed Jun 8 10:04:26 2022
    On 2022-06-08 09:31, Jerry wrote:
    On Tuesday, June 7, 2022 at 8:56:00 AM UTC-7, Fabien Chouteau wrote:
    On Monday, June 6, 2022 at 3:40:38 PM UTC+2, Fabien Chouteau wrote:
    But this feature could be activated with a switch only when needed.
    Well, it turns our this is already implemented in GNAT ^^

    Example here: https://godbolt.org/z/fcTEaq3xP
    Indeed. The switch is -GNATeE. It provides additional information for the program at that page,

    procedure Main is
    procedure Test (A : Integer) is
    type T is range 0 .. 42;
    begin
    Ada.Text_IO.Put_Line (T (A)'Img);
    end;
    begin
    Test (-1);
    end Main;

    But has no effect on this program;

    procedure CE_2 is
    i : Positive;
    j : Integer := 1;
    begin
    i := -j;
    end CE_2;

    The switches are -E for binder and -g for everything else. Try this:

    --- test_ce.gpr ----------------------------------------
    project Test_CE is
    for Source_Files use ("test_ce.adb");
    for Main use ("test_ce.adb");

    package Binder is
    for Default_Switches ("ada") use ("-E");
    end Binder;

    package Builder is
    for Default_Switches ("ada") use ("-g");
    end Builder;

    package Compiler is
    for Default_Switches ("ada") use ("-g");
    end Compiler;

    package Linker is
    for Default_Switches ("ada") use ("-g");
    end Linker;

    end Test_CE;
    --- test_ce.adb ----------------------------------------
    with System.Exception_Traces; use System.Exception_Traces;
    with System.Traceback.Symbolic;

    procedure Test_CE is
    i : Positive;
    j : Integer := 1;
    begin
    Trace_On (System.Exception_Traces.Unhandled_Raise);
    Set_Trace_Decorator
    ( System.Traceback.Symbolic.Symbolic_Traceback'Access
    );
    i := -j;
    end Test_CE;

    Notes:

    1. You can just use Symbolic_Traceback whenever you want. E.g. you
  • From Dmitry A. Kazakov@21:1/5 to Jerry on Wed Jun 8 11:08:44 2022
    On 2022-06-08 09:31, Jerry wrote:

    But has no effect on this program;

    procedure CE_2 is
    i : Positive;
    j : Integer := 1;
    begin
    i := -j;
    end CE_2;

    I noticed that it requires a user-defined [sub]type AND nested subprogram:

    procedure Test (A : Integer) is
    subtype T is Integer range 0 .. 42;
    i : T;
    begin
    i := A; -- This will work
    end;
    begin
    Test (-1);

    --
    Regards,
    Dmitry A. Kazakov
    http://www.dmitry-kazakov.de

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Jerry@21:1/5 to Dmitry A. Kazakov on Wed Jun 8 19:39:16 2022
    On Wednesday, June 8, 2022 at 1:04:32 AM UTC-7, Dmitry A. Kazakov wrote:
    On 2022-06-08 09:31, Jerry wrote:
    On Tuesday, June 7, 2022 at 8:56:00 AM UTC-7, Fabien Chouteau wrote:
    On Monday, June 6, 2022 at 3:40:38 PM UTC+2, Fabien Chouteau wrote:
    But this feature could be activated with a switch only when needed.
    Well, it turns our this is already implemented in GNAT ^^

    Example here: https://godbolt.org/z/fcTEaq3xP
    Indeed. The switch is -GNATeE. It provides additional information for the program at that page,

    procedure Main is
    procedure Test (A : Integer) is
    type T is range 0 .. 42;
    begin
    Ada.Text_IO.Put_Line (T (A)'Img);
    end;
    begin
    Test (-1);
    end Main;

    But has no effect on this program;

    procedure CE_2 is
    i : Positive;
    j : Integer := 1;
    begin
    i := -j;
    end CE_2;
    The switches are -E for binder and -g for everything else. Try this:

    --- test_ce.gpr ----------------------------------------
    project Test_CE is
    for Source_Files use ("test_ce.adb");
    for Main use ("test_ce.adb");

    package Binder is
    for Default_Switches ("ada") use ("-E");
    end Binder;

    package Builder is
    for Default_Switches ("ada") use ("-g");
    end Builder;

    package Compiler is
    for Default_Switches ("ada") use ("-g");
    end Compiler;

    package Linker is
    for Default_Switches ("ada") use ("-g");
    end Linker;

    end Test_CE;
    --- test_ce.adb ----------------------------------------
    with System.Exception_Traces; use System.Exception_Traces;
    with System.Traceback.Symbolic;

    procedure Test_CE is
    i : Positive;
    j : Integer := 1;
    begin
    Trace_On (System.Exception_Traces.Unhandled_Raise);
    Set_Trace_Decorator
    ( System.Traceback.Symbolic.Symbolic_Traceback'Access
    );
    i := -j;
    end Test_CE;

    Notes:

    1. You can just use Symbolic_Traceback whenever you want. E.g. you can
    set an exception handler and dump traceback at the raising point. It is
    slow as hell, of course.

    2. There are problems getting symbolic traceback working on ARM.

    3. This becomes pretty much useless with relocated libraries. I do not
    know how to make it work with them.

    4. Under Windows you will not get traceback from non-GCC compiled stuff because it does not understand *.pdb files.
    --
    Regards,
    Dmitry A. Kazakov
    http://www.dmitry-kazakov.de
    Hmm.... I get the same "Message" i.e. no extra information and only hex traceback info. Docs say -E is the same as -Ea meaning hex traceback, plus my set-up rejects -Ea (and -Es) as illegal switches. (Not sure at this point if we're chasing symbolic
    traceback or extra compiler information.)

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Robin Vowels@21:1/5 to roda...@gmail.com on Thu Jun 9 01:21:29 2022
    On Monday, June 6, 2022 at 11:02:25 PM UTC+10, roda...@gmail.com wrote:
    Hi all,

    Any thoughts on pro's/con's of having the Ada standard packages
    runtime provide extra information in the message string of exceptions ?

    For instance, a Constraint_Error message might provide details on
    the variable name, the legal range and the erroneous value which caused
    the exception.
    .
    PL/I provides a description of an error, e.g. mentioning the condition
    that has been raised, e.g., SUBSCRIPTRANGE, ZERODIVIDE.
    The user can then take control and print the value of a variable or values of any
    group of variables. E.g., for a SUBSCRIPTRANGE error, the user can also print the
    upper and lower bounds of the array, though this is usually not done,
    it being sufficient to print the name of the variable(s) and value(s).

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Rod Kay@21:1/5 to Dmitry A. Kazakov on Thu Oct 27 22:56:45 2022
    On 8/6/22 19:08, Dmitry A. Kazakov wrote:
    On 2022-06-08 09:31, Jerry wrote:

    But has no effect on this program;

    procedure CE_2 is
         i : Positive;
         j : Integer := 1;
    begin
         i := -j;
    end CE_2;

    I noticed that it requires a user-defined [sub]type AND nested subprogram:

       procedure Test (A : Integer) is
          subtype T is Integer range 0 .. 42;
          i : T;
       begin
          i := A; -- This will work
       end;
    begin
       Test (-1);


    Are you sure about this ?

    I tried ...


    procedure Example
    is
    X : Positive := 5;
    begin
    loop
    X := X - 1;
    end loop;
    end Example;


    ... with the -gnateE and saw this result ...


    [rod@orth example]$ ./example

    raised CONSTRAINT_ERROR : example.adb:6:14 range check failed
    value 0 not in 1..2147483647
    [./example]
    0x55916975377f Example at example.adb:6
    0x559169753b74 Main at b__example.adb:193
    [/usr/lib/libc.so.6]
    0x7f9230be728e
    0x7f9230be7348
    [./example]
    0x559169753623 _start at start.S:115
    0xfffffffffffffffe

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Jerry@21:1/5 to roda...@gmail.com on Fri Oct 28 17:35:18 2022
    On Thursday, October 27, 2022 at 4:57:08 AM UTC-7, roda...@gmail.com wrote:
    On 8/6/22 19:08, Dmitry A. Kazakov wrote:
    On 2022-06-08 09:31, Jerry wrote:

    But has no effect on this program;

    procedure CE_2 is
    i : Positive;
    j : Integer := 1;
    begin
    i := -j;
    end CE_2;

    I noticed that it requires a user-defined [sub]type AND nested subprogram:

    procedure Test (A : Integer) is
    subtype T is Integer range 0 .. 42;
    i : T;
    begin
    i := A; -- This will work
    end;
    begin
    Test (-1);

    Are you sure about this ?

    I tried ...


    procedure Example
    is
    X : Positive := 5;
    begin
    loop
    X := X - 1;
    end loop;
    end Example;


    ... with the -gnateE and saw this result ...


    [rod@orth example]$ ./example

    raised CONSTRAINT_ERROR : example.adb:6:14 range check failed
    value 0 not in 1..2147483647
    [./example]
    0x55916975377f Example at example.adb:6
    0x559169753b74 Main at b__example.adb:193
    [/usr/lib/libc.so.6]
    0x7f9230be728e
    0x7f9230be7348
    [./example]
    0x559169753623 _start at start.S:115
    0xfffffffffffffffe

    So -gnateE works part of the time?
    Jerry

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Rod Kay@21:1/5 to Jerry on Sat Oct 29 14:10:02 2022
    On 29/10/22 11:35, Jerry wrote:
    On Thursday, October 27, 2022 at 4:57:08 AM UTC-7, roda...@gmail.com
    wrote:
    On 8/6/22 19:08, Dmitry A. Kazakov wrote:

    I noticed that it requires a user-defined [sub]type AND nested
    subprogram:

    procedure Test (A : Integer) is
    subtype T is Integer range 0 .. 42;
    i : T;
    begin
    i := A; -- This will work
    end;
    begin
    Test (-1);

    Are you sure about this ?

    I tried ...


    procedure Example
    is
    X : Positive := 5;
    begin
    loop
    X := X - 1;
    end loop;
    end Example;


    ... with the -gnateE and saw this result ...


    [rod@orth example]$ ./example

    raised CONSTRAINT_ERROR : example.adb:6:14 range check failed
    value 0 not in 1..2147483647
    [./example]
    0x55916975377f Example at example.adb:6
    0x559169753b74 Main at b__example.adb:193
    [/usr/lib/libc.so.6]
    0x7f9230be728e
    0x7f9230be7348
    [./example]
    0x559169753623 _start at start.S:115
    0xfffffffffffffffe

    So -gnateE works part of the time?
    Jerry

    I've not tested this extensively but assume the extra info would be
    shown in most cases.

    One exception is the following ...


    procedure Example
    is
    X : Positive := 0 with Unreferenced;
    begin
    null;
    end Example;


    ... which shows a compile time warning ...


    gprbuild -d -P/home/rod/Desktop/sandbox/ada/example/example.gpr -XLace_Build_Mode=debug -XLace_Restrictions=xgc -XLace_OS=Linux -Xrestrictions=xgc
    Compile
    [Ada] example.adb
    example.adb:3:20: warning: value not in range of type
    "Standard.Positive" [enabled by default]
    example.adb:3:20: warning: Constraint_Error will be raised at run time
    [enabled by default]
    Bind
    [gprbind] example.bexch
    [Ada] example.ali
    Link
    [link] example.adb
    [2022-10-29 13:56:36] process terminated successfully, elapsed time: 00.60s


    ... and when run ...


    [rod@orth example]$ ./example

    raised CONSTRAINT_ERROR : example.adb:3 range check failed
    [./example]
    0x560439f23710 Example at example.adb:3
    0x560439f23b00 Main at b__example.adb:193
    [/usr/lib/libc.so.6]
    0x7f746d52928e
    0x7f746d529348
    [./example]
    0x560439f23623 _start at start.S:115
    0xfffffffffffffffe


    I'm a little surprised that the compiler shows a warning rather than
    an error but I suppose there must be some reason for that.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Gautier write-only address@21:1/5 to All on Fri Oct 28 23:30:01 2022
    One exception is the following ...

    procedure Example
    is
    X : Positive := 0 with Unreferenced;
    begin
    null;
    end Example;

    ... which shows a compile time warning ...
    [...]
    I'm a little surprised that the compiler shows a warning rather than
    an error but I suppose there must be some reason for that.

    HAC (and perhaps other compilers) is stricter on that point:
    procedure Example is
    X : Positive := 0;
    begin
    null;
    end Example;

    example.adb: 2:20-21: error in range constraint: value of expression (0) is out the destination's range, 1 .. 9223372036854775807
    E

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From G.B.@21:1/5 to Rod Kay on Sat Oct 29 10:59:53 2022
    On 29.10.22 05:10, Rod Kay wrote:

       I'm a little surprised that the compiler shows a warning rather than an error but I suppose there must be some reason for that.


    Formal language reasons aside, a program's author may have wanted
    the program to raise an exception. (For example: "There is
    a TODO here, so make sure the program never runs past this point.
    Assign out of range.")

    GNAT just emits a warning for the following program, albeit not the
    same warning.
    BTW, what would SPARK do here?

    procedure Excpt
    is
    Works_As_Expected: exception;

    procedure Test is
    begin
    if 1 = 1 then
    raise Works_As_Expected;
    else
    raise Program_Error;
    end if;
    end Test;
    begin
    Test;
    end Excpt;

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Jerry@21:1/5 to Jerry on Mon Oct 31 17:05:04 2022
    On Friday, October 28, 2022 at 5:35:20 PM UTC-7, Jerry wrote:
    On Thursday, October 27, 2022 at 4:57:08 AM UTC-7, roda...@gmail.com wrote:
    On 8/6/22 19:08, Dmitry A. Kazakov wrote:
    On 2022-06-08 09:31, Jerry wrote:

    But has no effect on this program;

    procedure CE_2 is
    i : Positive;
    j : Integer := 1;
    begin
    i := -j;
    end CE_2;

    I noticed that it requires a user-defined [sub]type AND nested subprogram:

    procedure Test (A : Integer) is
    subtype T is Integer range 0 .. 42;
    i : T;
    begin
    i := A; -- This will work
    end;
    begin
    Test (-1);

    Are you sure about this ?

    I tried ...


    procedure Example
    is
    X : Positive := 5;
    begin
    loop
    X := X - 1;
    end loop;
    end Example;


    ... with the -gnateE and saw this result ...


    [rod@orth example]$ ./example

    raised CONSTRAINT_ERROR : example.adb:6:14 range check failed
    value 0 not in 1..2147483647
    [./example]
    0x55916975377f Example at example.adb:6
    0x559169753b74 Main at b__example.adb:193
    [/usr/lib/libc.so.6]
    0x7f9230be728e
    0x7f9230be7348
    [./example]
    0x559169753623 _start at start.S:115
    0xfffffffffffffffe
    So -gnateE works part of the time?
    Jerry
    I simply do not get the robust results others are reporting, and as I noted earlier in this thread, some of the suggested switches are flagged as illegal on macOS

    From the docs at https://gcc.gnu.org/onlinedocs/gcc-4.9.4/gnat_ugn_unw/Symbolic-Traceback.html#Symbolic-Traceback:
    "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."

    I'm using an older version of GNAT (2017) on Mac and the list of supported platforms is actually in s-trasym.ads and reads as such:
    -- The full capability is currently supported on the following targets:

    -- HP-UX ia64
    -- GNU/Linux x86, x86_64, ia64
    -- FreeBSD x86, x86_64
    -- Solaris sparc and x86
    -- Windows

    Maybe newer versions of GNAT are more Mac-friendly. So in order to get both extra information and symbolic tracebacks I've had to write my own garbage-y handler that redirects text output to a file, calls system stuff such as tail and atos, bla bla bla.
    I hope atos is still supported when I eventually move to ARM. atos I think is Apple's thing that works like addr2line.

    BTW, for others attempting this on macOS, turn of address randomization with -no_pie. That is, in my gpr, I have this:
    package Linker is
    for Default_Switches ("Ada") use ("-Wl,-no_pie");
    end Linker;

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)