Linux 6nd Day

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 <http://gnu.org/licenses/gpl.html>
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:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/zab08/Desktop/Linux/gdb/test...done.
(gdb)

3.(gdb)break main

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

4.(gdb)run

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

5.(gdb)n

7            printf("i = %d\n", i);
6.(gdb)c

......(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)

4.(gdb)run

means run the program.

5.(gdb)n

means execute program execute one step.

6.(gdb)c

means continue execute the progream util stop.

 

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

你可能感兴趣的:(linux,linux,gdb,职场,休闲)