简体   繁体   中英

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. 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. 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".

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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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