CLION+gdbserver远程调试postgresql源码

CLION+gdbserver远程调试postgresql源码

编译postgresql

创建目录:

# root下执行
mkdir -p /data/postgres/11.11
chown -R postgres:postgres /data

编译:

#以postgres账号登录
tar zxvf postgresql-11.11.tar.gz
cd postgresql-11.11
./configure --prefix=/data/postgres/11.11 --enable-debug --enable-cassert --enable-depend CFLAGS="-O0"
make world
make check #可不执行
make install-world

如果要调试,需要开启debug选项。

–enable-debug:向gcc传递-g参数

CFLAGS=“-O0”:向gcc传递 -O0参数

make world成功会出现:

PostgreSQL, contrib, and documentation successfully made. Ready to install.

make install-world成功会出现:

PostgreSQL, contrib, and documentation installation complete.

初始化数据库

/data/postgres/11.11/bin/initdb -D /data/postgres/11.11/data

输出:

The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale "en_US.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".

Data page checksums are disabled.

creating directory /data/postgres/11.11/data ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default timezone ... Asia/Shanghai
selecting dynamic shared memory implementation ... posix
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok

WARNING: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.

Success. You can now start the database server using:

    /data/postgres/11.11/bin/pg_ctl -D /data/postgres/11.11/data -l logfile start

设置环境变量

vi .bash_profile

export PGDATA=/data/postgres/11.11/data
export PATH=/data/postgres/11.11/bin:$PATH

安装gdb

参考文章CLION+gdbserver远程调试C项目

启动postgresql

在postgresql的入口下断点,main函数入口src/backend/main/main.c

这样就不能使用pg_ctl启动pg,需要直接启动postgres。

gdbserver :1234 postgres

输出:

Process postgres created; pid = 58113
Listening on port 1234

客户端clion设置远程调试

在这里插入图片描述

注意设置这里的路径映射,否则调试的时候无法在断点处停留下来。

在这里插入图片描述

点击debug进行调试,发现已经在指定的断点处停下来。

在这里插入图片描述

参考文档:

https://www.jetbrains.com/help/clion/remote-debug.html#remote-config

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

shulu

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值