]> git.saurik.com Git - wxWidgets.git/blame - include/wx/stackwalk.h
wxUSE_CRASHREPORT and wxUSE_STACKWALKER can't be used if wxUSE_ON_FATAL_EXCEPTION...
[wxWidgets.git] / include / wx / stackwalk.h
CommitLineData
7beafee9
VZ
1///////////////////////////////////////////////////////////////////////////////
2// Name: wx/wx/stackwalk.h
3// Purpose: wxStackWalker and related classes, common part
4// Author: Vadim Zeitlin
5// Modified by:
6// Created: 2005-01-07
7// RCS-ID: $Id$
8// Copyright: (c) 2004 Vadim Zeitlin <vadim@wxwindows.org>
9// Licence: wxWindows licence
10///////////////////////////////////////////////////////////////////////////////
11
12#ifndef _WX_STACKWALK_H_
13#define _WX_STACKWALK_H_
14
15#include "wx/defs.h"
16
17#if wxUSE_STACKWALKER
18
19class WXDLLIMPEXP_BASE wxStackFrame;
20
21// ----------------------------------------------------------------------------
22// wxStackFrame: a single stack level
23// ----------------------------------------------------------------------------
24
25class WXDLLIMPEXP_BASE wxStackFrameBase
26{
27private:
28 // put this inline function here so that it is defined before use
29 wxStackFrameBase *ConstCast() const
30 { return wx_const_cast(wxStackFrameBase *, this); }
31
32public:
33 wxStackFrameBase(size_t level, void *address = NULL)
34 {
35 m_level = level;
36
37 m_line =
38 m_offset = 0;
39
40 m_address = address;
41 }
42
43 // get the level of this frame (deepest/innermost one is 0)
44 size_t GetLevel() const { return m_level; }
45
46 // return the address of this frame
47 void *GetAddress() const { return m_address; }
48
49
50 // return the unmangled (if possible) name of the function containing this
51 // frame
52 wxString GetName() const { ConstCast()->OnGetName(); return m_name; }
53
54 // return the instruction pointer offset from the start of the function
55 size_t GetOffset() const { ConstCast()->OnGetName(); return m_offset; }
56
57
58 // return true if we have the filename and line number for this frame
59 bool HasSourceLocation() const { return !GetFileName().empty(); }
60
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; }
65
66 // return the line number of this frame, 0 if unavailable
67 size_t GetLine() const { ConstCast()->OnGetLocation(); return m_line; }
68
69
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
72 // parameters)
73 virtual size_t GetParamCount() const { return 0; }
74
75 // get the name, type and value (in text form) of the given parameter
76 //
77 // any pointer may be NULL
78 //
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
84 {
85 return false;
86 }
87
88
89 // although this class is not supposed to be used polymorphically, give it
90 // a virtual dtor to silence compiler warnings
91 virtual ~wxStackFrameBase() { }
92
93protected:
94 // hooks for derived classes to initialize some fields on demand
95 virtual void OnGetName() { }
96 virtual void OnGetLocation() { }
97
98
99 // fields are protected, not private, so that OnGetXXX() could modify them
100 // directly
101 size_t m_level;
102
103 wxString m_name,
104 m_filename;
105 size_t m_line;
106
107 void *m_address;
108 size_t m_offset;
109};
110
111// ----------------------------------------------------------------------------
112// wxStackWalker: class for enumerating stack frames
113// ----------------------------------------------------------------------------
114
115class WXDLLIMPEXP_BASE wxStackWalkerBase
116{
117public:
118 // ctor does nothing, use Walk() to walk the stack
119 wxStackWalkerBase() { }
120
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;
126
127 // enumerate stack frames from the location of uncaught exception
128 //
129 // this version can only be called from wxApp::OnFatalException()
130 virtual void WalkFromException() = 0;
131
132protected:
133 // this function must be overrided to process the given frame
134 virtual void OnStackFrame(const wxStackFrame& frame) = 0;
135};
136
137#ifdef __WXMSW__
138 #include "wx/msw/stackwalk.h"
139#endif
140
141#endif // wxUSE_STACKWALKER
142
143#endif // _WX_STACKWALK_H_
144