gdb调试1+2+...100 C语言程序:
[root@localhost ilysm]# vim gg.c
[root@localhost ilysm]# gcc -g gg.c -o gg[root@localhost ilysm]# ./gg
5050
[root@localhost ilysm]# gdb gg
GNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-64.el7
Copyright (C) 2013 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 "x86_64-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /run/media/ilysm/gg...done.
(gdb) l
1 #include<stdio.h>
2 void main()
3 {
4 int i=1,sum=0;
5 while(i<=100) {
6 sum+=i;
7 i++;
8 }
9 printf("%d\n",sum);
10 }
(gdb) b 5
Breakpoint 1 at 0x400546: file gg.c, line 5.
(gdb) r
Starting program: /run/media/ilysm/gg
Breakpoint 1, main () at gg.c:5
5 while(i<=100) {
Missing separate debuginfos, use: debuginfo-install glibc-2.17-78.el7.x86_64
(gdb) p /x i
$1 = 0x1
(gdb) p /d i
$2 = 1
(gdb) p /o i
$3 = 01
(gdb) p /l i
$4 = Undefined output format "l".
(gdb) p /t i
$5 = 1
(gdb) i b
Num Type Disp Enb Address What
1 breakpoint keep y 0x0000000000400546 in main at gg.c:5
breakpoint already hit 1 time
(gdb) step
6 sum+=i;
(gdb) l
1 #include<stdio.h>
2 void main()
3 {
4 int i=1,sum=0;
5 while(i<=100) {
6 sum+=i;
7 i++;
8 }
9 printf("%d\n",sum);
10 }
(gdb) next
7 i++;
(gdb) c
Continuing.
5050
[Inferior 1 (process 6829) exited with code 05]
(gdb) p /x i
No symbol "i" in current context.
(gdb) quit