]> git.saurik.com Git - wxWidgets.git/blame - interface/wx/stackwalk.h
don't replace . and .. with the corresponding directoties names in GetLongPath()...
[wxWidgets.git] / interface / wx / stackwalk.h
CommitLineData
23324ae1
FM
1/////////////////////////////////////////////////////////////////////////////
2// Name: stackwalk.h
e54c96f1 3// Purpose: interface of wxStackWalker
23324ae1
FM
4// Author: wxWidgets team
5// RCS-ID: $Id$
6// Licence: wxWindows license
7/////////////////////////////////////////////////////////////////////////////
8
9/**
10 @class wxStackWalker
7c913512 11
23324ae1
FM
12 wxStackWalker allows an application to enumerate, or walk, the stack frames
13 (the function callstack).
7c913512 14
4701dc09
FM
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.
7c913512 22
23324ae1
FM
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
4701dc09
FM
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.
7c913512 38
23324ae1 39 @library{wxbase}
4701dc09 40 @category{debugging}
7c913512 41
e54c96f1 42 @see wxStackFrame
23324ae1 43*/
7c913512 44class wxStackWalker
23324ae1
FM
45{
46public:
47 /**
4701dc09 48 Constructor does nothing, use Walk() to walk the stack.
23324ae1
FM
49 */
50 wxStackWalker();
51
52 /**
53 Destructor does nothing neither but should be virtual as this class is used as
54 a base one.
55 */
adaaa686 56 virtual ~wxStackWalker();
23324ae1
FM
57
58 /**
59 This function must be overrided to process the given frame.
60 */
61 void OnStackFrame(const wxStackFrame& frame);
62
63 /**
64 Enumerate stack frames from the current location, skipping the initial
65 number of them (this can be useful when Walk() is called from some known
66 location and you don't want to see the first few frames anyhow; also
67 notice that Walk() frame itself is not included if skip = 1).
4701dc09 68
4cc4bfaf 69 Up to @a maxDepth frames are walked from the innermost to the outermost one.
23324ae1 70 */
adaaa686 71 virtual void Walk(size_t skip = 1, size_t maxDepth = 200);
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.
23324ae1 78 */
adaaa686 79 virtual void WalkFromException(size_t maxDepth = 200);
23324ae1
FM
80};
81
82
e54c96f1 83
23324ae1
FM
84/**
85 @class wxStackFrame
7c913512 86
23324ae1 87 wxStackFrame represents a single stack frame, or a single function in the call
4701dc09
FM
88 stack, and is used exclusively together with wxStackWalker, see there for a more
89 detailed discussion.
7c913512 90
23324ae1 91 @library{wxbase}
4701dc09 92 @category{debugging}
7c913512 93
e54c96f1 94 @see wxStackWalker
23324ae1 95*/
7c913512 96class wxStackFrame
23324ae1
FM
97{
98public:
99 /**
100 Return the address of this frame.
101 */
328f5751 102 void* GetAddress() const;
23324ae1
FM
103
104 /**
4701dc09
FM
105 Return the name of the file containing this frame, empty if unavailable
106 (typically because debug info is missing).
107
108 Use HasSourceLocation() to check whether the file name is available.
23324ae1 109 */
328f5751 110 wxString GetFileName() const;
23324ae1
FM
111
112 /**
113 Get the level of this frame (deepest/innermost one is 0).
114 */
328f5751 115 size_t GetLevel() const;
23324ae1
FM
116
117 /**
118 Return the line number of this frame, 0 if unavailable.
3c4f71cc 119
4cc4bfaf 120 @see GetFileName()
23324ae1 121 */
328f5751 122 size_t GetLine() const;
23324ae1
FM
123
124 /**
125 Get the module this function belongs to (empty if not available).
126 */
328f5751 127 wxString GetModule() const;
23324ae1
FM
128
129 /**
4701dc09 130 Return the unmangled (if possible) name of the function containing this frame.
23324ae1 131 */
328f5751 132 wxString GetName() const;
23324ae1
FM
133
134 /**
135 Return the return address of this frame.
136 */
328f5751 137 size_t GetOffset() const;
23324ae1
FM
138
139 /**
140 Get the name, type and value (in text form) of the given parameter.
4701dc09
FM
141 Any pointer may be @NULL if you're not interested in the corresponding value.
142
23324ae1 143 Return @true if at least some values could be retrieved.
4701dc09 144 This function currently is only implemented under Win32 and requires a PDB file.
23324ae1 145 */
4cc4bfaf 146 bool GetParam(size_t n, wxString* type, wxString* name,
328f5751 147 wxString* value) const;
23324ae1
FM
148
149 /**
150 Return the number of parameters of this function (may return 0 if we
151 can't retrieve the parameters info even although the function does have
152 parameters).
153 */
adaaa686 154 virtual size_t GetParamCount() const;
23324ae1
FM
155
156 /**
157 Return @true if we have the file name and line number for this frame.
158 */
328f5751 159 bool HasSourceLocation() const;
23324ae1 160};
e54c96f1 161