/[ascend]/trunk/base/generic/utilities/ascPanic.h
ViewVC logotype

Contents of /trunk/base/generic/utilities/ascPanic.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 976 - (show annotations) (download) (as text)
Tue Dec 19 13:52:51 2006 UTC (16 years, 9 months ago) by johnpye
File MIME type: text/x-chdr
File size: 5655 byte(s)
Improved line/file/func reporting via Asc_Panic, using CPP var-arg macros under GCC.
Added ASC_ASSERT_LT and ASC_ASSERT_EQ assertion macros.
Tracking down a crash in IDA (ongoing).
1 /*
2 ASCEND Language Interpreter
3 AscPanic by Mark Thomas, created 15 May 1997
4 Copyright (C) 2005 Carnegie-Mellon University
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 This file is part of the SLV solver.
20 */
21
22 /** @file
23 Ascend Panic - fatal error handling.
24
25 Requires
26 #include <stdarg.h>
27 #include "utilities/ascConfig.h"
28 */
29
30 /* removed changelog -- see ViewCVS for full history */
31
32 #ifndef ASC_ASCPANIC_H
33 #define ASC_ASCPANIC_H
34
35 #ifndef __GNUC__
36 # ifndef __FUNCTION__
37 # define __FUNCTION__ NULL
38 # endif
39 #endif
40
41 NORETURN ASC_DLLSPEC(void) asc_panic_line(
42 const int status, const char *file, const int line, const char *function,
43 const char *format, ...
44 );
45
46 /* for 'Asc_Panic', use a var-args macro to get local line numbers if possible */
47
48 #if defined(__GNUC__) && !defined(__STRICT_ANSI__)
49 # define Asc_Panic(STAT,FUNC,ARGS...) asc_panic_line(STAT,__FILE__,__LINE__,__func__, ##ARGS)
50 #else
51 # define Asc_Panic asc_panic
52
53 NORETURN ASC_DLLSPEC(void) asc_panic(
54 CONST int status, CONST char *function,
55 CONST char *format, ...
56 );
57
58 #endif
59
60 /**
61 Our assertion macros. Use asc_panic_line to report & handle assertion failure. Disabled if ASC_NO_ASSERTIONS is defined.
62 */
63 #ifdef ASC_NO_ASSERTIONS
64 # define asc_assert(x) ((void)0)
65
66 #else
67 # define asc_assert(cond) \
68 ((cond) ? (void)0 : asc_panic_line(ASCERR_ASSERTION_FAILED\
69 , __FILE__, __LINE__, __FUNCTION__\
70 ,"Assertion failed: %s", #cond))
71
72 #define ASC_ASSERT_LT(A,B) \
73 (((A)<(B)) ? (void)0 : asc_panic_line(ASCERR_ASSERTION_FAILED\
74 , __FILE__, __LINE__, __FUNCTION__\
75 ,"Assertion failed: %s < %s (lhs = %f, rhs = %f)" \
76 , #A, #B \
77 , (float)A, (float)B))
78
79 #define ASC_ASSERT_EQ(A,B) \
80 (((A)==(B)) ? (void)0 : asc_panic_line(ASCERR_ASSERTION_FAILED\
81 , __FILE__, __LINE__, __FUNCTION__\
82 ,"Assertion failed: %s < %s (lhs = %f, rhs = %f)" \
83 , #A, #B \
84 , (float)A, (float)B))
85
86 #endif
87
88 /**< Print fatal error message, run callback function & (usually) exit the program.
89
90 @param status Status code passed by the calling function.
91 @param function Pointer to the name of the calling function.
92 @param format printf-style format string for VAR_ARGS to follow.
93
94 This is the fatal error handler for the ASCEND system. It prints
95 the printf-style variable arguments using the specified format to
96 ASCERR file handle. The message is formatted with a header
97 (e.g. 'ASCEND PANIC!!) and the name of the function (if non-NULL),
98 followed by the variables & format passed as arguments. ASCERR
99 should have been initialized to a valid file stream or else the
100 message will not be printed (checked by assertion). @par
101
102 If a valid file name has been previously set using
103 Asc_PanicSetOutfile(), the message is printed to this file also.
104 Under Windows, a MessageBox will also be displayed with the
105 message. @par
106
107 If a callback has been set using Asc_PanicSetCallback(), the
108 registered function will be called with the specified status.
109 If the callback returns non-NULL, then exit() is called to end
110 the program. This is the default behavior. If the callback
111 is able to resolve the problem, then it should return zero and
112 Asc_Panic() will just return. This will be useful mostly for
113 testing purposes, and should be used with caution.
114 */
115
116 ASC_DLLSPEC(void ) Asc_PanicSetOutfile(CONST char *filename);
117 /**< Sets a file name for reporting of Asc_Panic() messages.
118
119 @param filename Pointer to the name of the file to print messages to.
120
121 Calling this function with a non-NULL "filename" will cause
122 Asc_Panic() to write panic messages to "filename" in addition to the
123 ASCERR file handle. Passing in a "filename" of NULL causes panic
124 messages not to be written to disk---this undoes the effect of
125 previous calls to Asc_PanicSetOutfile().
126 */
127
128 typedef int (*PanicCallbackFunc)(int);
129 /**< Signature of the callback function called by Asc_Panic().
130
131 @param the status code passed to Asc_Panic() by the original caller.
132 @return nonzero if ASCEND should exit, 0 if Asc_Panic should just return.
133
134 This functionality is provided primarily for internal testing
135 purposes. It should be used with extreme caution in release
136 code. Asc_Panic() is called from all over ASCEND for many
137 error conditions, and current calls assume no return.
138 */
139
140 ASC_DLLSPEC(PanicCallbackFunc ) Asc_PanicSetCallback(PanicCallbackFunc func);
141 /**< Registers a callback function to be called by Asc_Panic().
142
143 @param func Pointer to the new function to call during an Asc_Panic().
144 @return A pointer to the previously-registered callback, or NULL
145 if none was registered.
146
147 This allows the user to specify a cleanup function to be
148 called during a fatal error.
149
150 @see PanicCallbackFunc for the form this callback function takes.
151 */
152
153 ASC_DLLSPEC(void ) Asc_PanicDisplayMessageBox(int is_displayed);
154 /**<
155 Controls whether a MessageBox is displayed by Asc_Panic() on Windows.
156
157 @param is_displayed if non-zero, messagebox should be displayed, else not.
158
159 Has no effect on non-Windows platforms.
160 */
161
162 #endif /* ASC_ASCPANIC_H */

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22