Debugging PostgreSQL with GDB

Lists: pgsql-hackers
From: "Manolo SupaMA" <manolo(dot)espa(at)gmail(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Debugging PostgreSQL with GDB
Date: 2008-04-01 15:35:53
Message-ID: 7a32fc660804010835j123c61f1s92b9862dd5bee713@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hi.

I have problems on how to debug PostgreSQL on Linux using GDB. I made some
changes to src/backend/utils/sort/tuplesort.c but it hangs while performing
run formation (where my changes are).

I configured it using

./configure --prefix="/usr/local/pgsql/8.3/" CFLAGS="-O0 -DTRACE_SORT"
--enable-debug --enable-cassert --enable-depend

and trying to debug it using

'gdb postmaster'
(which revealed to be not a very good idea) and
'gdb pg_ctl' followed by 'run -D /usr/local/psql/data'

This last choice allowed me to set a breackpoint on puttuple_common
(contained into tuplesort.c) but then I'm unable to run 'psql'.
http://pastebin.com/m6a97b4dd

I'm new on GDB and it's also my first postgrest patch. I just want some
suggestion to know if I'm on the right way or not.

Thanks for your time.

PS: I suppose I'll write some related "HowTo Debug PostgreSQL with GDB -
Basics" for newbies like me.


From: "korry" <korry(dot)douglas(at)enterprisedb(dot)com>
To: "Manolo SupaMA" <manolo(dot)espa(at)gmail(dot)com>
Cc: <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Debugging PostgreSQL with GDB
Date: 2008-04-01 15:42:00
Message-ID: 47F257C8.9080901@enterprisedb.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers


> I have problems on how to debug PostgreSQL on Linux using GDB. I made
> some changes to src/backend/utils/sort/tuplesort.c but it hangs while
> performing run formation (where my changes are).
>
> I configured it using
>
> ./configure --prefix="/usr/local/pgsql/8.3/" CFLAGS="-O0 -DTRACE_SORT"
> --enable-debug --enable-cassert --enable-depend
>
> and trying to debug it using
>
> 'gdb postmaster'
> (which revealed to be not a very good idea) and
> 'gdb pg_ctl' followed by 'run -D /usr/local/psql/data'
>
> This last choice allowed me to set a breackpoint on puttuple_common
> (contained into tuplesort.c) but then I'm unable to run 'psql'.
> http://pastebin.com/m6a97b4dd
Run psql, find the process ID of the backend (server) process by
executing the command "SELECT * FROM pg_backend_pid();",
then attach to that process with gdb and set a breakpoint in your new
code; finally, go back to your psql session and execute a command that
exercises your code.

-- Korry

--

Korry Douglas <korryd(at)enterprisedb(dot)com>
EnterpriseDB http://www.enterprisedb.com


From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: Manolo SupaMA <manolo(dot)espa(at)gmail(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Debugging PostgreSQL with GDB
Date: 2008-04-01 15:43:24
Message-ID: 47F2581C.2020801@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Manolo SupaMA wrote:
> Hi.
>
> I have problems on how to debug PostgreSQL on Linux using GDB. I made
> some changes to src/backend/utils/sort/tuplesort.c but it hangs while
> performing run formation (where my changes are).
>
> I configured it using
>
> ./configure --prefix="/usr/local/pgsql/8.3/" CFLAGS="-O0 -DTRACE_SORT"
> --enable-debug --enable-cassert --enable-depend
>
> and trying to debug it using
>
> 'gdb postmaster'
> (which revealed to be not a very good idea) and
> 'gdb pg_ctl' followed by 'run -D /usr/local/psql/data'
>
> This last choice allowed me to set a breackpoint on puttuple_common
> (contained into tuplesort.c) but then I'm unable to run 'psql'.
> http://pastebin.com/m6a97b4dd
>
> I'm new on GDB and it's also my first postgrest patch. I just want
> some suggestion to know if I'm on the right way or not.
>
> Thanks for your time.
>
> PS: I suppose I'll write some related "HowTo Debug PostgreSQL with
> GDB - Basics" for newbies like me.

The way to do this is to start the postmaster normally, run psql, and
then attach the debugger to the backend that is talking to your psql
session.

I would also personally advise using a gdb frontend like ddd. I am also
told eclipse can work well.

cheers

andrew