implemented wxStackWalker for Unix (using glibc-specific methods); moved wxUSE_STACKWALKER to common setu_inc.h

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@31474 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2005-01-19 01:15:12 +00:00
parent e926f2efc7
commit eaff0f0d3f
13 changed files with 753 additions and 27 deletions

View File

@@ -128,6 +128,15 @@
#define wxUSE_ON_FATAL_EXCEPTION 0
#endif
// Set this to 1 to be able to generate a human-readable (unlike
// machine-readable minidumop created by wxCrashReport::Generate()) stack back
// trace when your program crashes using wxStackWalker
//
// Default is 1 if supported by the compiler.
//
// Recommended setting: 1, set to 0 if your programs never crash
#define wxUSE_STACKWALKER 1
// ----------------------------------------------------------------------------
// Unicode support
// ----------------------------------------------------------------------------
@@ -1039,6 +1048,9 @@
#undef wxUSE_STD_IOSTREAM
#define wxUSE_STD_IOSTREAM 1
#undef wxUSE_STACKWALKER
#define wxUSE_STACKWALKER 0
#endif
// things not implemented under Mac

View File

@@ -127,6 +127,15 @@
#define wxUSE_ON_FATAL_EXCEPTION 0
#endif
// Set this to 1 to be able to generate a human-readable (unlike
// machine-readable minidumop created by wxCrashReport::Generate()) stack back
// trace when your program crashes using wxStackWalker
//
// Default is 1 if supported by the compiler.
//
// Recommended setting: 1, set to 0 if your programs never crash
#define wxUSE_STACKWALKER 1
// ----------------------------------------------------------------------------
// Unicode support
// ----------------------------------------------------------------------------
@@ -1111,15 +1120,6 @@
// Recommended setting: 1, set to 0 if your programs never crash
#define wxUSE_CRASHREPORT 1
// Set this to 1 to be able to generate a human-readable (unlike
// machine-readable minidumop created by wxCrashReport::Generate()) stack back
// trace when your program crashes using wxStackWalker
//
// Default is 1 if supported by the compiler.
//
// Recommended setting: 1, set to 0 if your programs never crash
#define wxUSE_STACKWALKER 1
// ----------------------------------------------------------------------------
// obsolete settings
// ----------------------------------------------------------------------------

View File

@@ -84,7 +84,9 @@ private:
class WXDLLIMPEXP_BASE wxStackWalker : public wxStackWalkerBase
{
public:
wxStackWalker() { }
// we don't use ctor argument, it is for compatibility with Unix version
// only
wxStackWalker(const char * WXUNUSED(argv0) = NULL) { }
virtual void Walk(size_t skip = 1);
virtual void WalkFromException();

View File

@@ -112,6 +112,15 @@
#define wxUSE_ON_FATAL_EXCEPTION 0
#endif
// Set this to 1 to be able to generate a human-readable (unlike
// machine-readable minidumop created by wxCrashReport::Generate()) stack back
// trace when your program crashes using wxStackWalker
//
// Default is 1 if supported by the compiler.
//
// Recommended setting: 1, set to 0 if your programs never crash
#define wxUSE_STACKWALKER 1
// ----------------------------------------------------------------------------
// Unicode support
// ----------------------------------------------------------------------------

View File

@@ -54,6 +54,9 @@ public:
// return the instruction pointer offset from the start of the function
size_t GetOffset() const { ConstCast()->OnGetName(); return m_offset; }
// get the module this function belongs to (not always available)
wxString GetModule() const { ConstCast()->OnGetName(); return m_module; }
// return true if we have the filename and line number for this frame
bool HasSourceLocation() const { return !GetFileName().empty(); }
@@ -101,7 +104,9 @@ protected:
size_t m_level;
wxString m_name,
m_module,
m_filename;
size_t m_line;
void *m_address;
@@ -118,6 +123,9 @@ public:
// ctor does nothing, use Walk() to walk the stack
wxStackWalkerBase() { }
// dtor does nothing neither but should be virtual
virtual ~wxStackWalkerBase() { }
// 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
@@ -136,6 +144,10 @@ protected:
#ifdef __WXMSW__
#include "wx/msw/stackwalk.h"
#elif defined(__UNIX__)
#include "wx/unix/stackwalk.h"
#else
#error "wxStackWalker is not supported, set wxUSE_STACKWALKER to 0"
#endif
#endif // wxUSE_STACKWALKER

View File

@@ -0,0 +1,69 @@
///////////////////////////////////////////////////////////////////////////////
// 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
{
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
wxStackFrame(size_t level, void *address, const char *syminfo)
: wxStackFrameBase(level, address)
{
m_hasName =
m_hasLocation = false;
m_syminfo = syminfo;
}
protected:
virtual void OnGetName();
virtual void OnGetLocation();
private:
const char *m_syminfo;
bool m_hasName,
m_hasLocation;
};
// ----------------------------------------------------------------------------
// 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
wxStackWalker(const char *argv0 = NULL) { ms_exepath = argv0; }
virtual void Walk(size_t skip = 1);
virtual void WalkFromException() { Walk(2); }
static const wxString& GetExePath() { return ms_exepath; }
private:
static wxString ms_exepath;
};
#endif // _WX_UNIX_STACKWALK_H_