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 mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by yquem.inria.fr (Postfix) with ESMTP id 30FB5BC57 for ; Tue, 2 Mar 2010 01:52:03 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AuIAADvwi0tKfVM0mWdsb2JhbACPK4N/h1QIFQEBAQEBCAsKBxMir05ChBoiiFUBAQMFhHYEgxeJAw X-IronPort-AV: E=Sophos;i="4.49,563,1262559600"; d="scan'208";a="45727564" Received: from mail-gw0-f52.google.com ([74.125.83.52]) by mail2-smtp-roc.national.inria.fr with ESMTP; 02 Mar 2010 01:52:02 +0100 Received: by gwb1 with SMTP id 1so1239832gwb.39 for ; Mon, 01 Mar 2010 16:52:02 -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=ae2p44YhxzbYtYIdntWsBK9MfyO6DCvK4Tanof8AQ/4=; b=f3XAjN07Xah3T29m6ZO5hc8sgdLC6JkVD0biI5n8hfNA7efthYknUwvgIDO6h0Bfjb GcWbFRIqVWrEiGadqoXr6T+ti7xHXWfEy6Gx2fhIUpfY8icdmfTmBNhcOMlGIXDcgok6 3D4McXsu0lCsn5OmR8BUOREBBwUkSQR2Amu8A= 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=e3X679vGjRPJ9XyQvA2qoMlrc3ZEd5J4N1NNqhFgYp2pPQ6nz0evkhZhOE4BRCO8Eo WYwc8ozA3ecmCpeTtQJRYvAUitJlp6NJMdndrXUHENE9QJBORqy9yVostiGeJ32SzAFp GiA7zOyI08q7ewx8AlilSaDMi4tCp4Kq6HPis= MIME-Version: 1.0 Sender: jianzhou.zh@gmail.com Received: by 10.101.174.17 with SMTP id b17mr7394445anp.242.1267491121884; Mon, 01 Mar 2010 16:52:01 -0800 (PST) In-Reply-To: <9dfe358d1003011648g58c07831p9b27bc76276a9461@mail.gmail.com> References: <9dfe358d1003010710r69799c1duae37c42a3725b899@mail.gmail.com> <20100301151940.GD26002@janestreet.com> <9dfe358d1003011648g58c07831p9b27bc76276a9461@mail.gmail.com> Date: Mon, 1 Mar 2010 19:52:01 -0500 X-Google-Sender-Auth: 3815c4f628c4e583 Message-ID: <9dfe358d1003011652p5732e592t465468d0d8a64b42@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 7:48 PM, Jianzhou Zhao wro= te: > On Mon, Mar 1, 2010 at 10:19 AM, Mark Shinwell = wrote: >> 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= (amd64.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 = the >> assembly level -- does that work? =A0Unfortunately at the moment there i= s 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 = easy to >> read, and you should be able to get something resembling a backtrace usi= ng >> "where". > > Now I can debug into OCaml assembly from C, and its stack frames. > > #0 =A00x00007ffff6cad3f4 in caml_interprete () > #1 =A00x00007ffff6caa54f in caml_callbackN_exn () > #2 =A00x00007ffff6caa64a in caml_callback_exn () > #3 =A00x00007ffff6caa658 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. If we do native compilation, will each OCaml function be assembled to a function in assemly with a readable name? That will help a lot while reading the assemly code. > >> >> Mark >> > > > > -- > Jianzhou > --=20 Jianzhou