简体   繁体   English

如何在Visual Studio 2008中进行调试

[英]How to debug in visual studio 2008

I keep getting these line numbers for errors in the external libraries cpp files, i have no way of knowing which part of my code it makes this error. 我一直在外部库cpp文件中获取有关错误的这些行号,但是我无法知道我的代码的哪一部分会导致此错误。 Sometimes it even shows assembly code piece where it crashed... 有时它甚至在崩溃的地方显示汇编代码。

How do i get the line where my own code caused this error? 如何获得我自己的代码导致此错误的行? Or at least a clue which part of my code makes this crash... 或者至少是我的代码的哪一部分导致崩溃的线索...

Sometimes it doesnt even tell any line number, i dont really understand how this debug mode works. 有时它甚至不告诉任何行号,我真的不明白这种调试模式是如何工作的。 I've used application verifier, and it gives some line numbers sometimes. 我使用了应用程序验证程序,有时会提供一些行号。 It looks like its telling me randomly these things... how do i solve this? 看来它随机地告诉我这些事情...我该如何解决?

This is what i get: 这就是我得到的:

First-chance exception at 0x7c812aeb in test.exe: Microsoft C++ exception: std::bad_alloc at memory location 0x0012dd4c..
First-chance exception at 0x7c812aeb in test.exe: Microsoft C++ exception: std::bad_alloc at memory location 0x0012dc50..
First-chance exception at 0x7c812aeb in test.exe: Microsoft C++ exception: std::bad_alloc at memory location 0x0012dc50..
First-chance exception at 0x7c812aeb in test.exe: Microsoft C++ exception: std::bad_alloc at memory location 0x0012dd48..
First-chance exception at 0x7c812aeb in test.exe: Microsoft C++ exception: std::bad_alloc at memory location 0x0012d9a8..
First-chance exception at 0x7c812aeb in test.exe: Microsoft C++ exception: std::bad_alloc at memory location 0x0012dc6c..
First-chance exception at 0x7c812aeb in test.exe: Microsoft C++ exception: std::bad_alloc at memory location 0x0012dcd0..
First-chance exception at 0x7c812aeb in test.exe: Microsoft C++ exception: std::bad_alloc at memory location 0x0012dabc..
First-chance exception at 0x7c812aeb in test.exe: Microsoft C++ exception: std::bad_alloc at memory location 0x0012dabc..
First-chance exception at 0x7c812aeb in test.exe: Microsoft C++ exception: std::bad_alloc at memory location 0x0012dabc..
First-chance exception at 0x7c812aeb in test.exe: Microsoft C++ exception: std::bad_alloc at memory location 0x0012db5c..
First-chance exception at 0x7c812aeb in test.exe: Microsoft C++ exception: std::bad_alloc at memory location 0x0012dabc..
First-chance exception at 0x7c812aeb in test.exe: Microsoft C++ exception: std::bad_alloc at memory location 0x0012dc30..
First-chance exception at 0x7c812aeb in test.exe: Microsoft C++ exception: std::bad_alloc at memory location 0x0012db48..
First-chance exception at 0x7c812aeb in test.exe: Microsoft C++ exception: std::bad_alloc at memory location 0x0012db64..
First-chance exception at 0x7c812aeb in test.exe: Microsoft C++ exception: std::bad_alloc at memory location 0x0012db5c..
First-chance exception at 0x7c812aeb in test.exe: Microsoft C++ exception: std::bad_alloc at memory location 0x0012db48..
First-chance exception at 0x7c812aeb in test.exe: Microsoft C++ exception: std::bad_alloc at memory location 0x0012db04..
First-chance exception at 0x7c812aeb in test.exe: Microsoft C++ exception: std::bad_alloc at memory location 0x0012dabc..
First-chance exception at 0x7c812aeb in test.exe: Microsoft C++ exception: std::bad_alloc at memory location 0x0012da04..
First-chance exception at 0x7c812aeb in test.exe: Microsoft C++ exception: std::bad_alloc at memory location 0x0012dc30..
First-chance exception at 0x7c812aeb in test.exe: Microsoft C++ exception: std::bad_alloc at memory location 0x0012dcd0..

The MSVC debugger is extremely powerful. MSVC调试器非常强大。 The price you pay is it is also complex. 您付出的代价是它也很复杂。

You can tell the debugger to break on any unhandled exception. 您可以告诉调试器在任何未处理的异常上中断。 This is turned off by default. 默认情况下是关闭的。 In your case, you want to break of first-chance exceptions. 对于您的情况,您想打破优先机会例外。 Do this: 做这个:

Go to Debug>Exceptions... In the dialog that comes up, check the boxes next to "C++ Exceptions" and "Win32 Exceptions". 转到Debug> Exceptions ...在出现的对话框中,选中“ C ++ Exceptions”和“ Win32 Exceptions”旁边的框。

Run your program. 运行程序。 It should break when these exceptions occur. 这些异常发生时,它应该会中断。

Keep in mind that first-chance exceptions are used extensively within MFC to communicate between components. 请记住,优先机会异常在MFC中广泛用于在组件之间进行通信。 These are not errors. 这些不是错误。 But you will see them reported int he output window. 但是您会看到它们在输出窗口中报告了它们。 If they go unhandled, that's when it becomes a problem you have to solve. 如果他们不处理,那就是必须解决的问题。

Use breakpoints at the line of code where you want to "pause" program execution. 在要“暂停”程序执行的代码行中使用断点。 That way you will be able to see the program state (the values of variables, etc, etc). 这样,您将能够看到程序状态(变量的值等)。

Here you have a series of tutorials on how to setup everything, to get debugging. 在这里,您有一系列有关如何设置所有内容以及如何进行调试的教程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM