From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id 6E5A9D460 for ; Wed, 26 Oct 2005 00:26:17 +0200 (CEST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j9PMQHkW026410 for ; Wed, 26 Oct 2005 00:26:17 +0200 Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id AAA02092 for ; Wed, 26 Oct 2005 00:26:16 +0200 (MET DST) Received: from xproxy.gmail.com (xproxy.gmail.com [66.249.82.205]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j9PMQFNV026407 for ; Wed, 26 Oct 2005 00:26:16 +0200 Received: by xproxy.gmail.com with SMTP id i27so52449wxd for ; Tue, 25 Oct 2005 15:26:15 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition; b=XcOQxUVfYpdlvdl8KP1RiMi2W2OBZUnzmAetF027McJb7L1WKMJW19/7S/KPBNmzE//bqKK/ZzhHqfWdjCI1oVH6N4x8iOlCpPKm2gOy43n9YxQepCGAJiIhtBvfsLcgnDNwgPFNfpt0P3ePoXw55/bMLHqQZFw4Bs8bfkvCRqQ= Received: by 10.65.232.19 with SMTP id j19mr131751qbr; Tue, 25 Oct 2005 15:26:15 -0700 (PDT) Received: by 10.65.135.19 with HTTP; Tue, 25 Oct 2005 15:26:15 -0700 (PDT) Message-ID: Date: Tue, 25 Oct 2005 23:26:15 +0100 From: Robert Schneck-McConnell To: caml-list@inria.fr Subject: Stack backtrace for exception in a running program MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline X-Miltered: at nez-perce with ID 435EB109.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at nez-perce with ID 435EB107.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; stack:01 backtrace:01 backtrace:01 mlvalues:01 alloc:01 camlprim:01 val:01 ocaml:01 ocaml:01 bytecode:01 -custom:01 ocamlc:01 -custom:01 exception:01 exception:01 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_BY_IP autolearn=disabled version=3.0.3 I saw that back in January someone asked about printing a backtrace for an exception without killing the program. I recently needed to do this and found that the suggestion from that earlier thread to write a C extension (which didn't seem to work for the original poster) worked fine for me. In case anyone else needs this information, here's how. (1) You need this short C file, call it "ml_backtrace.c" #include #include #include #include #include CAMLextern void caml_print_exception_backtrace(void); CAMLprim value ml_print_exception_backtrace (value unit) { caml_print_exception_backtrace(); return Val_unit; } (2) In your OCaml program, include the line external print_exception_backtrace : unit -> unit =3D "ml_print_exception_backtrace" (3) Call "print_exception_backtrace ()" anytime you need it after catching an exception. (4) Compile the OCaml program in bytecode with -g, link with -g -custom and against the ml_backtrace.o file. In one line, ocamlc -o program -g -custom program.ml ml_backtrace.c (5) Make sure the environment variable OCAMLRUNPARAM=3Db is set when you run the program. Best, Robert