From: Dmitry Tkach <dmitry@openratings.com>
To: pgsql-sql@postgresql.org
To: pgsql-general@postgresql.org
Subject: Debugging C functions...
Date: Fri, 15 Mar 2002 21:04:23 -0500
Message-ID: <3C92A827.6050409@openratings.com> (raw)
Hi, everybody!
Here is me again, with my bitwise indexing troubles :-)
(Refer to btree index extension topic from yesterday)...
I have, pretty much, given up the idea to make btrees (or rtrees) do
what I need... now I am trying to make it work with a GiST index (as Tom
Lane suggested earlier)... Because I am too stupid and too lazy to
figure out how to implement GiST from scratch, I am trying to use the
intarray code from contrib - it seems to do exactly what I need, except
it deals with _int4 arrays instead of bitsets.
So, I wrote a C function called pack (should be unpack really, but never
mind :-), that converts my bits into an array, and try to index my table:
create index bset_idx on bset using gist (pack (flags));
this runs for a few minutes, and then the backend crashes. All I can see
in the log is:
----
Server process (pid 29372) exited with status 11 at Fri Mar 15 18:33:50 2002
Terminating any active server processes...
Server processes were terminated at Fri Mar 15 18:33:50 2002
Reinitializing shared memory and semaphores
The Data Base System is starting up
----
I assume, there must be some bug in the func. I wrote, that's causing
the crash... The question is - how do I debug it?
Are there some techniques to do that (like attaching to the running
backend with a debugger, or something else, perhaps, somehow turning
more debug output on)?
Below is the entire C code I wrote (I am attaching it, hoping, that,
perhaps, somebody would be able to just spot the problem by looking at
it)... It creates one function, that takes an int4 (the bits) and a
second arg, being the maximum bit, that can be set (this is to be able
to work with both int2 and int4)...
And then I have sql wrappers:
create function pack(int4) returns _int4 as 'select pack($1, 1<<31);'
language 'sql';
create function pack(int2) returns _int4 as 'select pack($1::int4,
1<<15);' language 'sql';
Here is the C source:
#include "postgres.h"
#include "utils/array.h"
ArrayType *pack(int,long);
ArrayType *wrap_array(void *, int, int);
ArrayType *pack (int bits, long max)
{
static int4 buff [sizeof (long)];
long b;
int count;
for (b = 1, count = 0; b <= max; b <<= 1)
if (bits & b)
buff [count++] = b;
return wrap_array (buff, count, sizeof(int4));
}
ArrayType *wrap_array (void *ptr, int alen, int elen)
{
int numbytes = alen*elen;
int sz = numbytes + ARR_OVERHEAD (1);
ArrayType *result = (ArrayType *) palloc (sz);
result -> size = sz;
result -> ndim = 1;
result -> flags = 0;
ARR_DIMS(result)[0] = alen;
ARR_LBOUND(result)[0] = 1;
memmove (ARR_DATA_PTR(result), ptr, numbytes);
return result;
}
I compile it with:
gcc -Wall -Wmissing-prototypes -Wmissing-declarations -fpic -I.
-I../../src/include -DPGSQL71 -c _bits.c -o _bits.o
I will greatly appreciate your responses...
Thanks a lot!
Dima
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: dmitry@openratings.com, pgsql-general@postgresql.org
Subject: Re: Debugging C functions...
In-Reply-To: <3C92A827.6050409@openratings.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox