GDB: GDB is a tool for debug the c program.

Here is test.c source code.

#include <stdio.h>

int main(){

        int i;

       for (i = 0; i < 1000; ++i)

             printf("i = %d\n", i);

      printf("Hello world!\n");

     return 0;


follow the commands:

1. $gcc -g test.c -o test

2.$gdb test

Here is the message for gdb, eg:

GNU gdb (GDB) Red Hat Enterprise Linux (7.1-28.el6)
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-redhat-linux-gnu".
For bug reporting instructions, please see:
Reading symbols from /home/zab08/Desktop/Linux/gdb/test...done.

3.(gdb)break main

Breakpoint 1 at 0x80483fd: file test.c, line 5.


Breakpoint 1, main () at test.c:5
5        for(i = 0; i < 10000; ++i)


7            printf("i = %d\n", i);

......(to much)


we have 6 commands in the example.

1. $gcc -g test.c -o test

means compling the test.c by gdb style to the exeute file named test.

2.$gdb test

means use gdb to debug the test.

3.(gdb)break main

means make a break point on the main function. (ps: (gdb) means we use gdb commands here)


means run the program.


means execute program execute one step.


means continue execute the progream util stop.


a short tutorial for gdb, more detail use google please, have fun and enjoy it!