如何调试C ++运行时错误 [英] how to debug c++ runtime errors

查看:89
本文介绍了如何调试C ++运行时错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用MinGW作为编译器,并使用CodeBlocks作为IDE。如果发生运行时错误,该程序将停止运行,而不会出现任何错误消息。

I'm using MinGW as compiler and CodeBlocks as IDE. When there's a runtime error, the program simply stop working without any error messages. Is it possible to get conventional error messages like the type of error and where it occurs?

推荐答案

我知道这不是一个错误消息吗?真正的答案,但我仍然是新手,因此我无法评论问题。无论如何,与Mats所说的一样,请尝试使用GDB。这是下载页面 http://www.gnu.org/software/gdb/

I know this isn't a real 'answer', but I'm still new, so I can't comment on the questions yet. Anyway, same thing as Mats said, try GDB. Here is the download page http://www.gnu.org/software/gdb/

有很多使用调试器的教程。这是相当不错的。 http://www.cs.cmu.edu/~gilpin/tutorial/

There are plenty of tutorials for using the debugger. This one is fairly good. http://www.cs.cmu.edu/~gilpin/tutorial/

如果您从未使用过调试器,则它基本上逐行运行代码。您可以控制要进行的操作以及停止代码以检查错误的位置。调试器还跟踪其他重要信息,例如变量值,变量地址,循环计数等。

If you never used a debugger, it basically runs your code line by line. You can control how far you want to proceed and where you want the code to stop to check for errors. Debuggers also keep track of other important information like variable values, variable addresses, loop counts, and so on.

如果您不想使用调试器,则始终可以在可能怀疑程序崩溃的地方使用print语句。例如,如果您有一个函数foo(),则可以在该函数的第一行上添加一条打印语句,其内容类似于在函数foo中。但是,如果您有很多代码,此方法可能会变得非常乏味。您还必须记得完成后删除打印语句。

If you don't want to use the debugger, you can always use print statements where you might suspect the program is crashing. For instance, if you have a function foo(), you can put a print statement on the first line of that function saying something like "in function foo". However, this method could become very tedious if you have a large piece of code. You must also remember to remove the print statements when you are finished.

这篇关于如何调试C ++运行时错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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