Gdb For Dummies

debugging a multi threaded program on GDB

make sure to have ” -g ” compliler flag enabled while enabling.

enter the gdb prompt

preetam@preetam-desktop:/src$ gdb GNU gdb (Ubuntu/Linaro 7.4-2012.04-0ubuntu2.1) 7.4-2012.04 Copyright (C) 2012 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later 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”. For bug reporting instructions, please see: (gdb)

then provide your application program

(gdb) exec-file

to get information on threads

(gdb) info threads Id Target Id Frame 3 Thread 0x7ffff6df4700 (LWP 28351) “rtdecore” 0x00007ffff7bcc04d in accept () from /lib/x86_64-linux-gnu/ 2 Thread 0x7ffff75f5700 (LWP 28350) “rtdecore” 0x00007ffff76b538d in nanosleep () from /lib/x86_64-linux-gnu/ * 1 Thread 0x7ffff7fd9700 (LWP 28347) “rtdecore” 0x00007ffff76dc4bd in read () from /lib/x86_64-linux-gnu/

switching threads

(gdb) thread 1 [Switching to thread 1 (Thread 0x7ffff7fd9700 (LWP 28347))]
0 0x00007ffff76dc4bd in read () from /lib/x86_64-linux-gnu/

to find the current stack

(gdb) where
0 0x00007ffff76dc4bd in read () from /lib/x86_64-linux-gnu/
1 0x00007ffff7670278 in _IO_file_underflow () from /lib/x86_64-linux-gnu/
2 0x00007ffff76712be in _IO_default_uflow () from /lib/x86_64-linux-gnu/
3 0x00007ffff7667da8 in getchar () from /lib/x86_64-linux-gnu/
4 0x000000000040514c in ?? ()
5 0x000000000060b370 in ?? ()
6 0x000000000060b010 in ?? ()
7 0x00007fffffffe130 in ?? ()
8 0x0000000000400ff0 in ?? ()
9 0x00007fffffffe130 in ?? ()
10 0x000000000040545b in ?? ()
11 0x00007fffffffe218 in ?? ()
12 0x00000001004069e0 in ?? ()
13 0x0000000000000000 in ?? ()

if you want to do a post-mortem of your apps segmentation fault make to enable dumping of core on with below command on “bash shell”

ulimit -c unlimited


article 1

article 2

article 3

few more indepth articles:

full tutorial on GDB but my interest was on segmentation fault debugging

Article on multiple debugging tools

extensive cheat sheet of GDB


About preetammn

engineer trying to figure out the world, people and machines.
This entry was posted in LINUX. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s