User Tools

Site Tools


haas:spring2013:common:intro-to-gdb

Introduction to GDB

Overview

Google defines a debugger as:

  • A computer program that assists in the detection and correction of errors in computer programs.

There is an important concept we must acknowledge here- a debugger is a program, just like the programs we've been writing.

But as a program, it works with other programs. It is a program for programs. See the depth there?

GDB, the GNU Debugger, is certainly not the only debugger in existence, but it is most likely among the most available general purpose debuggers we can get our hands on.

Learning one debugger, like GDB, well will introduce you to many important concepts that all debuggers share (some just may enable certain actions better than others, or be more specialized for certain tasks– but they all, as debuggers, share a common underlying functionality).

The prime value we are looking to get out of our debugger use is to aid us in finding (and therefore fixing) runtime and logical errors in programs we write. It is also a phenomenal investigative tool, allowing us to see what a particular piece of code is ACTUALLY doing, as far down as the assembly instructions, but in our case the line-by-line execution of our programs in C.

Debugger Features

Common fundamental features a debugger may provide:

  • stepping: the ability to comb over your running program a line at a time. Often referred to as “single step”- we can execute a line of code (much as an interpreter might), and analyze the state of variables. This is great for seeing if things are as they should be at various points in a program's execution (into a function, a particular iteration of a loop, etc.)
  • viewing data: as indicated in stepping- in the debugger we can view the state of any existing variable or memory location at any stage of the program's execution.
  • breakpoints: the magic that makes single stepping even more useful. A breakpoint is us communicating to the debugger where we'd like it to pause execution so that we may check out the current state of things. By strategically setting breakpoints throughout a program, we can run through the sections of code we're not interested, then break to analyze areas of particular interest.
  • continue: the cessation of single step mode, when we wish to resume regular execution (until the next breakpoint is encountered).
  • manipulating data: we also have the ability to modify existing data, such as variables… setting them to desired values and watching what will happen in our code.

There are many, many more features, but we're just getting started, and these are by far the most useful for us in our endeavors.

haas/spring2013/common/intro-to-gdb.txt · Last modified: 2012/09/29 16:12 by 127.0.0.1