使用gdb編譯除錯mysql

Michael_DD發表於2015-08-21
使用gdb編譯除錯mysql


首先下載一個版本比較低的mysql,比如5.1.66等
[root@mysqlsource mysql]# ll
total 144240
drwxrwxr-x. 33 mysql mysql     4096 Aug 21 14:39 mysql-5.1.66
-rw-r--r--.  1 root  root  24771341 Aug 21 11:00 mysql-5.1.66.tar.gz
drwxrwxrwx. 32  7155 wheel     4096 Aug 21 14:46 mysql-5.1.73
-rw-r--r--.  1 root  root  24023347 Aug 21 11:00 mysql-5.1.73.tar.gz
-rw-r--r--.  1 root  root  24258297 Aug 21 11:00 mysql-5.5.8.tar.gz
-rw-r--r--.  1 root  root  33115516 Aug 21 11:01 mysql-5.6.22.tar.gz
-rw-r--r--.  1 root  root  41514167 Aug 21 11:00 mysql-5.6.26.zip
[root@mysqlsource mysql]# 

解壓一下:
tar -xvf mysql-5.1.66.tar.gz

cd mysql-5.1.66


執行編譯:
[root@mysqlsource mysql-5.1.66]# ./configure --with-debug 

報錯1:

編譯MySQL的過程中提示:
/bin/rm: cannot remove `libtoolt': No such file or directory
解決:
1、確認libtool是否已經安裝,如果沒有安裝的話,則先安裝libtool
# yum -y install libtool
2、分別執行以下三條命令:
# autoreconf --force --install
# libtoolize --automake --force
# automake --force --add-missing
再重新編譯安裝,問題解決!

或者
直接開啟 configure,把 $RM "$cfgfile" 那行刪除掉,重新再執行 ./configure 


報錯2:
執行make時報錯
[root@mysqlsource mysql-5.1.66]# make

cc1: warnings being treated as errors
terminal.c: In function ‘terminal_set’:
terminal.c:911: error: passing argument 1 of ‘tgetflag’ discards qualifiers from pointer target type
/usr/include/term.h:783: note: expected ‘char *’ but argument is of type ‘const char *’
terminal.c:912: error: passing argument 1 of ‘tgetflag’ discards qualifiers from pointer target type
/usr/include/term.h:783: note: expected ‘char *’ but argument is of type ‘const char *’
terminal.c:914: error: passing argument 1 of ‘tgetflag’ discards qualifiers from pointer target type
/usr/include/term.h:783: note: expected ‘char *’ but argument is of type ‘const char *’
terminal.c:915: error: passing argument 1 of ‘tgetflag’ discards qualifiers from pointer target type
/usr/include/term.h:783: note: expected ‘char *’ but argument is of type ‘const char *’
terminal.c:917: error: passing argument 1 of ‘tgetflag’ discards qualifiers from pointer target type
/usr/include/term.h:783: note: expected ‘char *’ but argument is of type ‘const char *’
terminal.c:918: error: passing argument 1 of ‘tgetflag’ discards qualifiers from pointer target type
/usr/include/term.h:783: note: expected ‘char *’ but argument is of type ‘const char *’
terminal.c:920: error: passing argument 1 of ‘tgetnum’ discards qualifiers from pointer target type
/usr/include/term.h:784: note: expected ‘char *’ but argument is of type ‘const char *’
terminal.c:921: error: passing argument 1 of ‘tgetnum’ discards qualifiers from pointer target type
/usr/include/term.h:784: note: expected ‘char *’ but argument is of type ‘const char *’
make[2]: *** [terminal.o] Error 1
make[2]: Leaving directory `/home/mysql/mysql-5.1.73/cmd-line-utils/libedit'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/home/mysql/mysql-5.1.73/cmd-line-utils'
make: *** [all-recursive] Error 1
[root@mysqlsource mysql-5.1.73]# 

編譯使用另外的命令,則不報錯:
[root@mysqlsource mysql-5.1.66]# ./configure --with-debug --enable-mysql-maintainer-mode=no

*****************************************************************************************
chown -R mysql:mysql  /home/mysql

./configure --prefix=/home/mysql/mysql-5.1.73/ddmysql --localstatedir=/home/mysql/mysql-5.1.73/ddmysql/data --with-debug --enable-mysql-maintainer-mode=no    

bin/mysql_install_db --basedir=/home/mysql/mysql-5.1.73/ddmysql --datadir=/home/mysql/mysql-5.1.73/ddmysql/data --user=mysql

--basedir=/home/mysql/mysql-5.1.73/ddmysql/ --datadir=/home/mysql/mysql-5.1.73/ddmysql/data/ --socket=/tmp/mysql.sock --user=mysql
*****************************************************************************************

