]> git.saurik.com Git - wxWidgets.git/blob - interface/wx/stackwalk.h
add 'redirection page' for wxULongLong
[wxWidgets.git] / interface / wx / stackwalk.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: stackwalk.h
3 // Purpose: interface of wxStackWalker
4 // Author: wxWidgets team
5 // RCS-ID: $Id$
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
8
9 /**
10 @class wxStackWalker
11
12 wxStackWalker allows an application to enumerate, or walk, the stack frames
13 (the function callstack).
14
15 It is mostly useful in only two situations: inside wxApp::OnFatalException
16 function to programmatically get the location of the crash and, in debug builds,
17 in wxApp::OnAssertFailure to report the caller of the failed assert.
18
19 wxStackWalker works by repeatedly calling the wxStackWalker::OnStackFrame
20 method for each frame in the stack, so to use it you must derive your own
21 class from it and override this method.
22
23 This class will not return anything except raw stack frame addresses if the
24 debug information is not available. Under Win32 this means that the PDB file
25 matching the program being executed should be present.
26 Note that if you use Microsoft Visual C++ compiler, you can create PDB files
27 even for the programs built in release mode and it doesn't affect the program
28 size (at least if you don't forget to add @c /opt:ref option which is suppressed
29 by using @c /debug linker option by default but should be always enabled for
30 release builds).
31 Under Unix, you need to compile your program with debugging information
32 (usually using @c -g compiler and linker options) to get the file and line
33 numbers information, however function names should be available even without it.
34 Of course, all this is only @true if you build using a recent enough version
35 of GNU libc which provides the @c backtrace() function needed to walk the stack.
36
37 See @ref overview_debugging for how to make it available.
38
39 @library{wxbase}
40 @category{debugging}
41
42 @see wxStackFrame
43 */
44 class wxStackWalker
45 {
46 public:
47 /**
48 Constructor does nothing, use Walk() to walk the stack.
49 */
50 wxStackWalker(const char* argv0 = NULL);
51
52 /**
53 Destructor does nothing neither but should be virtual as this class is used as
54 a base one.
55 */
56 virtual ~wxStackWalker();
57
58 /**
59 Enumerate stack frames from the current location, skipping the initial
60 number of them (this can be useful when Walk() is called from some known
61 location and you don't want to see the first few frames anyhow; also
62 notice that Walk() frame itself is not included if skip = 1).
63
64 Up to @a maxDepth frames are walked from the innermost to the outermost one.
65 */
66 virtual void Walk(size_t skip = 1, size_t maxDepth = 200);
67
68 /**
69 Enumerate stack frames from the location of uncaught exception.
70 This method can only be called from wxApp::OnFatalException().
71
72 Up to @a maxDepth frames are walked from the innermost to the outermost one.
73 */
74 virtual void WalkFromException(size_t maxDepth = 200);
75
76 protected:
77 /**
78 This function must be overrided to process the given frame.
79 */
80 virtual void OnStackFrame(const wxStackFrame& frame) = 0;
81 };
82
83
84
85 /**
86 @class wxStackFrame
87
88 wxStackFrame represents a single stack frame, or a single function in the call
89 stack, and is used exclusively together with wxStackWalker, see there for a more
90 detailed discussion.
91
92 @library{wxbase}
93 @category{debugging}
94
95 @see wxStackWalker
96 */
97 class wxStackFrame
98 {
99 public:
100 /**
101 Return the address of this frame.
102 */
103 void* GetAddress() const;
104
105 /**
106 Return the name of the file containing this frame, empty if unavailable
107 (typically because debug info is missing).
108
109 Use HasSourceLocation() to check whether the file name is available.
110 */
111 wxString GetFileName() const;
112
113 /**
114 Get the level of this frame (deepest/innermost one is 0).
115 */
116 size_t GetLevel() const;
117
118 /**
119 Return the line number of this frame, 0 if unavailable.
120
121 @see GetFileName()
122 */
123 size_t GetLine() const;
124
125 /**
126 Get the module this function belongs to (empty if not available).
127 */
128 wxString GetModule() const;
129
130 /**
131 Return the unmangled (if possible) name of the function containing this frame.
132 */
133 wxString GetName() const;
134
135 /**
136 Return the return address of this frame.
137 */
138 size_t GetOffset() const;
139
140 /**
141 Get the name, type and value (in text form) of the given parameter.
142 Any pointer may be @NULL if you're not interested in the corresponding value.
143
144 Return @true if at least some values could be retrieved.
145 This function currently is only implemented under Win32 and requires a PDB file.
146 */
147 virtual bool GetParam(size_t n, wxString* type, wxString* name,
148 wxString* value) const;
149
150 /**
151 Return the number of parameters of this function (may return 0 if we
152 can't retrieve the parameters info even although the function does have
153 parameters).
154 */
155 virtual size_t GetParamCount() const;
156
157 /**
158 Return @true if we have the file name and line number for this frame.
159 */
160 bool HasSourceLocation() const;
161 };
162