编译 调试 练习

[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]#    

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值