From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id C49BABC57 for ; Tue, 2 Mar 2010 01:48:57 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AjgBANLui0vRVdLDkGdsb2JhbACPK4tTCBUBAQEBCQkMBxMDH69XQoQUIohVAQEDBYR2BIMXiQM X-IronPort-AV: E=Sophos;i="4.49,563,1262559600"; d="scan'208";a="53838957" Received: from mail-yx0-f195.google.com ([209.85.210.195]) by mail1-smtp-roc.national.inria.fr with ESMTP; 02 Mar 2010 01:48:57 +0100 Received: by yxe33 with SMTP id 33so1290122yxe.1 for ; Mon, 01 Mar 2010 16:48:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:sender:received:in-reply-to :references:date:x-google-sender-auth:message-id:subject:from:to:cc :content-type:content-transfer-encoding; bh=1NAOAicYzeNOnGnbwP5FIZkKfnJ0uDKnt+ADy30ttFs=; b=JqVeasHtE7KPDEYAE2WPLAdJdYlcdTVLH8IQgPTEDfABDnh2nCaNTgcCILhRizzWmO fQfEkwRaY1twtebRYg0/XWPp+fNRYVkafzcVjIbLGD+yGg8IRt6YMk6uHJi+8dcdVEL0 M8PNB0zrcT/cIvc/BLSGGWUraNFmQH6GgtnU0= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :content-transfer-encoding; b=N7JGHQKounln3ne+vnqR4jDRg9IkwshvcJO3TGtToIRcdVbXp4q/DKx5iFj7+n9x0q htDkpcinRAN1VVgDCMhh7rqxjS8cMQ1MOKWaj4VNkCKjP1eRTpG9N5Q2cYSNWPHwdzGB kItvQ2nYOIfgzlR1NBo48BmXV8CA6x+d9u3ag= MIME-Version: 1.0 Sender: jianzhou.zh@gmail.com Received: by 10.100.236.5 with SMTP id j5mr7635085anh.60.1267490936257; Mon, 01 Mar 2010 16:48:56 -0800 (PST) In-Reply-To: <20100301151940.GD26002@janestreet.com> References: <9dfe358d1003010710r69799c1duae37c42a3725b899@mail.gmail.com> <20100301151940.GD26002@janestreet.com> Date: Mon, 1 Mar 2010 19:48:56 -0500 X-Google-Sender-Auth: 9012063de96d42d6 Message-ID: <9dfe358d1003011648g58c07831p9b27bc76276a9461@mail.gmail.com> Subject: Re: [Caml-list] Debugging C and OCaml From: Jianzhou Zhao To: Mark Shinwell Cc: caml-list@yquem.inria.fr Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Spam: no; 0.00; ocaml:01 shinwell:01 ocaml:01 compilation:01 'ocamlc:01 -custom:01 -output-obj:01 compilation:01 usr:01 lib:01 gcc:01 ocaml-:01 lib:01 libasmrun:01 recompile:01 On Mon, Mar 1, 2010 at 10:19 AM, Mark Shinwell w= rote: > On Mon, Mar 01, 2010 at 10:10:44AM -0500, Jianzhou Zhao wrote: >> My main program is C++. It uses C functions to call >> OCaml functions, and these OCaml functions also call >> C functions and wrapped C++ functions sometimes. >> >> I can debug from C++, but it stops when it meets >> an OCaml binding. Does anyone know an efficient >> solution about how to debug across different languages? > > Is this native code compilation? I compiled OCaml code into *.o by 'ocamlc -custom -output-obj...', and then linked it with *.o from C and C++ code. I think this isnt a native compilation. My main C++ program is eventually compiled into a shared library. If I do 'ocamlopt', ld reports: /usr/lib64/gcc/x86_64-suse-linux/4.3/../../../../x86_64-suse-linux/bin/ld: /mnt/eclipse/acg/users/jianzhou/tools/ocaml-3.11.2//lib/ocaml/libasmrun.a(a= md64.o): relocation R_X86_64_PC32 against symbol `caml_last_return_address' can not be used when making a shared object; recompile with -fPIC So I am doing ''ocamlc -custom' for the time being. > > If so, you should be able to use gdb to debug into the Caml bindings at t= he > assembly level -- does that work? =A0Unfortunately at the moment there is= no Caml > compiler support for emitting the debug info required by gdb to debug at = the > language level. =A0That said, ocamlopt-compiled assembly code is fairly e= asy to > read, and you should be able to get something resembling a backtrace usin= g > "where". Now I can debug into OCaml assembly from C, and its stack frames. #0 0x00007ffff6cad3f4 in caml_interprete () #1 0x00007ffff6caa54f in caml_callbackN_exn () #2 0x00007ffff6caa64a in caml_callback_exn () #3 0x00007ffff6caa658 in caml_callback () ... It seems that OCaml runtime is interpreting via 'caml_interprete' the OCaml function which C calls at runtime. If this is true, we cannot really debug that OCaml function, but we can see how it is interpreted. But I guess we can debug the real assembly if I = do native compilation. > > Mark > --=20 Jianzhou