利用gdb对mysql进行debug

gdb的安装:

下载:http://www.gnu.org/software/gdb/download/

安装:
./configure --prefix=/tools/gdb/
make & make install

安装时会遇到下列错误,需要安装termcap类库。
checking for iconv declaration... install-shextern size_t iconv (iconv_t cd, char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft);
checking for library containing waddstr... no
configure: WARNING: no enhanced curses library found; disabling TUI
checking for library containing tgetent... no
configure: error: no termcap library found
make[1]: *** [configure-gdb] Error 1
make[1]: Leaving directory `/gdb-7.6'
make: *** [all] Error 2

mysql安装:

下载:
mysql源码:http://dev.mysql.com/downloads/mysql/5.0.html
cmake:http://www.cmake.org

以debug模式编译mysql:

cmake -DCMAKE_INSTALL_PREFIX=/tools/5.6.17   \
-DMYSQL_UNIX_ADDR=/tools/mysql.sock          \
-DDEFAULT_CHARSET=utf8                       \
-DDEFAULT_COLLATION=utf8_general_ci          \
-DWITH_MYISAM_STORAGE_ENGINE=1               \
-DWITH_INNOBASE_STORAGE_ENGINE=1             \
-DWITH_ARCHIVE_STORAGE_ENGINE=1              \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1            \
-DWITH_MEMORY_STORAGE_ENGINE=1               \
-DWITH_READLINE=1                            \
-DENABLED_LOCAL_INFILE=1                     \
-DMYSQL_DATADIR=/tools/data                  \
-DMYSQL_USER=mysql                           \
-DMYSQL_TCP_PORT=3306                        \
-DWITH_DEBUG=1                             

make & make install

在编译时会遇到
CMake Warning (dev) at CMakeLists.txt:187 (INCLUDE):
  Syntax Warning in cmake code at

    /tools/mysql-5.6.17/cmake/ssl.cmake:237:55

  Argument not separated from preceding token by whitespace.
This warning is for project developers.  Use -Wno-dev to suppress it.

-- MySQL 5.6.17
-- Packaging as: mysql-5.6.17-Linux-x86_64
-- HAVE_VISIBILITY_HIDDEN
-- HAVE_VISIBILITY_HIDDEN
-- HAVE_VISIBILITY_HIDDEN
-- Could NOT find Curses (missing:  CURSES_LIBRARY CURSES_INCLUDE_PATH)
CMake Error at cmake/readline.cmake:85 (MESSAGE):
  Curses library not found.  Please install appropriate package,

      remove CMakeCache.txt and rerun cmake.On Debian/Ubuntu, package name is libncurses5-dev, on Redhat and derivates it is ncurses-devel.
Call Stack (most recent call first):
  cmake/readline.cmake:128 (FIND_CURSES)
  cmake/readline.cmake:202 (MYSQL_USE_BUNDLED_EDITLINE)
  CMakeLists.txt:411 (MYSQL_CHECK_EDITLINE)


-- Configuring incomplete, errors occurred!
See also "/tools/mysql-5.6.17/CMakeFiles/CMakeOutput.log".
See also "/tools/mysql-5.6.17/CMakeFiles/CMakeError.log".

通过删除文件CMakeCache.txt通过。
mv CMakeCache.txt ..

下面演示如何使用gdb进行debug:

查找mysqld进程号:
ps -ef|grep mysqld
31513

启动gdb

设置断点 b mysqld_show_create
继续执行c
下一步n
查看记录print

GNU gdb (GDB) 7.6
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-unknown-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
(gdb) attach 31513                     --关联进程 attach 31513
Attaching to process 31513
Reading symbols from /tools/mysql/5.6.17/bin/mysqld...done.
Reading symbols from /lib64/libpthread.so.0...(no debugging symbols found)...done.[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/lib64/libaio.so.1...(no debugging symbols found)...done.
Loaded symbols for /usr/lib64/libaio.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/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 /usr/lib64/libstdc++.so.6...(no debugging symbols found)...done.
Loaded symbols for /usr/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 /tools/mysql/5.6.17/lib/plugin/validate_password.so...done.
Loaded symbols for /tools/mysql/5.6.17/lib/plugin/validate_password.so
warning: no loadable sections found in added symbol-file system-supplied DSO at 0x7fff679a9000
0x00000038a1ecbab6 in poll () from /lib64/libc.so.6
(gdb) b mysqld_show_create            --设置断点
Breakpoint 1 at 0x7ecc6a: file /data02/mysqltest/luanchangmiao531/mysql-5.6.17/sql/sql_show.cc, line 831.
(gdb) c
Continuing.
[Switching to Thread 0x40ac6940 (LWP 31539)]

打开第二个窗口,登陆mysql数据库,执行语句show create table test\G

在debug窗口中执行:
Breakpoint 1, mysqld_show_create (thd=0x1eab0d90, table_list=0x1eb97d40) at /data02/mysqltest/luanchangmiao531/mysql-5.6.17/sql/sql_show.cc:831
831   Protocol *protocol= thd->protocol;
(gdb) n                      --下一步
834   List field_list;
(gdb) n
835   bool error= TRUE;
(gdb) n
836   DBUG_ENTER("mysqld_show_create");
(gdb) n
837   DBUG_PRINT("enter",("db: %s  table: %s",table_list->db,
(gdb) n
844   MDL_savepoint mdl_savepoint= thd->mdl_context.mdl_savepoint();
(gdb) n
847   thd->lex->context_analysis_only|= CONTEXT_ANALYSIS_ONLY_VIEW;
(gdb) p table_list->db       --打印db名
$4 = 0x1eb982a0 "mydb"
(gdb) p table_list->table_name       --打印表名        
$5 = 0x1eb97d08 "test"


来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/25105315/viewspace-1172028/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/25105315/viewspace-1172028/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
使用 GDB 工具对 MySQL core 文件进行分析和调试的步骤如下: 1.获取 MySQL core 文件:在 MySQL 出现异常时,MySQL 会生成一个 core 文件,用于记录程序崩溃时的内存状态。从产生 core 文件的服务器上,将 core 文件下载到分析工具所在的机器上。 2.安装 GDBGDB 工具是 Linux 下的一款调试工具,需要进行安装。如果未安装可以通过以下命令进行安装: ``` yum install gdb ``` 3.开启 core 文件的调试:默认情况下,Linux 禁止 core 文件的调试,需要手动进行开启。在 shell 终端中,执行以下命令: ``` ulimit -c unlimited ``` 4.使用 GDB 配置文件:为了方便进行调试,可以使用 GDB 的配置文件自动加载调试信息。在命令行中输入以下命令: ``` echo "set auto-load safe-path /" > ~/.gdbinit ``` 5.启动 GDB 调试:在命令行中输入以下命令启动 GDB 调试: ``` gdb /usr/sbin/mysqld /path/to/core ``` 其中,/usr/sbin/mysqld 是 MySQL 的可执行文件路径;/path/to/core 是 MySQL 生成的 core 文件路径。 6.分析 MySQL core 文件:在 GDB 调试模式下,可以使用一系列命令查看和分析 MySQL core 文件中的数据和信息。例如: ``` bt: 显示运行到崩溃点时的函数调用栈 info registers: 显示当前 CPU 寄存器的值 x/20x $rsp: 显示当前栈帧的堆栈信息 ``` 通过以上步骤,可以使用 GDB 工具对 MySQL core 文件进行分析和调试,更好地定位 MySQL 程序的异常。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值