caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* RE: [Caml-list] How do I get a stack trace in a running program?
@ 2005-01-10 19:04 HENRIKSON, JEFFREY
  0 siblings, 0 replies; 5+ messages in thread
From: HENRIKSON, JEFFREY @ 2005-01-10 19:04 UTC (permalink / raw)
  To: caml-list

> 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!

I brought this up on the list a year or two back.  I still see this as a
stumbling block on the path toward production code in ocaml.  One use
case was wanting to be able to email bug reports from crashes on user
machines back to myself.  Only having the ability to print on stdout
without compiler modification makes this a headache.

I do see parameter recording and printing as necessary for a robust
implementation.  In the toplevel, it seems that printing a stack frame
parameter means the same thing as printing a value.  It should be
configurable as a default behavior to print uncaught exceptions with a
stack backtrace, perhaps with some kind of #turn_on_backtrace_printing
toplevel command.  However, in binary executables, I would be happy to
have binary runtime parameter printing, ala the OReily book's C
interface chapter.  Even a supported way to configure binary parameter
printing in the toplevel via a user handler would be very helpful for
me.  I had a C hack to get a backtrace out sans parameters in the
toplevel in version 3.04, but it broke when I went to 3.06.

Regards,


Jeff Henrikson



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

* Re: [Caml-list] How do I get a stack trace in a running program?
       [not found]       ` <20050111103546.GA16257@furbychan.cocan.org>
@ 2005-01-11 10:59         ` Alex Baretta
  0 siblings, 0 replies; 5+ messages in thread
From: Alex Baretta @ 2005-01-11 10:59 UTC (permalink / raw)
  To: Richard Jones, Ocaml

Richard Jones wrote:
> On Tue, Jan 11, 2005 at 11:30:11AM +0100, Alex Baretta wrote:
> [...]
> 
> Depending on how busy I am today, I might be motivated enough to try
> and patch the OCaml sources so that we can get backtraces as strings ...
> I'll let you know.
> 
> Rich.
> 
> -- 
> 

This is fairly easy. All you need to do is remove enough "static" 
function attributes from the byterun/backtrace.c source file and add the 
corresponding prototypes in byterun/backtrace.h.

Alex

-- 
*********************************************************************
http://www.barettadeit.com/
Baretta DE&IT
A division of Baretta SRL

tel. +39 02 370 111 55
fax. +39 02 370 111 54

Our technology:

The Application System/Xcaml (AS/Xcaml)
<http://www.asxcaml.org/>

The FreerP Project
<http://www.freerp.org/>


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

* Re: [Caml-list] How do I get a stack trace in a running program?
  2005-01-10 18:09   ` Alex Baretta
@ 2005-01-11 10:30     ` Alex Baretta
       [not found]       ` <20050111103546.GA16257@furbychan.cocan.org>
  0 siblings, 1 reply; 5+ messages in thread
From: Alex Baretta @ 2005-01-11 10:30 UTC (permalink / raw)
  To: Richard Jones; +Cc: Ocaml

Alex Baretta wrote:
> Richard Jones wrote:
> 
>> 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!
> 
> 
> This is more or less what I'm doing...

This failed pathetically. This is the best I was able to do.

alex@alex:~/darcs/sw/lib/unixlib-addons$ cat backtrace.ml

open Unix
external print_exception_backtrace : file_descr -> unit =
   "user_print_exception_backtrace"

alex@alex:~/darcs/sw/lib/unixlib-addons$ cat fail.ml

open Backtrace
let () = try
   failwith "No backtrace, folks!" with x ->
     print_exception_backtrace Unix.stderr

alex@alex:~/darcs/sw/lib/unixlib-addons$ ocamlfind ocamlc -g -package 
"unixlib-addons" -linkpkg fail.ml -o fail
Error on dynamically loaded library: ./dllunixlib-addons.so: undefined 
symbol: caml_start_code

Why in the world can't I get a backtrace for a caught exception!?

Alex

-- 
*********************************************************************
http://www.barettadeit.com/
Baretta DE&IT
A division of Baretta SRL

tel. +39 02 370 111 55
fax. +39 02 370 111 54

Our technology:

The Application System/Xcaml (AS/Xcaml)
<http://www.asxcaml.org/>

The FreerP Project
<http://www.freerp.org/>


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

* Re: [Caml-list] How do I get a stack trace in a running program?
  2005-01-10 17:58 ` [Caml-list] " Richard Jones
@ 2005-01-10 18:09   ` Alex Baretta
  2005-01-11 10:30     ` Alex Baretta
  0 siblings, 1 reply; 5+ messages in thread
From: Alex Baretta @ 2005-01-10 18:09 UTC (permalink / raw)
  To: Richard Jones; +Cc: Ocaml

Richard Jones wrote:
> 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.
> 

> 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!

This is more or less what I'm doing...


Alex


-- 
*********************************************************************
http://www.barettadeit.com/
Baretta DE&IT
A division of Baretta SRL

tel. +39 02 370 111 55
fax. +39 02 370 111 54

Our technology:

The Application System/Xcaml (AS/Xcaml)
<http://www.asxcaml.org/>

The FreerP Project
<http://www.freerp.org/>


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

* Re: [Caml-list] How do I get a stack trace in a running program?
  2005-01-10 17:20 Alex Baretta
@ 2005-01-10 17:58 ` Richard Jones
  2005-01-10 18:09   ` Alex Baretta
  0 siblings, 1 reply; 5+ messages in thread
From: Richard Jones @ 2005-01-10 17:58 UTC (permalink / raw)
  To: Alex Baretta; +Cc: Ocaml

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
using OCAMLRUNPARAM=b.

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!

Rich.

-- 


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

end of thread, other threads:[~2005-01-11 11:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-01-10 19:04 [Caml-list] How do I get a stack trace in a running program? HENRIKSON, JEFFREY
  -- strict thread matches above, loose matches on Subject: below --
2005-01-10 17:20 Alex Baretta
2005-01-10 17:58 ` [Caml-list] " Richard Jones
2005-01-10 18:09   ` Alex Baretta
2005-01-11 10:30     ` Alex Baretta
     [not found]       ` <20050111103546.GA16257@furbychan.cocan.org>
2005-01-11 10:59         ` Alex Baretta

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).