English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
How do I get a stack trace in a running program?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2005-01-10 (17:59)
From: Richard Jones <rich@a...>
Subject: Re: [Caml-list] How do I get a stack trace in a running program?
On Mon, Jan 10, 2005 at 06:20:56PM +0100, Alex Baretta wrote:
> I need to print a backtrace for an exception which I catch in the 
> outmost loop of a long-running server, which the exception must not 
> kill. Printexc does not help here.

The following only applies in bytecode, when backtraces are enabled

When an exception is raised the backtrace is stashed in a global
[per-thread?] buffer (byterun/backtrace.c:caml_stash_backtrace).  If
an exception is uncaught (byterun/printexc.c:
caml_fatal_uncaught_exception), then the backtrace is printed
(byterun/backtrace.c:caml_print_exception_backtrace) last thing before
the program exits.

Therefore it seems there is no way to trigger the printing of
backtraces except by modifying the sources to the OCaml compuiler.
Except that possibly you could write a C extension which calls
caml_print_exception_backtrace, if that symbol is visible, and it
might do the right thing, with luck!

It would be really nice if OCaml (a) recorded the function parameters
in backtraces, and (b) made available the backtraces programmatically.
Both Java and Perl do this, so there is no excuse for our favorite
language not to do it too!