$ cd /usr/local/GreatSQL-8.0.25-16-Linux-glibc2.28-x86_64
$ ./bin/mysqld-debug --verbose --version
/usr/local/GreatSQL-8.0.25-16-Linux-glibc2.28-x86_64/bin/mysqld-debug Ver 8.0.25-16-debug for Linux on x86_64 (Source distribution)
复制代码
可以看到,输出的结果中包含 debug 关键字,这就表示成功了。
2. 安装gdb
直接执行yum安装gdb即可:
$ yum install -y gdb
$ gdb --version
GNU gdb (GDB) Red Hat Enterprise Linux 9.2-4.el8
Copyright (C) 2020 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.
复制代码
gdb常用的调试相关指令有以下几个:
命令缩写备注attach挂接/进入准备调试的进程piddetach取消挂接进程(退出进程)listl显示多行源代码breakb设置断点,程序运行到断点的位置会停下来infoi描述程序的状态runr开始运行程序displaydisp跟踪查看某个变量,每次停下来都显示它的值steps执行下一条语句,如果该语句为函数调用,则进入函数执行其中的第一条语句nextn执行下一条语句,如果该语句为函数调用,不会进入函数内部执行(即不会一步步地调试函数内部语句)printp打印内部变量值continuec继续程序的运行,直到遇到下一个断点set var name=v设置变量的值startst开始执行程序,在main函数的第一条语句前面停下来file装入需要调试的程序killk终止正在调试的程序watch监视变量值的变化backtracebt查看函数调用信息(堆栈)framef查看栈帧quitq退出gdb3. 开始调试GreatSQL源码
第一次运行gdb准备调试时,可能会提示类似下面的信息
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
0x00007ffb358ada41 in poll () from /lib64/libc.so.6
Missing separate debuginfos, use: dnf debuginfo-install keyutils-libs-1.5.10-9.el8.x86_64 ...