[mysql@mysqlsource bin]$ ps -ef | grep mysql
root      1431  1417  0 16:46 ?        00:00:00 [mysqld] <defunct>
mysql     1992  2757  0 16:50 pts/1    00:00:00 /home/mysql/mysql-5.1.73/sql/mysqld --basedir=/home/mysql/mysql-5.1.73/ddmysql/ --datadir=/home/mysql/mysql-5.1.73/ddmysql/data/ --socket=/tmp/mysql.sock
mysql     2029 25296  1 16:52 pts/3    00:00:00 ps -ef
mysql     2031 25296  0 16:52 pts/3    00:00:00 grep mysql
root      2037     1  0 Aug19 ?        00:05:25 /usr/bin/Xvnc :1 -desktop mysqlsource:1 (root) -auth /root/.Xauthority -geometry 1024x768 -rfbwait 30000 -rfbauth /root/.vnc/passwd -rfbport 5901 -fp catalogue:/etc/X11/fontpath.d -pn
root     25295  7364  0 16:33 pts/3    00:00:00 su - mysql
mysql    25296 25295  0 16:33 pts/3    00:00:00 -bash


[mysql@mysqlsource bin]$ gdb
GNU gdb (GDB) Red Hat Enterprise Linux (7.2-60.el6)
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later < /> 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:
< /> (gdb) attach 1992     //關聯程式
Attaching to process 1992
Reading symbols from /home/mysql/mysql-5.1.73/sql/mysqld...done.
Reading symbols from /lib64/libpthread.so.0...(no debugging symbols found)...done.
[New LWP 1998]
[Thread debugging using libthread_db enabled]
Loaded symbols for /lib64/libpthread.so.0
Reading symbols from /lib64/libz.so.1...(no debugging symbols found)...done.
Loaded symbols for /lib64/libz.so.1
Reading symbols from /lib64/libdl.so.2...(no debugging symbols found)...done.
Loaded symbols for /lib64/libdl.so.2
Reading symbols from /lib64/libcrypt.so.1...(no debugging symbols found)...done.
Loaded symbols for /lib64/libcrypt.so.1
Reading symbols from /lib64/libnsl.so.1...(no debugging symbols found)...done.
Loaded symbols for /lib64/libnsl.so.1
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 /lib64/libfreebl3.so...(no debugging symbols found)...done.
Loaded symbols for /lib64/libfreebl3.so
Reading symbols from /lib64/libnss_files.so.2...(no debugging symbols found)...done.
Loaded symbols for /lib64/libnss_files.so.2
0x0000003b39ae14f3 in select () from /lib64/libc.so.6
Missing separate debuginfos, use: debuginfo-install glibc-2.12-1.107.el6.x86_64 libgcc-4.4.7-3.el6.x86_64 libstdc++-4.4.7-3.el6.x86_64 nss-softokn-freebl-3.12.9-11.el6.x86_64 zlib-1.2.3-29.el6.x86_64
(gdb) b mysqld_show_create      //設定斷點
Breakpoint 1 at 0x6a45e8: file sql_show.cc, line 712.
(gdb) c                                   //繼續
Continuing.
[New Thread 0x7f3f55be0700 (LWP 2083)]
[Switching to Thread 0x7f3f55be0700 (LWP 2083)]


另一視窗操作:
[root@mysqlsource bin]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.1.73-debug Source distribution
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> show tables;
+---------------------------+
| Tables_in_mysql           |
+---------------------------+
| columns_priv              |
| db                        |
| event                     |
| func                      |
| general_log               |
| help_category             |
| help_keyword              |
| help_relation             |
| help_topic                |
| host                      |
| ndb_binlog_index          |
| plugin                    |
| proc                      |
| procs_priv                |
| servers                   |
| slow_log                  |
| tables_priv               |
| time_zone                 |
| time_zone_leap_second     |
| time_zone_name            |
| time_zone_transition      |
| time_zone_transition_type |
| user                      |
+---------------------------+
23 rows in set (0.00 sec)
mysql> show create table user\G;   (設定了斷點,會卡住)


返回原來視窗:

Breakpoint 1, mysqld_show_create (thd=0x25efd50, table_list=0x7f3f48004bb0) at sql_show.cc:712
712     {
(gdb) n                         //下一步
713       Protocol *protocol= thd->protocol;
(gdb) n
715       String buffer(buff, sizeof(buff), system_charset_info);
(gdb) n
716       DBUG_ENTER("mysqld_show_create");
(gdb) n
717       DBUG_PRINT("enter",("db: %s  table: %s",table_list->db,
(gdb) n
721       thd->lex->context_analysis_only|= CONTEXT_ANALYSIS_ONLY_VIEW;
(gdb) n
724         Show_create_error_handler view_error_suppressor(thd, table_list);
(gdb) n
725         thd->push_internal_handler(&view_error_suppressor);
(gdb) n
726         bool error= open_normal_and_derived_tables(thd, table_list, 0);
(gdb) n
727         thd->pop_internal_handler();
(gdb) n
728         if (error && (thd->killed || thd->main_da.is_error()))
(gdb) n
729           DBUG_RETURN(TRUE);
(gdb) n
733       if (thd->lex->only_view && !table_list->view)
(gdb) n
740       buffer.length(0);
(gdb) n
742       if (table_list->view)
(gdb) n
751       List<Item> field_list;
(gdb) n
752       if (table_list->view)
(gdb) p table_list->db
$1 = 0x7f3f48004ee0 "mysql"
(gdb) p table_list->table_name
$2 = 0x7f3f48004b78 "user"
(gdb) 

之前都用root使用者有 ptrace: Operation not permitted.  報錯!!

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29500582/viewspace-1778849/,如需轉載,請註明出處,否則將追究法律責任。

相關文章