1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: 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_FWD_BASE wxStackFrame
;
21 #define wxSTACKWALKER_MAX_DEPTH (200)
23 // ----------------------------------------------------------------------------
24 // wxStackFrame: a single stack level
25 // ----------------------------------------------------------------------------
27 class WXDLLIMPEXP_BASE wxStackFrameBase
30 // put this inline function here so that it is defined before use
31 wxStackFrameBase
*ConstCast() const
32 { return const_cast<wxStackFrameBase
*>(this); }
35 wxStackFrameBase(size_t level
, void *address
= NULL
)
45 // get the level of this frame (deepest/innermost one is 0)
46 size_t GetLevel() const { return m_level
; }
48 // return the address of this frame
49 void *GetAddress() const { return m_address
; }
52 // return the unmangled (if possible) name of the function containing this
54 wxString
GetName() const { ConstCast()->OnGetName(); return m_name
; }
56 // return the instruction pointer offset from the start of the function
57 size_t GetOffset() const { ConstCast()->OnGetName(); return m_offset
; }
59 // get the module this function belongs to (not always available)
60 wxString
GetModule() const { ConstCast()->OnGetName(); return m_module
; }
63 // return true if we have the filename and line number for this frame
64 bool HasSourceLocation() const { return !GetFileName().empty(); }
66 // return the name of the file containing this frame, empty if
67 // unavailable (typically because debug info is missing)
68 wxString
GetFileName() const
69 { ConstCast()->OnGetLocation(); return m_filename
; }
71 // return the line number of this frame, 0 if unavailable
72 size_t GetLine() const { ConstCast()->OnGetLocation(); return m_line
; }
75 // return the number of parameters of this function (may return 0 if we
76 // can't retrieve the parameters info even although the function does have
78 virtual size_t GetParamCount() const { return 0; }
80 // get the name, type and value (in text form) of the given parameter
82 // any pointer may be NULL
84 // return true if at least some values could be retrieved
85 virtual bool GetParam(size_t WXUNUSED(n
),
86 wxString
* WXUNUSED(type
),
87 wxString
* WXUNUSED(name
),
88 wxString
* WXUNUSED(value
)) const
94 // although this class is not supposed to be used polymorphically, give it
95 // a virtual dtor to silence compiler warnings
96 virtual ~wxStackFrameBase() { }
99 // hooks for derived classes to initialize some fields on demand
100 virtual void OnGetName() { }
101 virtual void OnGetLocation() { }
104 // fields are protected, not private, so that OnGetXXX() could modify them
118 // ----------------------------------------------------------------------------
119 // wxStackWalker: class for enumerating stack frames
120 // ----------------------------------------------------------------------------
122 class WXDLLIMPEXP_BASE wxStackWalkerBase
125 // ctor does nothing, use Walk() to walk the stack
126 wxStackWalkerBase() { }
128 // dtor does nothing neither but should be virtual
129 virtual ~wxStackWalkerBase() { }
131 // enumerate stack frames from the current location, skipping the initial
132 // number of them (this can be useful when Walk() is called from some known
133 // location and you don't want to see the first few frames anyhow; also
134 // notice that Walk() frame itself is not included if skip >= 1)
135 virtual void Walk(size_t skip
= 1, size_t maxDepth
= wxSTACKWALKER_MAX_DEPTH
) = 0;
137 #if wxUSE_ON_FATAL_EXCEPTION
138 // enumerate stack frames from the location of uncaught exception
140 // this version can only be called from wxApp::OnFatalException()
141 virtual void WalkFromException(size_t maxDepth
= wxSTACKWALKER_MAX_DEPTH
) = 0;
142 #endif // wxUSE_ON_FATAL_EXCEPTION
145 // this function must be overrided to process the given frame
146 virtual void OnStackFrame(const wxStackFrame
& frame
) = 0;
150 #include "wx/msw/stackwalk.h"
151 #elif defined(__UNIX__)
152 #include "wx/unix/stackwalk.h"
154 #error "wxStackWalker is not supported, set wxUSE_STACKWALKER to 0"
157 #endif // wxUSE_STACKWALKER
159 #endif // _WX_STACKWALK_H_