您的位置:首页 > 数据库 > MySQL

使用gdb编译调试mysql

2015-08-21 17:10 495 查看
使用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 <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 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 3ff7 .
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/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/29500582/viewspace-1778849/

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: