如何在Windows上调试C程序? [英] How do you debug a C program on Windows?

查看:67
本文介绍了如何在Windows上调试C程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从来没有使用过调试器,现在该尝试一下了.MinGW似乎与我一直在尝试使用的GDB一起提供.应该从命令行运行gdb并键入 run myprog.exe 会启动调试器,但是当我这样做时,我会得到

I've never used a debugger and the time has come to give them a try. MinGW appears to come with GDB which I've been trying to use. Supposdly running gdb from the command line and typing run myprog.exe starts the debugger but when I do this I get

启动程序:C:\ MinGW \ bin \ myprog.exe MyProg.exe[新线程1828.0xd8c]打开文件时出错.[下级1(过程1828)以代码02退出]

Starting program: C:\MinGW\bin\myprog.exe MyProg.exe [New Thread 1828.0xd8c] Error opening file. [Inferior 1 (process 1828) exited with code 02]

如何继续进行?有什么更简单的方法?

How to proceed or what's an easier way?

特别是我正在尝试清除未定义的行为.

推荐答案

由于程序终止,因此您需要设置一个断点才能看到任何内容.在运行行之前尝试 break main .然后,您可以在命令行 next (下一行), step (进入/退出函数调用), print expression (其中expression 可以是变量名,函数调用或计算), display expression (与print相同,但仅在每个提示之前打印).在任何给定点,您都可以键入 backtrace 来获取调用堆栈.您甚至可以输入 up down 来向上移动堆栈,以便您可以打印较高的局部变量.

Since your program terminates, you'll need to set a breakpoint to see anything. Try break main before the run line. Then you can do commands line next (next line), step (step into/outof function calls), print expression (where expression can be a variable name or a function-call or a calculation), display expression (same as print, but prints just before each prompt). At any given point you can type backtrace to get a call stack. You can even type up and down to move up the callstack, so you can print higher local variables.

这篇关于如何在Windows上调试C程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