Debugging drizzle with GDB-refer from Padraig's blog

Source: Internet
Author: User

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 obviusly 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 previusly 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
View raw this gist brought to you by GitHub.

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 hassystemic 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 
View raw this gist brought to you by GitHub.

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) 
View raw this gist brought to you by GitHub.

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 View raw this gist brought to you by GitHub.

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.

Written by posulliv

May 21st, 2009 at pm

Posted in database, Drizzle

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.