Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] getting stack traces in running code
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2003-12-03 (03:25)
From: Nicolas Cannasse <warplayer@f...>
Subject: Re: [Caml-list] getting stack traces in running code
> > Is there a reason why stack traces are available only on a crash?  I
> > have a project (a distributed OpenPGP keyserver system,
> > that is a long-running daemon.  Unexpected
> > errors are caught and logged, but unfortunately, there's no way of
> > getting a stack-trace, since I don't let the exceptions kill the
> > program.  This makes debugging much more difficult, and is one of the
> > single largest difficulties I have with ocaml.  Is there a technical
> > reason that a bytecode-compiled executable couldn't have access to the
> > stack trace during execution?
> I have a partial solution:
> It's not quite right yet because it only prints out the
> place where the exception was raised (which will be in
> Pervasives if you use failwith), and the place where it
> was caught and printed.  Does someone know how to make it
> print the whole stack?

I think this is because you're adding an additional call to "print", that is
writing on the stack (!). Since you can't write on the stack, you can't call
any ML handler between catching and printing the exception.
You should then have no and only a mli with :

external print_stack_strace : unit -> unit = "internal_print"

the user can then print the exception using a Printexc... after printing the

BTW, if the "print_exception_backtrace" of the caml sources was exported as
Primitive, we would be able to do it without the need of any C stub : the
other way to do it is then to run a modified interpreter where CAMLexport
have been replaced with CAMLprim in backtrace.c....

Nicolas Cannasse

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: