comp.lang.ada
 help / color / mirror / Atom feed
* Extra information in the message string of exceptions.
@ 2022-06-06 12:59 Rod Kay
  2022-06-06 13:40 ` Fabien Chouteau
                   ` (4 more replies)
  0 siblings, 5 replies; 31+ messages in thread
From: Rod Kay @ 2022-06-06 12:59 UTC (permalink / raw)


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.

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: Extra information in the message string of exceptions.
  2022-06-06 12:59 Extra information in the message string of exceptions Rod Kay
@ 2022-06-06 13:40 ` Fabien Chouteau
  2022-06-06 18:40   ` G.B.
                     ` (2 more replies)
  2022-06-06 14:31 ` Gautier write-only address
                   ` (3 subsequent siblings)
  4 siblings, 3 replies; 31+ messages in thread
From: Fabien Chouteau @ 2022-06-06 13:40 UTC (permalink / raw)


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. 

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: Extra information in the message string of exceptions.
  2022-06-06 12:59 Extra information in the message string of exceptions Rod Kay
  2022-06-06 13:40 ` Fabien Chouteau
@ 2022-06-06 14:31 ` Gautier write-only address
  2022-06-07  2:33   ` Randy Brukardt
  2022-06-07 11:29   ` Rod Kay
  2022-06-06 20:14 ` Luke A. Guest
                   ` (2 subsequent siblings)
  4 siblings, 2 replies; 31+ messages in thread
From: Gautier write-only address @ 2022-06-06 14:31 UTC (permalink / raw)


> 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

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: Extra information in the message string of exceptions.
  2022-06-06 13:40 ` Fabien Chouteau
@ 2022-06-06 18:40   ` G.B.
  2022-06-06 19:24     ` Dmitry A. Kazakov
  2022-06-07 11:26   ` Rod Kay
  2022-06-07 15:55   ` Fabien Chouteau
  2 siblings, 1 reply; 31+ messages in thread
From: G.B. @ 2022-06-06 18:40 UTC (permalink / raw)


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?

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: Extra information in the message string of exceptions.
  2022-06-06 18:40   ` G.B.
@ 2022-06-06 19:24     ` Dmitry A. Kazakov
  0 siblings, 0 replies; 31+ messages in thread
From: Dmitry A. Kazakov @ 2022-06-06 19:24 UTC (permalink / raw)


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

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: Extra information in the message string of exceptions.
  2022-06-06 12:59 Extra information in the message string of exceptions Rod Kay
  2022-06-06 13:40 ` Fabien Chouteau
  2022-06-06 14:31 ` Gautier write-only address
@ 2022-06-06 20:14 ` Luke A. Guest
  2022-06-07 11:51   ` Rod Kay
  2022-06-06 20:49 ` DrPi
  2022-06-09  8:21 ` Robin Vowels
  4 siblings, 1 reply; 31+ messages in thread
From: Luke A. Guest @ 2022-06-06 20:14 UTC (permalink / raw)


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.


^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: Extra information in the message string of exceptions.
  2022-06-06 12:59 Extra information in the message string of exceptions Rod Kay
                   ` (2 preceding siblings ...)
  2022-06-06 20:14 ` Luke A. Guest
@ 2022-06-06 20:49 ` DrPi
  2022-06-06 23:17   ` Jerry
  2022-06-09  8:21 ` Robin Vowels
  4 siblings, 1 reply; 31+ messages in thread
From: DrPi @ 2022-06-06 20:49 UTC (permalink / raw)


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.

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: Extra information in the message string of exceptions.
  2022-06-06 20:49 ` DrPi
@ 2022-06-06 23:17   ` Jerry
  2022-06-07  1:53     ` Gautier write-only address
  0 siblings, 1 reply; 31+ messages in thread
From: Jerry @ 2022-06-06 23:17 UTC (permalink / raw)


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

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: Extra information in the message string of exceptions.
  2022-06-06 23:17   ` Jerry
@ 2022-06-07  1:53     ` Gautier write-only address
  2022-06-07  2:35       ` Randy Brukardt
                         ` (2 more replies)
  0 siblings, 3 replies; 31+ messages in thread
From: Gautier write-only address @ 2022-06-07  1:53 UTC (permalink / raw)


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...

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: Extra information in the message string of exceptions.
  2022-06-06 14:31 ` Gautier write-only address
@ 2022-06-07  2:33   ` Randy Brukardt
  2022-06-07 11:47     ` Rod Kay
  2022-06-07 11:29   ` Rod Kay
  1 sibling, 1 reply; 31+ messages in thread
From: Randy Brukardt @ 2022-06-07  2:33 UTC (permalink / raw)


"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.


^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: Extra information in the message string of exceptions.
  2022-06-07  1:53     ` Gautier write-only address
@ 2022-06-07  2:35       ` Randy Brukardt
  2022-06-07  8:07       ` Simon Wright
  2022-06-08  7:14       ` Jerry
  2 siblings, 0 replies; 31+ messages in thread
