Using gdb to look at core files

This document explains how ot use gdb, a debugger for the unix environment, to examine a core file. If you have questions on how to compile source code in the unix environment and/or gdb in general, look at the quickstarts for gdb, make and compiling code.

What is a core file?

A core file is an image of a process that has crashed It contains all process information pertinent to debugging: contents of hardware registers, process status, and process data. Gdb will allow you use this file to determine where your program crashed.

How to use gdb to examine core files

First, the program must be compiled with debugging information otherwise the information that gdb can display will be fairly cryptic. Second, the program must have crashed and left a core file. It should tell you if it has left a core file with the message "core dumped".

The command line to start gdb to look at the core file is:

where "program" is the name of the program you're working on. Gdb will then load the program's debugging information and examine the core file to determine the cause of the crash.

The last line that gdb will print before the "(gdb)" prompt will be something like:

This corresponds to the last statement that was attempted which likely caused the crash.

You can find out which function called the current function by using the "up" command which will print out a similar line. The "down" command does the opposite of the "up" command. Finally, to view the entire stack frame, use the "backtrace" command or it's abbreviation "bt".