MySQL8.0源码学习(8.0.18编译安装+debug基础调试)-阿里云开发者社区

开发者社区> 数据库> 正文

MySQL8.0源码学习(8.0.18编译安装+debug基础调试)

简介: MySQL 8.0 debug 源码

一、编译安装MySQL8.0.18

1.1 安装依赖包

yum -y install ntpdate gcc gcc-c++ ncurses ncurses-devel cmake readline-devel zlib.x86_64 zlib-devel.x86_64 bison libcurl-* net-tool* tree nmap sysstat lrzsz dos2unix telnet.x86_64 nethogs iftop iotop unzip ftp.x86_64 xfs* expect vim wget psmisc openssh-client* libaio libaio1 libnuma openssl-devel bzip2 flex clang

1.2 基础环境配置

#关闭防火墙
systemctl stop firewalld
systemctl disable firewalld
#关闭postfix
systemctl stop postfix
systemctl disable postfix
#关闭SELINUX
sed -i 's/^SELINUX=.*/SELINUX=disabled/g' /etc/selinux/config
setenforce 0
getenforce
#关闭numa
sed -i 's/GRUB_CMDLINE_LINUX.*/GRUB_CMDLINE_LINUX="crashkernel=auto rd.lvm.lv=centos\/root rd.lvm.lv=centos\/swap rhgb quiet numa=off"/g' /etc/default/grub
grub2-mkconfig -o /etc/grub2.cfg
cat /etc/grub2.cfg
reboot
cat /proc/cmdline
dmesg | grep -i numa
#内核参数修改
echo "vm.swappiness=10">>/etc/sysctl.conf
echo "net.ipv4.tcp_tw_recycle=1">>/etc/sysctl.conf
echo "net.ipv4.tcp_tw_reuse=1">>/etc/sysctl.conf
echo "vm.dirty_background_ratio=8">>/etc/sysctl.conf
echo "* soft nproc 65536" >>/etc/security/limits.conf
echo "* hard nproc 65536" >>/etc/security/limits.conf
echo "* soft nofile 65536" >>/etc/security/limits.conf
echo "* hard nproc 65536" >>/etc/security/limits.conf
#创建用户
useradd -M -s /sbin/nologin mysql
#创建相关目录
mkdir -pv /data/{conf,redo1,redo2,mysql3306/{data,tmp,logs}}
#授权
chown -R mysql:mysql /data/mysql3306/

1.3 配置环境变量

export PATH=$PATH:/usr/local/mysql/bin:
echo 'export PATH=$PATH:/usr/local/mysql/bin' >> /etc/profile

1.4 升级gcc

mkdir /usr/local/gcc && cd /usr/local/gcc
wget https://github.com/gcc-mirror/gcc/archive/gcc-5_5_0-release.tar.gz
tar xf gcc-5.5.0.tar.xz
cd gcc-gcc-5_5_0-release
./contrib/download_prerequisites
mkdir build && cd build
../configure --enable-checking=release --enable-languages=c,c++ --disable-multilib
make && make install

1.5 升级cmake

