Linux环境下的调试器—gdb

来源:互联网 发布:lic授权软件破解 编辑:程序博客网 时间:2024/05/16 03:30

一、含义

gdb是GNU发布的一款功能强大的程序调试工具。GDB主要完成下面三个方面的功能:
1、启动被调试程序。
2、让被调试的程序在指定的位置停住。
3、当程序被停住时,可以检查程序状态-变量值

二、简单命令示例

$ gcc -g test.c -o test
$ gdb test
GNU gdb Red Hat Linux (6.3.0.0-1.21rh)
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/libthread_db.so.1".
(gdb)

三、编译步骤

1.编译生成可执行文件:
gcc -g tst.c -o tst
2.启动GDB
gdb tst
3. 在main函数处设置断点
break main
4. 运行程序
run
5. 单步运行
next
6. 继续运行
continue

#include <stdio.h>


void main()


{
int i;
long result = 0;
for(i=1; i<=100; i++)
{
result += i;
}
printf("result = %d \n", result );


}


0 0