comp.lang.ada
 help / color / mirror / Atom feed
* gnat: symbolic traceback on exceptions
@ 2005-05-23 10:48 Manuel Collado
  2005-05-23 11:03 ` Ludovic Brenta
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Manuel Collado @ 2005-05-23 10:48 UTC (permalink / raw)


Using gnat 3.15p on WindowsXP. Wanted symbolic traceback automatically 
generated on unhandled exceptions. Mainly for student programs.

The following recipe can produce the wanted info, as suggested by the 
gnat user's guide:

...> gnatmake -g main_program -bargs -E

...> main_program
Execution terminated by unhandled exception
Exception name: CONSTRAINT_ERROR
Message: main_program.adb:5 explicit raise
Call stack traceback locations:
0x404a69 0x401bdf 0x4012f3 0x40130b 0x40131c 0x4012bb 0x401103

...>addr2line --exe=main_progam.exe 0x404a69 0x401bdf 0x4012f3 0x40130b 
0x40131c 0x4012bb 0x401103
00404A69 at c:/manual/build-kiev/src/ada/rts/a-except.adb:1320
00401BDF at c:/manual/build-kiev/src/ada/rts/a-except.adb:592
004012F3 at E:/.../main_program.adb:5
0040130B at E:/.../main_program.adb:10
0040131C at E:/.../main_program.adb:14
004012BB at E:/...//b~main_program.adb:109
00401103 at fake:0

This is an unfriendly way of doing things. The list of binary addresses 
must be manually grabbed from the exception message and pasted in the 
addr2line command.

Is there a different set of gnat switches that could be used to have the 
symbolic traceback directly listed in the exception message?

Or can it be programmatically generated, by explicitly invoking the 
message generation from the main program? Something like:

   procedure main_program is
   begin
     ...
   exception
     when others => Trace_Exception;
  end main_program;

Where Trace_Exception is a general trace routine that uses gnat specific 
features and library routines. (which ones?)

Thanks in advance.
-- 
To reply by e-mail, please remove the extra dot
in the given address:  m.collado -> mcollado



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

* Re: gnat: symbolic traceback on exceptions
  2005-05-23 10:48 gnat: symbolic traceback on exceptions Manuel Collado
@ 2005-05-23 11:03 ` Ludovic Brenta
  2005-05-23 15:23 ` Björn Lundin
  2005-05-23 18:20 ` Bernd Specht
  2 siblings, 0 replies; 9+ messages in thread
From: Ludovic Brenta @ 2005-05-23 11:03 UTC (permalink / raw)


[how to get a symbolic traceback]

The GNAT User manual explains how to use GNAT.Traceback and
GNAT.Traceback.Symbolic.  See the chapter "Running and Debugging Ada
Programs".

-- 
Ludovic Brenta.




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

* Re: gnat: symbolic traceback on exceptions
  2005-05-23 10:48 gnat: symbolic traceback on exceptions Manuel Collado
  2005-05-23 11:03 ` Ludovic Brenta
@ 2005-05-23 15:23 ` Björn Lundin
  2005-05-24 12:37   ` Manuel Collado
  2005-05-23 18:20 ` Bernd Specht
  2 siblings, 1 reply; 9+ messages in thread
From: Björn Lundin @ 2005-05-23 15:23 UTC (permalink / raw)
  To: Manuel Collado; +Cc: comp.lang.ada


2005-05-23 kl. 12.48 skrev Manuel Collado:
>
> ..> gnatmake -g main_program -bargs -E

This is a requirement below as well


> Or can it be programmatically generated, by explicitly invoking the 
> message generation from the main program? Something like:
>
>   procedure main_program is
>   begin
>     ...
>   exception
>     when others => Trace_Exception;
>  end main_program;
>
> Where Trace_Exception is a general trace routine that uses gnat 
> specific features and library routines. (which ones?)

Not compiled, not tested, but should work
You could put it in a separate package if you like.
/Björn

