comp.lang.ada
 help / color / mirror / Atom feed
* Package name
@ 2001-05-16 12:56 Atle R�stad
  2001-05-16 13:28 ` Preben Randhol
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Atle R�stad @ 2001-05-16 12:56 UTC (permalink / raw)


Is it possible to print out the package name?

It would be a nice feature in tracing. Maybe even print the
procedure/function name.

Regards Atle





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

* Re: Package name
  2001-05-16 12:56 Atle R�stad
@ 2001-05-16 13:28 ` Preben Randhol
  2001-05-16 13:46   ` Atle R�stad
  2001-05-16 14:00   ` Marin David Condic
  2001-05-16 16:10 ` Jeffrey Carter
  2001-05-16 17:08 ` David C. Hoos, Sr.
  2 siblings, 2 replies; 12+ messages in thread
From: Preben Randhol @ 2001-05-16 13:28 UTC (permalink / raw)


On Wed, 16 May 2001 14:56:38 +0200, Atle R�stad wrote:
> Is it possible to print out the package name?
>
> It would be a nice feature in tracing. Maybe even print the
> procedure/function name.

What do you mean?

-- 
Preben Randhol ------------------- http://www.pvv.org/~randhol/ --
                 �For me, Ada95 puts back the joy in programming.�



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

* Re: Package name
  2001-05-16 13:28 ` Preben Randhol
@ 2001-05-16 13:46   ` Atle R�stad
  2001-05-16 14:00   ` Marin David Condic
  1 sibling, 0 replies; 12+ messages in thread
From: Atle R�stad @ 2001-05-16 13:46 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 951 bytes --]


Preben Randhol <randhol+abuse@pvv.org> wrote in message
news:slrn9g509m.f4.randhol+abuse@kiuk0156.chembio.ntnu.no...
> On Wed, 16 May 2001 14:56:38 +0200, Atle R�stad wrote:
> > Is it possible to print out the package name?
> >
> > It would be a nice feature in tracing. Maybe even print the
> > procedure/function name.
>
> What do you mean?
>

Example:
Text_Io.Put_Line(Get_Package_Name&"::"&Get_Procedure_Name&": Some trace
comment");

Where output would be something like:
Perfect_World::Meaning_Of_Life: Some trace comment

where the package name the Text_Io statement was written in is Perfect_World
and the name of the procedure was Meaning_Of_Life.

This would be helpful in debugging a big system. The procedure name may be
overkill, but at least the package name would be nice.

/Atle


> --
> Preben Randhol ------------------- http://www.pvv.org/~randhol/ --
>                  �For me, Ada95 puts back the joy in programming.�





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

* Re: Package name
  2001-05-16 13:28 ` Preben Randhol
  2001-05-16 13:46   ` Atle R�stad
@ 2001-05-16 14:00   ` Marin David Condic
  2001-05-16 16:45     ` Claude SIMON
  2001-05-16 18:24     ` Randy Brukardt
  1 sibling, 2 replies; 12+ messages in thread
From: Marin David Condic @ 2001-05-16 14:00 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1986 bytes --]

I think the idea is to have something like a pragma or attribute that lets
you get the name of the module you are in as a string. I have frequently
wished I could write a more general exception handler (or error handler or
simple messages at runtime...) by having something like "Context'Image" or
some other function that would provide the fully qualified name of the
subprogram, package, whatever that I am currently in. Example:

