Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
Re: [Caml-list] Tips to find the cause of a seg fault
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2010-12-05 (14:50)
From: Philippe Veber <philippe.veber@g...>
Subject: Re: [Caml-list] Tips to find the cause of a seg fault
Thanks everyone for your answers. For the record, I finally understood the
cause of my problem: first I noticed that I had no segfault on the same
machine replacing my touchpad with a usual mouse. I then wrote a C
equivalent of my minimal program, which worked perfectly (also according to
valgrind). This basically meant the problem lied in the binding. So I
finally checked at the C level every mouse event incoming and saw that there
were mouse button events containing unexpected mouse button codes. These
codes corresponded to horizontal two finger scrolling, that is indeed not
available on a standard mouse, and not incorporated in ocamlsdl API. The
thing is that button codes are used directly to encode variants in the
binding and, as a consequence used to compute a jump in the pattern
matching. So what happened is the following: by using vertical two finger
scrolling a bit too fast, I would also generate (unintentionally) an
horizontal scrolling event at the end of my move, and right after that do a
pattern matching on its variant representation, which triggered a jump in
some unexpected zone of memory, leading to either segmentation fault or
illegal instruction error.

So, long story short: doing pattern matching on mouse events of ocamlsdl (or
the sdl binding of glcaml, by the way) may lead to a crash when using a
touchpad. For now I'll use a cheap workaround in my program, but if the
authors of ocamlsdl are interested, I'll gladly work on a patch.


2010/12/3 Damien Doligez <>

> On 2010-12-01, at 00:08, Philippe Veber wrote:
> > Short story (details below): I'm currently writing a program relying on
> react, lablgl and ocamlsdl. This program segfaults on my laptop under two
> linux distributions (ubuntu and gentoo) but doesn't on a PC under ubuntu.
> The seg fault occurs with both bytecode and native executables. I don't do
> any marshaling nor use any typing magic; stack overflow is not likely. I
> humbly ask this list about means to improve valgrind or gdb outputs, which
> don't report informative function names, or more generally, any tip that
> could help me to locate the origin of the problem.
> You should try to compile the OCaml runtime in debug mode: just "make
> ocamlrund"
> in the ...ocaml/bytecode directory, then run your program with ocamlrund.
> > Many thanks for the clarification. Maybe I could (partially) "unplug" the
> GC by setting space_overhead to 100 ? That could give an indication on the
> moment the problem occurs ?
> The default space_overhead is already 80.  If you want the major GC
> to run very slowly, set the overhead to 1000 or 10000.  But usually
> you want to do the opposite, so that the crash happens soon after the
> execution of the buggy code.  You can try to pepper your code with
> calls to Gc.compact, for example.  In your case, I would call it just
> before the pattern matching that crashes mysteriously.
> -- Damien
> _______________________________________________
> Caml-list mailing list. Subscription management:
> Archives:
> Beginner's list:
> Bug reports: