Re: How to debugging a an external C function(IMMUTABLE STRICT )

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: dave(dot)potts(at)pinan(dot)co(dot)uk
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: How to debugging a an external C function(IMMUTABLE STRICT )
Date: 2012-02-26 17:46:58
Message-ID: 10375.1330278418@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Dave Potts <dave(dot)potts(at)pinan(dot)co(dot)uk> writes:
> I have written an external C function to be called by postgres called
> using the LANGUAGE 'C' IMMUNTABLE STRICT interface
> Most of the time when call it, I get the expected results. Some times I
> get random rubbish in the result set.
> If there any debug support in Postgres to catch this type of thing?

You should pretty much always do development of any C code in a backend
built with --enable-cassert --enable-debug. In particular that will
turn on clobbering of freed memory, which is really helpful in turning
some types of sometimes-failure into consistent failures that can be
debugged. That might not be your problem here, but it's worth a try.

I also get the impression that the only debug technique you know about
is inserting printfs. Learn to use gdb or another debugger to step
through your code --- the learning curve isn't that steep, and the
benefits numerous. There's useful Postgres-specific info about using
gdb here:
http://wiki.postgresql.org/wiki/Getting_a_stack_trace_of_a_running_PostgreSQL_backend_on_Linux/BSD

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Clodoaldo Neto 2012-02-26 18:47:56 Re: Constant value for a partitioned table query inside a plpgsql function
Previous Message Karsten Hilbert 2012-02-26 16:38:52 Re: Four issues why "old elephants" lack performance: Explanation sought Four issues why "old elephants" lack performance: Explanation sought