How to debug an application

If you want to debug an application that is shipped with the fedora, you can use the following command.

[root@localhost ~]# debuginfo-install gedit-3.4.2-1.fc17.x86_64
Loaded plugins: langpacks, presto, refresh-packagekit
enabling fedora-debuginfo
enabling updates-debuginfo
--> Running transaction check
---> Package atk-debuginfo.x86_64 0:2.4.0-1.fc17 will be installed
---> Package cairo-debuginfo.x86_64 0:1.10.2-7.fc17 will be installed
---> Package enchant-debuginfo.x86_64 1:1.6.0-4.fc17 will be installed
---> Package gdk-pixbuf2-debuginfo.x86_64 0:2.26.1-1.fc17 will be installed
---> Package gedit-debuginfo.x86_64 2:3.4.1-2.fc17 will be updated
---> Package gedit-debuginfo.x86_64 2:3.4.2-1.fc17 will be an update
---> Package glib2-debuginfo.x86_64 0:2.32.4-1.fc17 will be installed
---> Package glibc-debuginfo.x86_64 0:2.15-56.fc17 will be installed
--> Processing Dependency: glibc-debuginfo-common = 2.15-56.fc17 for package: glibc-debuginfo-2.15-56.fc17.x86_64
...
...
Installing for dependencies:
 glibc-debuginfo-common           x86_64 2.15-56.fc17   updates-debuginfo 8.1 M

Transaction Summary
================================================================================
Install  17 Packages (+1 Dependent package)
Upgrade   1 Package

Total download size: 42 M
Is this ok [y/N]: y
…

As a first step, you need to install debug info package for the related application. In this case, I’m going to debug ‘gedit’, so I installed ‘gedit-debuginfo’.

And as a next step, check the location of the gedit.debug.

[root@localhost ~]# rpm -ql gedit-debuginfo | grep gedit.debug
/usr/lib/debug/usr/bin/gedit.debug
...

Now we know where this debug info is located. So, we can start gdb with this symbol file.

[root@localhost ~]# gdb /bin/gedit --sym=/usr/lib/debug/usr/bin/gedit.debug
GNU gdb (GDB) Fedora (7.4.50.20120120-50.fc17)
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-redhat-linux-gnu".
For bug reporting instructions, please see:
...
Reading symbols from /usr/bin/gedit...Reading symbols from /usr/lib/debug/usr/bin/gedit.debug...done.
done.
(gdb) list
214		gedit_dirs_shutdown ();
215	
216	#ifndef ENABLE_GVFS_METADATA
217		gedit_metadata_manager_shutdown ();
218	#endif
219	}
220	
221	int
222	main (int argc, char *argv[])
223	{
(gdb) 

Yeah, so, you are now ready to debug the file.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com 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

This site uses Akismet to reduce spam. Learn how your comment data is processed.