2、从上面看来,GDB和一般的调试工具没有什么两样,基本上也是完成这些功能,不过在细节上,你会发现GDB这个调试工具的强大,大家可能比较习惯了图形化的调试工具,但有时候,命令行的调试工具却有着图形化工具所不能完成的功能。让我们一一看来。-->一个调试示例源程序:tst.c1 #include 23 int func(int n)4 {5 int sum=0,i;6 for(i=0; i
4、 Inc.GDB is free software, covered by the GNU General Public License, and you arewelcome 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 c
5、onfigured as "i386-suse-linux"(gdb) l <-------------------- l命令相当于list,从第一行开始例出原码。1 #include 23 int func(int n)4 {5 int sum=0,i;6 for(i=0; i
6、 i<=100; i++)19 {20 result += i;(gdb) break 16 <-------------------- 设置断点,在源程序第16行处。Breakpoint 1 at 0x: file tst.c, line 16.(gdb) break func <-------------------- 设置断点,在函数func()入口处。Breakpoint 2 at 0x: file tst.c, line 5.(gdb) info break <-------------------- 查看断点信息。Num Type Disp Enb Addr
7、ess What1 breakpoint keep y 0x in main at tst.c:162 breakpoint keep y 0x in func at tst.c:5(gdb) r <--------------------- 运行程序,run命令简写Starting program: /home/hchen/test/tstGDB 命令行参数启动 GDB:l gdbexecutablel gdb-eexecutable-ccore-filel gdbexecutable-pidprocess-id(使用命令 'ps