1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/wx/stackwalk.h
3 // Purpose: wxStackWalker and related classes, common part
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 2004 Vadim Zeitlin <vadim@wxwindows.org>
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_STACKWALK_H_
13 #define _WX_STACKWALK_H_
19 class WXDLLIMPEXP_BASE wxStackFrame
;
21 // ----------------------------------------------------------------------------
22 // wxStackFrame: a single stack level
23 // ----------------------------------------------------------------------------
25 class WXDLLIMPEXP_BASE wxStackFrameBase
28 // put this inline function here so that it is defined before use
29 wxStackFrameBase
*ConstCast() const
30 { return wx_const_cast(wxStackFrameBase
*, this); }
33 wxStackFrameBase(size_t level
, void *address
= NULL
)
43 // get the level of this frame (deepest/innermost one is 0)
44 size_t GetLevel() const { return m_level
; }
46 // return the address of this frame
47 void *GetAddress() const { return m_address
; }
50 // return the unmangled (if possible) name of the function containing this
52 wxString
GetName() const { ConstCast()->OnGetName(); return m_name
; }
54 // return the instruction pointer offset from the start of the function
55 size_t GetOffset() const { ConstCast()->OnGetName(); return m_offset
; }
57 // get the module this function belongs to (not always available)
58 wxString
GetModule() const { ConstCast()->OnGetName(); return m_module
; }
61 // return true if we have the filename and line number for this frame
62 bool HasSourceLocation() const { return !GetFileName().empty(); }
64 // return the name of the file containing this frame, empty if
65 // unavailable (typically because debug info is missing)
66 wxString
GetFileName() const
67 { ConstCast()->OnGetLocation(); return m_filename
; }
69 // return the line number of this frame, 0 if unavailable
70 size_t GetLine() const { ConstCast()->OnGetLocation(); return m_line
; }
73 // return the number of parameters of this function (may return 0 if we
74 // can't retrieve the parameters info even although the function does have
76 virtual size_t GetParamCount() const { return 0; }
78 // get the name, type and value (in text form) of the given parameter
80 // any pointer may be NULL
82 // return true if at least some values could be retrieved
83 virtual bool GetParam(size_t WXUNUSED(n
),
84 wxString
* WXUNUSED(type
),
85 wxString
* WXUNUSED(name
),
86 wxString
* WXUNUSED(value
)) const
92 // although this class is not supposed to be used polymorphically, give it
93 // a virtual dtor to silence compiler warnings
94 virtual ~wxStackFrameBase() { }
97 // hooks for derived classes to initialize some fields on demand
98 virtual void OnGetName() { }
99 virtual void OnGetLocation() { }
102 // fields are protected, not private, so that OnGetXXX() could modify them
116 // ----------------------------------------------------------------------------
117 // wxStackWalker: class for enumerating stack frames
118 // ----------------------------------------------------------------------------
120 class WXDLLIMPEXP_BASE wxStackWalkerBase
123 // ctor does nothing, use Walk() to walk the stack
124 wxStackWalkerBase() { }
126 // dtor does nothing neither but should be virtual
127 virtual ~wxStackWalkerBase() { }
129 // enumerate stack frames from the current location, skipping the initial
130 // number of them (this can be useful when Walk() is called from some known
131 // location and you don't want to see the first few frames anyhow; also
132 // notice that Walk() frame itself is not included if skip >= 1)
133 virtual void Walk(size_t skip
= 1, size_t maxDepth
= 200) = 0;
135 // enumerate stack frames from the location of uncaught exception
137 // this version can only be called from wxApp::OnFatalException()
138 virtual void WalkFromException() = 0;
141 // this function must be overrided to process the given frame
142 virtual void OnStackFrame(const wxStackFrame
& frame
) = 0;
146 #include "wx/msw/stackwalk.h"
147 #elif defined(__UNIX__)
148 #include "wx/unix/stackwalk.h"
150 #error "wxStackWalker is not supported, set wxUSE_STACKWALKER to 0"
153 #endif // wxUSE_STACKWALKER
155 #endif // _WX_STACKWALK_H_