2breakpointkeep y0x08048456 in func at tst.c:5
(gdb) r<---------------------运行程序,run命令简写
Starting program: /home/hchen/test/tst
Breakpoint 1, main () at tst.c:17<----------在断点处停住。
17long result = 0;
(gdb) n<---------------------单条语句执行,next命令简写。
18for(i=1; i<=100; i)
(gdb) n
20result = i;
(gdb) n
18for(i=1; i<=100; i)
(gdb) n
20result = i;
(gdb) c<---------------------继续运行程序,continue命令简写。
Continuing.
result[1-100] = 5050<----------程序输出。
Breakpoint 2, func (n=250) at tst.c:5
5int sum=0,i;
(gdb) n
6for(i=1; i<=n; i)
(gdb) p i<---------------------打印变量i的,print命令简写。
$1 = 134513808
(gdb) n
8sum=i;
(gdb) n
6for(i=1; i<=n; i)
(gdb) p sum
$2 = 1
(gdb) n
8sum=i;
(gdb) p i
$3 = 2
(gdb) n
6for(i=1; i<=n; i)
(gdb) p sum
$4 = 3
(gdb) bt<---------------------查看函数堆栈。
#0func (n=250) at tst.c:5
#10x080484e4 in main () at tst.c:24
#20x400409ed in __libc_start_main () from /lib/libc.so.6
(gdb) finish<---------------------退出函数。
Run till exit from #0func (n=250) at tst.c:5
0x080484e4 in main () at tst.c:24
24printf("result[1-250] = %d /n", func(250) );
Value returned is $6 = 31375
(gdb) c<---------------------继续运行。
Continuing.
result[1-250] = 31375<----------程序输出。
Program exited with code 027. <--------程序退出,调试结束。
(gdb) q<---------------------退出gdb。
hchen/test>
好了,有了以上的感性认识,还是让我们来系统地认识一下gdb吧。
使用GDB
————
启动GDB的方法有以下几种:
1、gdb <program>
program也就是你的执行文件,一般在当然目录下。
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-40593-2.html
我姐姐明明最高
感觉是美国品牌评选