Martin Kersten a écrit :
Guillaume Yziquel wrote:
Martin Kersten a écrit :
Program received signal SIGSEGV, Segmentation fault. [Switching to Thread 0x2aaaaf66d910 (LWP 4061)] 0x00002aaaac676de3 in findBox () from /usr/lib/libmonetdb5.so.5
i miss here the line number, seems that is ubunti specific you can do print i print box[i] print name
Here it is:
(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)
And weirdly, when I run gdb on the native code version, I get the same values for i, box[i] and name, but it doesn't segfault at this specific point:
(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)
As for Debian packages with debugging symbols on amd64, you can find monetdb5-server-debug on my repository: http://yziquel.homelinux.org/debian/pool/main/m/monetdb5-server-debug/ Instructions, in french, for the repo, are here: http://yziquel.homelinux.org/topos/debian-repository.html By the way, please note that the Debian package of monetdb5-server does not compile properly with newer autoconfs. Autoconf 2.65 doesn't work fine. Updating the package to a newer autoconf or modifying the Build-Depends field to limit the version to 2.63 or lower would be a good idea. Moreover, the packages fail to build from source. If you already have binary packages installed, you can indeed recompile the source, but if you do not, you encounter problems with dpkg-shlibdeps / dh_shlibdeps. Such as:
dpkg-shlibdeps: erreur: impossible de trouver la bibliothèque libmonetdb5.so.5 demandée par debian/monetdb5-server-dbg/usr/bin/mserver5 (format ELF : « elf64-x86-64 », RPATH : « /usr/lib »). Note : les bibliothèques ne sont pas recherchées dans d'autres paquets binaires qui n'ont pas de fichier shlibs ou de fichier de symboles. Pour aider dpkg-shlibdeps à trouver des bibliothèques privées, vous devriez définir LD_LIBRARY_PATH. dh_shlibdeps: dpkg-shlibdeps -Tdebian/monetdb5-server-dbg.substvars debian/monetdb5-server-dbg/usr/bin/stethoscope debian/monetdb5-server-dbg/usr/bin/mserver5 debian/monetdb5-server-dbg/usr/bin/Mbeddedmal returned exit code 2 make: *** [binary-predeb-IMPL/monetdb5-server-dbg] Erreur 9 dpkg-buildpackage: erreur: fakeroot debian/rules binary a produit une erreur de sortie de type 2
So you have a problem compiling the package from source.
i suspect box[i] is not properly initialized to 0
Well, it seems that it is properly initialised to 0.
(gdb) backtrace #0 0x00002aaaac676de3 in findBox () from /usr/lib/libmonetdb5.so.5
this gives one hint, it is likely passed without name causing idcmp to fail
It seems that name has the value "time". Moreover, I do not exactly understand the meaning of the idcmp function. What's the big difference between idcmp and strcmp?
#1 0x00002aaaac677086 in openBox () from /usr/lib/libmonetdb5.so.5 #2 0x00002aaab7a51cbb in MTIMEprelude () from
happens while loading the data/time module. It initializes the "time" module
Should I assume that the mtime.mal + lib_mtime.so is the first one to be loaded? Just to know if some dynamic linking successfully happened before or not.
no. it is not the first one. For that you have to breakpoint on loadLibrary.
Here's the output for this breakpoint:
(gdb) break loadLibrary Function "loadLibrary" not defined. Make breakpoint pending on future shared library load? (y or [n]) y Breakpoint 1 (loadLibrary) pending. (gdb) run Starting program: /usr/bin/ocamlrun test/monetdb_sql.byte [Thread debugging using libthread_db enabled] [New Thread 0x2aaaaf670910 (LWP 24370)] [Switching to Thread 0x2aaaaf670910 (LWP 24370)]
Breakpoint 1, loadLibrary (filename=0x642dd8 "mdb", flag=1) at mal_linker.c:94 94 int mode = RTLD_NOW | RTLD_GLOBAL; (gdb) backtrace #0 loadLibrary (filename=0x642dd8 "mdb", flag=1) at mal_linker.c:94 #1 0x00002aaaac69f85d in parseLibrary (cntxt=0x2aaaac981000) at mal_parser.c:719 #2 0x00002aaaac6a9c98 in parseMAL (cntxt=0x2aaaac981000, curPrg=0x656a78) at mal_parser.c:3440 #3 0x00002aaaac67118b in malInclude (c=0x2aaaac981000, name=0x2aaaac6ce8e0 "mal_init", listing=0) at mal_import.c:87 #4 0x00002aaaac671f80 in malBootstrap () at mal_session.c:32 #5 0x00002aaaac662fa5 in mal_init () at mal.c:61 #6 0x00002aaaab91ef60 in ?? () from /usr/lib/libembeddedsql5.so #7 0x00002aaaab39b73a in start_thread () from /lib/libpthread.so.0 #8 0x00002aaaab67c69d in clone () from /lib/libc.so.6 #9 0x0000000000000000 in ?? () (gdb) info locals mode = 10922 nme = "\330-d\000\000\000\000\000\002\001\000\000\000\000\000\000\003\000\000\000\000\000\000\000\031\060紪*\000\000mdb\000\000\000\000\000H\372f\257\252*", '\000'
, "\002\000\000\000\000\000\000`\016\220\253\252*\000\000\020\002\000\000\000\000\000\000P\372f\257\252*\000\000\000\000\000\000\000\000\000\000\003\000\000\000\000\000\000\000\240jb\253\252*\000\000H\334e\000\000\000\000\000\t\003g\253\252*\000\000\000\000\000\000\000\000\000\000\v", '\000' , " \327e\000\000\000\000\000\220\372f\257\252*\000\000 \327e\000\000\000\000\000\270\246\371\255\252*\000\000@\200̪\252*\000\000\003\000\000\000\000\000\000\000\227\352a\253\252*\000\000\300\360a\253\252*\000\000`\016\220\253\252*\000\000(\000\000\000\000\000\000\000\200X:\253\252*\000\000 `e\000\000\000\000\000@\200̪\252*\000\000"... handle = 0x2aaab4e7301a fullname = 0x2aaaaf66fdb0 "\360\375f\257\252*" s = 0x2aaaac69da19 "H\213E\350H\213\200`\001" idx = 0 errmsg = 0x102 (gdb) continue Continuing. Breakpoint 1, loadLibrary (filename=0x65db48 "unix", flag=1) at mal_linker.c:94 94 int mode = RTLD_NOW | RTLD_GLOBAL; (gdb) Continuing.
Breakpoint 1, loadLibrary (filename=0x665de8 "lock", flag=1) at mal_linker.c:94 94 int mode = RTLD_NOW | RTLD_GLOBAL; (gdb) Continuing.
Breakpoint 1, loadLibrary (filename=0x67cfc8 "sema", flag=1) at mal_linker.c:94 94 int mode = RTLD_NOW | RTLD_GLOBAL; (gdb) Continuing.
[...]
Breakpoint 1, loadLibrary (filename=0xd0ef98 "opt_remoteQueries", flag=0) at mal_linker.c:94 94 int mode = RTLD_NOW | RTLD_GLOBAL; (gdb) Continuing.
Breakpoint 1, loadLibrary (filename=0xd0f8f8 "crackers", flag=0) at mal_linker.c:94 94 int mode = RTLD_NOW | RTLD_GLOBAL; (gdb) Continuing.
Program received signal SIGSEGV, Segmentation fault. 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)
So in the malBootstrap in mal_session.c, malInclude seems to work fine, and malEngine fails. However, I'm stll unsure about how to check that the libraries have been properly loaded.
I would like to pinpoint the segfault more precisely in order to go back to the OCaml mailing list about potential dynamic loading issues.
I think it can not find your libraries
How can I check that? Moreover, I'm quite surprise about the segfault I get, since box[i] is set to 0.
if (box[i] != NULL && idcmp(name, box[i]->name) == 0) {
As &&'s semantics are to evaluate the idcmp expression only when box[i] != NULL evaluates to true, there are two possibilities: -1- idcmp is called, which means that box[i] != NULL evaluates to true. As box[i] has value 0, this seems rather fishy. -2- idcmp is not called. But then I really wonder why an expression such as box[i] != NULL would segfault. However, when run on native code, we are in the same situation. But adressing box[i]->name would yield a segfault. Which does not occur. Therefore idcmp is not called in native code. I find this really curious.
set the variable gdk_debug=10 this will show you the environment settings as seen upon start. Including the location where it expect database and libraries to recide.
I've set gdk_debug=10 in /etc/monetdb5.conf. I checked that my code is called with this parameter. But I do not understand where I should look for debugging output.
Will do that. However, I believe it is not a problem of location, as this works out fine when the OCaml binding is compiled to native code.
Programming is like mathematics not based on belief, but finding proofs using the proper tools and analysis steps. I have seen no proof that the MonetDB modules are properly loaded yet,
For this, I do not know how to check. A hint would be welcome.
nor if you have set the environment paths correctly.
Here is the value with which GDKinit is called:
(gdb) break GDKinit Function "GDKinit" not defined. Make breakpoint pending on future shared library load? (y or [n]) y Breakpoint 1 (GDKinit) pending. (gdb) run Starting program: /usr/bin/ocamlrun test/monetdb_sql.byte [Thread debugging using libthread_db enabled] [New Thread 0x2aaaaf562910 (LWP 15715)] [Switching to Thread 0x2aaaaf562910 (LWP 15715)]
Breakpoint 1, GDKinit (set=0x659540, setlen=57) at gdk_utils.c:1440 warning: Source file is more recent than executable. 1440 char *dbname = mo_find_option(set, setlen, "gdk_dbname"); (gdb) p *set@setlen $1 = {{kind = opt_builtin, name = 0x642d10 "gdk_arch", value = 0x642d30 "64bitx86_64-pc-linux-gnu"}, {kind = opt_builtin, name = 0x642d60 "gdk_version", value = 0x642d80 "1.34.2"}, {kind = opt_builtin, name = 0x642da0 "prefix", value = 0x642dc0 "/usr"}, {kind = opt_builtin, name = 0x642de0 "exec_prefix", value = 0x6320d0 "${prefix}"}, {kind = opt_builtin, name = 0x6320f0 "gdk_dbname", value = 0x632110 "tst"}, {kind = opt_builtin, name = 0x632130 "gdk_dbfarm", value = 0x655880 "/var/MonetDB"}, {kind = opt_builtin, name = 0x6558a0 "gdk_debug", value = 0x6558c0 "8"}, {kind = opt_builtin, name = 0x6558e0 "gdk_alloc_map", value = 0x655900 "yes"}, {kind = opt_builtin, name = 0x655920 "gdk_vmtrim", value = 0x655940 "yes"}, {kind = opt_builtin, name = 0x655960 "monet_admin", value = 0x655980 "adm"}, {kind = opt_builtin, name = 0x6559a0 "monet_prompt", value = 0x6559c0 ">"}, {kind = opt_builtin, name = 0x6559e0 "monet_welcome", value = 0x655a00 "yes"}, {kind = opt_builtin, name = 0x655a20 "monet_mod_path", value = 0x655a40 "${exec_prefix}/lib/MonetDB"}, {kind = opt_builtin, name = 0x655a70 "monet_daemon", value = 0x655a90 "yes"}, {kind = opt_builtin, name = 0x655ab0 "host", value = 0x655ad0 "localhost"}, {kind = opt_builtin, name = 0x655af0 "mapi_port", value = 0x655b10 "50000"}, {kind = opt_builtin, name = 0x655b30 "mapi_noheaders", value = 0x655b50 "no"}, {kind = opt_builtin, name = 0x655b70 "mapi_debug", value = 0x655b90 "0"}, {kind = opt_builtin, name = 0x655bb0 "mapi_clients", value = 0x655bd0 "2"}, {kind = opt_builtin, name = 0x655bf0 "sql_debug", value = 0x655c10 "0"}, {kind = opt_builtin, name = 0x655c30 "standoff_ns", value = 0x655c50 "http://monetdb.cwi.nl/standoff"}, {kind = opt_builtin, name = 0x655c80 "standoff_start", value = 0x655ca0 "start"}, {kind = opt_builtin, name = 0x655cc0 "standoff_end", value = 0x655ce0 "end"}, { kind = opt_config, name = 0x642ae0 "prefix", value = 0x642b00 "/usr"}, {kind = opt_config, name = 0x642b20 "config", value = 0x642b40 "/etc/monetdb5.conf"}, {kind = opt_config, name = 0x642b60 "monet_mod_path", value = 0x642b80 "${exec_prefix}/lib/MonetDB5:${exec_prefix}/lib/MonetDB5/lib:${exec_prefix}/lib/MonetDB5/bin"}, { kind = opt_config, name = 0x642c10 "prefix", value = 0x642c30 "/usr"}, {kind = opt_config, name = 0x642c50 "exec_prefix", value = 0x642c70 "${prefix}"}, {kind = opt_config, name = 0x642c90 "gdk_dbfarm", value = 0x642cb0 "/var/MonetDB5/dbfarm"}, {kind = opt_config, name = 0x642cd0 "gdk_dbname", value = 0x642cf0 "demo"}, { kind = opt_config, name = 0x655d00 "gdk_alloc_map", value = 0x655d20 "no"}, {kind = opt_config, name = 0x655d40 "gdk_embedded", value = 0x655d60 "no"}, {kind = opt_config, name = 0x655d80 "gdk_debug", value = 0x655da0 "10"}, {kind = opt_config, name = 0x655dc0 "monet_mod_path", value = 0x655de0 "${exec_prefix}/lib/MonetDB5:${exec_prefix}/lib/MonetDB5/lib:${exec_prefix}/lib/MonetDB5/bin"}, {kind = opt_config, name = 0x655e50 "monet_daemon", value = 0x655e70 "no"}, {kind = opt_config, name = 0x655e90 "monet_welcome", value = 0x655eb0 "yes"}, {kind = opt_config, name = 0x655ed0 "mero_msglog", value = 0x655ef0 "/var/log/MonetDB/merovingian.log"}, {kind = opt_config, name = 0x655f20 "mero_errlog", value = 0x655f40 "/var/log/MonetDB/merovingian.log"}, {kind = opt_config, name = 0x656570 "mero_pidfile", value = 0x656590 "/var/run/MonetDB/merovingian.pid"}, {kind = opt_config, name = 0x6561c0 "mero_controlport", value = 0x6561e0 "50001"}, {kind = opt_config, name = 0x656200 "mal_init", value = 0x656220 "${exec_prefix}/lib/MonetDB5/mal_init.mal"}, {kind = opt_config, name = 0x656260 "mal_listing", value = 0x656280 "2"}, {kind = opt_config, name = 0x6562a0 "mapi_port", value = 0x6562c0 "50000"}, {kind = opt_config, name = 0x6562e0 "mapi_autosense", value = 0x656300 "false"}, {kind = opt_config, name = 0x656320 "mapi_open", value = 0x656340 "false"}, {kind = opt_config, name = 0x656360 "sql_optimizer", value = 0x656380 "default_pipe"}, {kind = opt_config, name = 0x6563a0 "default_pipe", value = 0x6563c0 "inline,remap,evaluate,costModel,coercions,emptySet,aliases,mergetable,deadcode,constants,commonTerms,joinPath,deadcode,reduce,garbageCollector,dataflow,history,multiplex"}, {kind = opt_config, name = 0x656480 "replication_pipe", value = 0x6564a0 "inline,remap,evaluate,costModel,coercions,emptySet,aliases,mergetable,deadcode,constants,commonTerms,joinPath,deadcode,reduce,garbageCollector,dataflow,history,replication,multiplex"}, {kind = opt_config, name = 0x656a60 "accumulator_pipe", value = 0x656a80 "inline,remap,evaluate,costModel,coercions,emptySet,aliases,mergetable,deadcode,constants,commonTerms,joinPath,deadcode,reduce,accumulators,garbageCollector,dataflow,history,multiplex"}, {kind = opt_config, name = 0x6565c0 "recycler_pipe", value = 0x6565e0 "inline,remap,evaluate,costModel,coercions,emptySet,aliases,deadcode,constants,commonTerms,joinPath,deadcode,recycle,reduce,garbageCollector,dataflow,history,multiplex"}, {kind = opt_config, name = 0x656690 "cracker_pipe", value = 0x6566b0 "inline,remap,evaluate,costModel,coercions,emptySet,aliases,selcrack,deadcode,constants,commonTerms,joinPath,deadcode,reduce,garbageCollector,dataflow,history,multiplex"}, {kind = opt_config, name = 0x656760 "datacell_pipe", value = 0x656780 "inline,remap,evaluate,costModel,coercions,emptySet,aliases,deadcode,constants,commonTerms,joinPath,datacell,deadcode,reduce,garbageCollector,dataflow,history,multiplex"}, {kind = opt_config, name = 0x656830 "octopus_pipe", value = 0x656850 "inline,remap,evaluate,costModel,coercions,emptySet,mitosis,aliases,mergetable,deadcode,constants,commonTerms,joinPath,octopus,deadcode,reduce,garbageCollector,dataflow,history,multiplex"}, {kind = opt_config, name = 0x656920 "mitosis_pipe", value = 0x656940 "inline,remap,evaluate,costModel,coercions,emptySet,mitosis,aliases,mergetable,deadcode,constants,commonTerms,joinPath,reorder,deadcode,reduce,garbageCollector,dataflow,history,multiplex"}, {kind = opt_cmdline, name = 0x642bf0 "gdk_dbfarm", value = 0x656a10 "/home/yziquel/sandbox/monetdb"}, { kind = opt_cmdline, name = 0x656a40 "gdk_dbname", value = 0x655f80 "testdb"}, {kind = opt_cmdline, name = 0x656b40 "gdk_embedded", value = 0x656b60 "yes"}} (gdb)
I think I have already explained that the following issues (malloc, threads) are not a problem.
And then I ignore possible low level interferences (e.g.malloc) that might occur when linking two systems this way. The action described sofar are really basic steps towards C programming and testing.
All the best, -- Guillaume Yziquel http://yziquel.homelinux.org/