package body Some_Package is
    procedure Some_Procedure is
        ....
        Put_Line ("Running in: " & Current_Context'Image) ;

having that print:

Running in: Standard.Some_Package.Some_Procedure

It would be useful for diagnostics in the event of various errors or other
conditions. Maybe even have "Current_Context'Line_Number" and similar
capabilities? One would wish that Exception_Message and
Exception_Information had this sort of information in their returned strings
(Never seen it myself in the implementations I've used), but I think you'd
want it to be available without an exception being raised.

And of course, one could also want some sort of access to the dynamic
context as well. (The call stack). There's no limit to the things I can
want. But as my mother used to observe, "People in Hell want ice water,
too!"  :-)

MDC
--
Marin David Condic
Senior Software Engineer
Pace Micro Technology Americas    www.pacemicro.com
Enabling the digital revolution
e-Mail:    marin.condic@pacemicro.com
Web:      http://www.mcondic.com/


"Preben Randhol" <randhol+abuse@pvv.org> wrote in message
news:slrn9g509m.f4.randhol+abuse@kiuk0156.chembio.ntnu.no...
> On Wed, 16 May 2001 14:56:38 +0200, Atle R�stad wrote:
> > Is it possible to print out the package name?
> >
> > It would be a nice feature in tracing. Maybe even print the
> > procedure/function name.
>
> What do you mean?
>
> --
> Preben Randhol ------------------- http://www.pvv.org/~randhol/ --
>                  �For me, Ada95 puts back the joy in programming.�





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

* Re: Package name
  2001-05-16 12:56 Atle R�stad
  2001-05-16 13:28 ` Preben Randhol
@ 2001-05-16 16:10 ` Jeffrey Carter
  2001-05-16 17:08 ` David C. Hoos, Sr.
  2 siblings, 0 replies; 12+ messages in thread
From: Jeffrey Carter @ 2001-05-16 16:10 UTC (permalink / raw)


"Atle R�stad" wrote:
> 
> Is it possible to print out the package name?
> 
> It would be a nice feature in tracing. Maybe even print the
> procedure/function name.
> 
> Regards Atle

This is easily done. See package PragmARC.Reflection in the PragmAda
Reusable Components, available at

http://home.earthlink.net/~jrcarter010/pragmarc.htm

which does exactly what you want.

--
Jeffrey Carter



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

* RE: Package name
@ 2001-05-16 16:17 Beard, Frank
  2001-05-16 18:11 ` tmoran
  0 siblings, 1 reply; 12+ messages in thread
From: Beard, Frank @ 2001-05-16 16:17 UTC (permalink / raw)
  To: 'comp.lang.ada@ada.eu.org'


-----Original Message-----
From: Marin David Condic [mailto:marin.condic.auntie.spam@pacemicro.com]

> I think the idea is to have something like a pragma or attribute that lets
> you get the name of the module you are in as a string. I have frequently
> wished I could write a more general exception handler (or error handler or
> simple messages at runtime...) by having something like "Context'Image" or
> some other function that would provide the fully qualified name of the
> subprogram, package, whatever that I am currently in. Example:
>
> package body Some_Package is
>    procedure Some_Procedure is
>        ....
>        Put_Line ("Running in: " & Current_Context'Image) ;
>
> having that print:
>
> Running in: Standard.Some_Package.Some_Procedure

The Aonix ObjectAda compiler on Windows NT, returns the Package,
Procedure, and line number when Exception_Information is called.
That is, assuming you produced the executable with at least
CodeView debugging included.  If you build the executable without
any debugging, then all you get is useless addresses.

For general debugging, we had to defined our own constants.  The
PACKAGE_NAME/CLASS_NAME was defined globally in the package body,
while each procedure or function had a local constant (METHOD_NAME).
It would have been really nice to have something like Context'image,
as Marin suggests.

Frank




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

* Re: Package name
  2001-05-16 14:00   ` Marin David Condic
@ 2001-05-16 16:45     ` Claude SIMON
  2001-05-17 13:59       ` Marin David Condic
  2001-05-16 18:24     ` Randy Brukardt
  1 sibling, 1 reply; 12+ messages in thread
From: Claude SIMON @ 2001-05-16 16:45 UTC (permalink / raw)


You could use the external_tag attribute of a tagged type :

with Text_Io;
procedure P1 is
   type Trace is tagged null record;

   procedure P2 is
      type Trace is tagged null record;
   begin
       Text_Io.Put_Line (Trace'External_Tag);
   end P2;

begin
    P2;
    Text_Io.Put_Line (Trace'External_Tag);
end P1;


Marin David Condic a �crit :

> I think the idea is to have something like a pragma or attribute that lets
> you get the name of the module you are in as a string. I have frequently
> wished I could write a more general exception handler (or error handler or
> simple messages at runtime...) by having something like "Context'Image" or
> some other function that would provide the fully qualified name of the
> subprogram, package, whatever that I am currently in. Example:
>
> package body Some_Package is
>     procedure Some_Procedure is
>         ....
>         Put_Line ("Running in: " & Current_Context'Image) ;
>
> having that print:
>
> Running in: Standard.Some_Package.Some_Procedure
>
> It would be useful for diagnostics in the event of various errors or other
> conditions. Maybe even have "Current_Context'Line_Number" and similar
> capabilities? One would wish that Exception_Message and
> Exception_Information had this sort of information in their returned strings
> (Never seen it myself in the implementations I've used), but I think you'd
> want it to be available without an exception being raised.
>
> And of course, one could also want some sort of access to the dynamic
> context as well. (The call stack). There's no limit to the things I can
> want. But as my mother used to observe, "People in Hell want ice water,
> too!"  :-)
>
> MDC
> --
> Marin David Condic
> Senior Software Engineer
> Pace Micro Technology Americas    www.pacemicro.com
> Enabling the digital revolution
> e-Mail:    marin.condic@pacemicro.com
> Web:      http://www.mcondic.com/
>
> "Preben Randhol" <randhol+abuse@pvv.org> wrote in message
> news:slrn9g509m.f4.randhol+abuse@kiuk0156.chembio.ntnu.no...
> > On Wed, 16 May 2001 14:56:38 +0200, Atle R�stad wrote:
> > > Is it possible to print out the package name?
> > >
> > > It would be a nice feature in tracing. Maybe even print the
> > > procedure/function name.
> >
> > What do you mean?
> >
> > --
> > Preben Randhol ------------------- http://www.pvv.org/~randhol/ --
> >                  �For me, Ada95 puts back the joy in programming.�




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

* Re: Package name
  2001-05-16 12:56 Atle R�stad
  2001-05-16 13:28 ` Preben Randhol
  2001-05-16 16:10 ` Jeffrey Carter
@ 2001-05-16 17:08 ` David C. Hoos, Sr.
  2 siblings, 0 replies; 12+ messages in thread
From: David C. Hoos, Sr. @ 2001-05-16 17:08 UTC (permalink / raw)


This is a piece of "boilerplate" code I put in library unit bodies
to do just that.

It does so at the expense of two identifiers (ID and Exception_Name)
that are used only for the purpose of defining the value of the
Unit_Name string.

   ---------------------------------------------------------------------
   -- The next three declarations are an artifice to obtain the name
   -- of this unit -- e.g. for use in error messages.
   ---------------------------------------------------------------------
   ID : exception;
   Exception_Name : constant String :=
     Ada.Exceptions.Exception_Name (Id'Identity);
   Unit_Name : String renames
     Exception_Name (Exception_Name'First .. Exception_Name'Last - 3);


"Atle R�stad" <aer@edh.ericsson.se> wrote in message
news:990017804.158478@edh3...
> Is it possible to print out the package name?
>
> It would be a nice feature in tracing. Maybe even print the
> procedure/function name.
>
> Regards Atle
>
>




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

* RE: Package name
  2001-05-16 16:17 Package name Beard, Frank
@ 2001-05-16 18:11 ` tmoran
  0 siblings, 0 replies; 12+ messages in thread
From: tmoran @ 2001-05-16 18:11 UTC (permalink / raw)


>The Aonix ObjectAda compiler on Windows NT, returns the Package,
>Procedure, and line number when Exception_Information is called.
     In Janus Ada:
with Ada.Exceptions,
     Ada.Text_Io;

procedure Show_Me is

  procedure Show(Msg : in String) is
    E : exception;
  begin
    raise E;
  exception
    when Debug : E =>
      Ada.Text_Io.Put_Line(Msg & ":"
        & Ada.Exceptions.Exception_Information(Debug));
  end Show;

  procedure Testp is
  begin
    Show("inside testp");
    Show("still in testp");
  end Testp;

begin
  Show("main program");
  Testp;
end Show_Me;

gives:
main program:SHOW_ME.SHOW.E
   On Line Number 9 In SHOW_ME.SHOW
Called from line number 23 In SHOW_ME

inside testp:SHOW_ME.SHOW.E
   On Line Number 9 In SHOW_ME.SHOW
Called from line number 18 In SHOW_ME.TESTP
Called from line number 24 In SHOW_ME

still in testp:SHOW_ME.SHOW.E
   On Line Number 9 In SHOW_ME.SHOW
Called from line number 19 In SHOW_ME.TESTP
Called from line number 24 In SHOW_ME

Of course not all compilers are this helpful, so the PragmAda
generic approach may be preferable.



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

* Re: Package name
  2001-05-16 14:00   ` Marin David Condic
  2001-05-16 16:45     ` Claude SIMON
@ 2001-05-16 18:24     ` Randy Brukardt
  1 sibling, 0 replies; 12+ messages in thread
From: Randy Brukardt @ 2001-05-16 18:24 UTC (permalink / raw)


Marin David Condic wrote in message <9du16o$fr3$1@nh.pace.co.uk>...
>It would be useful for diagnostics in the event of various errors or
other
>conditions. Maybe even have "Current_Context'Line_Number" and similar
>capabilities? One would wish that Exception_Message and
>Exception_Information had this sort of information in their returned
strings
>(Never seen it myself in the implementations I've used)...

You've obviously never used Janus/Ada. It includes a complete traceback
of the calls in Exception_Information:

   ** Unhandled CONSTRAINT_ERROR
      Index or Subtype out of bounds - Pos of Error Value =  12
   On Line Number 7 In PROC.FOO.BAR
   Called from line number 123 In PROC.FOO
   Called from line number 11 In PROC

(It always has had this, but there wasn't a clean way to get it in Ada
83 except to let the program terminate with an unhandled exception.)
This is a godsend when debugging. (It also keeps limited information
about reraised exceptions, so the original traceback isn't lost.)

All of the Claw exception handlers display Exception_Information in
order to be able to access this information. On some compilers,
Exception_Information is pretty useless (and we try to debug Claw with
other compilers, usually Janus/Ada and GNAT) unless the problem is
compiler-specific. One problem with Claw is that many exceptions are
raised by a subprogram Raise_Windows_Error (which sets up an appropriate
Exception_Message), so you need the line number and package of the call
to that routine in order to find out anything useful. Only Janus/Ada
gives enough information to easily debug such exceptions.

                Randy Brukardt.


            Randy.






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

* Re: Package name
  2001-05-16 16:45     ` Claude SIMON
@ 2001-05-17 13:59       ` Marin David Condic
  2001-05-17 15:06         ` Samuel T. Harris
  0 siblings, 1 reply; 12+ messages in thread
From: Marin David Condic @ 2001-05-17 13:59 UTC (permalink / raw)


That might work nicely in a number of spots. It would be A Good Thing if
there were some way of doing it in a way that Ada guarantees you get the
string you want. The external_tag may not produce a result you want on all
systems.

MDC
--
Marin David Condic
Senior Software Engineer
Pace Micro Technology Americas    www.pacemicro.com
Enabling the digital revolution
e-Mail:    marin.condic@pacemicro.com
Web:      http://www.mcondic.com/


"Claude SIMON" <claude.simon@setra.fr> wrote in message
news:3B02AE98.BDAAC10E@setra.fr...
> You could use the external_tag attribute of a tagged type :
>






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

* Re: Package name
  2001-05-17 13:59       ` Marin David Condic
@ 2001-05-17 15:06         ` Samuel T. Harris
  0 siblings, 0 replies; 12+ messages in thread
From: Samuel T. Harris @ 2001-05-17 15:06 UTC (permalink / raw)


Marin David Condic wrote:
> 
> That might work nicely in a number of spots. It would be A Good Thing if
> there were some way of doing it in a way that Ada guarantees you get the
> string you want. The external_tag may not produce a result you want on all
> systems.
> 

Use Ada.Tags.External_Name instead.
It is a precisely define content which is a string
representing the fully expanded name of the type.

One can easily strip off the last .identifier to
get the fully expanded name of the enclosing declaration.

Another method is to establish a code pattern where
each declarative scope defines a known string constant
of the same name and use ASIS to auto-insert the string
declarations into code.

-- 
Samuel T. Harris, Principal Engineer
Raytheon, Aerospace Engineering Services
"If you can make it, We can fake it!"



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

end of thread, other threads:[~2001-05-17 15:06 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-05-16 16:17 Package name Beard, Frank
2001-05-16 18:11 ` tmoran
  -- strict thread matches above, loose matches on Subject: below --
2001-05-16 12:56 Atle R�stad
2001-05-16 13:28 ` Preben Randhol
2001-05-16 13:46   ` Atle R�stad
2001-05-16 14:00   ` Marin David Condic
2001-05-16 16:45     ` Claude SIMON
2001-05-17 13:59       ` Marin David Condic
2001-05-17 15:06         ` Samuel T. Harris
2001-05-16 18:24     ` Randy Brukardt
2001-05-16 16:10 ` Jeffrey Carter
2001-05-16 17:08 ` David C. Hoos, Sr.

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