2005-01-16 20:23:20 -05:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2010-06-26 07:43:13 -04:00
|
|
|
// Name: wx/stackwalk.h
|
2005-01-16 20:23:20 -05:00
|
|
|
// Purpose: wxStackWalker and related classes, common part
|
|
|
|
// Author: Vadim Zeitlin
|
|
|
|
// Modified by:
|
|
|
|
// Created: 2005-01-07
|
|
|
|
// Copyright: (c) 2004 Vadim Zeitlin <vadim@wxwindows.org>
|
|
|
|
// Licence: wxWindows licence
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#ifndef _WX_STACKWALK_H_
|
|
|
|
#define _WX_STACKWALK_H_
|
|
|
|
|
|
|
|
#include "wx/defs.h"
|
|
|
|
|
|
|
|
#if wxUSE_STACKWALKER
|
|
|
|
|
2016-03-12 20:03:48 -05:00
|
|
|
#include "wx/string.h"
|
|
|
|
|
2007-07-09 06:09:52 -04:00
|
|
|
class WXDLLIMPEXP_FWD_BASE wxStackFrame;
|
2005-01-16 20:23:20 -05:00
|
|
|
|
2009-01-14 10:01:23 -05:00
|
|
|
#define wxSTACKWALKER_MAX_DEPTH (200)
|
|
|
|
|
2005-01-16 20:23:20 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxStackFrame: a single stack level
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class WXDLLIMPEXP_BASE wxStackFrameBase
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
// put this inline function here so that it is defined before use
|
|
|
|
wxStackFrameBase *ConstCast() const
|
2008-11-01 22:39:52 -04:00
|
|
|
{ return const_cast<wxStackFrameBase *>(this); }
|
2005-01-16 20:23:20 -05:00
|
|
|
|
|
|
|
public:
|
|
|
|
wxStackFrameBase(size_t level, void *address = NULL)
|
|
|
|
{
|
|
|
|
m_level = level;
|
|
|
|
|
|
|
|
m_line =
|
|
|
|
m_offset = 0;
|
|
|
|
|
|
|
|
m_address = address;
|
|
|
|
}
|
|
|
|
|
|
|
|
// get the level of this frame (deepest/innermost one is 0)
|
|
|
|
size_t GetLevel() const { return m_level; }
|
|
|
|
|
|
|
|
// return the address of this frame
|
|
|
|
void *GetAddress() const { return m_address; }
|
|
|
|
|
|
|
|
|
|
|
|
// return the unmangled (if possible) name of the function containing this
|
|
|
|
// frame
|
|
|
|
wxString GetName() const { ConstCast()->OnGetName(); return m_name; }
|
|
|
|
|
|
|
|
// return the instruction pointer offset from the start of the function
|
|
|
|
size_t GetOffset() const { ConstCast()->OnGetName(); return m_offset; }
|
|
|
|
|
2005-01-18 20:15:12 -05:00
|
|
|
// get the module this function belongs to (not always available)
|
|
|
|
wxString GetModule() const { ConstCast()->OnGetName(); return m_module; }
|
|
|
|
|
2005-01-16 20:23:20 -05:00
|
|
|
|
|
|
|
// return true if we have the filename and line number for this frame
|
|
|
|
bool HasSourceLocation() const { return !GetFileName().empty(); }
|
|
|
|
|
|
|
|
// return the name of the file containing this frame, empty if
|
|
|
|
// unavailable (typically because debug info is missing)
|
|
|
|
wxString GetFileName() const
|
|
|
|
{ ConstCast()->OnGetLocation(); return m_filename; }
|
|
|
|
|
|
|
|
// return the line number of this frame, 0 if unavailable
|
|
|
|
size_t GetLine() const { ConstCast()->OnGetLocation(); return m_line; }
|
|
|
|
|
|
|
|
|
|
|
|
// 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)
|
|
|
|
virtual size_t GetParamCount() const { return 0; }
|
|
|
|
|
|
|
|
// get the name, type and value (in text form) of the given parameter
|
|
|
|
//
|
|
|
|
// any pointer may be NULL
|
|
|
|
//
|
|
|
|
// return true if at least some values could be retrieved
|
|
|
|
virtual bool GetParam(size_t WXUNUSED(n),
|
|
|
|
wxString * WXUNUSED(type),
|
|
|
|
wxString * WXUNUSED(name),
|
|
|
|
wxString * WXUNUSED(value)) const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// although this class is not supposed to be used polymorphically, give it
|
|
|
|
// a virtual dtor to silence compiler warnings
|
|
|
|
virtual ~wxStackFrameBase() { }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
// hooks for derived classes to initialize some fields on demand
|
|
|
|
virtual void OnGetName() { }
|
|
|
|
virtual void OnGetLocation() { }
|
|
|
|
|
|
|
|
|
|
|
|
// fields are protected, not private, so that OnGetXXX() could modify them
|
|
|
|
// directly
|
|
|
|
size_t m_level;
|
|
|
|
|
|
|
|
wxString m_name,
|
2005-01-18 20:15:12 -05:00
|
|
|
m_module,
|
2005-01-16 20:23:20 -05:00
|
|
|
m_filename;
|
2005-01-18 20:15:12 -05:00
|
|
|
|
2005-01-16 20:23:20 -05:00
|
|
|
size_t m_line;
|
|
|
|
|
|
|
|
void *m_address;
|
|
|
|
size_t m_offset;
|
|
|
|
};
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxStackWalker: class for enumerating stack frames
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class WXDLLIMPEXP_BASE wxStackWalkerBase
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// ctor does nothing, use Walk() to walk the stack
|
|
|
|
wxStackWalkerBase() { }
|
|
|
|
|
2005-01-18 20:15:12 -05:00
|
|
|
// dtor does nothing neither but should be virtual
|
|
|
|
virtual ~wxStackWalkerBase() { }
|
|
|
|
|
2005-01-16 20:23:20 -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)
|
2009-01-14 10:01:23 -05:00
|
|
|
virtual void Walk(size_t skip = 1, size_t maxDepth = wxSTACKWALKER_MAX_DEPTH) = 0;
|
2005-01-16 20:23:20 -05:00
|
|
|
|
2008-09-13 20:26:29 -04:00
|
|
|
#if wxUSE_ON_FATAL_EXCEPTION
|
2005-01-16 20:23:20 -05:00
|
|
|
// enumerate stack frames from the location of uncaught exception
|
|
|
|
//
|
|
|
|
// this version can only be called from wxApp::OnFatalException()
|
2009-01-14 10:01:23 -05:00
|
|
|
virtual void WalkFromException(size_t maxDepth = wxSTACKWALKER_MAX_DEPTH) = 0;
|
2008-09-13 20:26:29 -04:00
|
|
|
#endif // wxUSE_ON_FATAL_EXCEPTION
|
2005-01-16 20:23:20 -05:00
|
|
|
|
|
|
|
protected:
|
|
|
|
// this function must be overrided to process the given frame
|
|
|
|
virtual void OnStackFrame(const wxStackFrame& frame) = 0;
|
|
|
|
};
|
|
|
|
|
2012-03-03 19:29:31 -05:00
|
|
|
#ifdef __WINDOWS__
|
2005-01-16 20:23:20 -05:00
|
|
|
#include "wx/msw/stackwalk.h"
|
2005-01-18 20:15:12 -05:00
|
|
|
#elif defined(__UNIX__)
|
|
|
|
#include "wx/unix/stackwalk.h"
|
|
|
|
#else
|
|
|
|
#error "wxStackWalker is not supported, set wxUSE_STACKWALKER to 0"
|
2005-01-16 20:23:20 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif // wxUSE_STACKWALKER
|
|
|
|
|
|
|
|
#endif // _WX_STACKWALK_H_
|
|
|
|
|