-----------
with Ada.Exceptions;
with Text_Io; use Text_Io;
with Gnat.Traceback;


procedure A_Test is
   A : String (1..1);

   procedure Tracebackinfo(E : Ada.Exceptions.Exception_Occurrence) is
     Last_Exception_Name     : constant String := 
Ada.Exceptions.Exception_Name(E);
     Last_Exception_Messsage : constant String:= 
Ada.Exceptions.Exception_Message(E);
     Last_Exception_Info     : constant String:= 
Ada.Exceptions.Exception_Information(E);
   begin
     Put("Exception raised : ");  Put_Line(Last_Exception_Name);
     New_Line;
     Put_Line("Message : " & Last_Exception_Messsage);
     Put_Line(Last_Exception_Info);
     Put_Line("...................................................");
     New_Line;
     Put_Line("Hex      Subprogram name and file");
     Put_Line("-----    ------------------------");
     Put_Line(Gnat.Traceback.Symbolic.Symbolic_Traceback(E));
     Put_Line("-------------------------------------------------");
   end Tracebackinfo;

begin
  A := "Hello, this raises Constraint_Error";
exception
   when E: others =>
     Tracebackinfo(E);
end A_Test;



Björn Lundin
bnl at spray dot se




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

* Re: gnat: symbolic traceback on exceptions
  2005-05-23 10:48 gnat: symbolic traceback on exceptions Manuel Collado
  2005-05-23 11:03 ` Ludovic Brenta
  2005-05-23 15:23 ` Björn Lundin
@ 2005-05-23 18:20 ` Bernd Specht
  2005-05-24 11:05   ` Manuel Collado
  2 siblings, 1 reply; 9+ messages in thread
From: Bernd Specht @ 2005-05-23 18:20 UTC (permalink / raw)


Manuel Collado <m.collado@lml.ls.fi.upm.es> wrote in 
news:4291b4ed@news.upm.es:

> Using gnat 3.15p on WindowsXP. Wanted symbolic traceback automatically 
> generated on unhandled exceptions. Mainly for student programs.


Did you try it with AdaGide with switch "Trace exception" set? Compile F3, 
run F4.



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

* Re: gnat: symbolic traceback on exceptions
  2005-05-23 18:20 ` Bernd Specht
@ 2005-05-24 11:05   ` Manuel Collado
  2005-05-25  7:42     ` gautier_niouzes
  0 siblings, 1 reply; 9+ messages in thread
From: Manuel Collado @ 2005-05-24 11:05 UTC (permalink / raw)


Bernd Specht escribi�:
> Manuel Collado <m.collado@lml.ls.fi.upm.es> wrote in 
> news:4291b4ed@news.upm.es:
> 
>>Using gnat 3.15p on WindowsXP. Wanted symbolic traceback automatically 
>>generated on unhandled exceptions. Mainly for student programs.
> 
> Did you try it with AdaGide with switch "Trace exception" set? Compile F3, 
> run F4.

No, I din't. But I've done it now without success. It seems that the 
"Trace exceptions" option lets AdaGide to run the program through an 
"AD" utility that interfaces with GDB. In my machine AD itself seems to 
crash. Example:
------------------------------------
  1
AD: executable=.\a_test.exe


raised CONSTRAINT_ERROR : ad_siph.adb:143
AD crashes... Re-run with /D option for details
Bug report GNAT/DOS: Gautier.deMontmollin@Maths.UniNe.CH
            GNAT/NT:  mcc@cs.usafa.af.mil

raised ADA.IO_EXCEPTIONS.USE_ERROR : s-fileio.adb:813
-------------------------------------

The /D option does nothing.

Thanks, anyway.
-- 
To reply by e-mail, please remove the extra dot
in the given address:  m.collado -> mcollado



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

* Re: gnat: symbolic traceback on exceptions
  2005-05-23 15:23 ` Björn Lundin
