Using GNU's GDB Debugger

Administrata

By Peter Jay Salzman


Previous: Table Of ContentsNext: Introduction



Why Write This Tutorial?

This is one of the most comprehensive GDB tutorials on the Internet. It's more than you'd find in most books, which tend to discuss GDB as an afterthought. I initially wrote this because I couldn't find a good GDB tutorial. The only source of information about GDB is GNU's GDB User's Manual (this was 1997, so a long time ago by now), but learning GDB from it is like learning a foreign language from a dictionary.

I'll be using sample programs, and there will be links to the source code in each section that uses them, along with compilation instructions. I urge you to download the code and follow along with the examples. Following along, doing it yourself as you read, is really the second best way to learn.

The best way to learn is by playing. Go beyond the scope of what I talk about. Use your knowledge in ways neither of us anticipated. Not everyone has the capacity to "play" with knowledge, but if you're one of them, experimenting with your own ideas and curiosities will take you far.



Acknowledgements And Dedication

I'm in a perpetual state of learning, and thanks goes to the following people who've helped me understand C and GDB:



Authorship And Copyright

This entire tutorial is copyright (c) 2004 Peter Jay Salzman, p@dirac.org. Permission is granted to copy, distribute and/or modify it under the terms of The Open Source License, version 1.1. You can find a copy of this license at opensource.org/licenses/osl.php

The canonical and most updated version of this document can be found at www.dirac.org/linux/gdb.

If you want to create a derivative work or publish this document for commercial purposes, I would appreciate it if you contacted me first. This will give me a chance to give you the most recent version. It'll also stroke my ego. I'd also appreciate either a copy of whatever it is you're doing or a spinach, garlic, mushroom, feta cheese and artichoke heart pizza.



About Exercises

There are exercises at the end of most sections. The exercises are mandatory. These exercises are designed to both cover topics I don't formally cover, and give you experience using your new-found skills.

There are topics I don't cover except for in the exercises. This isn't because I'm lazy. It's because I want you to think. Use your noggin to begin understanding concepts in your own words, not in my words. I want you to develop intuition. The best debugging tool is not GDB. And it certainly isn't printf(). The best debugging tool is your brain.



Thank Yous

The following people sent in corrections (remove the "ZZZ" in the email address):



A Plug For The Electronic Frontier Foundation (EFF)

If you're not a member of the EFF, you must stop everything you're doing and become a member right this moment. 9/11 was a horrible tragedy; I was in New York City at the time and witnessed the chaos with my own two eyes. I love my country, and am a very proud United States citizen, but the steady erosion of our freedoms and civil liberty is another tragic casualty of the post 9/11 era. I'm very worried for my country.

The EFF is the most important defense we have in protecting our on-line and digital rights. If you have any interest in protecting your civil liberties in a digital age that has gone out of balance, please read their very short . Please consider becoming a member of the EFF. Honestly, it's only the price of a pizza. Or the cost of two movie tickets plus popcorn.



A Request For Help

This tutorial took (takes?) more time than I care to admit. It's a tremendous job. If you found this tutorial to be at all useful, please consider helping me maintain and actively develop it. There are many ways you can help. Pick one that suits you or your talents (in no particular order):

I may not respond to all email. It really depends on how busy my life is at the moment (this isn't my whole life, you see). If I have time, I'll try to reply. But please don't get upset if I can't reply. It means I'm swamped with work and can't afford to reply. Rest assured, even if you don't hear from me, receiving an email from you is still helpful. It reassures me that people are reading and benefiting from my work.



Links to my GDB pages

Some day I'd like to see my GDB tutorial as the first return on a Google search for "GDB tutorial". There are currently (Jan 2006) four returns before my tutorial. If you find my tutorial to be at all useful, please link to it and give me some Google-love. :) I'll return the favor. So far, these GDB pages have been linked to by:

  1. The Debian GNU/Linux package comes with a file usr/share/doc/gdb/README.Debian that contains:
    GDB is a complex program.  It comes with an Info manual (`info gdb' or your
    favorite other info browser), which serves as a good command reference.
    
    There are also a number of books and tutorials devoted to GDB.  One
    particularly useful guide is Peter Jay Salzman's, at:
      http://www.dirac.org/linux/gdb/
    
    I nearly fainted when I saw that, since the person who wrote this is probably Daniel Jacobowitz, who is a lead developer of GDB and a member of the GDB steering committee. Quite an honor!

If you link to my pages or use these pages for training material, please let me know so I can put you and a link to your work up in this section (or simply describe it), which I'm officially calling my "ego page".  :)

 



back   Back: Table Of Contentsup  Up to the TOCNext: Introduction   next
email  Email comments and corrections
printable  Printable version