调试MySQL


1.安装

首先在configure时:sudo ./configure --prefix=/usr/local/mysql --with-debug

sudo make

sudo make install

2.启动

1)启动mysqld

./mysqld --debug

2)找到mysqld的进程ID:ps -A | grep mysql

20504 pts/0 00:00:00 mysqld

3)使用attach进行gdb的关联,gdb要有root权限:

sudo gdb

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 "i686-linux-gnu".

For bug reporting instructions, please see:

.

(gdb) attach 20504

Attaching to process 20504

Reading symbols from /usr/local/mysql/libexec/mysqld...done.

Reading symbols from /lib/i386-linux-gnu/libpthread.so.0...Reading symbols from /usr/lib/debug/lib/i386-linux-gnu/libpthread-2.13.so...done.

[Thread debugging using libthread_db enabled]

[New Thread 0xb70ceb70 (LWP 20506)]

done.

Loaded symbols for /lib/i386-linux-gnu/libpthread.so.0

Reading symbols from /lib/i386-linux-gnu/libz.so.1...(no debugging symbols found)...done.

Loaded symbols for /lib/i386-linux-gnu/libz.so.1

……

……

……

……

在attach后,就可以直接设置断点了。!!!,例如:

(gdb) break sql_show.cc:207

Breakpoint 1 at 0x82cf7b4: file sql_show.cc, line 207.

(gdb) continue

Continuing.

然后在另外一个终端启动mysql

root@iMac:/usr/local/mysql/bin# ./mysql

Welcome to the MySQL monitor. Commands end with ; or /g.

Your MySQL connection id is 6

Server version: 5.1.34-debug Source distribution

Type 'help;' or '/h' for help. Type '/c' to clear the current input statement.

mysql> show authors

这时候在gdb中会出现调试信息:

[New Thread 0xb70adb70 (LWP 20851)]

[Thread 0xb70adb70 (LWP 20851) exited]

[New Thread 0xb70adb70 (LWP 20854)]

[Thread 0xb70adb70 (LWP 20854) exited]

[New Thread 0xb70adb70 (LWP 20858)]

[Thread 0xb70adb70 (LWP 20858) exited]

[New Thread 0xb70adb70 (LWP 20870)]

[Thread 0xb70adb70 (LWP 20870) exited]

[New Thread 0xb70adb70 (LWP 20883)]

[Thread 0xb70adb70 (LWP 20883) exited]

[New Thread 0xb70adb70 (LWP 20886)]

[Switching to Thread 0xb70adb70 (LWP 20886)]

Breakpoint 1, mysqld_show_authors (thd=0x8c0f380) at sql_show.cc:213

213 {

(gdb)

Continuing.

相关内容