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; 25+ 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] 25+ 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; 25+ 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] 25+ 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; 25+ 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] 25+ 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; 25+ 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] 25+ 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; 25+ 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] 25+ 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; 25+ 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] 25+ 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; 25+ 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] 25+ 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; 25+ 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] 25+ 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; 25+ 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] 25+ 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; 25+ 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] 25+ 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; 25+ 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] 25+ 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; 25+ 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] 25+ 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; 25+ 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] 25+ 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; 25+ 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] 25+ 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; 25+ 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] 25+ 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; 25+ 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] 25+ 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; 25+ 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] 25+ 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; 25+ 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] 25+ 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; 25+ 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] 25+ 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; 25+ 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] 25+ 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; 25+ 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] 25+ 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; 25+ 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] 25+ 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
  1 sibling, 0 replies; 25+ 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] 25+ 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; 25+ 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] 25+ 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; 25+ 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] 25+ messages in thread

end of thread, other threads:[~2022-06-09  8:21 UTC | newest]

Thread overview: 25+ 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-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