mkdir /usr/local/cmake && cd /usr/local/cmake
wget https://github.com/Kitware/CMake/releases/download/v3.14.5/cmake-3.14.5.tar.Z
./bootstrap
make && make install
#如果出现以下类似错误,需要更新libstdc++:
libstdc++.so.6: version `CXXABI_1.3.9' not found (required by ./destructor)
strings ./libstdc++.so.6 | grep CXXABI
CXXABI_1.3
CXXABI_1.3.1
CXXABI_1.3.2
CXXABI_1.3.3
CXXABI_1.3.4
CXXABI_1.3.5
CXXABI_1.3.6
CXXABI_1.3.7
CXXABI_TM_1
mv /usr/lib64/libstdc++.so.6.0.19 /tmp/
cp /usr/local/gcc/gcc-gcc-5_5_0-release/build/x86_64-unknown-linux-gnu/libstdc++-v3/src/.libs/libstdc++.so.6.0.21 /usr/lib64/
mv /usr/lib64/libstdc++.so.6 /tmp/
ln -s libstdc++.so.6.0.21 libstdc++.so.6

1.6 编译安装MySQL

cd ~
tar xf  mysql-boost-8.0.18.tar.gz
cd mysql-8.0.18
cmake . \
-DWITH_BOOST=/root/mysql-8.0.18/boost/boost_1_70_0 \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/data/mysql3306/data \
-DWITHOUT_CSV_STORAGE_ENGINE=1 \
-DWITHOUT_FEDERATED_STORAGE_ENGINE=1 \
-DWITHOUT_ARCHIVE_STORAGE_ENGINE=1 \
-DFORCE_INSOURCE_BUILD=1 \
-DWITH_SSL=system \
-DWITH_DEBUG=1 \
-DCMAKE_CXX_COMPILER=/usr/local/bin/g++ \
-DCMAKE_C_COMPILER=/usr/local/bin/gcc
# -j 表示使用几个CPU同时编译
make -j 2
make install

1.7 初始化&启动数据库

#编辑配置文件
vi /data/conf/my.cnf
#建立软链接
ln -s /data/conf/my.cnf /etc/my.cnf
#初始化数据库
mysqld --defaults-file=/etc/my.cnf --initialize-insecure &
#启动数据库
mysqld_safe --defaults-file=/etc/my.cnf &
#登陆后修改密码
mysql
alter user root@localhost identified by 'xxx';

二、调试环境配置

2.1 调试工具基本使用

#安装调试工具gdb
yum install -y gdb

  gdb常用选项:

命令 命令缩写 命令说明
attach 挂接进程的PID
detach 取消挂接的进程
list l 显示多行源代码
break b 设置断点,程序运行到断点的位置会停下来
info i 描述程序的状态
run r 开始运行程序
display disp 跟踪查看某个变量,每次停下来都显示它的值
step s 执行下一条语句,如果该语句为函数调用,则进入函数执行其中的第一条语句
next n 执行下一条语句,如果该语句为函数调用,不会进入函数内部执行(即不会一步步地调试函数内部语句)
print p 打印内部变量值
continue c 继续程序的运行,直到遇到下一个断点
set var name=v 设置变量的值
start st 开始执行程序,在main函数的第一条语句前面停下来
file 装入需要调试的程序
kill k 终止正在调试的程序
watch 监视变量值的变化
backtrace bt 查看函数调用信息(堆栈)
frame f 查看栈帧
quit q 退出GDB环境

2.2 MySQL和OS线程的对应关系

  mysqld是一个单进程多线程的程序,进程实际上就是运行中的程序,一个进程中可以包含一个或多个线程。一个进程内部的所有线程都拥有相同的代码程序、堆、全局变量、共享库等,但是每个线程拥有自己独立栈空间和寄存器,他们共享进程的虚拟内存地址空间。在Linux中线程也叫轻量级进程(LWP)。进程是内存分配的最小单位,线程是CPU调度的最小单位,也就是说如果CPU是多核,那么多个线程可以达到并行处理的效果,内核直接调度线程。在OS上通过ps -eLlf可以查看线程ID LWP:
_
  通过performance_schema.threads表可以查看操作系统线程号与mysql哪个功能线程相对应:

root@mysql8 16:42:  [(none)]> select THREAD_ID,PROCESSLIST_ID,THREAD_OS_ID,name,TYPE from performance_schema.threads;
+-----------+----------------+--------------+---------------------------------------------+------------+
| THREAD_ID | PROCESSLIST_ID | THREAD_OS_ID | name                                        | TYPE       |
+-----------+----------------+--------------+---------------------------------------------+------------+
|         1 |           NULL |         3117 | thread/sql/main                             | BACKGROUND |
|         3 |           NULL |         3124 | thread/innodb/io_ibuf_thread                | BACKGROUND |
|         4 |           NULL |         3125 | thread/innodb/io_log_thread                 | BACKGROUND |
|         5 |           NULL |         3126 | thread/innodb/io_read_thread                | BACKGROUND |
|         6 |           NULL |         3127 | thread/innodb/io_read_thread                | BACKGROUND |
|         7 |           NULL |         3128 | thread/innodb/io_read_thread                | BACKGROUND |
|         8 |           NULL |         3129 | thread/innodb/io_read_thread                | BACKGROUND |
|         9 |           NULL |         3130 | thread/innodb/io_read_thread                | BACKGROUND |
|        10 |           NULL |         3131 | thread/innodb/io_read_thread                | BACKGROUND |
|        11 |           NULL |         3132 | thread/innodb/io_read_thread                | BACKGROUND |
|        12 |           NULL |         3133 | thread/innodb/io_read_thread                | BACKGROUND |
|        13 |           NULL |         3134 | thread/innodb/io_write_thread               | BACKGROUND |
|        14 |           NULL |         3135 | thread/innodb/io_write_thread               | BACKGROUND |
|        15 |           NULL |         3136 | thread/innodb/io_write_thread               | BACKGROUND |
|        16 |           NULL |         3137 | thread/innodb/io_write_thread               | BACKGROUND |
|        17 |           NULL |         3138 | thread/innodb/io_write_thread               | BACKGROUND |
|        18 |           NULL |         3139 | thread/innodb/io_write_thread               | BACKGROUND |
|        19 |           NULL |         3140 | thread/innodb/io_write_thread               | BACKGROUND |
|        20 |           NULL |         3141 | thread/innodb/io_write_thread               | BACKGROUND |
|        21 |           NULL |         3142 | thread/innodb/page_flush_coordinator_thread | BACKGROUND |
|        22 |           NULL |         3143 | thread/innodb/page_flush_thread             | BACKGROUND |
|        23 |           NULL |         3144 | thread/innodb/page_flush_thread             | BACKGROUND |
|        24 |           NULL |         3145 | thread/innodb/page_flush_thread             | BACKGROUND |
|        25 |           NULL |         3146 | thread/innodb/log_checkpointer_thread       | BACKGROUND |
|        26 |           NULL |         3147 | thread/innodb/log_closer_thread             | BACKGROUND |
|        27 |           NULL |         3148 | thread/innodb/log_flush_notifier_thread     | BACKGROUND |
|        28 |           NULL |         3149 | thread/innodb/log_flusher_thread            | BACKGROUND |
|        29 |           NULL |         3150 | thread/innodb/log_write_notifier_thread     | BACKGROUND |
|        30 |           NULL |         3151 | thread/innodb/log_writer_thread             | BACKGROUND |
|        31 |           NULL |         3152 | thread/innodb/srv_lock_timeout_thread       | BACKGROUND |
|        32 |           NULL |         3153 | thread/innodb/srv_error_monitor_thread      | BACKGROUND |
|        33 |           NULL |         3154 | thread/innodb/srv_monitor_thread            | BACKGROUND |
|        34 |           NULL |         3156 | thread/innodb/buf_resize_thread             | BACKGROUND |
|        35 |           NULL |         3157 | thread/innodb/srv_master_thread             | BACKGROUND |
|        36 |           NULL |         3158 | thread/innodb/dict_stats_thread             | BACKGROUND |
|        37 |           NULL |         3159 | thread/innodb/fts_optimize_thread           | BACKGROUND |
|        38 |           NULL |         3160 | thread/mysqlx/worker                        | BACKGROUND |
|        39 |           NULL |         3161 | thread/mysqlx/worker                        | BACKGROUND |
|        40 |           NULL |         3162 | thread/mysqlx/acceptor_network              | BACKGROUND |
|        41 |           NULL |         3163 | thread/mysqlx/acceptor_network              | BACKGROUND |
|        44 |           NULL |         3166 | thread/innodb/buf_dump_thread               | BACKGROUND |
|        45 |           NULL |         3167 | thread/innodb/clone_gtid_thread             | BACKGROUND |
|        46 |           NULL |         3168 | thread/innodb/srv_purge_thread              | BACKGROUND |
|        47 |           NULL |         3168 | thread/innodb/srv_purge_thread              | BACKGROUND |
|        48 |           NULL |         3169 | thread/innodb/srv_worker_thread             | BACKGROUND |
|        49 |           NULL |         3169 | thread/innodb/srv_worker_thread             | BACKGROUND |
|        50 |           NULL |         3170 | thread/innodb/srv_worker_thread             | BACKGROUND |
|        51 |           NULL |         3170 | thread/innodb/srv_worker_thread             | BACKGROUND |
|        52 |           NULL |         3171 | thread/innodb/srv_worker_thread             | BACKGROUND |
|        53 |           NULL |         3171 | thread/innodb/srv_worker_thread             | BACKGROUND |
|        54 |              4 |         3172 | thread/sql/event_scheduler                  | FOREGROUND |
|        55 |           NULL |         3173 | thread/sql/signal_handler                   | BACKGROUND |
|        56 |              6 |         3174 | thread/sql/compress_gtid_table              | FOREGROUND |
|        59 |              9 |         3177 | thread/sql/one_connection                   | FOREGROUND |
+-----------+----------------+--------------+---------------------------------------------+------------+
54 rows in set (0.01 sec)

2.4 mysql调试基本使用

  启动gdb:

gdb
GNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-115.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命令挂接mysql

gdb
GNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-115.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 3117
Attaching to process 3117
Reading symbols from /usr/local/mysql/bin/mysqld...done.
Reading symbols from /lib64/libpthread.so.0...(no debugging symbols found)...done.
[New LWP 14341]
...
[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 /usr/local/mysql/bin/../lib/private/libprotobuf-lite.so.3.6.1...done.
Loaded symbols for /usr/local/mysql/bin/../lib/private/libprotobuf-lite.so.3.6.1
Reading symbols from /lib64/libcrypt.so.1...(no debugging symbols found)...done.
Loaded symbols for /lib64/libcrypt.so.1
Reading symbols from /lib64/librt.so.1...(no debugging symbols found)...done.
Loaded symbols for /lib64/librt.so.1
Reading symbols from /lib64/libssl.so.10...Reading symbols from /lib64/libssl.so.10...(no debugging symbols found)...done.
(no debugging symbols found)...done.
Loaded symbols for /lib64/libssl.so.10
Reading symbols from /lib64/libcrypto.so.10...Reading symbols from /lib64/libcrypto.so.10...(no debugging symbols found)...done.
(no debugging symbols found)...done.
Loaded symbols for /lib64/libcrypto.so.10
Reading symbols from /lib64/libdl.so.2...(no debugging symbols found)...done.
Loaded symbols for /lib64/libdl.so.2
Reading symbols from /lib64/libnuma.so.1...(no debugging symbols found)...done.
Loaded symbols for /lib64/libnuma.so.1
Reading symbols from /lib64/libstdc++.so.6...done.
Loaded symbols for /lib64/libstdc++.so.6
Reading symbols from /lib64/libm.so.6...(no debugging symbols found)...done.
Loaded symbols for /lib64/libm.so.6
Reading symbols from /lib64/libgcc_s.so.1...(no debugging symbols found)...done.
Loaded symbols for /lib64/libgcc_s.so.1
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 /usr/lib/debug/usr/lib64/libfreebl3.so.debug...done.
done.
Loaded symbols for /lib64/libfreebl3.so
Reading symbols from /lib64/libgssapi_krb5.so.2...Reading symbols from /lib64/libgssapi_krb5.so.2...(no debugging symbols found)...done.
(no debugging symbols found)...done.
Loaded symbols for /lib64/libgssapi_krb5.so.2
Reading symbols from /lib64/libkrb5.so.3...Reading symbols from /lib64/libkrb5.so.3...(no debugging symbols found)...done.
(no debugging symbols found)...done.
Loaded symbols for /lib64/libkrb5.so.3
Reading symbols from /lib64/libcom_err.so.2...Reading symbols from /lib64/libcom_err.so.2...(no debugging symbols found)...done.
(no debugging symbols found)...done.
Loaded symbols for /lib64/libcom_err.so.2
Reading symbols from /lib64/libk5crypto.so.3...Reading symbols from /lib64/libk5crypto.so.3...(no debugging symbols found)...done.
(no debugging symbols found)...done.
Loaded symbols for /lib64/libk5crypto.so.3
Reading symbols from /lib64/libz.so.1...Reading symbols from /lib64/libz.so.1...(no debugging symbols found)...done.
(no debugging symbols found)...done.
Loaded symbols for /lib64/libz.so.1
Reading symbols from /lib64/libkrb5support.so.0...Reading symbols from /lib64/libkrb5support.so.0...(no debugging symbols found)...done.
(no debugging symbols found)...done.
Loaded symbols for /lib64/libkrb5support.so.0
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/libselinux.so.1...Reading symbols from /lib64/libselinux.so.1...(no debugging symbols found)...done.
(no debugging symbols found)...done.
Loaded symbols for /lib64/libselinux.so.1
Reading symbols from /lib64/libpcre.so.1...Reading symbols from /lib64/libpcre.so.1...(no debugging symbols found)...done.
(no debugging symbols found)...done.
Loaded symbols for /lib64/libpcre.so.1
Reading symbols from /lib64/libnss_files.so.2...(no debugging symbols found)...done.
Loaded symbols for /lib64/libnss_files.so.2
0x00007fe69f0d2bed in poll () from /lib64/libc.so.6
Missing separate debuginfos, use: debuginfo-install glibc-2.17-292.el7.x86_64 keyutils-libs-1.5.8-3.el7.x86_64 krb5-libs-1.15.1-37.el7_7.2.x86_64 libcom_err-1.42.9-16.el7.x86_64 libgcc-4.8.5-39.el7.x86_64 libnuma1-2.0.12-4.1.x86_64 libselinux-2.5-14.1.el7.x86_64 openssl-libs-1.0.2k-19.el7.x86_64 pcre-8.32-17.el7.x86_64 zlib-1.2.7-18.el7.x86_64

  从输出中可以看出缺少一些包,需要额外安装:

#安装对应版本的debuginfo
rpm -ivh kernel-debuginfo-common-x86_64-3.10.0-1062.el7.x86_64.rpm
rpm -ivh kernel-debuginfo-3.10.0-1062.el7.x86_64.rpm
#安装相关包
yum install -y nss-softokn-debuginfo --nogpgcheck
yum install -y yum-utils
debuginfo-install glibc-2.17-292.el7.x86_64 keyutils-libs-1.5.8-3.el7.x86_64 krb5-libs-1.15.1-37.el7_7.2.x86_64 libcom_err-1.42.9-16.el7.x86_64 libgcc-4.8.5-39.el7.x86_64 libnuma1-2.0.12-4.1.x86_64 libselinux-2.5-14.1.el7.x86_64 openssl-libs-1.0.2k-19.el7.x86_64 pcre-8.32-17.el7.x86_64 zlib-1.2.7-18.el7.x86_64

  下面来完整的演示调试过程

#首先获取mysqld进程的PID
[root@mysql8 tmp]# ps -ef | grep mysql
root       8371   8230  0 17:41 pts/0    00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf
mysql      9916   8371  1 17:41 pts/0    00:00:12 /usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/data/mysql3306/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql3306/logs/error.log --open-files-limit=65535 --pid-file=mysql8.pid --socket=/data/mysql3306/data/mysql.sock --port=3306
#然后使用gdb命令进行调试
[root@mysql8 ~]# gdb /usr/local/mysql/bin/mysqld 9916
GNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-115.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/>...
Reading symbols from /usr/local/mysql/bin/mysqld...done.
Attaching to program: /usr/local/mysql/bin/mysqld, process 9916
Reading symbols from /lib64/libpthread.so.0...Reading symbols from /usr/lib/debug/usr/lib64/libpthread-2.17.so.debug...done.
done.
[New LWP 10064]
...
[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 /usr/local/mysql/bin/../lib/private/libprotobuf-lite.so.3.6.1...done.
Loaded symbols for /usr/local/mysql/bin/../lib/private/libprotobuf-lite.so.3.6.1
Reading symbols from /lib64/libcrypt.so.1...Reading symbols from /usr/lib/debug/usr/lib64/libcrypt-2.17.so.debug...done.
done.
Loaded symbols for /lib64/libcrypt.so.1
Reading symbols from /lib64/librt.so.1...Reading symbols from /usr/lib/debug/usr/lib64/librt-2.17.so.debug...done.
done.
Loaded symbols for /lib64/librt.so.1
Reading symbols from /lib64/libssl.so.10...Reading symbols from /usr/lib/debug/usr/lib64/libssl.so.1.0.2k.debug...done.
done.
Loaded symbols for /lib64/libssl.so.10
Reading symbols from /lib64/libcrypto.so.10...Reading symbols from /usr/lib/debug/usr/lib64/libcrypto.so.1.0.2k.debug...done.
done.
Loaded symbols for /lib64/libcrypto.so.10
Reading symbols from /lib64/libdl.so.2...Reading symbols from /usr/lib/debug/usr/lib64/libdl-2.17.so.debug...done.
done.
Loaded symbols for /lib64/libdl.so.2
Reading symbols from /lib64/libnuma.so.1...done.
Loaded symbols for /lib64/libnuma.so.1
Reading symbols from /lib64/libstdc++.so.6...done.
Loaded symbols for /lib64/libstdc++.so.6
Reading symbols from /lib64/libm.so.6...Reading symbols from /usr/lib/debug/usr/lib64/libm-2.17.so.debug...done.
done.
Loaded symbols for /lib64/libm.so.6
Reading symbols from /lib64/libgcc_s.so.1...Reading symbols from /usr/lib/debug/usr/lib64/libgcc_s-4.8.5-20150702.so.1.debug...done.
done.
Loaded symbols for /lib64/libgcc_s.so.1
Reading symbols from /lib64/libc.so.6...Reading symbols from /usr/lib/debug/usr/lib64/libc-2.17.so.debug...done.
done.
Loaded symbols for /lib64/libc.so.6
Reading symbols from /lib64/ld-linux-x86-64.so.2...Reading symbols from /usr/lib/debug/usr/lib64/ld-2.17.so.debug...done.
done.
Loaded symbols for /lib64/ld-linux-x86-64.so.2
Reading symbols from /lib64/libfreebl3.so...Reading symbols from /usr/lib/debug/usr/lib64/libfreebl3.so.debug...done.
done.
Loaded symbols for /lib64/libfreebl3.so
Reading symbols from /lib64/libgssapi_krb5.so.2...Reading symbols from /usr/lib/debug/usr/lib64/libgssapi_krb5.so.2.2.debug...done.
done.
Loaded symbols for /lib64/libgssapi_krb5.so.2
Reading symbols from /lib64/libkrb5.so.3...Reading symbols from /usr/lib/debug/usr/lib64/libkrb5.so.3.3.debug...done.
done.
Loaded symbols for /lib64/libkrb5.so.3
Reading symbols from /lib64/libcom_err.so.2...Reading symbols from /usr/lib/debug/usr/lib64/libcom_err.so.2.1.debug...done.
done.
Loaded symbols for /lib64/libcom_err.so.2
Reading symbols from /lib64/libk5crypto.so.3...Reading symbols from /usr/lib/debug/usr/lib64/libk5crypto.so.3.1.debug...done.
done.
Loaded symbols for /lib64/libk5crypto.so.3
Reading symbols from /lib64/libz.so.1...Reading symbols from /usr/lib/debug/usr/lib64/libz.so.1.2.7.debug...done.
done.
Loaded symbols for /lib64/libz.so.1
Reading symbols from /lib64/libkrb5support.so.0...Reading symbols from /usr/lib/debug/usr/lib64/libkrb5support.so.0.1.debug...done.
done.
Loaded symbols for /lib64/libkrb5support.so.0
Reading symbols from /lib64/libkeyutils.so.1...Reading symbols from /usr/lib/debug/usr/lib64/libkeyutils.so.1.5.debug...done.
done.
Loaded symbols for /lib64/libkeyutils.so.1
Reading symbols from /lib64/libresolv.so.2...Reading symbols from /usr/lib/debug/usr/lib64/libresolv-2.17.so.debug...done.
done.
Loaded symbols for /lib64/libresolv.so.2
Reading symbols from /lib64/libselinux.so.1...Reading symbols from /usr/lib/debug/usr/lib64/libselinux.so.1.debug...done.
done.
Loaded symbols for /lib64/libselinux.so.1
Reading symbols from /lib64/libpcre.so.1...Reading symbols from /usr/lib/debug/usr/lib64/libpcre.so.1.2.0.debug...done.
done.
Loaded symbols for /lib64/libpcre.so.1
Reading symbols from /lib64/libnss_files.so.2...Reading symbols from /usr/lib/debug/usr/lib64/libnss_files-2.17.so.debug...done.
done.
Loaded symbols for /lib64/libnss_files.so.2
0x00007f88d3ab4bed in poll () at ../sysdeps/unix/syscall-template.S:81
81      T_PSEUDO (SYSCALL_SYMBOL, SYSCALL_NAME, SYSCALL_NARGS)
#设置断点,比如在mysql_execute_command函数设置断点
(gdb) b mysql_execute_command
Breakpoint 1 at 0x350d370: file /usr/local/tools/mysql-8.0.18/sql/sql_parse.cc, line 2625.
#再起一个终端连接到MySQL,执行命令
select version();
#此时在gdb会话终端,会停在断点处,执行命令:p thd->m_query_string,可以看到断点处,thd变量内部的成员变量记录着当前正在执行的SQL语句:
(gdb) p thd->m_query_string
$1 = {str = 0x7f87b000c6f8 "select version()", length = 16}
#此时执行bt命令查看函数调用信息:
(gdb) bt
#0  mysql_execute_command (thd=0x7f87b0000d70, first_level=true)
    at /usr/local/tools/mysql-8.0.18/sql/sql_parse.cc:2625
#1  0x000000000351561a in mysql_parse (thd=0x7f87b0000d70, parser_state=0x7f87d40f0b20)
    at /usr/local/tools/mysql-8.0.18/sql/sql_parse.cc:5257
#2  0x000000000350aa63 in dispatch_command (thd=0x7f87b0000d70, com_data=0x7f87d40f1bd0,
    command=COM_QUERY) at /usr/local/tools/mysql-8.0.18/sql/sql_parse.cc:1765
#3  0x0000000003508fa8 in do_command (thd=0x7f87b0000d70)
    at /usr/local/tools/mysql-8.0.18/sql/sql_parse.cc:1273
#4  0x00000000036ca595 in handle_connection (arg=0x87c16b0)
    at /usr/local/tools/mysql-8.0.18/sql/conn_handler/connection_handler_per_thread.cc:302
#5  0x0000000005183038 in pfs_spawn_thread (arg=0x89c8800)
    at /usr/local/tools/mysql-8.0.18/storage/perfschema/pfs.cc:2854
#6  0x00007f88d5600e65 in start_thread (arg=0x7f87d40f2700) at pthread_create.c:307
#7  0x00007f88d3abf88d in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:111
#使用c命令继续运行,直到遇到下一个断点

三、总结

  本文简单介绍了如何编译安装MySQL8.0,并且进行简单的调试。

版权声明:本文中所有内容均属于阿里云开发者社区所有,任何媒体、网站或个人未经阿里云开发者社区协议授权不得转载、链接、转贴或以其他方式复制发布/发表。申请授权请邮件developerteam@list.alibaba-inc.com,已获得阿里云开发者社区协议授权的媒体、网站,在转载使用时必须注明"稿件来源:阿里云开发者社区,原文作者姓名",违者本社区将依法追究责任。 如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件至:developer2020@service.aliyun.com 进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容。

分享:
数据库
使用钉钉扫一扫加入圈子
+ 订阅

分享数据库前沿,解构实战干货,推动数据库技术变革

其他文章