From: Randy Brukardt @ 2022-06-07  2:35 UTC (permalink / raw)


"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.


^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: Extra information in the message string of exceptions.
  2022-06-07  1:53     ` Gautier write-only address
  2022-06-07  2:35       ` Randy Brukardt
@ 2022-06-07  8:07       ` Simon Wright
  2022-06-08  7:14       ` Jerry
  2 siblings, 0 replies; 31+ messages in thread
From: Simon Wright @ 2022-06-07  8:07 UTC (permalink / raw)


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.

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: Extra information in the message string of exceptions.
  2022-06-06 13:40 ` Fabien Chouteau
  2022-06-06 18:40   ` G.B.
@ 2022-06-07 11:26   ` Rod Kay
  2022-06-07 15:55   ` Fabien Chouteau
  2 siblings, 0 replies; 31+ messages in thread
From: Rod Kay @ 2022-06-07 11:26 UTC (permalink / raw)


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.

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: Extra information in the message string of exceptions.
  2022-06-06 14:31 ` Gautier write-only address
  2022-06-07  2:33   ` Randy Brukardt
@ 2022-06-07 11:29   ` Rod Kay
  1 sibling, 0 replies; 31+ messages in thread
From: Rod Kay @ 2022-06-07 11:29 UTC (permalink / raw)


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.

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: Extra information in the message string of exceptions.
  2022-06-07  2:33   ` Randy Brukardt
@ 2022-06-07 11:47     ` Rod Kay
  0 siblings, 0 replies; 31+ messages in thread
From: Rod Kay @ 2022-06-07 11:47 UTC (permalink / raw)


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.

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: Extra information in the message string of exceptions.
  2022-06-06 20:14 ` Luke A. Guest
@ 2022-06-07 11:51   ` Rod Kay
  2022-06-07 21:06     ` Luke A. Guest
  0 siblings, 1 reply; 31+ messages in thread
From: Rod Kay @ 2022-06-07 11:51 UTC (permalink / raw)


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 ?

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: Extra information in the message string of exceptions.
  2022-06-06 13:40 ` Fabien Chouteau
  2022-06-06 18:40   ` G.B.
  2022-06-07 11:26   ` Rod Kay
@ 2022-06-07 15:55   ` Fabien Chouteau
  2022-06-07 16:41     ` Anh Vo
  2022-06-08  7:31     ` Jerry
  2 siblings, 2 replies; 31+ messages in thread
From: Fabien Chouteau @ 2022-06-07 15:55 UTC (permalink / raw)


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

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: Extra information in the message string of exceptions.
  2022-06-07 15:55   ` Fabien Chouteau
@ 2022-06-07 16:41     ` Anh Vo
  2022-06-08  7:31     ` Jerry
  1 sibling, 0 replies; 31+ messages in thread
From: Anh Vo @ 2022-06-07 16:41 UTC (permalink / raw)


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.

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: Extra information in the message string of exceptions.
  2022-06-07 11:51   ` Rod Kay
@ 2022-06-07 21:06     ` Luke A. Guest
  0 siblings, 0 replies; 31+ messages in thread
From: Luke A. Guest @ 2022-06-07 21:06 UTC (permalink / raw)



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.

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: Extra information in the message string of exceptions.
  2022-06-07  1:53     ` Gautier write-only address
  2022-06-07  2:35       ` Randy Brukardt
  2022-06-07  8:07       ` Simon Wright
@ 2022-06-08  7:14       ` Jerry
  2 siblings, 0 replies; 31+ messages in thread
From: Jerry @ 2022-06-08  7:14 UTC (permalink / raw)


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.

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: Extra information in the message string of exceptions.
  2022-06-07 15:55   ` Fabien Chouteau
  2022-06-07 16:41     ` Anh Vo
@ 2022-06-08  7:31     ` Jerry
  2022-06-08  8:04       ` Dmitry A. Kazakov
  2022-06-08  9:08       ` Dmitry A. Kazakov
  1 sibling, 2 replies; 31+ messages in thread
From: Jerry @ 2022-06-08  7:31 UTC (permalink / raw)


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

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: Extra information in the message string of exceptions.
  2022-06-08  7:31     ` Jerry
@ 2022-06-08  8:04       ` Dmitry A. Kazakov
  2022-06-09  2:39         ` Jerry
  2022-06-08  9:08       ` Dmitry A. Kazakov
  1 sibling, 1 reply; 31+ messages in thread
From: Dmitry A. Kazakov @ 2022-06-08  8:04 UTC (permalink / raw)


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

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: Extra information in the message string of exceptions.
  2022-06-08  7:31     ` Jerry
  2022-06-08  8:04       ` Dmitry A. Kazakov
@ 2022-06-08  9:08       ` Dmitry A. Kazakov
  2022-10-27 11:56         ` Rod Kay
  1 sibling, 1 reply; 31+ messages in thread
