2005-01-18 20:15:12 -05:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: wx/unix/stackwalk.h
|
|
|
|
// Purpose: declaration of wxStackWalker for Unix
|
|
|
|
// Author: Vadim Zeitlin
|
|
|
|
// Modified by:
|
|
|
|
// Created: 2005-01-19
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Copyright: (c) 2005 Vadim Zeitlin <vadim@wxwindows.org>
|
|
|
|
// Licence: wxWindows licence
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#ifndef _WX_UNIX_STACKWALK_H_
|
|
|
|
#define _WX_UNIX_STACKWALK_H_
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxStackFrame
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class WXDLLIMPEXP_BASE wxStackFrame : public wxStackFrameBase
|
|
|
|
{
|
2006-11-12 09:33:03 -05:00
|
|
|
friend class wxStackWalker;
|
|
|
|
|
2005-01-18 20:15:12 -05:00
|
|
|
public:
|
|
|
|
// arguments are the stack depth of this frame, its address and the return
|
|
|
|
// value of backtrace_symbols() for it
|
|
|
|
//
|
|
|
|
// NB: we don't copy syminfo pointer so it should have lifetime at least as
|
|
|
|
// long as ours
|
2006-11-12 09:33:03 -05:00
|
|
|
wxStackFrame(size_t level = 0, void *address = NULL, const char *syminfo = NULL)
|
2005-01-18 20:15:12 -05:00
|
|
|
: wxStackFrameBase(level, address)
|
|
|
|
{
|
|
|
|
m_syminfo = syminfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual void OnGetName();
|
2006-11-12 09:33:03 -05:00
|
|
|
|
|
|
|
// optimized for the 2 step initialization done by wxStackWalker
|
|
|
|
void Set(const wxString &name, const wxString &filename, const char* syminfo,
|
|
|
|
size_t level, size_t numLine, void *address)
|
|
|
|
{
|
|
|
|
m_level = level;
|
|
|
|
m_name = name;
|
|
|
|
m_filename = filename;
|
|
|
|
m_syminfo = syminfo;
|
|
|
|
|
|
|
|
m_line = numLine;
|
|
|
|
m_address = address;
|
|
|
|
}
|
2005-01-18 20:15:12 -05:00
|
|
|
|
|
|
|
private:
|
|
|
|
const char *m_syminfo;
|
|
|
|
};
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxStackWalker
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class WXDLLIMPEXP_BASE wxStackWalker : public wxStackWalkerBase
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// we need the full path to the program executable to be able to use
|
|
|
|
// addr2line, normally we can retrieve it from wxTheApp but if wxTheApp
|
|
|
|
// doesn't exist or doesn't have the correct value, the path may be given
|
|
|
|
// explicitly
|
2005-01-19 15:13:49 -05:00
|
|
|
wxStackWalker(const char *argv0 = NULL)
|
|
|
|
{
|
|
|
|
ms_exepath = wxString::FromAscii(argv0);
|
|
|
|
}
|
2005-01-18 20:15:12 -05:00
|
|
|
|
2006-11-12 09:33:03 -05:00
|
|
|
~wxStackWalker()
|
|
|
|
{
|
|
|
|
FreeStack();
|
|
|
|
}
|
|
|
|
|
2009-01-14 09:38:00 -05:00
|
|
|
virtual void Walk(size_t skip = 1, size_t maxDepth = wxSTACKWALKER_MAX_DEPTH);
|
2008-09-13 20:26:29 -04:00
|
|
|
#if wxUSE_ON_FATAL_EXCEPTION
|
2009-01-14 09:38:00 -05:00
|
|
|
virtual void WalkFromException(size_t maxDepth = wxSTACKWALKER_MAX_DEPTH) { Walk(2, maxDepth); }
|
2008-09-13 20:26:29 -04:00
|
|
|
#endif // wxUSE_ON_FATAL_EXCEPTION
|
2005-01-18 20:15:12 -05:00
|
|
|
|
|
|
|
static const wxString& GetExePath() { return ms_exepath; }
|
|
|
|
|
2006-11-12 09:33:03 -05:00
|
|
|
|
|
|
|
// these two may be used to save the stack at some point (fast operation)
|
|
|
|
// and then process it later (slow operation)
|
|
|
|
void SaveStack(size_t maxDepth);
|
|
|
|
void ProcessFrames(size_t skip);
|
|
|
|
void FreeStack();
|
|
|
|
|
2005-01-18 20:15:12 -05:00
|
|
|
private:
|
2006-11-12 09:33:03 -05:00
|
|
|
int InitFrames(wxStackFrame *arr, size_t n, void **addresses, char **syminfo);
|
|
|
|
|
2005-01-18 20:15:12 -05:00
|
|
|
static wxString ms_exepath;
|
2006-11-12 09:33:03 -05:00
|
|
|
static void *ms_addresses[];
|
|
|
|
static char **ms_symbols;
|
|
|
|
static int m_depth;
|
2005-01-18 20:15:12 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // _WX_UNIX_STACKWALK_H_
|