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/