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:

    The bar is the male kingdom. For centuries it was the bastion of male privilege, the gathering place for men away from their women, a place where men could go to freely indulge in The Bull Session ... the release of the guilty anxiety of the oppressor class.
    Shulamith Firestone (b. 1945)