From: Guillaume Yziquel <guillaume.yziquel@citycable.ch>
To: Jake Donham <jake@donham.org>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Wrapping C code using pthread.
Date: Thu, 31 Dec 2009 00:50:46 +0100 [thread overview]
Message-ID: <4B3BE756.2000401@citycable.ch> (raw)
In-Reply-To: <c7e4e9f0912281939n1dc34ae6u7f72fff27aa26e21@mail.gmail.com>
Jake Donham a écrit :
> On Sun, Dec 27, 2009 at 1:33 PM, Guillaume Yziquel
> <guillaume.yziquel@citycable.ch> wrote:
>
>> If someone knows how to use gdb on a bytecode executable to locate the
>> segfault in MonetDB's .so file, I'd be quite happy to know.
>
> You can just gdb ocamlrun, then run with the bytecode file as
> argument. (Assuming you are not building in -custom mode.)
Thanks Jake.
For the record, here is the last mail I sent on the MonetDB users
mailing list on this topic:
http://sourceforge.net/mailarchive/forum.php?thread_name=4B3BDC5E.10801%40citycable.ch&forum_name=monetdb-users
I encountered a weird issue while running gdb --args ocamlrun, which
doesn't appear in native code. Here is the binded C source code in which
gdb steps into: Line 330 of mal_box.mx, available at
http://monetdb.cvs.sourceforge.net/viewvc/monetdb/MonetDB5/src/mal/mal_box.mx?revision=1.101&view=markup
You got this function
> 322 Box
> 323 findBox(str name)
> 324 {
> 325 int i;
> 326
> 327 mal_set_lock(mal_contextLock, "findBox");
> 328
> 329 for (i = 0; i < MAXSPACES; i++)
> 330 if (box[i] != NULL && name && idcmp(name, box[i]->name) == 0) {
> 331 #ifdef DEBUG_MAL_BOX
> 332 stream_printf(GDKout, "found the box '%s' %d\n", name, i);
> 333 #endif
> 334 mal_unset_lock(mal_contextLock, "findBox");
> 335 return box[i];
> 336 }
> 337 mal_unset_lock(mal_contextLock, "findBox");
> 338 #ifdef DEBUG_MAL_BOX
> 339 stream_printf(GDKout, "could not find the box '%s' \n", name);
> 340 #endif
> 341 return 0;
> 342
> 343 }
And gdb complains with bytecode OCaml. Segfault.
> (gdb) run
> Starting program: /usr/bin/ocamlrun test/monetdb_sql.byte
> [Thread debugging using libthread_db enabled]
> [New Thread 0x2aaaaf670910 (LWP 23863)]
>
> Program received signal SIGSEGV, Segmentation fault.
> [Switching to Thread 0x2aaaaf670910 (LWP 23863)]
> 0x00002aaaac66c42c in findBox (name=0x2aaab7ac6a37 "time") at mal_box.c:89
> 89 if (box[i] != NULL && idcmp(name, box[i]->name) == 0) {
> (gdb) backtrace
> #0 0x00002aaaac66c42c in findBox (name=0x2aaab7ac6a37 "time") at mal_box.c:89
> #1 0x00002aaaac66c54a in openBox (name=0x2aaab7ac6a37 "time") at mal_box.c:107
> #2 0x00002aaab7ac03b4 in MTIMEprelude () at mtime.c:2147
> #3 0x00002aaaac67e7f6 in runMALsequence (cntxt=0x2aaaac981000, mb=0x669348, startpc=1, stoppc=0, stk=0x2aaaaf66fb80, env=0x0, pcicaller=0x0) at mal_interpreter.c:3260
> #4 0x00002aaaac67443a in runMAL (cntxt=0x2aaaac981000, mb=0x669348, startpc=1, mbcaller=0x0, env=0x0, pcicaller=0x0)
> at mal_interpreter.c:272
> #5 0x00002aaaac6738b7 in MALengine (c=0x2aaaac981000) at mal_session.c:580
> #6 0x00002aaaac671fdb in malBootstrap () at mal_session.c:37
> #7 0x00002aaaac662fa5 in mal_init () at mal.c:61
> #8 0x00002aaaab91ef60 in ?? () from /usr/lib/libembeddedsql5.so
> #9 0x00002aaaab39b73a in start_thread () from /lib/libpthread.so.0
> #10 0x00002aaaab67c69d in clone () from /lib/libc.so.6
> #11 0x0000000000000000 in ?? ()
> (gdb) print i
> $1 = 0
> (gdb) print box[i]
> $2 = (Box) 0x0
> (gdb) print name
> $3 = (str) 0x2aaab7ac6a37 "time"
> (gdb)
But in native code, it works quite well:
> (gdb) break findBox
> Function "findBox" not defined.
> Make breakpoint pending on future shared library load? (y or [n]) y
> Breakpoint 1 (findBox) pending.
> (gdb) run
> Starting program: /home/yziquel/git/ocaml-monetdb5/test/monetdb_sql.native [Thread debugging using libthread_db enabled]
> [New Thread 0x2aaaaf467910 (LWP 15910)]
> [Switching to Thread 0x2aaaaf467910 (LWP 15910)]
>
> Breakpoint 1, findBox (name=0x2aaab78bda37 "time") at mal_box.c:86
> 86 mal_set_lock(mal_contextLock, "findBox");
> (gdb) info locals
> i = 10922
> (gdb) step
> 88 for (i = 0; i < MAXSPACES; i++)
> (gdb) info locals
> i = 10922
> (gdb) step
> 89 if (box[i] != NULL && idcmp(name, box[i]->name) == 0) {
> (gdb) info locals
> i = 0
> (gdb) print i
> $1 = 0
> (gdb) print box[i]
> $2 = (Box) 0x0
> (gdb) step
> 88 for (i = 0; i < MAXSPACES; i++)
> (gdb) print name
> $3 = (str) 0x2aaab78bda37 "time"
> (gdb)
What's weird is the context seems to be exactly the same: i=0, box[i]=0,
and name="time".
The segfault happens, as I believe, when doing the comparison
box[i] != NULL
I'm quite baffled by a segfault on such an expression, as box[i] seems
to be valid memory. Enlightenment would be highly appreciated.
For some context, there are some pthreads going on and some dynamic
loading. But it hardly seems to be the issue.
All the best,
--
Guillaume Yziquel
http://yziquel.homelinux.org/
prev parent reply other threads:[~2009-12-30 23:50 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-12-25 20:57 Guillaume Yziquel
2009-12-27 9:42 ` [Caml-list] " ygrek
2009-12-27 12:19 ` Guillaume Yziquel
2009-12-27 21:27 ` ygrek
2009-12-27 21:33 ` Guillaume Yziquel
2009-12-29 3:39 ` Jake Donham
2009-12-30 23:50 ` Guillaume Yziquel [this message]
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=4B3BE756.2000401@citycable.ch \
--to=guillaume.yziquel@citycable.ch \
--cc=caml-list@inria.fr \
--cc=jake@donham.org \
/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