[Vm-dev] Re: BerkeleyDbPlugin - debugging primitive failures - how?

David T. Lewis lewis at mail.msen.com
Sat May 9 23:04:41 UTC 2015

Hi Paul,

On Sat, May 09, 2015 at 10:35:11AM -0700, Paul DeBruicker wrote:
> Hi Dave -
> I've updated the github repo (https://github.com/pdebruic/BerkeleyDBPlugin) so that when building the plugin it links to the 4.1 version of BerkeleyDB.  Now when I attempt to use the plugin I'm getting failures rather than 'module not found' so thats progress, right?
> I'm not sure how to begin debugging plugin failures.  Is there a guide anywhere?  

I can't think of anything. Tim Rowledge has written some very good material
on VM and plugin development, but it's fairly old and I don't recall anything
specifically about debugging.

Fortunately it is pretty simple. There are two things I do for debugging:

1) Run the VM (and Squeak) under a gdb debugger. For this, I compile the VM
with compiler optimization off, and debugging symbols on. So the CFLAGS would
be "-g -O0". Then run Squeak, and attach it to a debugger (gdb squeakvm pid).
There may be permission issues, I use sudo if needed. Then put a breakpoint
in the primitive you want to debug, and see what happens.

2) Good old fashioned FORTRAN style debugging - put a bunch of print statements
in the code. Don't laugh, it works. Edit the generated source for the primitive,
and add printf() code to print the variables you want to see. If you are dealing
with VM crashes, add fflush(stdout) after the printf() lines so you do not lose
the output.

> Also the complilation errors when building the plugin are: 
> [ 50%] Building C object BerkeleyDbPlugin/CMakeFiles/BerkeleyDbPlugin.dir/home/deploy/src/trunk/src/plugins/BerkeleyDbPlugin/BerkeleyDbPlugin.c.o
> /home/deploy/src/trunk/src/plugins/BerkeleyDbPlugin/BerkeleyDbPlugin.c: In function ???initialiseModule???:
> /home/deploy/src/trunk/src/plugins/BerkeleyDbPlugin/BerkeleyDbPlugin.c:141:2: warning: passing argument 1 of ???sqDbInit??? from incompatible pointer type [enabled by default]
>   return sqDbInit(sqDbMalloc);
>   ^
> In file included from /home/deploy/src/trunk/src/plugins/BerkeleyDbPlugin/BerkeleyDbPlugin.c:37:0:
> /home/deploy/src/trunk/platforms/Cross/plugins/BerkeleyDbPlugin/BerkeleyDbPlugin.h:13:5: note: expected ???void * (*)(size_t)??? but argument is of type ???void * (*)(sqInt)???
>  int sqDbInit(void *(*sq_malloc)(size_t size) );
>      ^
> [100%] Building C object BerkeleyDbPlugin/CMakeFiles/BerkeleyDbPlugin.dir/home/deploy/src/trunk/platforms/Cross/plugins/BerkeleyDbPlugin/sqBerkeleyDatabase.c.o
> Linking C shared module so.BerkeleyDbPlugin
> [100%] Built target BerkeleyDbPlugin
> Are they serious or can they be ignored?  

Yes they are probably serious, at least if you are compiling for 64-bits. Many
of the VM plugins (probably including this one) were originally written on
32-bit machines, and it was common practice to store C pointers into the
default sqInt data type. This fails disasterously on 64-bit platforms, so
we'll probably need to clean this up. Mostly it's a matter of declaring method
signatures properly. It is not hard, just a bit tedious to get it all right.

> Thanks - 
> Paul

Thanks for the update, and sorry I have not done more to move this issue


More information about the Vm-dev mailing list