2008-03-08 08:52:38 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: stackwalk.h
|
2008-03-10 11:24:38 -04:00
|
|
|
// Purpose: interface of wxStackWalker
|
2008-03-08 08:52:38 -05:00
|
|
|
// Author: wxWidgets team
|
|
|
|
// RCS-ID: $Id$
|
2010-07-13 09:29:13 -04:00
|
|
|
// Licence: wxWindows licence
|
2008-03-08 08:52:38 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2009-01-14 09:38:00 -05:00
|
|
|
/**
|
|
|
|
This is the default value of the wxStackWalker::Walk function.
|
|
|
|
*/
|
|
|
|
#define wxSTACKWALKER_MAX_DEPTH (200)
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
/**
|
|
|
|
@class wxStackWalker
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
wxStackWalker allows an application to enumerate, or walk, the stack frames
|
|
|
|
(the function callstack).
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-10-07 12:57:34 -04:00
|
|
|
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.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
This class will not return anything except raw stack frame addresses if the
|
|
|
|
debug information is not available. Under Win32 this means that the PDB file
|
2008-10-07 12:57:34 -04:00
|
|
|
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 @c /opt:ref option which is suppressed
|
|
|
|
by using @c /debug linker option by default but should be always enabled for
|
|
|
|
release builds).
|
|
|
|
Under Unix, you need to compile your program with debugging information
|
|
|
|
(usually using @c -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 @c backtrace() function needed to walk the stack.
|
|
|
|
|
|
|
|
See @ref overview_debugging for how to make it available.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@library{wxbase}
|
2008-10-07 12:57:34 -04:00
|
|
|
@category{debugging}
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-10 11:24:38 -04:00
|
|
|
@see wxStackFrame
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-08 09:43:31 -05:00
|
|
|
class wxStackWalker
|
2008-03-08 08:52:38 -05:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
2008-10-07 12:57:34 -04:00
|
|
|
Constructor does nothing, use Walk() to walk the stack.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-11-13 16:32:53 -05:00
|
|
|
wxStackWalker(const char* argv0 = NULL);
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Destructor does nothing neither but should be virtual as this class is used as
|
|
|
|
a base one.
|
|
|
|
*/
|
2008-09-27 07:21:10 -04:00
|
|
|
virtual ~wxStackWalker();
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
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).
|
2008-10-07 12:57:34 -04:00
|
|
|
|
2008-03-09 08:33:59 -04:00
|
|
|
Up to @a maxDepth frames are walked from the innermost to the outermost one.
|
2009-01-14 09:38:00 -05:00
|
|
|
It defaults to ::wxSTACKWALKER_MAX_DEPTH.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2009-01-14 09:38:00 -05:00
|
|
|
virtual void Walk(size_t skip = 1, size_t maxDepth = wxSTACKWALKER_MAX_DEPTH);
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Enumerate stack frames from the location of uncaught exception.
|
2008-10-07 12:57:34 -04:00
|
|
|
This method can only be called from wxApp::OnFatalException().
|
|
|
|
|
2008-03-09 08:33:59 -04:00
|
|
|
Up to @a maxDepth frames are walked from the innermost to the outermost one.
|
2009-01-14 09:38:00 -05:00
|
|
|
It defaults to ::wxSTACKWALKER_MAX_DEPTH.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2009-01-14 09:38:00 -05:00
|
|
|
virtual void WalkFromException(size_t maxDepth = wxSTACKWALKER_MAX_DEPTH);
|
2008-10-13 07:29:37 -04:00
|
|
|
|
|
|
|
protected:
|
|
|
|
/**
|
|
|
|
This function must be overrided to process the given frame.
|
|
|
|
*/
|
2008-10-13 09:24:43 -04:00
|
|
|
virtual void OnStackFrame(const wxStackFrame& frame) = 0;
|
2008-03-08 08:52:38 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-03-10 11:24:38 -04:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
/**
|
|
|
|
@class wxStackFrame
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
wxStackFrame represents a single stack frame, or a single function in the call
|
2008-10-07 12:57:34 -04:00
|
|
|
stack, and is used exclusively together with wxStackWalker, see there for a more
|
|
|
|
detailed discussion.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@library{wxbase}
|
2008-10-07 12:57:34 -04:00
|
|
|
@category{debugging}
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-10 11:24:38 -04:00
|
|
|
@see wxStackWalker
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-08 09:43:31 -05:00
|
|
|
class wxStackFrame
|
2008-03-08 08:52:38 -05:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
Return the address of this frame.
|
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
void* GetAddress() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2008-10-07 12:57:34 -04:00
|
|
|
Return the name of the file containing this frame, empty if unavailable
|
|
|
|
(typically because debug info is missing).
|
|
|
|
|
|
|
|
Use HasSourceLocation() to check whether the file name is available.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
wxString GetFileName() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Get the level of this frame (deepest/innermost one is 0).
|
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
size_t GetLevel() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Return the line number of this frame, 0 if unavailable.
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-03-09 08:33:59 -04:00
|
|
|
@see GetFileName()
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
size_t GetLine() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Get the module this function belongs to (empty if not available).
|
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
wxString GetModule() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2008-10-07 12:57:34 -04:00
|
|
|
Return the unmangled (if possible) name of the function containing this frame.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
wxString GetName() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Return the return address of this frame.
|
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
size_t GetOffset() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Get the name, type and value (in text form) of the given parameter.
|
2008-10-07 12:57:34 -04:00
|
|
|
Any pointer may be @NULL if you're not interested in the corresponding value.
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
Return @true if at least some values could be retrieved.
|
2008-10-07 12:57:34 -04:00
|
|
|
This function currently is only implemented under Win32 and requires a PDB file.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-10-27 17:26:54 -04:00
|
|
|
virtual bool GetParam(size_t n, wxString* type, wxString* name,
|
|
|
|
wxString* value) const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Return the number of parameters of this function (may return 0 if we
|
|
|
|
can't retrieve the parameters info even although the function does have
|
|
|
|
parameters).
|
|
|
|
*/
|
2008-09-27 07:21:10 -04:00
|
|
|
virtual size_t GetParamCount() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Return @true if we have the file name and line number for this frame.
|
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
bool HasSourceLocation() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
};
|
2008-03-10 11:24:38 -04:00
|
|
|
|