how to debug into InitPostgres() and InitCatalogCache()?

Lists: pgsql-hackers
From: 土卜皿 <pengcz(dot)nwpu(at)gmail(dot)com>
To: PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>
Subject: how to debug into InitPostgres() and InitCatalogCache()?
Date: 2014-08-05 14:08:47
Message-ID: CADT5_1-Mbo9+QurdvsbXDMn=5dxWqULunqa+HW7wsruZm-iUng@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

hi, all
I already can debug general postgres using "ddd" and "select
pg_backend_pid();" , now, I want to study the details of the system
catalog cache and system cache management, so I need to debug the function
InitPostgres() and InitCatalogCache(), and I tried the following steps:

[refer: How to debug postgresql during initdb ]
<http://www.phacai.com/how-to-debug-postgresql-during-initdb>

(1) in first terminal:

ddd initdb

and set a breakpoint on the next executable line after “PG_CMD_OPEN” in
function bootstrap_template1() ,

Then within gdb, use “r $myfolder/mydb”,

and found the cursor stop at the breakpoint

(2) in the second terminal:

ps aux | grep "bin\/postgres"

after get the posgtres server pid, start a new ddd without args, and within
gdb, using "attach postgres.pid"

and set a breakpoint as InitCatalogCache()

(3) back to the first ddd window, hit the "cont" button. I hope it can stop
at the second ddd's breakpoint, but nothing happened?

I must make mistake in some step, or my understanding is fully wrong,
please give me some advice, thanks a lot!

Dillon


From: 土卜皿 <pengcz(dot)nwpu(at)gmail(dot)com>
To: PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: how to debug into InitPostgres() and InitCatalogCache()?
Date: 2014-08-06 01:11:19
Message-ID: CADT5_19XX84fSYKuMOhdgxVj6rgtm_aSPfoLrXq62U3iHG7fug@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

2014-08-05 22:08 GMT+08:00 土卜皿 <pengcz(dot)nwpu(at)gmail(dot)com>:

> hi, all
> I already can debug general postgres using "ddd" and "select
> pg_backend_pid();" , now, I want to study the details of the system
> catalog cache and system cache management, so I need to debug the function
> InitPostgres() and InitCatalogCache(), and I tried the following steps:
>
> [refer: How to debug postgresql during initdb ]
> <http://www.phacai.com/how-to-debug-postgresql-during-initdb>
>
> (1) in first terminal:
>
> ddd initdb
>
> and set a breakpoint on the next executable line after “PG_CMD_OPEN” in
> function bootstrap_template1() ,
>
> Then within gdb, use “r $myfolder/mydb”,
>
> and found the cursor stop at the breakpoint
>
> (2) in the second terminal:
>
> ps aux | grep "bin\/postgres"
>
> after get the posgtres server pid, start a new ddd without args, and
> within gdb, using "attach postgres.pid"
>
> and set a breakpoint as InitCatalogCache()
>
> (3) back to the first ddd window, hit the "cont" button. I hope it can
> stop at the second ddd's breakpoint, but nothing happened?
>
> I must make mistake in some step, or my understanding is fully wrong,
> please give me some advice, thanks a lot
>

I am sorry that this is a simple question. I found that the above steps
make the posgres reach boot_yyparse() of BootstrapModeMain(void), which
means postgres has already finished the initialization including
InitCatalogCache(), and it was waiting query command or other user command .

For debug initialization including system catalog cache, I add some code
like:

bool forDebug = true;

while (forDebug){
forDebug = true;
}

in the InitPosgres()'s starting position.

>
>
>
>
>


From: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
To: 土卜皿 <pengcz(dot)nwpu(at)gmail(dot)com>
Cc: PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: how to debug into InitPostgres() and InitCatalogCache()?
Date: 2014-08-06 02:37:27
Message-ID: 20140806023727.GG9388@eldon.alvh.no-ip.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

土卜皿 wrote:
> 2014-08-05 22:08 GMT+08:00 土卜皿 <pengcz(dot)nwpu(at)gmail(dot)com>:
>
> > hi, all
> > I already can debug general postgres using "ddd" and "select
> > pg_backend_pid();" , now, I want to study the details of the system
> > catalog cache and system cache management, so I need to debug the function
> > InitPostgres() and InitCatalogCache(), and I tried the following steps:

> For debug initialization including system catalog cache, I add some code
> like:
>
> bool forDebug = true;
>
> while (forDebug){
> forDebug = true;
> }
>
> in the InitPosgres()'s starting position.

There's also the -W switch, which makes it wait precisely to let you
attach a debugger.

--
Álvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services