里仁教育讲解调试器GDB的使用.docVIP

  • 3
  • 0
  • 约 5页
  • 2016-08-22 发布于重庆
  • 举报
里仁教育讲解调试器GDB的使用

调试器GDB的使用及GDB的基础命令常识 Linux包含了一个叫GDB的GNU调试程序。GDB是一个用来调试C和C++程序的强力调试器。它使你能在程序运行时观察的内部结构和内存的使用情况。一般来说:要一下4个方面的功能,里仁教育嵌入式学院(/)讲解: 启动需要调试程序,按照自定义的方式运行。 设置断点,断点可以是条件表达式。 程序暂停时的变量检查。 动态改变程序的执行环境。 从上面来看。GDB和一般的调试工具没有什么两样,基本上也是完成这些功能,在细节上,你会发现GDB这个调试工具的强大,命令行的调试工具却有着图形化工具所不能完成的功能。 里仁嵌入式培训——GDB的调试过程: 源程序://test.c #includestdio.h Int func(int n) { Int sum=0,i; For(i=0;in;i++) { Sum+=i; } Return sum; } Void main() { Int i=; Long=result=0; For(i=0;i=100;i++) { Result+=i; } Printf(result[1-100]=%d\n result); Printf(result[1-250]=%d\n func(250)); } 编译生成执行文件(注意要加上-g调试选项) Src/testGcc-g test.c -o test 使用GDB调试: Src/testGDB test //启动GDB GNU GDB 5.1.1 Copyright 2002 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. Thus GDB was configured as i386-suse=linux..... (gdb) //命令相当于list,从第一行开始列出源码 #includestdio.h Int func(int n) { Int sum=0,i; For(i=0;in;i++) { Sum+=i; } Return sum; (gdb) //直接按回车键表示重复上一次命令 } Main() { Int i=; Long result=0; For(i=1;i=100;i++) { Result+=i; } (gdb) break; //设置断点 Breakpoint 1 at 0x8048496: file test.c; (gdb) break func; //设置断点,在函数func()入口处 Breakpoint 2 at 0x8048456: file test.c; (gdb) info break; //查看断点信息 Num type disp address what 1 breakpoint keep y 0x8048496 in main at Test.c; 2 breakpoint keep y 0x8048456 in func at test.c; (gdb) r //运行程序,run命令简写 Staring program:/home/zhum/src/test/test breakpoint 1,main() Test.c:17 //在断点处停住 Long result=0; (gdb) n; //单条语句执行。Next命令简写 For(i=1;i=100;i++) (gdb) n //单条语句执行。Next命令简写 Result += i; (gdb) n //单条语句执行。Next命令简写 For(i=1;i=100;i++) (gdb) n //单条语句执行。Next命令简写 Result += i; (gdb) c //继续运行程序,continue命令简写

文档评论(0)

1亿VIP精品文档

相关文档