From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by sympa.inria.fr (Postfix) with ESMTPS id 715B07FA15 for ; Thu, 26 Nov 2015 11:57:53 +0100 (CET) IronPort-PHdr: 9a23:Z1k4NhSLZMqJYOixjnK/PDUQfNpsv+yvbD5Q0YIujvd0So/mwa64YBSN2/xhgRfzUJnB7Loc0qyN4/2mCTRLuMbJmUtBWaIPfidNsd8RkQ0kDZzNImzAB9muURYHGt9fXkRu5XCxPBsdMs//Y1rPvi/6tmZKSV3BPAZ4bt74BpTVx5zukbviptuDO04R1HKUWvBbElaflU3prM4YgI9veO4a6yDihT92QdlQ3n5iPlmJnhzxtY+a9Z9n9DlM6bp6r5YTGfayQ6NtRrVdCHEiMnspzMztrxjKCwWVtVUGVWBDqB1NCgnDpDvzRJv2r2OurO140SicFcbsXKgoXi+v6bxmDhTvjXFUZHYC7GjLh5ko3+pgqxW7qkknzg== Authentication-Results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=romain@cryptosense.com; spf=None smtp.mailfrom=romain@cryptosense.com; spf=None smtp.helo=postmaster@11.mo3.mail-out.ovh.net Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of romain@cryptosense.com) identity=pra; client-ip=87.98.184.158; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="romain@cryptosense.com"; x-sender="romain@cryptosense.com"; x-conformance=sidf_compatible Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of romain@cryptosense.com) identity=mailfrom; client-ip=87.98.184.158; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="romain@cryptosense.com"; x-sender="romain@cryptosense.com"; x-conformance=sidf_compatible Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@11.mo3.mail-out.ovh.net) identity=helo; client-ip=87.98.184.158; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="romain@cryptosense.com"; x-sender="postmaster@11.mo3.mail-out.ovh.net"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0BoAABa5VZWnJ64YldehA5vv3YZhXYCgT08EAEBAQEBAQEBEAEBAQEBBg0JCSEugi2CCAEBBDg1CxELGAkWDwkDAgECAUUTCAKILgG+NQEBCCOKKYEpiTkFlleFKIhrfkmWR4NyOII8FgeBV3GFYAEBAQ X-IPAS-Result: A0BoAABa5VZWnJ64YldehA5vv3YZhXYCgT08EAEBAQEBAQEBEAEBAQEBBg0JCSEugi2CCAEBBDg1CxELGAkWDwkDAgECAUUTCAKILgG+NQEBCCOKKYEpiTkFlleFKIhrfkmWR4NyOII8FgeBV3GFYAEBAQ X-IronPort-AV: E=Sophos;i="5.20,346,1444687200"; d="scan'208";a="189204163" Received: from 11.mo3.mail-out.ovh.net ([87.98.184.158]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/ADH-AES256-GCM-SHA384; 26 Nov 2015 11:57:43 +0100 Received: from mail185.ha.ovh.net (gw6.ovh.net [213.251.189.206]) by mo3.mail-out.ovh.net (Postfix) with SMTP id 42D89101CB88 for ; Thu, 26 Nov 2015 11:57:42 +0100 (CET) Received: from localhost (HELO queueout) (127.0.0.1) by localhost with SMTP; 26 Nov 2015 12:57:41 +0200 Received: from alille-655-1-158-145.w83-192.abo.wanadoo.fr (HELO ?192.168.1.15?) (romain@bardou.fr@83.192.123.145) by ns0.ovh.net with SMTP; 26 Nov 2015 12:57:35 +0200 To: caml-list@inria.fr References: <5655AE66.6000307@coherentgraphics.co.uk> From: Romain Bardou Message-ID: <5656E59E.3000300@cryptosense.com> Date: Thu, 26 Nov 2015 11:57:34 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Icedove/38.3.0 MIME-Version: 1.0 In-Reply-To: <5655AE66.6000307@coherentgraphics.co.uk> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Ovh-Tracer-Id: 16545943556094554656 X-Ovh-Remote: 83.192.123.145 (alille-655-1-158-145.w83-192.abo.wanadoo.fr) X-Ovh-Local: 213.186.33.20 (ns0.ovh.net) X-OVH-SPAMSTATE: OK X-OVH-SPAMSCORE: 0 X-OVH-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrfeekhedrkedtucetufdoteggodftvfcurfhrohhfihhlvgemucfqggfjnecuuegrihhlohhuthemuceftddtnecu X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: 0 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrfeekhedrkedtucetufdoteggodftvfcurfhrohhfihhlvgemucfqggfjnecuuegrihhlohhuthemuceftddtnecu X-Validation-by: romain@cryptosense.com Subject: Re: [Caml-list] Do you use a debugger with OCaml? If not, why not? On 25/11/2015 13:49, John Whitington wrote: > Hi, > > Like, I suspect, many people, my method has always been to insert > Printfs, and stare at code until I find the problem. In fact, the > ocaml.org page on ocamldebug says: > > "In fact, for complex programs, it is likely the case that the > programmer will use explicit printing to find the bugs, since this > methodology allows the reduction of the trace material: only useful data > are printed and special purpose formats are more suited to get the > relevant information, than what can be output automatically by the > generic pretty-printer used by the trace mechanism." > > So, I ask: What do you use for debugging small and large OCaml programs? > If not a debugger, why not? What problems prevent it? How does your > debugging process differ when writing OCaml compared with other > languages you use? > > John > I used to program in Delphi, which is basically an IDE for Object Pascal. It had a debugger which I used, because it was easy: - click in the margin of your program to set up a breakpoint; - click on a button to run step-by-step; - learn the keyboard shortcut for this button by putting the mouse cursor over it; - view the value of a variable by putting the mouse cursor over it; - add conditions to breakpoints easily, like "only stop after the 100th time" or "only stop if x > 100". I did use the equivalent of printf sometimes though, because for some bugs it's just more convenient, even in a GUI such as Delphi. I almost never used a debugger for OCaml. I tried once, but: - the learning curve was really not as smooth; - it was not integrated into my editor (Emacs) or if it did, it was not easy to discover; - having to type debugger commands was actually slower than adding printf calls, maybe because I had to look up the commands first. I'm impressed by the capacity to rewind, but it turns out this feature is not enough to counterbalance the above. I would probably use a debugger for OCaml if it had the following features. - It's an easy-to-use GUI. - I can click to set up a breakpoint or just add something like Debug.breakpoint () in my code. I can run it step-by-step. - I'm able to see the state of the stack and the heap with some kind of OCaml value browser. This browser should know the types of values to display them with constructor and field names. I should be able to click to open or close a value so that I can hide large subtrees. The roots could be the roots of the GC, or the set of variables which are currently in scope. I can click on a variable in my code and the browser jumps to it immediately. - I can visualize the current backtrace, and use the value browser to explore function arguments in this backtrace. - The state is saved at each breakpoint so I can explore the past using the value browser. It would be an awesome challenge to program such a tool but it requires a lot of time! So I just use printf. Actually I think there has been work by OCamlPro which goes towards those goals. Printf-debugging would be even easier with some kind of "typeof" construct, which would return a runtime representation of the type of its argument, so that one could easily write a generic printer without the need for a ppx. Even if it only worked for non-polymorphic parts of said type it would be useful, as long as it uses the type after inference has finished. For instance one could write "let print_t (x: t) = print_generic (typeof x) x" and get a generic printer for type t. One can already write a generic printer with Obj, but it misses the field and constructor names, that typeof could provide. The type representation could be from compiler-libs or something. I might try to patch the compiler to add that one day, just for fun because it's not general enough to be integrated, I guess. Cheers -- Romain