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 ?
Visually trace the call stack In the Call Stack window, open the shortcut menu. Choose Show Call Stack on Code Map (Ctrl + Shift + `).
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.
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.
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.
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.
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.
StackWalk64 in the dbghelp.dll library should do what you're looking for.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With