Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

debug build against non-debug Tcl weird behaviour #5

Closed
gahr opened this issue May 9, 2016 · 3 comments
Closed

debug build against non-debug Tcl weird behaviour #5

gahr opened this issue May 9, 2016 · 3 comments

Comments

@gahr
Copy link
Contributor

gahr commented May 9, 2016

So, I nailed down the environment where I can reproduce the failure to this:

./configure --enable-symbols --with-system-lmdb --with-tcl=/usr/local/lib/tcl8.6/

I see this failure:

# cat test.tcl
puts [info patchlevel]
set dir [file dirname [info script]]
load [file join $dir liblmdb0.3.4.so]
package require lmdb

set myenv [lmdb env]
$myenv open -path $dir -mode 0664

# tclsh8.6 test.tcl
8.6.5
ERROR: No such file or directory
    while executing
"$myenv open -path $dir -mode 0664"
    (file "test.tcl" line 7)
root@dev.ptrcrt.ch:~/github/tcl-lmdb # 

Which I nailed down to this snippet.

1371│       for(i=2; i+1<objc; i+=2){
1372│         zArg = Tcl_GetStringFromObj(objv[i], 0);
1373│         if( strcmp(zArg, "-path")==0 ){
1374│             path = Tcl_GetStringFromObj(objv[i+1], 0);
1375│         } else if( strcmp(zArg, "-mode")==0 ){
1376│             if(Tcl_GetIntFromObj(interp, objv[i+1], (int *)&mode) != TCL_OK) {
1377│                 return TCL_ERROR;
1378│             }                                                                                                                                                  
1379├>        }

The for loop is entered twice, the first time to parse the -path "." arguments pair, the second time to parse the -mode 0664 arguments pair.

path is nice until the call at 1376 returns, then it's junk. Here's an extract from my debugging session:

Breakpoint 5, LMDB_ENV (cd=0x0, interp=0x801c30010, objc=6, objv=0x801c632f0) at ./generic/tclmdb.c:1374                                                             
(gdb) next                                                                                                                                                           
(gdb) p path                                                                                                                                                         
$3 = 0x801ce4810 "."                                                                                                                                                 
(gdb) c                                                                                                                                                              
Continuing.                                                                                                                                                          

Breakpoint 6, LMDB_ENV (cd=0x0, interp=0x801c30010, objc=6, objv=0x801c632f0) at ./generic/tclmdb.c:1376                                                             
(gdb) next                                                                                                                                                           
(gdb) p path                                                                                                                                                         
$4 = 0x801ce0000 "\001\b"   

I am not able to explain this yet.

@gahr
Copy link
Contributor Author

gahr commented May 9, 2016

Output from make:

# gmake
cc -DPACKAGE_NAME=\"lmdb\" -DPACKAGE_TARNAME=\"lmdb\" -DPACKAGE_VERSION=\"0.3.4\" -DPACKAGE_STRING=\"lmdb\ 0.3.4\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DBUIL
D_lmdb=/\*\*/ -DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 
-DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -DNO_VALUES_H=1 -DHAVE_LIMITS_H=1 -DHAVE_SYS_PARAM_H=1 -DHAVE_LMDB_H=1 -DUSE_SYSTEM_LMDB=1 -DUSE_THREAD_ALLOC=1 -D_REENTRANT=1 -D
_THREAD_SAFE=1 -DTCL_THREADS=1 -DMODULE_SCOPE=extern\ __attribute__\(\(__visibility__\(\"hidden\"\)\)\) -DHAVE_HIDDEN=1 -DHAVE_CAST_TO_UNION=1 -DTCL_WIDE_INT_IS_LONG
=1 -DUSE_TCL_STUBS=1  -I"/usr/local/include/tcl8.6"    -I/usr/local/include -O0 -pipe  -g -Wall -fPIC -I/usr/local/include -c `echo ./generic/tclmdb.c` -o tclmdb.o
rm -f liblmdb0.3.4.so
cc -shared -o liblmdb0.3.4.so tclmdb.o -llmdb -Wl,-soname,liblmdb0.3.4.so -L/usr/local/lib -ltclstub86 
: liblmdb0.3.4.so

With

# cc --version
FreeBSD clang version 3.4.1 (tags/RELEASE_34/dot1-final 208032) 20140512
Target: x86_64-unknown-freebsd10.3
Thread model: posix

@gahr
Copy link
Contributor Author

gahr commented May 9, 2016

Same with clang 3.7.1 and clang 3.8.0, gcc-4.8.5 works fine instead.

This is all on FreeBSD 10.3-RELEASE-p2, amd64.

@gahr
Copy link
Contributor Author

gahr commented May 9, 2016

I think I got it. mdb_mode_t is typedef'd to mode_t, which on FreeBSD amd64 is eventually typedef'd to unsigned short - 16 bits. Doing Tcl_GetIntFromObj on it overwrites part of the char * holding the path variable.
The fix would be to change mode to int and cast it to mdb_mode_t only when passing it to mdb_env_open.
I can provide a patch tomorrow.

gahr added a commit to gahr/tcl-lmdb that referenced this issue May 10, 2016
@gahr gahr closed this as completed May 10, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant