]> git.saurik.com Git - wxWidgets.git/blame - interface/wx/stackwalk.h
Try native method first in LoadFile() and SaveFile()
[wxWidgets.git] / interface / wx / stackwalk.h
CommitLineData
23324ae1
FM
1/////////////////////////////////////////////////////////////////////////////
2// Name: stackwalk.h
e54c96f1 3// Purpose: interface of wxStackWalker
23324ae1 4// Author: wxWidgets team
526954c5 5// Licence: wxWindows licence
23324ae1
FM
6/////////////////////////////////////////////////////////////////////////////
7
52499582
FM
8/**
9 This is the default value of the wxStackWalker::Walk function.
10*/
11#define wxSTACKWALKER_MAX_DEPTH (200)
12
23324ae1
FM
13/**
14 @class wxStackWalker
7c913512 15
23324ae1
FM
16 wxStackWalker allows an application to enumerate, or walk, the stack frames
17 (the function callstack).
7c913512 18
4701dc09
FM
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.
7c913512 26
23324ae1
FM
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
4701dc09
FM
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.
7c913512 42
23324ae1 43 @library{wxbase}
4701dc09 44 @category{debugging}
7c913512 45
e54c96f1 46 @see wxStackFrame
23324ae1 47*/
7c913512 48class wxStackWalker
23324ae1
FM
49{
50public:
51 /**
4701dc09 52 Constructor does nothing, use Walk() to walk the stack.
23324ae1 53 */
11e3af6e 54 wxStackWalker(const char* argv0 = NULL);
23324ae1
FM
55
56 /**
57 Destructor does nothing neither but should be virtual as this class is used as
58 a base one.
59 */
adaaa686 60 virtual ~wxStackWalker();
23324ae1 61
23324ae1
FM
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).
4701dc09 67
4cc4bfaf 68 Up to @a maxDepth frames are walked from the innermost to the outermost one.
52499582 69 It defaults to ::wxSTACKWALKER_MAX_DEPTH.
23324ae1 70 */
52499582 71 virtual void Walk(size_t skip = 1, size_t maxDepth = wxSTACKWALKER_MAX_DEPTH);
23324ae1
FM
72
73 /**
74 Enumerate stack frames from the location of uncaught exception.
4701dc09
FM
75 This method can only be called from wxApp::OnFatalException().
76
4cc4bfaf 77 Up to @a maxDepth frames are walked from the innermost to the outermost one.
52499582 78 It defaults to ::wxSTACKWALKER_MAX_DEPTH.
23324ae1 79 */
52499582 80 virtual void WalkFromException(size_t maxDepth = wxSTACKWALKER_MAX_DEPTH);
551266a9
FM
81
82protected:
83 /**
84 This function must be overrided to process the given frame.
85 */
da1ed74c 86 virtual void OnStackFrame(const wxStackFrame& frame) = 0;
23324ae1
FM
87};
88
89
e54c96f1 90
23324ae1
FM
91/**
92 @class wxStackFrame
7c913512 93
23324ae1 94 wxStackFrame represents a single stack frame, or a single function in the call
4701dc09
FM
95 stack, and is used exclusively together with wxStackWalker, see there for a more
96 detailed discussion.
7c913512 97
23324ae1 98 @library{wxbase}
4701dc09 99 @category{debugging}
7c913512 100
e54c96f1 101 @see wxStackWalker
23324ae1 102*/
7c913512 103class wxStackFrame
23324ae1
FM
104{
105public:
106 /**
107 Return the address of this frame.
108 */
328f5751 109 void* GetAddress() const;
23324ae1
FM
110
111 /**
4701dc09
FM
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.
23324ae1 116 */
328f5751 117 wxString GetFileName() const;
23324ae1
FM
118
119 /**
120 Get the level of this frame (deepest/innermost one is 0).
121 */
328f5751 122 size_t GetLevel() const;
23324ae1
FM
123
124 /**
125 Return the line number of this frame, 0 if unavailable.
3c4f71cc 126
4cc4bfaf 127 @see GetFileName()
23324ae1 128 */
328f5751 129 size_t GetLine() const;
23324ae1
FM
130
131 /**
132 Get the module this function belongs to (empty if not available).
133 */
328f5751 134 wxString GetModule() const;
23324ae1
FM
135
136 /**
4701dc09 137 Return the unmangled (if possible) name of the function containing this frame.
23324ae1 138 */
328f5751 139 wxString GetName() const;
23324ae1
FM
140
141 /**
142 Return the return address of this frame.
143 */
328f5751 144 size_t GetOffset() const;
23324ae1
FM
145
146 /**
147 Get the name, type and value (in text form) of the given parameter.
4701dc09
FM
148 Any pointer may be @NULL if you're not interested in the corresponding value.
149
23324ae1 150 Return @true if at least some values could be retrieved.
4701dc09 151 This function currently is only implemented under Win32 and requires a PDB file.
23324ae1 152 */
fadc2df6
FM
153 virtual bool GetParam(size_t n, wxString* type, wxString* name,
154 wxString* value) const;
23324ae1
FM
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 */
adaaa686 161 virtual size_t GetParamCount() const;
23324ae1
FM
162
163 /**
164 Return @true if we have the file name and line number for this frame.
165 */
328f5751 166 bool HasSourceLocation() const;
23324ae1 167};
e54c96f1 168