Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Printing the stack trace in C++ (MSVC)? [closed]

Tags:

c++

visual-c++

qt

In my C++ application (developed with Visual Studio 2003) and Qt4, I'd like to print the stack trace from a specific line of code, either to the console output or into a file.

What would it take ? Is Qt of any help to do this ?

like image 686
Jérôme Avatar asked Nov 19 '08 13:11

Jérôme


People also ask

How to Show stack trace in Visual Studio?

Visually trace the call stack In the Call Stack window, open the shortcut menu. Choose Show Call Stack on Code Map (Ctrl + Shift + `).

How to open call stack window in Visual Studio?

To open the Call Stack window in Visual Studio, from the Debug menu, choose Windows>Call Stack. To set the local context to a particular row in the stack trace display, select and hold (or double click) the first column of the row.

How to get the call stack in c#?

Get Call Stack [C#] Call stack is represented by StackTrace class and a method call is represented by StackFrame class. You can get the frames using StackTrace. GetFrames method. It returns array of frames.

What is call stack in debugging?

The call stack is a list of all the active functions that have been called to get to the current point of execution. The call stack includes an entry for each function called, as well as which line of code will be returned to when the function returns.


3 Answers

StackWalker by Jochen Kalmbach [MVP VC++] and available on codeproject is probably the easiest way to do this. It wraps up all of the details of dealing with the underlying StackWalk64 API.

like image 194
Len Holgate Avatar answered Oct 03 '22 07:10

Len Holgate


It's not in the public Qt API, but if you look in

$QTDIR/src/corelib/kernel/qcrashhandler.*

you can see the beginnings of a cross-platform implementation of exactly this.

like image 34
Michael Bishop Avatar answered Oct 03 '22 07:10

Michael Bishop


StackWalk64 in the dbghelp.dll library should do what you're looking for.

like image 38
Nik Avatar answered Oct 03 '22 07:10

Nik