1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/unix/stackwalk.h
3 // Purpose: declaration of wxStackWalker for Unix
4 // Author: Vadim Zeitlin
7 // Copyright: (c) 2005 Vadim Zeitlin <vadim@wxwindows.org>
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_UNIX_STACKWALK_H_
12 #define _WX_UNIX_STACKWALK_H_
14 // ----------------------------------------------------------------------------
16 // ----------------------------------------------------------------------------
18 class WXDLLIMPEXP_BASE wxStackFrame
: public wxStackFrameBase
20 friend class wxStackWalker
;
23 // arguments are the stack depth of this frame, its address and the return
24 // value of backtrace_symbols() for it
26 // NB: we don't copy syminfo pointer so it should have lifetime at least as
28 wxStackFrame(size_t level
= 0, void *address
= NULL
, const char *syminfo
= NULL
)
29 : wxStackFrameBase(level
, address
)
35 virtual void OnGetName();
37 // optimized for the 2 step initialization done by wxStackWalker
38 void Set(const wxString
&name
, const wxString
&filename
, const char* syminfo
,
39 size_t level
, size_t numLine
, void *address
)
43 m_filename
= filename
;
51 const char *m_syminfo
;
54 // ----------------------------------------------------------------------------
56 // ----------------------------------------------------------------------------
58 class WXDLLIMPEXP_BASE wxStackWalker
: public wxStackWalkerBase
61 // we need the full path to the program executable to be able to use
62 // addr2line, normally we can retrieve it from wxTheApp but if wxTheApp
63 // doesn't exist or doesn't have the correct value, the path may be given
65 wxStackWalker(const char *argv0
= NULL
)
67 ms_exepath
= wxString::FromAscii(argv0
);
75 virtual void Walk(size_t skip
= 1, size_t maxDepth
= wxSTACKWALKER_MAX_DEPTH
);
76 #if wxUSE_ON_FATAL_EXCEPTION
77 virtual void WalkFromException(size_t maxDepth
= wxSTACKWALKER_MAX_DEPTH
) { Walk(2, maxDepth
); }
78 #endif // wxUSE_ON_FATAL_EXCEPTION
80 static const wxString
& GetExePath() { return ms_exepath
; }
83 // these two may be used to save the stack at some point (fast operation)
84 // and then process it later (slow operation)
85 void SaveStack(size_t maxDepth
);
86 void ProcessFrames(size_t skip
);
90 int InitFrames(wxStackFrame
*arr
, size_t n
, void **addresses
, char **syminfo
);
92 static wxString ms_exepath
;
93 static void *ms_addresses
[];
94 static char **ms_symbols
;
98 #endif // _WX_UNIX_STACKWALK_H_