@ 2005-05-24 12:37   ` Manuel Collado
  2005-05-24 19:41     ` Björn Lundin
  0 siblings, 1 reply; 9+ messages in thread
From: Manuel Collado @ 2005-05-24 12:37 UTC (permalink / raw)


Bj�rn Lundin escribi�:
> ...
> Not compiled, not tested, but should work
> You could put it in a separate package if you like.
> 
> -----------
> with Ada.Exceptions;
> with Text_Io; use Text_Io;
> with Gnat.Traceback;
> ...[snipped]...
> begin
>  A := "Hello, this raises Constraint_Error";
> exception
>   when E: others =>
>     Tracebackinfo(E);
> end A_Test;

Thank you very much. Your code worked almost immediatly (after 
correcting a minor omission in a with clause). After putting the 
reporting routine in a separate compilation unit, the user's code is 
really simple:

------------------------------
with Trace_Exception;

procedure New_Test is
    A : String (1..1);

begin
    A := "Hello, this raises Constraint_Error";
exception
    when E: others =>
       Trace_Exception( E );
end New_Test;
------------------------------

..>new_test
Exception raised : CONSTRAINT_ERROR
Message : new_test.adb:8 length check failed
Call chain traceback :
  Address Subprogram name and source code location
-------- ----------------------------------------
0040536D in ada.exceptions.process_raise_exception at a-except.adb:1320
00402537 in <__gnat_rcheck_07> at a-except.adb:607
00401BEA in new_test at new_test.adb:8
004013D3 in main at b~new_test.adb:168
00401103 in ?? at fake:0
------------------------------

I've adapted your code to my own taste. The user's code is simple enough 
to be used by our students. I wonder why the gnat compiler doesn't 
provide a -gnat.. switch to turn on the symbolic call stack reporting at 
the user's request.

Thanks again,
-- 
To reply by e-mail, please remove the extra dot
in the given address:  m.collado -> mcollado



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

* Re: gnat: symbolic traceback on exceptions
  2005-05-24 12:37   ` Manuel Collado
@ 2005-05-24 19:41     ` Björn Lundin
  0 siblings, 0 replies; 9+ messages in thread
From: Björn Lundin @ 2005-05-24 19:41 UTC (permalink / raw)
  To: Manuel Collado; +Cc: comp.lang.ada

>
> I've adapted your code to my own taste. The user's code is simple 
> enough to be used by our students. I wonder why the gnat compiler 
> doesn't provide a -gnat.. switch to turn on the symbolic call stack 
> reporting at the user's request.

Yes, that would be nice...
(and perhaps put the dump on Standard_Error)

/Björn

Björn Lundin
bnl at spray dot se




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

