]> git.saurik.com Git - wxWidgets.git/blob - include/wx/unix/stackwalk.h
Use RIAA wrapper for wxSpinCtrl event disabling in wxGTK.
[wxWidgets.git] / include / wx / unix / stackwalk.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/unix/stackwalk.h
3 // Purpose: declaration of wxStackWalker for Unix
4 // Author: Vadim Zeitlin
5 // Modified by:
6 // Created: 2005-01-19
7 // Copyright: (c) 2005 Vadim Zeitlin <vadim@wxwindows.org>
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
10
11 #ifndef _WX_UNIX_STACKWALK_H_
12 #define _WX_UNIX_STACKWALK_H_
13
14 // ----------------------------------------------------------------------------
15 // wxStackFrame
16 // ----------------------------------------------------------------------------
17
18 class WXDLLIMPEXP_BASE wxStackFrame : public wxStackFrameBase
19 {
20 friend class wxStackWalker;
21
22 public:
23 // arguments are the stack depth of this frame, its address and the return
24 // value of backtrace_symbols() for it
25 //
26 // NB: we don't copy syminfo pointer so it should have lifetime at least as
27 // long as ours
28 wxStackFrame(size_t level = 0, void *address = NULL, const char *syminfo = NULL)
29 : wxStackFrameBase(level, address)
30 {
31 m_syminfo = syminfo;
32 }
33
34 protected:
35 virtual void OnGetName();
36
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)
40 {
41 m_level = level;
42 m_name = name;
43 m_filename = filename;
44 m_syminfo = syminfo;
45
46 m_line = numLine;
47 m_address = address;
48 }
49
50 private:
51 const char *m_syminfo;
52 };
53
54 // ----------------------------------------------------------------------------
55 // wxStackWalker
56 // ----------------------------------------------------------------------------
57
58 class WXDLLIMPEXP_BASE wxStackWalker : public wxStackWalkerBase
59 {
60 public:
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
64 // explicitly
65 wxStackWalker(const char *argv0 = NULL)
66 {
67 ms_exepath = wxString::FromAscii(argv0);
68 }
69
70 ~wxStackWalker()
71 {
72 FreeStack();
73 }
74
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
79
80 static const wxString& GetExePath() { return ms_exepath; }
81
82
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);
87 void FreeStack();
88
89 private:
90 int InitFrames(wxStackFrame *arr, size_t n, void **addresses, char **syminfo);
91
92 static wxString ms_exepath;
93 static void *ms_addresses[];
94 static char **ms_symbols;
95 static int m_depth;
96 };
97
98 #endif // _WX_UNIX_STACKWALK_H_