Thread: To connect a debbuger...

To connect a debbuger...

From
Jonathan Scher
Date:
Hello!

I'm trying to add some features to PostgreSQL, but I just can't figure 
out how to make gdb work with it.

I attach gdb to /usr/.../bin/postgres, then I put a breakpoint. Whenever 
postgres stop on that breakpoint, it just kills/restarts the server 
instead of asking me what to do.

It's surely a noob's question but how can I use a debugger with PostegreSQL?

Regards,
Jonathan Scher

(gdb) file  /usr/local/pgsql/bin/postgres
Reading symbols from /usr/local/pgsql/bin/postgres...(no debugging 
symbols found)...done.
(gdb) set args -D /home/heziva/pgsql/pgsql_data/
(gdb) b transformFromClause
Breakpoint 1 at 0x80e371e
(gdb) r
Starting program: /usr/local/pgsql/bin/postgres -D 
/home/heziva/pgsql/pgsql_data/
(no debugging symbols found)...(no debugging symbols found)...(no 
debugging symbols found)...(no debugging symbols found)...LOG:  database 
system was interrupted; last known up at 2007-03-12 18:04:04 UTC
LOG:  checkpoint record is at 0/481504
LOG:  redo record is at 0/481504; shutdown TRUE
LOG:  next transaction ID: 0/710; next OID: 16392
LOG:  next MultiXactId: 1; next MultiXactOffset: 0
LOG:  database system was not properly shut down; automatic recovery in 
progress
LOG:  record with zero length at 0/481544
LOG:  redo is not required
LOG:  database system is ready to accept connections
LOG:  autovacuum launcher started

=====> on another shell.... psql....\d

(gdb) file  /usr/local/pgsql/bin/postgres
Reading symbols from /usr/local/pgsql/bin/postgres...(no debugging 
symbols found)...done.
(gdb) set args -D /home/heziva/pgsql/pgsql_data/
(gdb) b transformFromClause
Breakpoint 1 at 0x80e371e
(gdb) r
Starting program: /usr/local/pgsql/bin/postgres -D 
/home/heziva/pgsql/pgsql_data/
(no debugging symbols found)...(no debugging symbols found)...(no 
debugging symbols found)...(no debugging symbols found)...LOG:  database 
system was interrupted; last known up at 2007-03-12 18:04:04 UTC
LOG:  checkpoint record is at 0/481504
LOG:  redo record is at 0/481504; shutdown TRUE
LOG:  next transaction ID: 0/710; next OID: 16392
LOG:  next MultiXactId: 1; next MultiXactOffset: 0
LOG:  database system was not properly shut down; automatic recovery in 
progress
LOG:  record with zero length at 0/481544
LOG:  redo is not required
LOG:  database system is ready to accept connections
LOG:  autovacuum launcher started






Re: To connect a debbuger...

From
Gregory Stark
Date:
"Jonathan Scher" <js@oxado.com> writes:

> I attach gdb to /usr/.../bin/postgres, then I put a breakpoint. Whenever
> postgres stop on that breakpoint, it just kills/restarts the server instead of
> asking me what to do.

Not sure why it's crashing but you don't want to run postgres itself under the
debugger, at least not usually. What you have to do is start postgres up
normally, connect to it with psql or whatever client you want, then in a
separate shell run something like:

(gdb) shell ps auxww | grep [i]dle
stark     3724  0.0  0.1  36180  2044 ?        Ts   18:07   0:00 postgres: stark postgres [local] idle       
(gdb) attach 3724
Attaching to process 3724
Reading symbols from /usr/local/pgsql/bin/postgres...done.
...

> Reading symbols from /usr/local/pgsql/bin/postgres...(no debugging symbols
> found)...done.

Also, you'll want to configure with --enable-debug or else your gdb session
isn't going to be very enlightening.

Personally I suggest:

CFLAGS='-O0 -g' ./configure --enable-debug --enable-depend --enable-cassert

--  Gregory Stark EnterpriseDB          http://www.enterprisedb.com