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 mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by yquem.inria.fr (Postfix) with ESMTP id CACEEBC57 for ; Wed, 1 Dec 2010 02:55:36 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AmQFAEs59UzV+668/2dsb2JhbACVAo5+w32FRwSEXA X-IronPort-AV: E=Sophos;i="4.59,282,1288566000"; d="scan'208";a="68888589" Received: from rastageeks.org (HELO mail.rastageeks.org) ([213.251.174.188]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/ADH-AES256-SHA; 01 Dec 2010 02:55:36 +0100 Received: from leonard.localnet (ip174-70-127-64.no.no.cox.net [174.70.127.64]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.rastageeks.org (Postfix) with ESMTPSA id E68048E993 for ; Wed, 1 Dec 2010 02:55:38 +0100 (CET) From: Romain Beauxis To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Tips to find the cause of a seg fault Date: Tue, 30 Nov 2010 19:59:03 -0600 User-Agent: KMail/1.13.5 (Linux/2.6.32-4-amd64; KDE/4.4.5; x86_64; ; ) References: In-Reply-To: MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-15" Content-Transfer-Encoding: quoted-printable Message-Id: <201011301959.04218.toots@rastageeks.org> X-Spam: no; 0.00; ocamlsdl:01 segfault:01 instanciated:01 bindings:01 segfault:01 gdb:01 ocaml:01 ocaml:01 bindings:01 gdb:01 assert:01 caml-list:01 expression:02 caml:02 confusing:02 Hi, Le mardi 30 novembre 2010 17:08:12, Philippe Veber a =E9crit : > The seg fault occurs during the call to this function with the button eve= nt > retrieved by ocamlsdl. What's really weird is that if I comment the third > case of the pattern matching, the seg fault does not occur. This is stran= ge > since with the "assert false" expression, I make sure this case is useless > (i don't press the left button). Also, in the various tests I made, I > obtained different errors, like segmentation fault in caml_absf_mask or > invalid instruction error. The function that triggers the segfault may be confusing, in particular in= =20 case of a memory corruption, which I suspect here. The pattern matching can cause a crash because it is using a value that is= =20 already corrupted and because the third case is one that, for some random=20 conditions, touches the part in memory that is corrupted. In this case, I would try to unroll the code and see where the value that i= s=20 used in this function was instanciated. Main source of corruption when using C bindings most often come from either= =20 the Gc or code executed while the global lock has been released. In the case of a segfault hapenning during a Gc call, this can be really=20 unrelated, for instance the instanciation of a new value triggers a Gc=20 collection to compact memory, which in turns triggers the recollection of a= =20 corrupted value, which causes a segfault. In the case of a segfault hapenning during a C call while the global lock h= as=20 been released, you may get more useful informations through gdb, in particu= lar=20 the trace of the C code used at the time of the segfault. You need have the= =20 debugging symbols for the dynamic C libraries used as well. We experienced a couple of segfault with ocaml SDL too but in unrelated par= ts=20 (video). I do not mean to criticize upstream's work on ocaml SDL because I= =20 know for a fact that these types of bindings are really hard to code. Howev= er,=20 I would suspect an issue there. =46inally, the best approach could be to actually look closely to the bindi= ng's=20 code and try to spot anything fishy there related to your issue. This gener= aly=20 worked better for me than trying to get information from gdb and the like.. Romain