How to Debug a MySQL Test Case Using gdb

This tells how I debugged one specific MySQL test case using gdb. (It is here mainly as a reminder to me so that I can do it more quickly the next time I need it.)

Some issues that it seems to solve:

  • mysqld is running as user mysql; I need to run gdb as root; I want to run the test case as me ("joe generic user");
  • I want to have the test case connect to an already running mysqd.
  • The test case needs a writeable /var directory

Here's how I do it:

  1. Build mysqld with debug symbols:
    $ ./BUILD/compile-pentium64-debug-max
  2. Edit /etc/my.cnf to be compatible with the test case I'll be running
  3. Create a writable "var" directory in the distribution's base directory (sibling to mysql-test)
    $ mkdir var2
  4. Start mysqld:
    $ cd sql
    $ sudo ./mysqld
  5. As Root, situated in the sql directory (beneath the distribution's base directory), start gdb and attach to mysqld, setting desired breakpoints
    # gdb
    (gdb) file ./mysqld
    (gdb) attach <pid>
  6. Run the test case as generic user:
    $ cd mysql-test
    $ ./mtr —extern socket=/var/lib/mysql/mysql.sock —vardir=/home/weldon/exports/2011-09-02-5.1.58_eig-22_bld/var2 user_limits

Debug as normal.