Debugging Drizzle with GDB -- refer from Padraig’s Blog
来源:互联网 发布:鸿合电子白板软件 编辑:程序博客网 时间:2024/05/01 00:20
This article is refered from Padraig’s Blog. It's useful for me debuging Drizzle on remote machine: )
While working with Drizzle this week for my GSoC project, I’ve been going through the source code to understand how INFORMATION_SCHEMA is currently implemented. Reading through the source code is obviously the best way to understand the logic behind the current I_S implementation but using a debugger to step through the execution of this code can be extremely helpful in speeding up this process. Toru previously published a related post on debugging Drizzle with gdb which may also be useful.
As Toru mentioned in his post, attaching gdb to Drizzle can be quite simple:
$ cd /path/to/drizzle_source/tests$ ./dtr --start-and-exit --gdb
The above commands will open a xterm window with a gdb session started that is attached to the Drizzle server process. While this works fine, sometimes I am working on a remote machine and don’t want to go to the hassle of setting up something like X11 forwarding or VNC to attach gdb to the server process. Also, while going through the I_S related code, I wanted to step through the code which occurs on server startup i.e. the things which happen before the xterm window with gdb opens as outlined above.
Thus, I wrote the following simple script that I use to debug Drizzle with gdb.
#!/bin/bash if [ $# -ne 1 ]then echo "incorrect number of arguments" echo "Usage" echo "./script DRIZZLE_BUILD_ROOT_DIR" exit 1fi bin_dir=$1 if [ ! -d ${bin_dir} ]then echo "Specified Drizzle build directory does not exist!" exit 1fi proc=`ps -ef | / grep drizzle | / grep -v -e 'grep drizzle' / -e 'bash' | / tee /dev/tty | / awk '{print $2}'` if [ `echo "$proc" | wc -w` -ne 0 ]then echo "Drizzle is already running..." exec gdb ${bin_dir}/drizzled/drizzled -silent "$proc"else echo "Drizzle is not already running..." exec gdb ${bin_dir}/drizzled/drizzledfi exit 0
This script takes as an argument the path to the root of a Drizzle build directory. It then simply checks to see if Drizzle is running already or not. If it is already running, it will attach gdb to the Drizzle process in the current terminal window, for example:
posulliv@aghadoe:~/repos/drizzle/local-build$ ./debug.sh $PWDposulliv 25544 1 0 15:04 pts/1 00:00:00 /home/posulliv/repos/drizzle/local-build/drizzled/drizzled --no-defaults --basedir=/home/posulliv/repos/drizzle/local-build/tests --default-storage-engine=innodb --secure-file-priv=/home/posulliv/repos/drizzle/local-build/tests/var --tmpdir=/home/posulliv/repos/drizzle/local-build/tests/var/tmp --connect-timeout=60 --user=root --pid-file=/home/posulliv/repos/drizzle/local-build/tests/var/run/master.pid --port=9306 --datadir=/home/posulliv/repos/drizzle/local-build/tests/var/master-data --log=/home/posulliv/repos/drizzle/local-build/tests/var/log/master.log --server-id=1 --loose-innodb_data_file_path=ibdata1:10M:autoextend --loose-innodb-lock-wait-timeout=5 --key_buffer_size=1M --sort_buffer=256K --max_heap_table_size=1M --core-fileDrizzle is already running...Attaching to program: /home/posulliv/repos/drizzle/local-build/drizzled/drizzled, process 25544Reading symbols from /usr/local/lib/libprotobuf.so.3...done.Loaded symbols for /usr/local/lib/libprotobuf.so.3Reading symbols from /usr/lib/libevent-1.3e.so.1...done.Loaded symbols for /usr/lib/libevent-1.3e.so.1Reading symbols from /usr/local/lib/libdrizzle.so.0...done.Loaded symbols for /usr/local/lib/libdrizzle.so.0Reading symbols from /lib/libz.so.1...done.Loaded symbols for /lib/libz.so.1Reading symbols from /lib/libuuid.so.1...done.Loaded symbols for /lib/libuuid.so.1Reading symbols from /lib/libdl.so.2...done.Loaded symbols for /lib/libdl.so.2Reading symbols from /lib/libpcre.so.3...done.Loaded symbols for /lib/libpcre.so.3Reading symbols from /lib/librt.so.1...done.Loaded symbols for /lib/librt.so.1Reading symbols from /lib/libcrypt.so.1...done.Loaded symbols for /lib/libcrypt.so.1Reading symbols from /lib/libnsl.so.1...done.Loaded symbols for /lib/libnsl.so.1Reading symbols from /usr/lib/libstdc++.so.6...done.Loaded symbols for /usr/lib/libstdc++.so.6Reading symbols from /lib/libm.so.6...done.Loaded symbols for /lib/libm.so.6Reading symbols from /lib/libgcc_s.so.1...done.Loaded symbols for /lib/libgcc_s.so.1Reading symbols from /lib/libpthread.so.0...done.[Thread debugging using libthread_db enabled][New Thread 0x7f18aec47750 (LWP 25544)][New Thread 0x7f18a3a51950 (LWP 25552)][New Thread 0x7f18a4252950 (LWP 25551)][New Thread 0x7f18a4c58950 (LWP 25550)][New Thread 0x7f18a5459950 (LWP 25549)][New Thread 0x7f18a5c5b950 (LWP 25548)][New Thread 0x7f18a645c950 (LWP 25547)][New Thread 0x7f18a6c5d950 (LWP 25546)][New Thread 0x7f18a745e950 (LWP 25545)]Loaded symbols for /lib/libpthread.so.0Reading symbols from /lib/libc.so.6...done.Loaded symbols for /lib/libc.so.6Reading symbols from /lib/libresolv.so.2...done.Loaded symbols for /lib/libresolv.so.2Reading symbols from /lib/ld-linux-x86-64.so.2...done.Loaded symbols for /lib64/ld-linux-x86-64.so.2Reading symbols from /lib/libnss_compat.so.2...done.Loaded symbols for /lib/libnss_compat.so.2Reading symbols from /lib/libnss_nis.so.2...done.Loaded symbols for /lib/libnss_nis.so.2Reading symbols from /lib/libnss_files.so.2...done.Loaded symbols for /lib/libnss_files.so.20x00007f18ac832496 in poll () from /lib/libc.so.6(gdb) break get_schema_tables_resultBreakpoint 1 at 0x50a9eb: file show.cc, line 4051.(gdb) cContinuing.[New Thread 0x7f18a3a40950 (LWP 4504)][Switching to Thread 0x7f18a3a40950 (LWP 4504)] Breakpoint 1, get_schema_tables_result (join=0x130f730, executed_place=PROCESSED_BY_JOIN_EXEC) at show.cc:40514051 JOIN_TAB *tmp_join_tab= join->join_tab+join->tables;(gdb) where#0 get_schema_tables_result (join=0x130f730, executed_place=PROCESSED_BY_JOIN_EXEC) at show.cc:4051#1 0x00000000005744ee in JOIN::exec (this=0x130f730) at sql_select.cc:2098#2 0x0000000000570906 in mysql_select (session=0x7f18a84885c0, rref_pointer_array=0x7f18a84899e8, tables=0x1307230, wild_num=0, fields=@0x7f18a8489928, conds=0x0, og_num=0, order=0x0, group=0x0, having=0x0, select_options=2684370944, result=0x1307a68, unit=0x7f18a84895b8, select_lex=0x7f18a8489830) at sql_select.cc:2670#3 0x0000000000575da4 in handle_select (session=0x7f18a84885c0, lex=0x7f18a8489598, result=0x1307a68, setup_tables_done_option=0) at sql_select.cc:297#4 0x0000000000540ebb in execute_sqlcom_select (session=0x7f18a84885c0, all_tables=0x1307230) at sql_parse.cc:1537#5 0x000000000054155d in mysql_execute_command (session=0x7f18a84885c0) at sql_parse.cc:539#6 0x00000000005447b7 in mysql_parse (session=0x7f18a84885c0, inBuf=0x1307080 "show databases", length=14, found_semicolon=0x7f18a3a40018) at sql_parse.cc:1772#7 0x00000000005449fe in dispatch_command (command=COM_QUERY, session=0x7f18a84885c0, packet=0x7f18a848aa31 "show databases", packet_length=14) at sql_parse.cc:217#8 0x00000000004fbea9 in Session::executeStatement (this=0x7f18a84885c0) at session.cc:709#9 0x0000000000528c08 in handle_one_connection (arg=0x7f18a84885c0) at sql_connect.cc:94#10 0x00007f18acacf3ba in start_thread () from /lib/libpthread.so.0#11 0x00007f18ac83bfcd in clone () from /lib/libc.so.6#12 0x0000000000000000 in ?? ()(gdb)
If Drizzle is not already running, the script starts gdb so we can then kick Drizzle off ourselves within gdb and debug the server startup, for example:
posulliv@aghadoe:~/repos/drizzle/local-build$ ./debug.sh $PWDDrizzle is not already running...GNU gdb 6.8-debianCopyright (C) 2008 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-linux-gnu"...(gdb) break mainBreakpoint 1 at 0x41bbcb: file drizzled.cc, line 1705.(gdb) run --no-defaults --basedir=/home/posulliv/repos/drizzle/local-build/tests --default-storage-engine=innodb --secure-file-priv=/home/posulliv/repos/drizzle/local-build/tests/var --tmpdir=/home/posulliv/repos/drizzle/local-build/tests/var/tmp --connect-timeout=60 --user=root --pid-file=/home/posulliv/repos/drizzle/local-build/tests/var/run/master.pid --port=9306 --datadir=/home/posulliv/repos/drizzle/local-build/tests/var/master-data --log=/home/posulliv/repos/drizzle/local-build/tests/var/log/master.log --server-id=1 --loose-innodb_data_file_path=ibdata1:10M:autoextend --loose-innodb-lock-wait-timeout=5 --key_buffer_size=1M --sort_buffer=256K --max_heap_table_size=1M --core-fileStarting program: /home/posulliv/repos/drizzle/local-build/drizzled/drizzled --no-defaults --basedir=/home/posulliv/repos/drizzle/local-build/tests --default-storage-engine=innodb --secure-file-priv=/home/posulliv/repos/drizzle/local-build/tests/var --tmpdir=/home/posulliv/repos/drizzle/local-build/tests/var/tmp --connect-timeout=60 --user=root --pid-file=/home/posulliv/repos/drizzle/local-build/tests/var/run/master.pid --port=9306 --datadir=/home/posulliv/repos/drizzle/local-build/tests/var/master-data --log=/home/posulliv/repos/drizzle/local-build/tests/var/log/master.log --server-id=1 --loose-innodb_data_file_path=ibdata1:10M:autoextend --loose-innodb-lock-wait-timeout=5 --key_buffer_size=1M --sort_buffer=256K --max_heap_table_size=1M --core-file[Thread debugging using libthread_db enabled][New Thread 0x7fe95a6f3750 (LWP 4716)][Switching to Thread 0x7fe95a6f3750 (LWP 4716)] Breakpoint 1, main (argc=19, argv=0x7fff62715808) at drizzled.cc:17051705 setlocale(LC_ALL, "");(gdb) where#0 main (argc=19, argv=0x7fff62715808) at drizzled.cc:1705(gdb) list1700 1701 int main(int argc, char **argv)1702 {1703 #if defined(ENABLE_NLS)1704 # if defined(HAVE_LOCALE_H)1705 setlocale(LC_ALL, "");1706 # endif1707 bindtextdomain("drizzle", LOCALEDIR);1708 textdomain("drizzle");1709 #endif(gdb)
That’s about all I have for this post. As you can see, attaching gdb to Drizzle is a pretty straightforward process. I like to use my script mainly on remote servers but I also find it useful when I want to debug server startup on my local box too.
- Debugging Drizzle with GDB -- refer from Padraig’s Blog
- Debugging with GDB
- Debugging with GDB
- Debugging with GDB
- Debugging with gdb
- Debugging with GDB
- Debugging with GDB
- Debugging with GDB
- 《Debugging with GDB》
- Debugging with GDB
- Linux software debugging with GDB
- Linux software debugging with GDB
- 用GDB调试(Debugging with gdb)
- The Art of Debugging with GDB
- Debugging with GDB (入门篇)
- Debugging with GDB学习记录(一)
- Debugging with GDB学习记录(二)
- Debugging with GDB学习记录(三)
- 用synce配置linux(gentoo)和HTC KaiserII(Dopoda)链接的方法
- Understanding Memory Sections in config.bib, boot.bib, and OEMAddressTable in Windows CE 5.0 and 6.0
- zend FrameWork 支持的数据库
- jsp+bean实现数据分页
- Apache HTTP Server 与 Tomcat 的三种连接方式介绍
- Debugging Drizzle with GDB -- refer from Padraig’s Blog
- j2ee常用的设计模式
- 几种排序算法的最简单实现方式
- map用法
- struts常用标签
- 数据库范式
- SQL应用实例
- 24个最好免费下载电子书(Ebooks)的网站
- Hook与AOP