编译安装openGauss并用GDB进行调试
编译安装openGauss并用GDB进行调试
惜月夜
于 2021-06-28 18:15:07 发布
1810
收藏 2
分类专栏: openGauss 文章标签: 数据库
版权
openGauss
专栏收录该内容
1 篇文章0 订阅
订阅专栏
编译安装openGauss并用GDB进行调试
关于编译opengauss,然后怎么去调试它,不知道花了多长时间.本来想着用类似Eclipse的IDE去编译调试源码,结果老是出现各种问题,不过好说歹说,现在可以通过GDB来进行调试,如果有哪位大佬会用IDE编译调试openGauss源码的话,请指教!!!
运行环境
Centos7.6(刚安装好的,啥也没有的那种)
内存8G
磁盘200G
omm用户的创建
首先创建一个omm用户和对应的用户组,创建两个文件夹.其中/opt/og文件夹用来存放源码文件和编译好的第三方库文件.而/opt/ogdata在数据库启动的时候会用到.
groupadd dbgrp -g 2000
useradd omm -g 2000 -u 2000
passwd omm
mkdir -p {/opt/og,/opt/ogdata}
1
2
3
4
passwd omm的時候会让你输入一个密码,随便输个1就行.
安装依赖
直接复制里面的代码然后在/opt/og/文件夹下执行就可以了,安装依赖的过程中可能需要让你确认一下.
PS:如果这里/opt/og不让操作,可以把后面步骤中 的赋权限操作在这里先执行一次,不过这里执行了以后后面还是要进行一次赋权限的操作.(这是因为后面git下载openGauss-server源码后这个文件夹的操作权限有问题,需要重新赋予)
yum install -y git
curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.rpm.sh | sudo bash
sudo yum install git-lfs
git lfs install
git clone https://gitee.com/opengauss/openGauss-server openGauss-server
yum install -y libaio-devel-0.3.109
yum install -y flex 2.5.37
yum install -y bison 2.7-4
yum install -y ncurses-devel 5.9-13.20130511
yum install -y glibc-devel 2.17-111
yum install -y patch 2.7.1-10
yum -y install redhat-lsb 4.1
yum install -y readline-devel 7.0-13
1
2
3
4
5
6
7
8
9
10
11
12
13
解压opengauss官网已经编译好的第三方库文件,然后修改gcc链接,下载python3.6并修改链接.修改完成后可以用gcc -v和 python --version看看修改成功没有.
tar -zxvf openGauss-third_party_binarylibs.tar.gz
mv openGauss-third_party_binarylibs binarylibs
cd binarylibs/buildtools/centos7.6_x86_64/gcc7.3/gcc/bin
rm -rf /usr/bin/gcc
ln -s /opt/og/binarylibs/buildtools/centos7.6_x86_64/gcc7.3/gcc/bin/gcc /usr/bin/gcc
yum install -y python3.6*
rm -rf /usr/bin/python
mv /usr/bin/python3.6 /usr/bin/python
1
2
3
4
5
6
7
8
python3.6安装完成后还需要修改下两个文件的文件头.
分别执行vi /usr/libexec/urlgrabber-ext-down和vi /usr/bin/yum,将这两个文件的第一行:#!/usr/bin/python修改为#!/usr/bin/python2.7 即可
文件夹赋权限
执行下面的语句给之前创建的文件夹赋予权限,然后su - omm切换到omm用户
chown -R omm: {/opt/og,/opt/ogdata}
chmod -R 755 /opt/og
chmod -R 700 /opt/ogdata
su - omm
1
2
3
4
设置环境变量
vi ~/.bashrc
1
把下面的内容复制进去:
export CODE_BASE=/opt/og/openGauss-server
export BINARYLIBS=/opt/og/binarylibs
export GAUSSHOME=$CODE_BASE/dest/
export GCC_PATH=$BINARYLIBS/buildtools/centos7.6_x86_64/gcc7.3
export CC=$GCC_PATH/gcc/bin/gcc
export CXX=$GCC_PATH/gcc/bin/g++
export LD_LIBRARY_PATH=$GAUSSHOME/lib:$GCC_PATH/gcc/lib64:$GCC_PATH/isl/lib:$GCC_PATH/mpc/lib/:$GCC_PATH/mpfr/lib/:$GCC_PATH/gmp/lib/:$LD_LIBRARY_PATH
export PATH=$GAUSSHOME/bin:$GCC_PATH/gcc/bin:$PATH
1
2
3
4
5
6
7
8
9
configure
直接复制然后执行即可.
source ~/.bashrc
cd /opt/og/openGauss-server/
./configure --gcc-version=7.3.0 CC=g++ CFLAGS='-O0' --prefix=$GAUSSHOME --3rd=$BINARYLIBS --enable-debug --enable-cassert --enable-thread-safety --without-readline --without-zlib
1
2
3
make and make install
不要用官方的make -sj.这命令老是把我虚拟机撑爆(8G内存). make -sj4好像也可以.不过我最后用的是make -j4.
make -j4
make install
1
2
初始化数据库
这里就用到了/opt/ogdata/ ,文件夹里面是空的.
gs_initdb --pgdata=/opt/ogdata/ --nodename=dn_6001 --encoding=utf-8
1
完成后大概会输出下面一段内容:
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 gs_initdb.
Success. You can now start the database server of single node using:
gaussdb -D /opt/ogdata --single_node
or
gs_ctl start -D /opt/ogdata -Z single_node -l logfile
1
2
3
4
5
6
7
8
启动数据库
直接用上面提示给出的命令启动数据库即可.第一次执行这条命令会失败.
gs_ctl start -D /opt/ogdata -Z single_node -l logfile
1
第一次启动失败之后执行下面一条语句重启一下就行了。
或者直接重启一下虚拟机,然后再执行一次上面的gs_ctl start -D /opt/ogdata -Z single_node -l logfile命令
gs_ctl restart -D /opt/ogdata -Z single_node -l logfile
1
连接数据库
启动完成后用如下命令进行数据库连接,端口默认是5432.
gsql -d postgres -p 5432
1
到这里为止整个数据库就算弄完了.然后就是通过gdb去调试opengauss了.首先gdb -v查看虚拟机上有没有gdb,没有的话需要安装一个.
GDB调试
[omm@localhost ~]$ gdb -v
GNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-114.el7
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
1
2
3
4
5
6
7
8
9
10
11
然后输入以下命令找一下GDB连接需要的ID
netstat -anp|grep gaussdb
1
大概会输出以下内容,注意找5432端口对应的.这里就是第一行的最后 20220/gaussdb的 20220.
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
tcp 0 0 127.0.0.1:5432 0.0.0.0:* LISTEN 20220/gaussdb
tcp 0 0 127.0.0.1:5433 0.0.0.0:* LISTEN 20220/gaussdb
tcp6 0 0 ::1:5432 :::* LISTEN 20220/gaussdb
tcp6 0 0 ::1:5433 :::* LISTEN 20220/gaussdb
udp6 0 0 ::1:46137 ::1:46137 ESTABLISHED 20220/gaussdb
unix 2 [ ACC ] STREAM LISTENING 73795 20220/gaussdb /tmp/.s.PGSQL.5432
unix 2 [ ACC ] STREAM LISTENING 73796 20220/gaussdb /tmp/.s.PGSQL.5433
1
2
3
4
5
6
7
8
9
10
gdb命令开始调试
首先输入gdb进入gdb环境,然后输入attach 20220连接数据库开始进行调试.
这里你再连接数据库的话就会发现请求被阻塞住了.然后输入bt可以看到当前的函数调用栈.输入n可以执行下一步等等.具体的GDB有哪些命令就不多说了,可以找一些详细的文档看一下.这里给一个参考链接,如果感觉不全可以在找找其他的
[omm@localhost ~]$ gdb ##进入gdb环境
GNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-114.el7
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
(gdb) attach 20220 ##连接数据库
Attaching to process 20220
Reading symbols from /opt/og/openGauss-server/dest/bin/gaussdb...done.
Reading symbols from /lib64/libcrypt.so.1...(no debugging symbols found)...done.
Loaded symbols for /lib64/libcrypt.so.1
Reading symbols from /lib64/libdl.so.2...(no debugging symbols found)...done.
Loaded symbols for /lib64/libdl.so.2
Reading symbols from /opt/og/openGauss-server/dest//lib/libssl.so.1.1...done.
Loaded symbols for /opt/og/openGauss-server/dest//lib/libssl.so.1.1
Reading symbols from /opt/og/openGauss-server/dest//lib/libcrypto.so.1.1...done.
Loaded symbols for /opt/og/openGauss-server/dest//lib/libcrypto.so.1.1
Reading symbols from /lib64/librt.so.1...(no debugging symbols found)...done.
Loaded symbols for /lib64/librt.so.1
Reading symbols from /opt/og/openGauss-server/dest//lib/libz.so.1...(no debugging symbols found)...done.
Loaded symbols for /opt/og/openGauss-server/dest//lib/libz.so.1
Reading symbols from /opt/og/openGauss-server/dest//lib/libeSDKOBS.so...(no debugging symbols found)...done.
Loaded symbols for /opt/og/openGauss-server/dest//lib/libeSDKOBS.so
Reading symbols from /opt/og/openGauss-server/dest//lib/libeSDKLogAPI.so...(no debugging symbols found)...done.
Loaded symbols for /opt/og/openGauss-server/dest//lib/libeSDKLogAPI.so
Reading symbols from /opt/og/openGauss-server/dest//lib/libpcre.so.1...(no debugging symbols found)...done.
Loaded symbols for /opt/og/openGauss-server/dest//lib/libpcre.so.1
Reading symbols from /opt/og/openGauss-server/dest//lib/libiconv.so.2...(no debugging symbols found)...done.
Loaded symbols for /opt/og/openGauss-server/dest//lib/libiconv.so.2
Reading symbols from /opt/og/openGauss-server/dest//lib/libnghttp2.so.14...(no debugging symbols found)...done.
Loaded symbols for /opt/og/openGauss-server/dest//lib/libnghttp2.so.14
Reading symbols from /opt/og/openGauss-server/dest//lib/liblog4cpp.so.5...(no debugging symbols found)...done.
Loaded symbols for /opt/og/openGauss-server/dest//lib/liblog4cpp.so.5
Reading symbols from /opt/og/openGauss-server/dest//lib/libcurl.so.4...(no debugging symbols found)...done.
Loaded symbols for /opt/og/openGauss-server/dest//lib/libcurl.so.4
Reading symbols from /opt/og/openGauss-server/dest//lib/liblz4.so.1...(no debugging symbols found)...done.
Loaded symbols for /opt/og/openGauss-server/dest//lib/liblz4.so.1
Reading symbols from /opt/og/openGauss-server/dest//lib/libcjson.so.1...(no debugging symbols found)...done.
Loaded symbols for /opt/og/openGauss-server/dest//lib/libcjson.so.1
Reading symbols from /opt/og/openGauss-server/dest//lib/libhll.so...(no debugging symbols found)...done.
Loaded symbols for /opt/og/openGauss-server/dest//lib/libhll.so
Reading symbols from /opt/og/openGauss-server/dest//lib/libcgroup.so.1...(no debugging symbols found)...done.
Loaded symbols for /opt/og/openGauss-server/dest//lib/libcgroup.so.1
Reading symbols from /opt/og/openGauss-server/dest//lib/libparquet.so.11...done.
Loaded symbols for /opt/og/openGauss-server/dest//lib/libparquet.so.11
Reading symbols from /opt/og/openGauss-server/dest//lib/libcom_err_gauss.so.3...(no debugging symbols found)...done.
Loaded symbols for /opt/og/openGauss-server/dest//lib/libcom_err_gauss.so.3
Reading symbols from /opt/og/openGauss-server/dest//lib/libgssapi_krb5_gauss.so.2...(no debugging symbols found)...done.
Loaded symbols for /opt/og/openGauss-server/dest//lib/libgssapi_krb5_gauss.so.2
Reading symbols from /opt/og/openGauss-server/dest//lib/libkrb5_gauss.so.3...(no debugging symbols found)...done.
Loaded symbols for /opt/og/openGauss-server/dest//lib/libkrb5_gauss.so.3
Reading symbols from /opt/og/openGauss-server/dest//lib/libgssrpc_gauss.so.4...(no debugging symbols found)...done.
Loaded symbols for /opt/og/openGauss-server/dest//lib/libgssrpc_gauss.so.4
Reading symbols from /opt/og/openGauss-server/dest//lib/libk5crypto_gauss.so.3...(no debugging symbols found)...done.
Loaded symbols for /opt/og/openGauss-server/dest//lib/libk5crypto_gauss.so.3
Reading symbols from /opt/og/openGauss-server/dest//lib/libkadm5clnt_mit.so.11...(no debugging symbols found)...done.
Loaded symbols for /opt/og/openGauss-server/dest//lib/libkadm5clnt_mit.so.11
Reading symbols from /opt/og/openGauss-server/dest//lib/libkadm5srv_mit.so.11...(no debugging symbols found)...done.
Loaded symbols for /opt/og/openGauss-server/dest//lib/libkadm5srv_mit.so.11
Reading symbols from /opt/og/openGauss-server/dest//lib/libkdb5.so.9...(no debugging symbols found)...done.
Loaded symbols for /opt/og/openGauss-server/dest//lib/libkdb5.so.9
Reading symbols from /opt/og/openGauss-server/dest//lib/libkrb5support_gauss.so.0...(no debugging symbols found)...done.
Loaded symbols for /opt/og/openGauss-server/dest//lib/libkrb5support_gauss.so.0
Reading symbols from /opt/og/openGauss-server/dest//lib/libstdc++.so.6...done.
Loaded symbols for /opt/og/openGauss-server/dest//lib/libstdc++.so.6
Reading symbols from /opt/og/openGauss-server/dest//lib/libxml2.so.2...(no debugging symbols found)...done.
Loaded symbols for /opt/og/openGauss-server/dest//lib/libxml2.so.2
Reading symbols from /lib64/libaio.so.1...Reading symbols from /lib64/libaio.so.1...(no debugging symbols found)...done.
(no debugging symbols found)...done.
Loaded symbols for /lib64/libaio.so.1
Reading symbols from /opt/og/openGauss-server/dest//lib/libgrpc++.so.1...(no debugging symbols found)...done.
Loaded symbols for /opt/og/openGauss-server/dest//lib/libgrpc++.so.1
Reading symbols from /opt/og/openGauss-server/dest//lib/libgpr.so.9...(no debugging symbols found)...done.
Loaded symbols for /opt/og/openGauss-server/dest//lib/libgpr.so.9
Reading symbols from /opt/og/openGauss-server/dest//lib/libgrpc.so.9...(no debugging symbols found)...done.
Loaded symbols for /opt/og/openGauss-server/dest//lib/libgrpc.so.9
Reading symbols from /opt/og/openGauss-server/dest//lib/libupb.so.9...(no debugging symbols found)...done.
Loaded symbols for /opt/og/openGauss-server/dest//lib/libupb.so.9
Reading symbols from /opt/og/openGauss-server/dest//lib/libabsl_str_format_internal.so...(no debugging symbols found)...done.
Loaded symbols for /opt/og/openGauss-server/dest//lib/libabsl_str_format_internal.so
Reading symbols from /opt/og/openGauss-server/dest//lib/libabsl_strings.so...(no debugging symbols found)...done.
Loaded symbols for /opt/og/openGauss-server/dest//lib/libabsl_strings.so
Reading symbols from /opt/og/openGauss-server/dest//lib/libabsl_spinlock_wait.so...(no debugging symbols found)...done.
Loaded symbols for /opt/og/openGauss-server/dest//lib/libabsl_spinlock_wait.so
Reading symbols from /opt/og/openGauss-server/dest//lib/libabsl_throw_delegate.so...(no debugging symbols found)...done.
Loaded symbols for /opt/og/openGauss-server/dest//lib/libabsl_throw_delegate.so
Reading symbols from /opt/og/openGauss-server/dest//lib/libabsl_strings_internal.so...(no debugging symbols found)...done.
Loaded symbols for /opt/og/openGauss-server/dest//lib/libabsl_strings_internal.so
Reading symbols from /opt/og/openGauss-server/dest//lib/libabsl_base.so...(no debugging symbols found)...done.
Loaded symbols for /opt/og/openGauss-server/dest//lib/libabsl_base.so
Reading symbols from /opt/og/openGauss-server/dest//lib/libabsl_dynamic_annotations.so...(no debugging symbols found)...done.
Loaded symbols for /opt/og/openGauss-server/dest//lib/libabsl_dynamic_annotations.so
Reading symbols from /opt/og/openGauss-server/dest//lib/libabsl_int128.so...(no debugging symbols found)...done.
Loaded symbols for /opt/og/openGauss-server/dest//lib/libabsl_int128.so
Reading symbols from /opt/og/openGauss-server/dest//lib/libabsl_bad_optional_access.so...(no debugging symbols found)...done.
Loaded symbols for /opt/og/openGauss-server/dest//lib/libabsl_bad_optional_access.so
Reading symbols from /opt/og/openGauss-server/dest//lib/libabsl_raw_logging_internal.so...(no debugging symbols found)...done.
Loaded symbols for /opt/og/openGauss-server/dest//lib/libabsl_raw_logging_internal.so
Reading symbols from /opt/og/openGauss-server/dest//lib/libabsl_log_severity.so...(no debugging symbols found)...done.
Loaded symbols for /opt/og/openGauss-server/dest//lib/libabsl_log_severity.so
Reading symbols from /opt/og/openGauss-server/dest//lib/libaddress_sorting.so.9...(no debugging symbols found)...done.
Loaded symbols for /opt/og/openGauss-server/dest//lib/libaddress_sorting.so.9
Reading symbols from /lib64/libncurses.so.5...Reading symbols from /lib64/libncurses.so.5...(no debugging symbols found)...done.
(no debugging symbols found)...done.
Loaded symbols for /lib64/libncurses.so.5
Reading symbols from /lib64/libtinfo.so.5...Reading symbols from /lib64/libtinfo.so.5...(no debugging symbols found)...done.
(no debugging symbols found)...done.
Loaded symbols for /lib64/libtinfo.so.5
Reading symbols from /lib64/libm.so.6...(no debugging symbols found)...done.
Loaded symbols for /lib64/libm.so.6
Reading symbols from /opt/og/openGauss-server/dest//lib/libgcc_s.so.1...done.
Loaded symbols for /opt/og/openGauss-server/dest//lib/libgcc_s.so.1
Reading symbols from /lib64/libpthread.so.0...(no debugging symbols found)...done.
[New LWP 20251]
[New LWP 20250]
[New LWP 20249]
[New LWP 20248]
[New LWP 20247]
[New LWP 20246]
[New LWP 20245]
[New LWP 20244]
[New LWP 20243]
[New LWP 20242]
[New LWP 20241]
[New LWP 20240]
[New LWP 20239]
[New LWP 20238]
[New LWP 20237]
[New LWP 20236]
[New LWP 20235]
[New LWP 20234]
[New LWP 20233]
[New LWP 20232]
[New LWP 20230]
[New LWP 20229]
[New LWP 20228]
[New LWP 20227]
[New LWP 20226]
[New LWP 20225]
[New LWP 20224]
[New LWP 20221]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
Loaded symbols for /lib64/libpthread.so.0
Reading symbols from /lib64/libc.so.6...(no debugging symbols found)...done.
Loaded symbols for /lib64/libc.so.6
Reading symbols from /lib64/ld-linux-x86-64.so.2...(no debugging symbols found)...done.
Loaded symbols for /lib64/ld-linux-x86-64.so.2
Reading symbols from /lib64/libfreebl3.so...Reading symbols from /lib64/libfreebl3.so...(no debugging symbols found)...done.
(no debugging symbols found)...done.
Loaded symbols for /lib64/libfreebl3.so
Reading symbols from /opt/og/openGauss-server/dest//lib/libsecurec.so...(no debugging symbols found)...done.
Loaded symbols for /opt/og/openGauss-server/dest//lib/libsecurec.so
Reading symbols from /lib64/libnsl.so.1...(no debugging symbols found)...done.
Loaded symbols for /lib64/libnsl.so.1
Reading symbols from /lib64/libkeyutils.so.1...Reading symbols from /lib64/libkeyutils.so.1...(no debugging symbols found)...done.
(no debugging symbols found)...done.
Loaded symbols for /lib64/libkeyutils.so.1
Reading symbols from /lib64/libresolv.so.2...(no debugging symbols found)...done.
Loaded symbols for /lib64/libresolv.so.2
Reading symbols from /lib64/liblzma.so.5...Reading symbols from /lib64/liblzma.so.5...(no debugging symbols found)...done.
(no debugging symbols found)...done.
Loaded symbols for /lib64/liblzma.so.5
Reading symbols from /lib64/libnss_files.so.2...(no debugging symbols found)...done.
Loaded symbols for /lib64/libnss_files.so.2
Reading symbols from /opt/og/openGauss-server/dest/lib/postgresql/security_plugin.so...done.
Loaded symbols for /opt/og/openGauss-server/dest/lib/postgresql/security_plugin.so
0x00007fac1de43ccd in poll () from /lib64/libc.so.6
Missing separate debuginfos, use: debuginfo-install glibc-2.17-324.el7_9.x86_64 keyutils-libs-1.5.8-3.el7.x86_64 libaio-0.3.109-13.el7.x86_64 ncurses-libs-5.9-14.20130511.el7_4.x86_64 nss-softokn-freebl-3.36.0-5.el7_5.x86_64 xz-libs-5.2.2-1.el7.x86_64
(gdb)
————————————————
版权声明:本文为CSDN博主「惜月夜」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/weixin_44359289/article/details/118308637