gdb 命令:是GNU的调试工具
【内部命令】
b/break :设置断点
delete :清除断点
continue :继续终止的程序
run/r :运行程序
step/s :单步运行,进入函数
next/n :单步运行,不进入函数
list/l :显示源代码,每次显示10行
bt/backtrace :显示栈中的内容
print/p :显示queue中的内容
kill :终止正在调试的程序
file :装入将要调试的文件
q :退出gdb
[root@vm-dev ~]# cat test.c #查看文件内容 #include int func(int n) { int sum=0,i; for(i=0; i{ sum+=i; } return sum; } main() { int i; long result = 0; for(i=1; i<=100; i++) { result += i; } printf(“result[1-100] = %d “, result ); printf(“result[1-250] = %d “, func(250) ); } [root@vm-dev ~]# gcc -g -o test test.c #准备调试用的程序 [root@vm-dev ~]# ./test #运行程序 result[1-100] = 5050 result[1-250] = 31125 [root@vm-dev ~]# gdb test #启动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“...Using host libthread_db library “/lib/tls/libthread_db.so.1“. (gdb) l #列出原始代吗 7 { 8 sum+=i; 9 } 10 return sum; 11 } 12 13 main() 14 { 15 int i; 16 long result = 0; (gdb) break 16 #设置断点 Note: breakpoint 1 also set at pc 0x80483b4. Breakpoint 2 at 0x80483b4: file test.c, line 16. (gdb) info break #查看断点信息 Num Type Disp Enb Address What 1 breakpoint keep y 0x080483b4 in main at test.c:16 2 breakpoint keep y 0x080483b4 in main at test.c:16 (gdb) r #运行程序 Starting program: /root/test Breakpoint 1, main () at test.c:16 16 long result = 0; #遇到断点停止 (gdb) c #继续运行 Continuing. result[1-100] = 5050 result[1-250] = 31125 Program exited with code 027. (gdb) q #退出调试
评论(1)
- wsg回复(2020-06-11 16:07:37): [回复]