| Version: 3.3.1

Public Member Functions | Protected Member Functions | List of all members
wxStackWalker Class Referenceabstract
Class List by Category » Debugging

`#include <wx/stackwalk.h>`

## Detailed Description

wxStackWalker allows an application to enumerate, or walk, the stack frames (the function callstack).

It is mostly useful in only two situations: inside wxApp::OnFatalException function to programmatically get the location of the crash and, in debug builds, in wxApp::OnAssertFailure to report the caller of the failed assert.

wxStackWalker works by repeatedly calling the wxStackWalker::OnStackFrame method for each frame in the stack, so to use it you must derive your own class from it and override this method.

This class will not return anything except raw stack frame addresses if the debug information is not available. Under Microsoft Windows this means that the PDB file matching the program being executed should be present. Note that if you use Microsoft Visual C++ compiler, you can create PDB files even for the programs built in release mode and it doesn't affect the program size (at least if you don't forget to add `/opt`:ref option which is suppressed by using `/debug` linker option by default but should be always enabled for release builds). If your compiler doesn't provide a direct way of generating PDB files but does produce debug information in the older "Code View" format or compatible, which is the case for MinGW, you can use `cv2pdb` tool available at https://github.com/rainers/cv2pdb to create PDB for your binaries which will work well when using this class.

Under Unix, you need to compile your program with debugging information (usually using `-g` compiler and linker options) to get the file and line numbers information, however function names should be available even without it. Of course, all this is only true if you build using a recent enough version of GNU libc which provides the `backtrace()` function needed to walk the stack.

See Debugging for how to make it available.

##

Library: wxBase
Category: Debugging

See also
  wxStackFrame

## Public Member Functions
| wxStackWalker (const char *argv0=nullptr)
| Constructor does nothing, use Walk() to walk the stack. More...
virtual | ~wxStackWalker ()
| Destructor does nothing either but should be virtual as this class is used as a base one. More...
virtual void | Walk (size_t skip=1, size_t maxDepth=wxSTACKWALKER_MAX_DEPTH)
| Enumerate stack frames from the current location, skipping the initial number of them (this can be useful when Walk() is called from some known location and you don't want to see the first few frames anyhow; also notice that Walk() frame itself is not included if skip = 1). More...
virtual void | WalkFromException (size_t maxDepth=wxSTACKWALKER_MAX_DEPTH)
| Enumerate stack frames from the location of uncaught exception. More...

## Protected Member Functions
virtual void | OnStackFrame (const wxStackFrame &frame)=0
| This function must be overridden to process the given frame. More...

## Constructor & Destructor Documentation

## ◆ wxStackWalker()

wxStackWalker::wxStackWalker | ( | const char * | argv0 = `nullptr` | ) |

Constructor does nothing, use Walk() to walk the stack.

## ◆ ~wxStackWalker()

virtual wxStackWalker::~wxStackWalker | ( |  | ) |
| virtual

Destructor does nothing either but should be virtual as this class is used as a base one.

## Member Function Documentation

## ◆ OnStackFrame()

virtual void wxStackWalker::OnStackFrame | ( | const wxStackFrame & | frame | ) |
| protected pure virtual

This function must be overridden to process the given frame.

## ◆ Walk()

virtual void wxStackWalker::Walk | ( | size_t | skip = `1`,
|  | size_t | maxDepth = `wxSTACKWALKER_MAX_DEPTH`
| ) |  |
| virtual

Enumerate stack frames from the current location, skipping the initial number of them (this can be useful when Walk() is called from some known location and you don't want to see the first few frames anyhow; also notice that Walk() frame itself is not included if skip = 1).

Up to maxDepth frames are walked from the innermost to the outermost one. It defaults to wxSTACKWALKER_MAX_DEPTH.

## ◆ WalkFromException()

virtual void wxStackWalker::WalkFromException | ( | size_t | maxDepth = `wxSTACKWALKER_MAX_DEPTH` | ) |
| virtual

Enumerate stack frames from the location of uncaught exception.

This method can only be called from wxApp::OnFatalException().

Up to maxDepth frames are walked from the innermost to the outermost one. It defaults to wxSTACKWALKER_MAX_DEPTH.