您的位置:首页 > 数据库

postgresql调试之关闭优化器

2016-01-07 00:00 190 查看
摘要: 编译的时候,gcc默认开启优化器选项,这样会导致gdb的时候代码乱跳,参数也无法print。所以如果是需要调试代码,那么关闭优化器选项;如果需要运用到生产中去,那么开启优化器选项。

开启优化器选项时的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


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息