windows下使用MinGW的调试工具gdb.exe调试C程序

1、编译源代码

C:MinGW\bin>gcc.exe -g -o program.exe program.c

  编译选项上要加上“g”,这样生成的目标程序会含有调试内容,再用gdb调试的时候才能使用。显然加上“g”选项生成的应用程序会比不加的大,但两者运行时没有差别。

2、启动调试

C:MinGW\bin>gdb.exe program.exe

3、设置断点并启动运行

(gdb)break main
(gdb)start

  不能直接start,因为程序运行太快了,直接start就运行到程序停止的地方。

  break main在start命令之前,设置程序运行的断点,这样start后程序就运行到main处中断。也可以用命令“break FILENAME:LINENO",程序会在FILENAME指定的文件的LINENO指定行停下,例如"break mycode.cpp:4”。

4、其他命令

  • print VARNAME. That's how you print values of variables, whether local, static, or global. For example, at the for loop, you can type print temp to print out the value of the temp variable.
  • step This is equivalent to "step into".
  • next or adv +1 Advance to the next line (like "step over"). You can also advance to a specific line of a specific file with, for example, adv mycode.cpp:8.
  • bt Print a backtrace. This is a stack trace, essentially.
  • continue Exactly like a "continue" operation of a visual debugger. It causes the program execution to continue until the next break point or the program exits.

 

参考资料:http://stackoverflow.com/questions/4671900/how-do-i-use-the-mingw-gdb-debugger-to-debug-a-c-program-in-windows

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值