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
; }
58 // return true if we have the filename and line number for this frame
59 bool HasSourceLocation() const { return !GetFileName().empty(); }
61 // return the name of the file containing this frame, empty if
62 // unavailable (typically because debug info is missing)
63 wxString
GetFileName() const
64 { ConstCast()->OnGetLocation(); return m_filename
; }
66 // return the line number of this frame, 0 if unavailable
67 size_t GetLine() const { ConstCast()->OnGetLocation(); return m_line
; }
70 // return the number of parameters of this function (may return 0 if we
71 // can't retrieve the parameters info even although the function does have
73 virtual size_t GetParamCount() const { return 0; }
75 // get the name, type and value (in text form) of the given parameter
77 // any pointer may be NULL
79 // return true if at least some values could be retrieved
80 virtual bool GetParam(size_t WXUNUSED(n
),
81 wxString
* WXUNUSED(type
),
82 wxString
* WXUNUSED(name
),
83 wxString
* WXUNUSED(value
)) const
89 // although this class is not supposed to be used polymorphically, give it
90 // a virtual dtor to silence compiler warnings
91 virtual ~wxStackFrameBase() { }
94 // hooks for derived classes to initialize some fields on demand
95 virtual void OnGetName() { }
96 virtual void OnGetLocation() { }
99 // fields are protected, not private, so that OnGetXXX() could modify them
111 // ----------------------------------------------------------------------------
112 // wxStackWalker: class for enumerating stack frames
113 // ----------------------------------------------------------------------------
115 class WXDLLIMPEXP_BASE wxStackWalkerBase
118 // ctor does nothing, use Walk() to walk the stack
119 wxStackWalkerBase() { }
121 // enumerate stack frames from the current location, skipping the initial
122 // number of them (this can be useful when Walk() is called from some known
123 // location and you don't want to see the first few frames anyhow; also
124 // notice that Walk() frame itself is not included if skip >= 1)
125 virtual void Walk(size_t skip
= 1) = 0;
127 // enumerate stack frames from the location of uncaught exception
129 // this version can only be called from wxApp::OnFatalException()
130 virtual void WalkFromException() = 0;
133 // this function must be overrided to process the given frame
134 virtual void OnStackFrame(const wxStackFrame
& frame
) = 0;
138 #include "wx/msw/stackwalk.h"
141 #endif // wxUSE_STACKWALKER
143 #endif // _WX_STACKWALK_H_