Solved

how to debug mysql with gdb .

Posted on 2012-04-09
7
671 Views
Last Modified: 2012-06-27
hi
i am trying to learn how to use Gdb to debug mysql. i read quite  a lot website in google .. but could not straight my head ..


now from documentation ,, its saying, i need to start mysqld with gdb ..

but the way i run mysql like bellow

/opt/mysql/mysqlserver5/bin/mysqld_safe --user=mysql &

but if i use gdb infront of this command , its say, its not a binary ..
can any one tell me..

how to use gdb with mysql and get output ??


please note : I installed mysql from source .. not by yum or  apt-get .

thanks for your help
0
Comment
Question by:fosiul01
  • 4
  • 3
7 Comments
 
LVL 76

Accepted Solution

by:
arnold earned 500 total points
ID: 37823649
The start is a script and not the binary file as the error says.

gdb --exec="/opt/mysql/mysqlserver5/bin/mysqld_safe --user=mysql "


alternatively you can attach to an existing process
strace -f -p <pid_of_process>

what output are you looking to get?

What are you trying to troubleshoot?
0
 
LVL 29

Author Comment

by:fosiul01
ID: 37824139
i am just trying to get use of gdb ..
as i am seeing too much semaphore although they are not too bad .. just want to try out those technique so that in bad time, i know what to do ..


just woundering if you can help me with a thread ..

bellow is a semaphore :
SEMAPHORES
----------
OS WAIT ARRAY INFO: reservation count 2437436, signal count 4990922
--Thread 139822454851328 has waited at btr0cur.c line 530 for 0.00 seconds the semaphore:
S-lock on RW-latch at 0xba80ea8 created in file dict0dict.c line 1723
a writer (thread id 139822417102592) has reserved it in mode  exclusive
number of readers 0, waiters flag 1, lock_word: 0
Last time read locked in file btr0cur.c line 530
Last time write locked in file /pb2/build/sb_0-5135321-1330717714.3/mysql-5.5.22/storage/innobase/btr/btr0cur.c line 523
Mutex spin waits 94388014, rounds 305573911, OS waits 1007616
RW-shared spins 3401896, rounds 48858411, OS waits 812488
RW-excl spins 3000245, rounds 24922097, OS waits 356572
Spin rounds per wait: 3.24 mutex, 14.36 RW-shared, 8.31 RW-excl


now the thread :
-Thread 139822454851328

i dont understand, which thread id its refering to  ...

is there any way to find out which mysql thread is refering to ??

currently only process runnign 109 and 126

but how doyou know  139822454851328 which mysql thread is refering to ??

thanks
0
 
LVL 76

Expert Comment

by:arnold
ID: 37824340
If you are lookin at fine tunning mysql, install myphpadmin from myphpadmin.net and look at the query performance.

dbg would usually be used to debug core dumps or failing programs.

It looks to me like a resource contention with a process that locked and is taking its time to process the data
a writer (thread id 139822417102592) has reserved it in mode  exclusive
number of readers 0, waiters flag 1, lock_word: 0

http://www.howtogeek.com/howto/linux/using-a-mysql-performance-tuning-analyzer-script/

http://drupal.org/node/51263
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 29

Author Comment

by:fosiul01
ID: 37824395
hmm..

i think i will be able to get that one from events_wait table..
but  those semaphore only staying for 0.00 seconds its hard to capture them.. ( in production i would of ignore those as they are not long wait..)
but i am producing those by script..so i want to  know .. from where those threads comming from ..

i meant, which mysql process is related to those threads
those threads are not mysql threads .. that definate.. but they are some how related to mysql_thread..
which i am trying to undestand ...how to find out which mysql thread is related to those threads ..
0
 
LVL 76

Expert Comment

by:arnold
ID: 37824908
You are going into the root seller to see where/how your guests are going/moving on the second floor.

Improving performance or diagnosing slow responses from the mysql server does not require going into the underbelly which is what dbg does.

dbg/strace is a way to determine what/where things are going wrong but you have to know what the process is more specifically your own code that generates an unexpected response to a specific input and you want to determine why.
0
 
LVL 29

Author Comment

by:fosiul01
ID: 37824953
You are going into the root seller to see where/how your guests are going/moving on the second floor.  : lol , yes it over kill!! i agree ..

but tel me something ..
the semaphore example i provided...

tel me, how will  you know which mysql  process is causing the semaphore ??

only clue is the thread Id , but how will you know which which process is related to threadid ??

with mysql 5.0 ( it showd the mysql thread id) but mysql 5.5 .. they dont show the mysql threadid .. they give a long number .which is OS thread id ..

so thats why some people is telling, you need to use gdb to find out what that thread is doing ..
0
 
LVL 76

Expert Comment

by:arnold
ID: 37824996
Not sure, did not see a need to such an indepth look of a functioning app.

You have to have the trace from the beginning. and then trace it back.
Not a linux/unix but is a good discussion that could help in providing overview.
http://www.scribd.com/doc/37724775/9/Section-VIII-Semaphore-Debugging-101

Presumably the issue will depend on where the semaphore is being handled i.e. whether it is an application internal event or whether it is part of the IPC to the kernel subsystem which this one seems to be either a cache lock on a table.

have not seen a need to delve that deep to look at the operation of a running app.
usually use strace to see what is going on if a failure is occurring.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now