From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 34331BB91 for ; Mon, 10 Jan 2005 18:59:07 +0100 (CET) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id j0AHx6EK013348 for ; Mon, 10 Jan 2005 18:59:06 +0100 Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id SAA02641 for ; Mon, 10 Jan 2005 18:59:06 +0100 (MET) Received: from furbychan.cocan.org ([80.68.91.176]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id j0AHx58g013327 for ; Mon, 10 Jan 2005 18:59:05 +0100 Received: from rich by furbychan.cocan.org with local (Exim 3.35 #1 (Debian)) id 1Co3oS-0003KK-00; Mon, 10 Jan 2005 17:58:44 +0000 Date: Mon, 10 Jan 2005 17:58:44 +0000 To: Alex Baretta Cc: Ocaml Subject: Re: [Caml-list] How do I get a stack trace in a running program? Message-ID: <20050110175844.GA11261@furbychan.cocan.org> References: <41E2B978.5090106@barettadeit.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <41E2B978.5090106@barettadeit.com> User-Agent: Mutt/1.3.28i From: Richard Jones X-Miltered: at concorde with ID 41E2C26A.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at concorde with ID 41E2C269.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 stack:01 baretta:01 wrote:01 backtrace:01 printexc:01 bytecode:01 backtrace:01 buffer:01 byterun:01 uncaught:01 byterun:01 printexc:01 uncaught:01 ocaml:01 X-Spam-Checker-Version: SpamAssassin 3.0.0 (2004-09-13) on yquem.inria.fr X-Spam-Status: No, score=0.1 required=5.0 tests=FORGED_RCVD_HELO autolearn=disabled version=3.0.0 X-Spam-Level: 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. --