[root@vm-dev wangjun]# ls
a.c a.cxx a.out b.cpp b.out test.c test.debug
[root@vm-dev wangjun]# gdb
GNU gdb Red Hat Linux (6.3.0.0-1.132.EL4rh)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "i386-redhat-linux-gnu".
(gdb) file test.debug
Reading symbols from /root/wangjun/test.debug...done.
Using host libthread_db library "/lib/tls/libthread_db.so.1".
(gdb) list
1 #include <stdio.h>
2 main()
3 {
4 int i,j,k;
5 for(i=1;i<=4;i++)
6 {
7 for(j=1;j<=4;j++);
8 {
9 if(i>=j)
10 {
(gdb)
11 k=i+j;
12 printf("%d+%d=%d ",i,j,k);
13 }
14 }
15 printf("\n");
16 }
17 }
(gdb) q
[root@vm-dev wangjun]# ls
a.c a.cxx a.out b.cpp b.out test.c test.debug
[root@vm-dev wangjun]# vi test.c
[root@vm-dev wangjun]# ls
a.c a.cxx a.out b.cpp b.out test.c test.debug
[root@vm-dev wangjun]# gcc test.c
[root@vm-dev wangjun]# gcc -g -o test.debug test.c
[root@vm-dev wangjun]# gdb
GNU gdb Red Hat Linux (6.3.0.0-1.132.EL4rh)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "i386-redhat-linux-gnu".
(gdb) file test.debug
Reading symbols from /root/wangjun/test.debug...done.
Using host libthread_db library "/lib/tls/libthread_db.so.1".
(gdb) list
1 #include <stdio.h>
2
3 main()
4 {
5 int i,j,k;
6 for(i=1;i<=4;i++)
7 {
8 for(j=1;j<=4;j++);
9 {
10 if(i>=j)
(gdb)
11 {
12 k=i+j;
13 printf("%d+%d=%d ",i,j,k);
14 }
15 }
16 printf("\n");
17 }
18 }
(gdb)
Line number 19 out of range; test.c has 18 lines.
(gdb) break 6
Breakpoint 1 at 0x8048384: file test.c, line 6.
(gdb) break
No default breakpoint address now.
(gdb) break 11
Breakpoint 2 at 0x80483ad: file test.c, line 11.
(gdb) break 12
Note: breakpoint 2 also set at pc 0x80483ad.
Breakpoint 3 at 0x80483ad: file test.c, line 12.
(gdb) break 13
Breakpoint 4 at 0x80483b6: file test.c, line 13.
(gdb) run
Starting program: /root/wangjun/test.debug
Breakpoint 1, main () at test.c:6
6 for(i=1;i<=4;i++)
(gdb) step
8 for(j=1;j<=4;j++);
(gdb) print i
$1 = 1
(gdb) step
10 if(i>=j)
(gdb) step
16 printf("\n");
(gdb) step
6 for(i=1;i<=4;i++)
(gdb) step
8 for(j=1;j<=4;j++);
(gdb) step
10 if(i>=j)
(gdb) step
16 printf("\n");
(gdb) step
6 for(i=1;i<=4;i++)
(gdb) step
8 for(j=1;j<=4;j++);
(gdb) step
10 if(i>=j)
(gdb) step
16 printf("\n");
(gdb) q
The program is running. Exit anyway? (y or n) y
[root@vm-dev wangjun]#