GNU Debugger - An Example Session

An Example Session

Consider the following source-code written in C:

#include #include #include size_t foo_len (const char *s) { return strlen (s); } int main (int argc, char *argv) { const char *a = NULL; printf ("size of a = %d\n", foo_len (a)); exit (0); }

Using the GCC compiler on GNU/Linux, the code above must be compiled using the -g flag in order to include appropriate debug information on the binary generated, thus making it possible to inspect it using GDB. Assuming that the file containing the code above is named example.c, the command for the compilation could be:

gcc example.c -g -o example

And the binary can now be run:

# ./example Segmentation fault

Since the example code, when executed, generates a segmentation fault, GDB can be used to inspect the problem.

# gdb ./example GNU gdb (GDB) Fedora (7.3.50.20110722-13.fc16) Copyright (C) 2011 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later

Read more about this topic:  GNU Debugger

Famous quotes containing the word session:

    I need not tell you of the inadequacy of the American shipping marine on the Pacific Coast.... For this reason it seems to me that there is no subject to which Congress can better devote its attention in the coming session than the passage of a bill which shall encourage our merchant marine in such a way as to establish American lines directly between New York and the eastern ports and South American ports, and both our Pacific Coast ports and the Orient and the Philippines.
    William Howard Taft (1857–1930)