How to get a stack trace when a C ++ program crashes? (using msvc8 / 2005)

Sometimes my C ++ program crashes in debug mode, and I get a window with a message stating that in some procedures for managing internal memory (access to unallocated memory, etc.), the statement failed. But I donโ€™t know where it came from, because I didnโ€™t have a stack trace. How to get a stack trace, or at least see where it doesn't work in my code (instead of library / built-in procedures)?

+6
c ++ debugging stack-trace visual-studio-2005
source share
8 answers

If you have a crash, you can get information about where the crash occurred, whether you have debugging or release builds. And you can see the call stack even if you are on a computer that does not have source code.

To do this, you need to use the PDB file that was created with your EXE. Place the PDB file in the same directory as the EXE that crashed. Note. Even if you have the same source code, creating twice and using the first EXE and the second PDB will not work. You need to use the exact PDB that was built with your EXE.

Then attach the debugger to the process that crashed. Example: windbg or VS.

Then just check your call stack and also open your threads window. You will need to select the thread that crashed and check it in that thread. Each thread has a different call stack.

If you already have your VS debugger, it will automatically go to the source code, which causes a crash for you.

If an accident occurs inside the library that you are using, you do not have a PDB. You cannot do anything.

+7
source share

If you run the debug version on a machine with VS, it should offer to raise it and see the stack trace.

The problem is that the real problem is no longer in the call stack. If you free the pointer twice, this may lead to the problem being in a different place not related to the program (next time something will turn to heap arrays)

I wrote this blog about some tips to identify a problem in the call stack so you can understand what is going on.

http://www.atalasoft.com/cs/blogs/loufranco/archive/2007/02/06/6-_2200_Pointers_2200_-on-Debugging-Unmanaged-Code.aspx

The best advice is to use the gflags utility to create problems with pointers causing immediate problems.

+3
source share

You can call a mini dump by setting a handler for thrown exceptions. Here's an article that explains everything about minidumps

Google actually implemented its own open source crash handler called BreakPad , which also uses mozilla, I think (that if you want something more serious - a rich and reliable crash handler).

+2
source share

This article describes how to calculate the stack trace.

+2
source share

If I remember correctly, the message box should have a button that says 'retry'. Then this should break the program (in the debugger) in the place where this statement occurred.

0
source share

CrashFinder can help you locate an exception based on the DLL and address of the exception message.
You can take this code and integrate it into your application to automatically generate a stack trace when there is an uncaught exception. This is usually done with __try{} __except{} or with a call to SetUnhandledExceptionFilter , which allows you to specify a callback for all unhandled exceptions.

0
source share

A debugger can also be installed in the client system after opening. This is a decent general way to get information when you donโ€™t have a dump built into your application (maybe for an older version, for which you should still get information).

R. You can install Watson on Windows by: drwtsn32 -i Starting drwtsn32 (without any parameters) will bring up a configuration dialog. This will allow you to create crash dump files that can later be analyzed using WinDbg or something similar.

0
source share

You can use Poppy for this. You just cover some macros through your code and it will collect the stack trace along with the actual parameter values, local variables, loop counts, etc. It is very lightweight, so you can leave it in the release build to collect this information from crashes on end-user machines

-one
source share

All Articles