回帰テスト中のデバッグ方法

MySQL回帰テスト中にgdbデバッグしたいような場合のために、mysql-test-run.plにはオプションが用意されています。

まず簡単なやり方は、オプション--gdbを付けること。例えばhogeというテストケースを実行する際にgdbデバッグかましたい場合。

./mysql-test-run.pl --gdb hoge

そうすると新しいコンソールが起動してそこでgdbから回帰テスト用のmysqldが起動するようになります。こんな感じで。

GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i386-redhat-linux-gnu"...Using host libthread_db library "/lib/i686/nosegneg/libthread_db.so.1".

Breakpoint 1 at 0x81fa30a: file sql_parse.cc, line 6056.
[Thread debugging using libthread_db enabled]
[New Thread -1209047360 (LWP 20120)]
[New Thread -1209980016 (LWP 20123)]
070807  8:35:04 [Note] /usr/local/mysql/bin/mysqld: ready for connections.
Version: '5.0.46-enterprise-gpl-modified-log'  socket: '/usr/local/mysql/mysql-test/var/tmp/master.sock'  port: 9306  MySQL Enterprise Server (GPL) (portions (c) Sumisho Computer Systems)
[New Thread -1210180720 (LWP 20125)]
[Switching to Thread -1210180720 (LWP 20125)]

Breakpoint 1, mysql_parse (thd=0x9d73bd8, inBuf=0x9dac820 "SET NAMES utf8", 
    length=14, found_semicolon=0xb7de11f0) at sql_parse.cc:6056
6056      lex_start(thd);
(gdb) 

この時、mysql_parse関数にbreakpointを入れておいてくれるので、最初に実行したクエリ(上記の例ではSET NAMES utf8)を処理するためにmysql_parse関数が呼ばれたところで止まります。あとはここから好きにやればいいと。

ただオイラみたいにgdbは--tui付きで使うのが好きな人は、これだとコードが見にくくて不便。そんな人には--manual-gdbオプションがmysql-test-run.plには用意されています。

./mysql-test-run.pl --manual-gdb hoge

(中略)

To start gdb for master_0, type in another window:
gdb -cd /usr/local/mysql/mysql-test -x /usr/local/mysql/mysql-test/var/tmp/gdbinit.master_0 /usr/local/mysql/bin/mysqld

するとこんな感じで、最終行にgdbでアタッチするためのコマンドがでてきます。そこで上記のコマンドに--tui(などの好きなオプション)を沿えて実行すれば、晴れて好みの状態で回帰テストgdbデバッグできます。

gdb --tui -cd /usr/local/mysql/mysql-test -x /usr/local/mysql/mysql-test/var/tmp/gdbinit.master_0 /usr/local/mysql/bin/mysqld

こういうのが必要になるケースというのは稀ですが、、、

  • テストケースのどの部分で落ちてるのかが分かりにくい場合(mysql_client_testとか)
  • mysqlコマンドラインクライアントで同じクエリを発行しても問題が再現しないが、mysql-test-run.plだと何故か再現する場合

などの場合にやらざるを得なかったりします。