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