From: Dmitry A. Kazakov @ 2022-06-08  9:08 UTC (permalink / raw)


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

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: Extra information in the message string of exceptions.
  2022-06-08  8:04       ` Dmitry A. Kazakov
@ 2022-06-09  2:39         ` Jerry
  0 siblings, 0 replies; 31+ messages in thread
From: Jerry @ 2022-06-09  2:39 UTC (permalink / raw)


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.)

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: Extra information in the message string of exceptions.
  2022-06-06 12:59 Extra information in the message string of exceptions Rod Kay
                   ` (3 preceding siblings ...)
  2022-06-06 20:49 ` DrPi
@ 2022-06-09  8:21 ` Robin Vowels
  4 siblings, 0 replies; 31+ messages in thread
From: Robin Vowels @ 2022-06-09  8:21 UTC (permalink / raw)


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).

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: Extra information in the message string of exceptions.
  2022-06-08  9:08       ` Dmitry A. Kazakov
@ 2022-10-27 11:56         ` Rod Kay
  2022-10-29  0:35           ` Jerry
  0 siblings, 1 reply; 31+ messages in thread
From: Rod Kay @ 2022-10-27 11:56 UTC (permalink / raw)


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


^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: Extra information in the message string of exceptions.
  2022-10-27 11:56         ` Rod Kay
@ 2022-10-29  0:35           ` Jerry
  2022-10-29  3:10             ` Rod Kay
  2022-11-01  0:05             ` Jerry
  0 siblings, 2 replies; 31+ messages in thread
From: Jerry @ 2022-10-29  0:35 UTC (permalink / raw)


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

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: Extra information in the message string of exceptions.
  2022-10-29  0:35           ` Jerry
@ 2022-10-29  3:10             ` Rod Kay
  2022-10-29  6:30               ` Gautier write-only address
  2022-10-29  8:59               ` G.B.
  2022-11-01  0:05             ` Jerry
  1 sibling, 2 replies; 31+ messages in thread
From: Rod Kay @ 2022-10-29  3:10 UTC (permalink / raw)


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.

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: Extra information in the message string of exceptions.
  2022-10-29  3:10             ` Rod Kay
@ 2022-10-29  6:30               ` Gautier write-only address
  2022-10-29  8:59               ` G.B.
  1 sibling, 0 replies; 31+ messages in thread
From: Gautier write-only address @ 2022-10-29  6:30 UTC (permalink / raw)


> 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

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: Extra information in the message string of exceptions.
  2022-10-29  3:10             ` Rod Kay
  2022-10-29  6:30               ` Gautier write-only address
@ 2022-10-29  8:59               ` G.B.
  1 sibling, 0 replies; 31+ messages in thread
From: G.B. @ 2022-10-29  8:59 UTC (permalink / raw)


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;

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: Extra information in the message string of exceptions.
  2022-10-29  0:35           ` Jerry
  2022-10-29  3:10             ` Rod Kay
@ 2022-11-01  0:05             ` Jerry
  1 sibling, 0 replies; 31+ messages in thread
From: Jerry @ 2022-11-01  0:05 UTC (permalink / raw)


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;

^ permalink raw reply	[flat|nested] 31+ messages in thread

end of thread, other threads:[~2022-11-01  0:05 UTC | newest]

Thread overview: 31+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-06 12:59 Extra information in the message string of exceptions Rod Kay
2022-06-06 13:40 ` Fabien Chouteau
2022-06-06 18:40   ` G.B.
2022-06-06 19:24     ` Dmitry A. Kazakov
2022-06-07 11:26   ` Rod Kay
2022-06-07 15:55   ` Fabien Chouteau
2022-06-07 16:41     ` Anh Vo
2022-06-08  7:31     ` Jerry
2022-06-08  8:04       ` Dmitry A. Kazakov
2022-06-09  2:39         ` Jerry
2022-06-08  9:08       ` Dmitry A. Kazakov
2022-10-27 11:56         ` Rod Kay
2022-10-29  0:35           ` Jerry
2022-10-29  3:10             ` Rod Kay
2022-10-29  6:30               ` Gautier write-only address
2022-10-29  8:59               ` G.B.
2022-11-01  0:05             ` Jerry
2022-06-06 14:31 ` Gautier write-only address
2022-06-07  2:33   ` Randy Brukardt
2022-06-07 11:47     ` Rod Kay
2022-06-07 11:29   ` Rod Kay
2022-06-06 20:14 ` Luke A. Guest
2022-06-07 11:51   ` Rod Kay
2022-06-07 21:06     ` Luke A. Guest
2022-06-06 20:49 ` DrPi
2022-06-06 23:17   ` Jerry
2022-06-07  1:53     ` Gautier write-only address
2022-06-07  2:35       ` Randy Brukardt
2022-06-07  8:07       ` Simon Wright
2022-06-08  7:14       ` Jerry
2022-06-09  8:21 ` Robin Vowels

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox