caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Re:  Where did the exception occur?
@ 2000-10-31 10:14 Damien Doligez
  2000-10-31 12:09 ` Mattias Waldau
  2000-10-31 15:27 ` Where did the exception occur? CREGUT Pierre FTRD/DTL/LAN
  0 siblings, 2 replies; 20+ messages in thread
From: Damien Doligez @ 2000-10-31 10:14 UTC (permalink / raw)
  To: caml-list

>From: "David McClain" <dmcclain@azstarnet.com>

>I found that the location of the exception is rarely the source of
>a problem...

Indeed, this discussion started because of an uncaught "Not_found".
Most likely, this is raised by Hashtbl.find, List.assoc, or
String.index (there are a few other).  Knowing exactly which one is
unlikely to help very much.

I don't like the idea of adding run-time information just for the case
when you cannot run the debugger, especially if it incurs a lot of
overhead.  IMO, it would be more interesting to make the debugger work
for embedded code.

In the short term, static analysis seems to be the way to go.

-- Damien



^ permalink raw reply	[flat|nested] 20+ messages in thread
* Where did the exception occur?
@ 2000-10-30 15:21 David McClain
  0 siblings, 0 replies; 20+ messages in thread
From: David McClain @ 2000-10-30 15:21 UTC (permalink / raw)
  To: caml-list

Here is another one to think about... I once wrote a major program in OCaml
using CPS. This is a nightmare to traceback since every function exits by
calling another. How would a stack frame help here? You don't have infinite
memory.

- DM



^ permalink raw reply	[flat|nested] 20+ messages in thread
* Where did the exception occur?
@ 2000-10-30 15:19 David McClain
  0 siblings, 0 replies; 20+ messages in thread
From: David McClain @ 2000-10-30 15:19 UTC (permalink / raw)
  To: caml-list

I would like to point out the folly of spending too much effort on language
design directed at displaying the location of an exception. As one who did
so, I can report that the effort was merciless, and although it does as
expected, I found that the location of the exception is rarely the source of
a problem...

Hence, I implemented an entire stack of last visited nodes to provide a
traceback. (I'm a glutton for punishment!).  This not only slows the system
down, but only offers marginal improvement to debugging.

The best way to achieve the stated goal, so far, that I have found, is to
plant a "source coordinate" in the exception itself - something you can do
manually after declaring the exception type to contain this information. But
beware! you will often halt at nonsensical places...

- D.McClain




^ permalink raw reply	[flat|nested] 20+ messages in thread
* RE: Where did the exception occur?
@ 2000-10-30 15:09 Greg Morrisett
  0 siblings, 0 replies; 20+ messages in thread
From: Greg Morrisett @ 2000-10-30 15:09 UTC (permalink / raw)
  To: 'stephanh@win.tue.nl', Pierre Weis, orodeh; +Cc: caml-list

> I'm not the OP, but this can of course be implemented by having an
> additional (hidden) field in the exception which contains the source
> co-ordinate.

This is really cheap to add.  But it's not very useful in
practice.  The problem is that you call a higher order
function (e.g., find or something like that) and you really
need to know who called that function to narrow down the
context suffiently.  What you really want is a stack backtrace
hence my suggestion.  And Pierre is (rightfully) worried
about the overhead of supporting the full backtrace.

Still, it's so useful that I would highly encourage its
support.  (We've done this with our Popcorn compiler recently
in a rather naive way, and in spite of the overhead, I leave 
it on all the time because it's just so useful.)

-Greg



^ permalink raw reply	[flat|nested] 20+ messages in thread
* RE: Where did the exception occur?
@ 2000-10-30 14:39 Greg Morrisett
  0 siblings, 0 replies; 20+ messages in thread
From: Greg Morrisett @ 2000-10-30 14:39 UTC (permalink / raw)
  To: 'Pierre Weis', orodeh; +Cc: caml-list

> Otherwise, the addition you mentioned is interesting, if only we could
> implement it with no penalty on the speed of exception raising. Have
> you an idea of such a compilation scheme ?

If you have a mapping from return addresses to functions,
then when raising an exception, you could walk the stack
frames and add the name of each function to a list that
gets accumulated as part of the exception packet.  This
only has overhead for exception raising, but believe me,
it's well worth it.  At the worst you could make it a compiler
option (like array bounds checks.)  

(To avoid allocating, you could pre-allocate k slots in
the exception packet and only record the first k stack
frames' function names.)

-Greg



^ permalink raw reply	[flat|nested] 20+ messages in thread
* RE: Where did the exception occur?
@ 2000-10-30 11:20 Dave Berry
  0 siblings, 0 replies; 20+ messages in thread
From: Dave Berry @ 2000-10-30 11:20 UTC (permalink / raw)
  To: Ohad Rodeh, Pierre Weis; +Cc: Mattias Waldau, caml-list

People seem to be confusing "language" and "implementation".  MLWorks (a now
defunct implementation of SML) implemented "pop" semantics by "pushing" a
handler onto the stack, which enabled debugging of the stack from the
debugger.  (Then again, MLWorks code couldn't be called from C, so Ohad's
case couldn't arise).  Other implementations of SML may well report the line
number where the exception occurred: this is definitely a useful feature.

Dave.


-----Original Message-----
From: Ohad Rodeh [mailto:orodeh@cs.huji.ac.il]
Sent: Monday, October 30, 2000 7:57
To: Pierre Weis
Cc: Mattias Waldau; caml-list@inria.fr
Subject: Re: Where did the exception occur?


List, 
  I'd like to point out, that my application (LARGE OCaml project) is
embedded in C code, so one cannot use the OCaml debugger to replay and
find the exception.  I'd be happy if a feature would be added to the
language to point out which line in the code the exception came from (I
understand this was added to SML ?).

	Ohad.



^ permalink raw reply	[flat|nested] 20+ messages in thread
* Where did the exception occur?
@ 2000-10-29  9:59 Mattias Waldau
  2000-10-30  7:36 ` Pierre Weis
  0 siblings, 1 reply; 20+ messages in thread
From: Mattias Waldau @ 2000-10-29  9:59 UTC (permalink / raw)
  To: Caml-List

I am running my program from the top-level, and the programs aborts to the
toplevel ans says:

Uncaught exception: Not_found.

Is there a way to tell where the exception occured, for example program
languages like SICStus Prolog, Lisp, Visual C++, Visual Basic normally stops
in a top-loop at the stack frame of the error. Is there a similar feature in
OCaml?

----
Mattias Waldau







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

end of thread, other threads:[~2000-11-03 18:04 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-10-31 10:14 Where did the exception occur? Damien Doligez
2000-10-31 12:09 ` Mattias Waldau
2000-10-31 16:52   ` Pierre Weis
2000-10-31 18:50     ` Where did the exception occur? with Not_found -> assert false Mattias Waldau
2000-11-02 14:53       ` Assert Ohad Rodeh
2000-11-02 18:45         ` Assert Nicolas barnier
2000-11-03 17:34           ` Assert John Max Skaller
2000-10-31 15:27 ` Where did the exception occur? CREGUT Pierre FTRD/DTL/LAN
  -- strict thread matches above, loose matches on Subject: below --
2000-10-30 15:21 David McClain
2000-10-30 15:19 David McClain
2000-10-30 15:09 Greg Morrisett
2000-10-30 14:39 Greg Morrisett
2000-10-30 11:20 Dave Berry
2000-10-29  9:59 Mattias Waldau
2000-10-30  7:36 ` Pierre Weis
2000-10-30  7:57   ` Ohad Rodeh
2000-10-30 11:02     ` Pierre Weis
2000-10-30 11:33       ` Stephan Houben
2000-10-30 12:12   ` David Mentré
2000-11-02 17:29     ` Pierre Weis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).