gdb_debugger - Last revised: 2009-Mar-07 Using the GDB...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Last revised: 2009-Mar-07 Using the GDB Debugger 1 Overview The webpage for the GDB debugger ( ) provides this introduction: GDB, the GNU Project debugger, allows you to see what is going on inside another program while it executes or what another program was doing at the moment it crashed. GDB can do four main kinds of things (plus other things in support of these) to help you catch bugs in the act: Start your program, specifying anything that might affect its behavior. Make your program stop on specified conditions. Examine what has happened, when your program has stopped. Change things in your program, so you can experiment with correcting the effects of one bug and go on to learn about another. The program being debugged can be written in C, C++ (and many other lan- guages). Those programs might be executing on the same machine as GDB (native) or on another machine (remote). GDB can run on most popular UNIX and Microsoft Windows variants. 2 Example Well use a contrived example in C++ based on the C code from the 2002 version of Guide to Faster, Less Frustrating Debugging by Norman Matloff (you can find this with a Google search). The source file is check_primes.cpp . The program, when working, will output a list of all primes less than or equal to an upper bound supplied by the user. 1. Compile and link the program using make_check_primes . The makefile is set to run without any of our usual warning switches; you should see this: g++ -c check_primes.cpp -o check_primes.o g++ -o check_primes check_primes.o If we used all of the warning options from our standard Makefile, we would catch many of the errors in check_primes.cpp at compile time. Since we want to illustrate gdb, well compile without those options (but you should ALWAYS use the warnings;-Wall will take care of most of the problems). 1 2. Try running the program check_primes . When it asks for an upper bound, enter 20 (without the quotes!). The program will exit with a Segmentation fault. This error means that the program tried to deference a pointer containing a bad value. (What?...
View Full Document

This note was uploaded on 06/30/2011 for the course PHYSICS 780 taught by Professor Furnstahl during the Winter '11 term at Ohio State.

Page1 / 4

gdb_debugger - Last revised: 2009-Mar-07 Using the GDB...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online