开启优化器选项时的gdb状态
gdb调试,需要打印出某个值时,出现“value optimized out”,这是是由于gcc默认开启了优化器所致。
(gdb) p found
$1 = <value optimized out>
2. 关闭优化器后的gdb状态
编辑src/Makefile.global文件,删除-O2选项
CFLAGS = -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -g
重行编译安装、重启服务
sudo make install
pg_ctl stop -D /pgdata
pg_ctl start -D /pgdata
attach postgres进程
[minmin@localhost ~]$ gdb attach 81968
设置断点
(gdb) b pg_analyze_and_rewrite
Breakpoint 1 at 0x78755f: file postgres.c, line 666.
在psql端执行SQL语句
postgres=# select * from t1;
打印query
(gdb) p *query