Debian Codegraph @

misc/pserror.h

raw symbols SCIP
1 /*
2 * Descent 3
3 * Copyright (C) 2024 Parallax Software
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 --- HISTORICAL COMMENTS FOLLOW ---
19
20 * $Logfile: /DescentIII/Main/lib/pserror.h $
21 * $Revision: 25 $
22 * $Date: 3/20/00 12:26p $
23 * $Author: Matt $
24 *
25 * error functions
26 *
27 * $Log: /DescentIII/Main/lib/pserror.h $
28 *
29 * 25 3/20/00 12:26p Matt
30 * Merge of Duane's post-1.3 changes.
31 * Mac include and assert changes
32 *
33 * 24 10/21/99 9:28p Jeff
34 * B.A. Macintosh code merge
35 *
36 * 23 7/28/99 3:13p Kevin
37 * Mac
38 *
39 * 22 5/10/99 10:53p Ardussi
40 * changes to compile on Mac
41 *
42 * 21 4/14/99 10:46a Kevin
43 * Removed OutrageMessageBox from release builds
44 *
45 * 20 4/01/99 4:50p Matt
46 * Took out Warning() function, chaning those calls to mprintf()
47 *
48 * 19 1/09/99 4:39p Jeff
49 * added some ifdefs and fixes to get files to compile under Linux
50 *
51 * 18 10/18/98 8:52p Matt
52 * Revamped debug/error system.
53 *
54 * 17 10/13/98 12:03p Kevin
55 * Changed use of preprocessors for debug, etc.
56 *
57 * 16 10/12/98 10:20a Samir
58 * added parameter to debug init.
59 *
60 * 15 6/23/98 2:40p Matt
61 * Added Yes/No/Cancel type to OutrageMessageBox() and
62 * Debug_MesssageBox(), and changed return value from a bool to an
63 * integer.
64 *
65 * 14 6/01/98 4:28p Samir
66 * added HEAPCHECK macro.
67 *
68 * 13 4/23/98 4:14a Samir
69 * added warning system.
70 *
71 * 12 4/08/98 7:19p Samir
72 * Added runtime debugging option.
73 *
74 * 11 4/07/98 9:20p Samir
75 * Changes to debug stuff.
76 *
77 * 10 4/03/98 5:15p Samir
78 * Implemented simple debug message filtering.
79 *
80 * 9 3/20/98 2:43p Samir
81 * Some better Int3 support.
82 *
83 * 8 3/19/98 11:27a Samir
84 * Better error checking.
85 *
86 * 7 3/17/98 2:37p Samir
87 * Added debug callback support for assert.
88 *
89 * 6 3/10/98 5:16p Samir
90 * Got debug callbacks working when you hit an Int3.
91 *
92 * 5 2/20/98 12:11p Matt
93 * Changed ASSERT() to print its own mono message and call debug_break
94 * directly, instead of using Int3().
95 *
96 * 4 12/01/97 2:12p Samir
97 * Int3 for assertions.
98 *
99 * 3 9/16/97 5:07p Matt
100 * Disable Int3() when _DEBUG not set
101 *
102 * 2 9/04/97 12:02p Matt
103 * Changed the simple form OutrageMessageBox() to be void (instead of
104 * bool) since it wasn't returning a meaningful value anyway
105 *
106 * 19 6/11/97 1:11p Samir
107 * Implemented new Debug system
108 *
109 * 18 3/14/97 4:15p Matt
110 * Changed title of OutrageMessageBox() dialogs
111 *
112 * 17 3/10/97 11:13a Samir
113 * Changes made to reflect deletion of OSDebug class from system
114 *
115 * 16 3/04/97 1:00p Samir
116 * Fixed return type prototype errors.
117 *
118 * 15 3/04/97 12:55p Samir
119 * Added yesno and ok messageboxes.
120 *
121 * 14 3/03/97 5:22p Samir
122 * Pass debug object to error_init.
123 *
124 * 13 2/26/97 7:06p Samir
125 * call err_Break instead of Int3 to keep PC code out of pserror.h
126 *
127 * 12 2/26/97 4:49 PM Jeremy
128 * Put "assert.h" as <assert.h> since it's an ANSI file not one of ours.
129 *
130 * 11 2/06/97 6:32p Samir
131 * Int3 now tells us where we broke.
132 *
133 * 10 2/06/97 11:28a Matt
134 * Put do..while around Int3 definition so Int3() acts like a normal
135 * statement.
136 *
137 * 9 1/31/97 2:12p Samir
138 * Fixed prototype for error_init
139 *
140 * 8 1/31/97 1:52p Samir
141 * added error_init function
142 *
143 * 7 1/30/97 6:02p Samir
144 * Added DEBUG_STACK macro
145 *
146 * $NoKeywords: $
147 */
148
149 #ifndef PSERROR_H
150 #define PSERROR_Hcxx . . $ `misc/pserror.h:150:9`!
151 #include <assert.h>
152 #include "debug.h"cxx . . $ `<file>/ddebug/debug.h`/
153 #include "mono.h"cxx . . $ `<file>/ddebug/mono.h`/
154
155 // initializes error handler.
156 bool error_Initcxx . . $ error_Init(c4501528ba8b3ce4).(bool debugger, const char *app_title);
157 // exits the application and prints out a standard error message
158 void Errorcxx . . $ Error(326aeb464d16410c).(const char *fmt, ...);
159 // prints out an assertion error
160 void AssertionFailedcxx . . $ AssertionFailed(5e891a9f77bb0eff).(const char *expstr, const char *file, int line);
161 // Brings up an error message for an int3
162 void Int3MessageBoxcxx . . $ Int3MessageBox(34d26762b42c433a).(const char *file, int line);
163 // Message box functions
164 #define MBOX_OKcxx . . $ `misc/pserror.h:164:9`! 1
165 #define MBOX_YESNOcxx . . $ `misc/pserror.h:165:9`! 2
166 #define MBOX_YESNOCANCELcxx . . $ `misc/pserror.h:166:9`! 3
167 #define MBOX_ABORTRETRYIGNOREcxx . . $ `misc/pserror.h:167:9`! 4
168 // prints out a standard OS messagebox
169 void OutrageMessageBoxcxx . . $ OutrageMessageBox(326aeb464d16410c).(const char *str, ...);
170 int OutrageMessageBoxcxx . . $ OutrageMessageBox(811d273381043e7b).(int type, const char *str, ...);
171 // Sets the title for future OutrageMessageBox() dialogs
172 void SetMessageBoxTitlecxx . . $ SetMessageBoxTitle(85c52e162fed56f9).(const char *title);
173 // Write a block of text to the system clipboard
174 void DumpTextToClipboardcxx . . $ DumpTextToClipboard(fda57c8427c60377).(char *text);
175 //////////////////////////////////////////////////////////////////////////////
176 // development debugging functions
177 // adds a function to be called when a debug break occurs.
178 // undefine any ASSERT macro previously defined.
179 #ifdef ASSERT
180 #undef ASSERT
181 #endif
182 // this callback is invoked when a DEBUG_BREAK macro is used.
183 // arguments
184 // style = 1 if ASSERT
185 // = 0 if Int3 debugger break.
186 extern void (*DebugBreak_callback_stopcxx . . $ DebugBreak_callback_stop.)();
187 extern void (*DebugBreak_callback_resumecxx . . $ DebugBreak_callback_resume.)();
188 // set DEBUG_BREAK callback
189 static inline void SetDebugBreakHandlerscxx . . $ SetDebugBreakHandlers(af7ac88fdfa0d6bb).(void (*stop)(), void (*resume)()) {
190 DebugBreak_callback_stopcxx . . $ DebugBreak_callback_stop. = stop;
191 DebugBreak_callback_resumecxx . . $ DebugBreak_callback_resume. = resume;
192 }
193 // DEBUG_BREAK()
194 // Calls the debug_break() macro surrounded by calls to the debug callbacks (to turn off & on graphics)
195 // ASSERT()
196 // Like the standard C assert(), but if the condition failed and debugging on,
197 // does a DEBUG_BREAK(). If debugging on, brings up a dialog.
198 // Int3()
199 // Does a DEBUG_BREAK() if debugging is turned on. Also does an mprintf().
200 // Define the macros
201 #ifndef RELEASE
202 #include <cstdlib>
203 #if defined(WIN32)
204 #define DEBUG_BREAK() \
205 do { \
206 if (DebugBreak_callback_stop) \
207 (*DebugBreak_callback_stop)(); \
208 debug_break(); \
209 if (DebugBreak_callback_resume) \
210 (*DebugBreak_callback_resume)(); \
211 } while (0)
212 #define ASSERT(x) \
213 do { \
214 if (!(x)) { \
215 mprintf(0, "Assertion failed (%s) in %s line %d.\n", #x, __FILE__, __LINE__); \
216 if (Debug_break) \
217 DEBUG_BREAK(); \
218 else \
219 AssertionFailed(#x, __FILE__, __LINE__); \
220 } \
221 } while (0)
222 #define Int3() \
223 do { \
224 mprintf(0, "Int3 at %s line %d.\n", __FILE__, __LINE__); \
225 if (Debug_break) \
226 DEBUG_BREAK(); \
227 else \
228 Int3MessageBox(__FILE__, __LINE__); \
229 } while (0)
230 #define HEAPCHECK() \
231 do { \
232 if (_heapchk() != _HEAPOK) \
233 Int3(); \
234 } while (0)
235 #elif defined(POSIXcxx . . $ `<built-in>:477:9`!)
236 #include "SDL.h"
237 // For some reason Linux doesn't like the \ continuation character, so I have to uglify this
238 #define DEBUG_BREAKcxx . . $ `misc/pserror.h:238:9`!() \
239 do { \
240 if (DebugBreak_callback_stop) \
241 (*DebugBreak_callback_stop)(); \
242 debug_break(); \
243 if (DebugBreak_callback_resume) \
244 (*DebugBreak_callback_resume)(); \
245 } while (0)
246 #define ASSERTcxx . . $ `misc/pserror.h:246:9`!(x) SDL_assertcxx . . $ `<external>/6134065512448797854/SDL_assert.h:177:12`!(x)
247 #define Int3cxx . . $ `misc/pserror.h:247:9`!() \
248 do { \
249 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Int3 at %s line %d.\n", __FILE__, __LINE__); \
250 if (Debug_break) \
251 DEBUG_BREAKcxx . . $ `misc/pserror.h:238:9`!(); \
252 else \
253 Int3MessageBox(__FILE__, __LINE__); \
254 } while (0)
255 #define HEAPCHECKcxx . . $ `misc/pserror.h:255:9`!()
256 #endif
257 #else
258 #define DEBUG_BREAK()
259 #define ASSERT(x)
260 #define Int3()
261 #define HEAPCHECK()
262 #endif
263 #endif