caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Török Edwin" <edwin+ml-ocaml@etorok.net>
To: caml-list@inria.fr
Subject: Re: [Caml-list] Do you use a debugger with OCaml? If not, why not?
Date: Wed, 25 Nov 2015 20:23:37 +0200	[thread overview]
Message-ID: <5655FCA9.9020506@etorok.net> (raw)
In-Reply-To: <F6461BB5-122D-4CC8-B761-3E620DBB82A4@gmail.com> (sfid-20151125_185239_422211_47BD5D78)

On 11/25/2015 06:52 PM, Michael Grünewald wrote:
> 
>> On 25 Nov 2015, at 17:16, Anton Bachin <antonbachin@yahoo.com> wrote:
>>
>> I always use prints and never debuggers when I have access to the
>> source, in any language. I use debuggers when reverse-engineering
>> binaries, however. As for why – setting up breakpoints, trying to
>> examine values usually takes more time for me than adding some
>> prints and reading and understanding the resulting trace. Perhaps
>> it only seems that way, but that has been my habit for a very long
>> time.
> 
> [ ... ]
> 
> Instead of print-peppering, I prefer to use structured failures
> (like the success monad https://github.com/michipili/lemonade)
> giving context for the failure, or improved logging capacities.

I use tools that I am familiar with when debugging because I don't want to focus on two things (learning a new tool and tracking down/fixing a bug).

For Lwt what helps is to add certain "labels" to a stack at well-known phases in the code (for example the HTTP method and URL as soon as request processing starts using Lwt.key), then the warning/exception
will have some context and helps towards creating a reproducible testcase.

I'd love to be able to use ocamldebug's functionality, but all my OCaml programs are compiled to native code which rules ocamldebug out for the moment.
Ideally I'd like to have something like http://rr-project.org/, unfortunately that doesn't work on my CPU (yet).

Additional logging is my preferred method too: sometimes I just add a printf, but often it is Lwt.log hidden behind a --debug flag,
and I keep these even after the bug is fixed.
I also try to turn debug/verbose mode of libraries (OCamlNet, Ocsigen, ..) where possible.

Often all I know about a problem is a warning or exception logged long ago, and if its Lwt then the stacktrace usually stops at map or some other uninteresting function,
which makes it hard to find the real origin of a bug.
What helps is to add certain "labels" to a stack at well-known phases in the code (for example the HTTP method and URL as soon as request processing starts using Lwt.key), then the warning/exception
will have some context and helps towards creating a reproducible testcase.
Once there is a testcase it is sometimes enough to observe the inputs/outputs using wireshark, sometimes more debugging has to be added.
The hardest ones to debug are probably bugs where timing matters (timeouts, intentional retry delays, etc.).

I would say this is exactly the way I'm debugging C multi-process/multi-threaded server applications too, not necessarily an efficient one though.
Some colleagues always use gdb on C code, but I find grepping logfiles more efficient.
For hard to reproduce bugs you can turn on debug mode - even on quasi-production servers for brief periods of time - , and analyze the logs later (quite likely few GB).

I haven't spent much time debugging single applications that are not networked, but when I'm writing new code/new module I usually just use utop (either directly or from (Spac)Emacs).

There is one case that requires a different debugging technique: SIGSEGV (quite rare, but quite time consuming to track down).
Then I use gdb to get a stacktrace, it is almost certainly a bug in C code.
Debugging it is similar to the approach I take when debugging incorrect code generated by C compilers (I had quite a few of these in C applications, more than bugs I had in C code linked with OCaml apps).
That is: build with debugging aids (in this case OCaml's debug runtime and Gc.compact called often), try to find a reproducible testcase, and then try to minimize the testcase
(either manually or via tools like delta.tigris.org). Often this means adding additional sanity checks to the C code being debugged.
Once there is a testcase of reasonable size then there is usually enough information to fix it or report to upstream bugtracker.
Unfortunately C debugging aids like address sanitizer or valgrind are not easily usable with OCaml C runtime/bindings, because they would only detect corruption at the C level,
and wouldn't always detect when C code corrupts OCaml's heap.

-- 
Edwin Török | Co-founder and Lead Developer

Skylable open-source object storage: reliable, fast, secure
http://www.skylable.com

  reply	other threads:[~2015-11-25 18:23 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-25 12:49 John Whitington
2015-11-25 13:12 ` Francois Berenger
2015-11-25 13:23 ` Ivan Gotovchits
2015-11-25 15:27   ` Gerd Stolpmann
2015-11-25 16:04     ` Chan Ngo
2015-11-25 13:26 ` Matthieu Dubuget
2015-12-01 12:06   ` Matthieu Dubuget
2015-11-25 14:02 ` Markus Weißmann
2015-11-25 14:05 ` Nils Becker
2015-11-25 15:55 ` Daniel Bünzli
2015-11-26  9:14   ` Leonardo Laguna Ruiz
2015-11-26 10:59     ` Tom Ridge
2015-11-30 17:56       ` Xavier Van de Woestyne
2015-11-25 16:06 ` Maverick Woo
2015-11-25 16:16 ` Anton Bachin
2015-11-25 16:52   ` Michael Grünewald
2015-11-25 18:23     ` Török Edwin [this message]
2015-11-25 20:23 ` David MENTRÉ
2015-11-26 10:11 ` Malcolm Matalka
2015-11-26 10:57 ` Romain Bardou
2015-12-11 18:58 ` Richard W.M. Jones

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5655FCA9.9020506@etorok.net \
    --to=edwin+ml-ocaml@etorok.net \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).