Debugging custom type libraries

Started by Will Harrowerabout 17 years ago3 messagesgeneral
Jump to latest
#1Will Harrower
wjh105@doc.ic.ac.uk

Hi,

I'm writing a custom type, with the associated functions (type_in,
type_out, etc) written in C, in an external shared library that Postgres
loads at runtime. I was wondering what the best way of debugging these
functions is... I can start postgres through gdb, but can't figure out
how to debug the dynamically loaded functions, or break when they are
executed. I've done my best to find the answer, but have unfortunately
failed.

Any help is much appreciated.

Many thanks,
Will.

#2Martijn van Oosterhout
kleptog@svana.org
In reply to: Will Harrower (#1)
Re: Debugging custom type libraries

On Wed, Feb 18, 2009 at 06:05:43PM +0000, Will Harrower wrote:

I'm writing a custom type, with the associated functions (type_in,
type_out, etc) written in C, in an external shared library that Postgres
loads at runtime. I was wondering what the best way of debugging these
functions is... I can start postgres through gdb, but can't figure out
how to debug the dynamically loaded functions, or break when they are
executed. I've done my best to find the answer, but have unfortunately
failed.

First step, you must connect with psql and then attach gdb to the
running process (there's a function to get the pid of your backend).
Next, you can use "LOAD foo" in psql to trigger the loading of your
module, gdb should then be able to see it (assuming you have debug
symbols everywhere).

Setting breakpoints should then be easy.

Have a nice day,
--
Martijn van Oosterhout <kleptog@svana.org> http://svana.org/kleptog/

Show quoted text

Please line up in a tree and maintain the heap invariant while
boarding. Thank you for flying nlogn airlines.

#3Tom Lane
tgl@sss.pgh.pa.us
In reply to: Martijn van Oosterhout (#2)
Re: Debugging custom type libraries

Martijn van Oosterhout <kleptog@svana.org> writes:

First step, you must connect with psql and then attach gdb to the
running process (there's a function to get the pid of your backend).
Next, you can use "LOAD foo" in psql to trigger the loading of your
module, gdb should then be able to see it (assuming you have debug
symbols everywhere).

On some platforms it's necessary to do the LOAD first (before attaching
with gdb). Experiment...

regards, tom lane