-
-
Notifications
You must be signed in to change notification settings - Fork 378
Developer How to debug
For C code you can use look in most all of our wrapper C code and see how to add 11#define DEBUGblocks to get access toDBG(...):macro that will output messages to as postgresql NOTICE messages. I C++ code it is a little trickier. You can get access to the elog function that is used in the CDBG()function but you have to#include <postgres.h>`` and it might cause other issues in the C++ code. So I added a similar block for C++:
#undef DEBUG
//#define DEBUG
#ifdef DEBUG
#include <stdio.h>
static FILE *dbg;
#define DBG(format, arg...) \
dbg = fopen("/tmp/sew-debug", "a"); \
fprintf(dbg, format, ## arg); \
fclose(dbg);
#else
#define DBG(format, arg...) do { ; } while (0)
#endif
You can add this in each C++ function you want to debug. To activate it uncomment the #define DEBUG in both the C and C++ code. Then add more DBG('I got here message\n").
In the C++ code these messages get written to a file '/tmp/sew-debug' and you can do a tail -f on that in another window to see your progress.
If you build your own Postgresql you might want to rebuild it with --enable-cassert option to configure, which will put the database backend into a more rigorous memory check mode.
Example for Debian/Ubuntu environment:
sudo /etc/init.d/postgresql stop
apt-get source postgresql-server-dev-9.2
sudo apt-get build-dep postgresql-server-dev-9.2
dpkg-source -x postgresql-9.2_9.2.4-1.pgdg60+1.dsc
cd postgresql-9.2-9.2.4/
DEB_BUILD_OPTIONS="--enable-cassert --enable-debug" fakeroot debian/rules binary
DEB_BUILD_OPTIONS="--enable-cassert --enable-debug" debian/rules binary
DEB_BUILD_OPTIONS="--enable-cassert --enable-debug" fakeroot debian/rules binary
cd ..
sudo dpkg -i postgresql-server-dev-9.2_9.2.4-1.pgdg60+1_i386.deb
sudo /etc/init.d/postgresql start