您的位置:首页 > 博客中心 > 数据库 >

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

时间:2022-03-10 17:59

1、编译源代码

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

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

2、启动调试

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

gxlsystem.com,布布扣

3、设置断点并启动运行

(gdb)break main
(gdb)start

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

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

gxlsystem.com,布布扣

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.

 

参考资料:

windows下使用MinGW的调试工具gdb.exe调试C程序,布布扣,bubuko.com

热门排行

今日推荐

热门手游