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