Categories: Contributing | Development | MySQLUniversity

How to Run MySQL With a Debugger


Contents


← Back to MySQL University main page

[edit] How to Run MySQL With a Debugger

[edit] Presentation

[edit] Summary

[edit] Shorten testcase

cd mysql-test; ./mtr yourbug

[edit] Tool 1: --debug (the DBUG library)

set session debug="+d,sleep_alter_enable_indexes" # see alter_table-big.test

[edit] Tool 2: mysql-test-run.pl (=mtr)

../client/mysql -u root -S var/tmp/master.sock test
source include/have_innodb.in

like ./mtr --start-and-exit innodb

CREATE TABLE IF NOT EXISTS plugin ( name char(64) ...

on its standard input.

file=$0-args.$$
input=$0-input.$$
echo file /usr/home/serg/Abk/mysql/sql/mysqld > $file
echo set args "$@" "--gdb < $input" >> $file
cat >> $file <<__EOF__
b my_message
__EOF__
cat >$input
xterm -e "/usr/home/serg/Abk/mysql/libtool --mode=execute gdb -x $file"
rm $file $input

[edit] Tool 3: look around, read code as you debug

[edit] Tool 4: debuggers (gdb, VisualStudio&cdbg, Eclipse)

help ("help condition"); run (=r); break (=b); continue (=c); condition; next (=n); step (=s); finish; backtrace (=bt);
up; down; until;
info break; disable break; enable break; delete break;
info threads; thread;
print (=p); whatis; ptype; display; watch; kill (=k);
./mtr --mem --gdb innodb
b begin_trans
c
Breakpoint 2, begin_trans (thd=0x8eb9f80) at sql_parse.cc:136
136       if (unlikely(thd->in_sub_stmt))
(gdb) l
131
132
133     bool begin_trans(THD *thd)
134     {
135       int error=0;
136       if (unlikely(thd->in_sub_stmt))
137       {
138         my_error(ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG, MYF(0));
139         return 1;
140       }
(gdb) p error
$2 = <value optimized out>      # grrr!
Breakpoint 2, Log_event::read_log_event (buf=0x89081a0 "\226)2G\017\002", 
    event_len=102, error=0xb738110c, description_event=0x8908080)
    at log_event.cc:1021
1021      DBUG_PRINT("read_event", ("%s(type_code: %d; event_len: %d)",
(gdb) p ev
$2 = (Log_event *) 0x890c6f0                     # not very helpful
(gdb) set print object on 
(gdb) p ev
$3 = (Format_description_log_event *) 0x890c6f0  # ah, thanks
Image:Xemacs-gdb.jpg
Image:Ddd-gdb.jpg
CritSec DeadLockDemo!CritSecTwo+0 at 004A0638
LockCount          1
RecursionCount     1
OwningThread       284
EntryCount         1
ContentionCount    1
*** Locked
Scanned 40 critical sections

[edit] Tool 5: Valgrind

{ int a;  if (a > 3) { ... } }
char *ptr; while(1) { ptr= malloc(100); }
[INS 17:39 /m/mysql-5.1-maint/mysql-test $] cat ~/bin/valgrind-db-attach
#! /bin/sh
# we sleep so that the window does not go away too fast
exec xterm -e "valgrind --db-attach=yes $*; sleep 36000"
[INS 17:39 /m/mysql-5.1-maint/mysql-test $] ./mtr --valgrind-path=~/bin/valgrind-db-attach alias

[edit] Tool 6: logs

[edit] Miscellaneous tools

fprintf(stderr,"your debugging message here %d\n",your variable here);

and recompile.

debug_sync_point("yourbug")

in the place to pause, and recompile; in connection2 do

SELECT GET_LOCK("yourbug", 1000);

then in connection1, start the code to pause: it will try to get the lock "bug" and so pause. To resume the paused connection, do

SELECT RELEASE_LOCK("yourbug").

[edit] Combine tools

[edit] Questions

[edit] Questions asked before the session

[NONE]

[edit] Questions asked during the session

[NONE]

[edit] Voice recording and other links

Retrieved from "http://forge.mysql.com/wiki/How_to_Run_MySQL_With_a_Debugger"

This page has been accessed 7,743 times. This page was last modified 09:26, 24 February 2008.

Find

Browse
MySQLForge
Main Page
Current events
Recent changes
Random page
Help
Edit
Edit this page
Editing help
This page
Discuss this page
Post a comment
Printable version
Context
Page history
What links here
Related changes
My pages
Special pages
New pages
File list
Statistics
Bug reports
More...