* Re: gnat: symbolic traceback on exceptions
  2005-05-24 11:05   ` Manuel Collado
@ 2005-05-25  7:42     ` gautier_niouzes
  2005-05-25  9:53       ` Manuel Collado
  0 siblings, 1 reply; 9+ messages in thread
From: gautier_niouzes @ 2005-05-25  7:42 UTC (permalink / raw)


Manuel Collado:

> > Did you try it with AdaGide with switch "Trace exception" set? Compile F3,
> > run F4.
>
> No, I din't. But I've done it now without success. It seems that the
> "Trace exceptions" option lets AdaGide to run the program through an
> "AD" utility that interfaces with GDB. In my machine AD itself seems to
> crash. Example:
(...)

This AD should disappear one day - I don't know if it even sometimes
works...

The solution to your problem ("the GNAT 3.13+ way") is, generically
written:

------------------------------------------------------------------------------
--  File:            TB_Wrap.ads
--  Description:     Trace-back wrapper for GNAT 3.13p+ (spec.)
------------------------------------------------------------------------------

generic

  with procedure My_main_procedure;

procedure TB_Wrap;


------------------------------------------------------------------------------
--  File:            TB_Wrap.adb
--  Description:     Trace-back wrapper for GNAT 3.13p+ (body)
------------------------------------------------------------------------------

with GNAT.Traceback.Symbolic, Ada.Exceptions, Ada.Text_IO;
use Ada.Exceptions, Ada.Text_IO;

procedure TB_Wrap is
  pragma Compiler_options("-g");
  pragma Binder_options("-E");
begin
  My_main_procedure;
exception
  when E: others =>
    New_Line;
    Put_Line("---------------[ Unhandled exception ]------------");
    Put_Line(" > Name of exception . . . . .: " &
             Ada.Exceptions.Exception_Name(E) );
    Put_Line(" > Message for exception . . .: " &
             Ada.Exceptions.Exception_Message(E) );
    Put_Line(" > Trace-back of call stack: " );
    Put_Line( GNAT.Traceback.Symbolic.Symbolic_Traceback(E) );
end TB_Wrap;

-----------

with TB_Wrap, Test;

procedure Test_TB_Wrap is new TB_Wrap(Test);

-----------

Of course you can do it without the generic wrapper, just paste
the exception part at the end of your main procedure.

The switches mentioned in the above code correspond to the compiler
switches "debug info" and "trace-back" in the "Debugging" group
of AdaGIDE's "Project settings" -> "Debug/Release settings".

HTH
______________________________________________________________
Gautier     --     http://www.mysunrise.ch/users/gdm/index.htm
Ada programming -- http://www.mysunrise.ch/users/gdm/gsoft.htm

NB: For a direct answer, e-mail address on the Web site!




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

* Re: gnat: symbolic traceback on exceptions
  2005-05-25  7:42     ` gautier_niouzes
@ 2005-05-25  9:53       ` Manuel Collado
  0 siblings, 0 replies; 9+ messages in thread
From: Manuel Collado @ 2005-05-25  9:53 UTC (permalink / raw)


gautier_niouzes@hotmail.com escribi�:
> Manuel Collado:
> 
>>>Did you try it with AdaGide with switch "Trace exception" set? Compile F3,
>>>run F4.
>>
>>No, I din't. But I've done it now without success. It seems that the
>>"Trace exceptions" option lets AdaGide to run the program through an
>>"AD" utility that interfaces with GDB. In my machine AD itself seems to
>>crash. Example:
> 
> (...)
> 
> This AD should disappear one day - I don't know if it even sometimes
> works...

Looking at the sources I see that your original AD was written for 
MS-DOS, and that AdaGide contains a modified version for WinNT. But even 
the adapted sources have not been updated since 1999.

> 
> The solution to your problem ("the GNAT 3.13+ way") is, generically
> written:

...[code snipped]...

Yes, this is an interesting alternative.

> 
> Of course you can do it without the generic wrapper, just paste
> the exception part at the end of your main procedure.

I've put the message reporting code in a separate subroutine, called 
from the exception part of the main procedure.

> 
> The switches mentioned in the above code correspond to the compiler
> switches "debug info" and "trace-back" in the "Debugging" group
> of AdaGIDE's "Project settings" -> "Debug/Release settings".

Your post has alerted me about a new version of AdaGide. I was using 
v7.0, thas has a different set of options. After installing v7.3 I see a 
checkbox that enables/disables the usage of AD.

Thanks, a lot.
-- 
To reply by e-mail, please remove the extra dot
in the given address:  m.collado -> mcollado



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

end of thread, other threads:[~2005-05-25  9:53 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-05-23 10:48 gnat: symbolic traceback on exceptions Manuel Collado
2005-05-23 11:03 ` Ludovic Brenta
2005-05-23 15:23 ` Björn Lundin
2005-05-24 12:37   ` Manuel Collado
2005-05-24 19:41     ` Björn Lundin
2005-05-23 18:20 ` Bernd Specht
2005-05-24 11:05   ` Manuel Collado
2005-05-25  7:42     ` gautier_niouzes
2005-05-25  9:53       ` Manuel Collado

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