Showing posts with label gdb. Show all posts
Showing posts with label gdb. Show all posts

Saturday, February 20, 2010

gdb

One of my coworkers has recently reintroduced me to gdb. My previous experience is using it for a couple of fun labs in my junior-level architecture class at BYU. I admit, however, that after these labs I reverted to printfs (and the like) as my preferred debugging tool. Not sophisticated or elegant, but it gets the job done. Most of the time.

There are a lot of useful tools from my architecture class site. The class uses Computer Programming: A Programmer's Perspective as its main text. That book comes with many great resources, including the labs and a student page. One lab uses gdb to determine the inputs for which an unknown program is looking, and another uses it to exploit a buffer overflow bug. Pretty fun.

To get started with gdb, try some of these:

  • gdb program - this starts up gdb
  • set args args - allows you to set arguments for the program
  • r - runs the program in gdb
  • bt - prints out a stack trace from the current program location
  • print variable - print out the contents of a given variable or memory location
  • up # - move up the call stack
  • down # - move down the call stack

Of course, there is much more to gdb. A good place to look for additional information is GDB's website or its wikipedia article. To learn gdb, I suggest going to my architecture class' book's student page. It has links for tutorials and reference cards. It points to some high-quality resources compiled by Norman Matloff (professor at UC Davis whom I have never met but seems like an awesome guy).