* How do I get a stack trace in a running program?
@ 2005-01-10 17:20 Alex Baretta
2005-01-10 17:58 ` [Caml-list] " Richard Jones
0 siblings, 1 reply; 5+ messages in thread
From: Alex Baretta @ 2005-01-10 17:20 UTC (permalink / raw)
To: Ocaml
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.
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 How do I get a stack trace in a running program? 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
* 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 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
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 17:20 How do I get a stack trace in a running program? 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