| 1 |
/* |
| 2 |
* tclPanic.c -- |
| 3 |
* |
| 4 |
* Source code for the "Tcl_Panic" library procedure for Tcl; individual |
| 5 |
* applications will probably call Tcl_SetPanicProc() to set an |
| 6 |
* application-specific panic procedure. |
| 7 |
* |
| 8 |
* Copyright (c) 1988-1993 The Regents of the University of California. |
| 9 |
* Copyright (c) 1994 Sun Microsystems, Inc. |
| 10 |
* Copyright (c) 1998-1999 by Scriptics Corporation. |
| 11 |
* |
| 12 |
* See the file "license.terms" for information on usage and redistribution of |
| 13 |
* this file, and for a DISCLAIMER OF ALL WARRANTIES. |
| 14 |
*/ |
| 15 |
|
| 16 |
#include "tclInt.h" |
| 17 |
#if defined(_WIN32) || defined(__CYGWIN__) |
| 18 |
MODULE_SCOPE TCL_NORETURN void tclWinDebugPanic(const char *format, ...); |
| 19 |
#endif |
| 20 |
|
| 21 |
/* |
| 22 |
* The panicProc variable contains a pointer to an application specific panic |
| 23 |
* procedure. |
| 24 |
*/ |
| 25 |
|
| 26 |
#if defined(__CYGWIN__) |
| 27 |
static Tcl_PanicProc *panicProc = tclWinDebugPanic; |
| 28 |
#else |
| 29 |
static Tcl_PanicProc *panicProc = NULL; |
| 30 |
#endif |
| 31 |
|
| 32 |
/* |
| 33 |
*---------------------------------------------------------------------- |
| 34 |
* |
| 35 |
* Tcl_SetPanicProc -- |
| 36 |
* |
| 37 |
* Replace the default panic behavior with the specified function. |
| 38 |
* |
| 39 |
* Results: |
| 40 |
* None. |
| 41 |
* |
| 42 |
* Side effects: |
| 43 |
* Sets the panicProc variable. |
| 44 |
* |
| 45 |
*---------------------------------------------------------------------- |
| 46 |
*/ |
| 47 |
|
| 48 |
void |
| 49 |
Tcl_SetPanicProc( |
| 50 |
TCL_NORETURN1 Tcl_PanicProc *proc) |
| 51 |
{ |
| 52 |
#if defined(_WIN32) |
| 53 |
/* tclWinDebugPanic only installs if there is no panicProc yet. */ |
| 54 |
if ((proc != tclWinDebugPanic) || (panicProc == NULL)) |
| 55 |
#elif defined(__CYGWIN__) |
| 56 |
if (proc == NULL) |
| 57 |
panicProc = tclWinDebugPanic; |
| 58 |
else |
| 59 |
#endif |
| 60 |
panicProc = proc; |
| 61 |
} |
| 62 |
|
| 63 |
/* |
| 64 |
*---------------------------------------------------------------------- |
| 65 |
* |
| 66 |
* Tcl_PanicVA -- |
| 67 |
* |
| 68 |
* Print an error message and kill the process. |
| 69 |
* |
| 70 |
* Results: |
| 71 |
* None. |
| 72 |
* |
| 73 |
* Side effects: |
| 74 |
* The process dies, entering the debugger if possible. |
| 75 |
* |
| 76 |
*---------------------------------------------------------------------- |
| 77 |
*/ |
| 78 |
|
| 79 |
TCL_NORETURN void |
| 80 |
Tcl_PanicVA( |
| 81 |
const char *format, /* Format string, suitable for passing to |
| 82 |
* fprintf. */ |
| 83 |
va_list argList) /* Variable argument list. */ |
| 84 |
{ |
| 85 |
char *arg1, *arg2, *arg3; /* Additional arguments (variable in number) |
| 86 |
* to pass to fprintf. */ |
| 87 |
char *arg4, *arg5, *arg6, *arg7, *arg8; |
| 88 |
|
| 89 |
arg1 = va_arg(argList, char *); |
| 90 |
arg2 = va_arg(argList, char *); |
| 91 |
arg3 = va_arg(argList, char *); |
| 92 |
arg4 = va_arg(argList, char *); |
| 93 |
arg5 = va_arg(argList, char *); |
| 94 |
arg6 = va_arg(argList, char *); |
| 95 |
arg7 = va_arg(argList, char *); |
| 96 |
arg8 = va_arg(argList, char *); |
| 97 |
|
| 98 |
if (panicProc != NULL) { |
| 99 |
panicProc(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8); |
| 100 |
#ifdef _WIN32 |
| 101 |
} else if (IsDebuggerPresent()) { |
| 102 |
tclWinDebugPanic(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8); |
| 103 |
#endif |
| 104 |
} else { |
| 105 |
fprintf(stderr, format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, |
| 106 |
arg8); |
| 107 |
fprintf(stderr, "\n"); |
| 108 |
fflush(stderr); |
| 109 |
} |
| 110 |
#if defined(_WIN32) || defined(__CYGWIN__) |
| 111 |
#if defined(__GNUC__) |
| 112 |
__builtin_trap(); |
| 113 |
#elif defined(_WIN64) |
| 114 |
__debugbreak(); |
| 115 |
#elif defined(_MSC_VER) && defined (_M_IX86) |
| 116 |
_asm {int 3} |
| 117 |
#else |
| 118 |
DebugBreak(); |
| 119 |
#endif |
| 120 |
#endif |
| 121 |
#if defined(_WIN32) |
| 122 |
ExitProcess(1); |
| 123 |
#else |
| 124 |
abort(); |
| 125 |
#endif |
| 126 |
} |
| 127 |
|
| 128 |
/* |
| 129 |
*---------------------------------------------------------------------- |
| 130 |
* |
| 131 |
* Tcl_Panic -- |
| 132 |
* |
| 133 |
* Print an error message and kill the process. |
| 134 |
* |
| 135 |
* Results: |
| 136 |
* None. |
| 137 |
* |
| 138 |
* Side effects: |
| 139 |
* The process dies, entering the debugger if possible. |
| 140 |
* |
| 141 |
*---------------------------------------------------------------------- |
| 142 |
*/ |
| 143 |
|
| 144 |
/* ARGSUSED */ |
| 145 |
|
| 146 |
/* |
| 147 |
* The following comment is here so that Coverity's static analyzer knows that |
| 148 |
* a Tcl_Panic() call can never return and avoids lots of false positives. |
| 149 |
*/ |
| 150 |
|
| 151 |
/* coverity[+kill] */ |
| 152 |
TCL_NORETURN void |
| 153 |
Tcl_Panic( |
| 154 |
const char *format, |
| 155 |
...) |
| 156 |
{ |
| 157 |
va_list argList; |
| 158 |
|
| 159 |
va_start(argList, format); |
| 160 |
Tcl_PanicVA(format, argList); |
| 161 |
} |
| 162 |
|
| 163 |
/* |
| 164 |
* Local Variables: |
| 165 |
* mode: c |
| 166 |
* c-basic-offset: 4 |
| 167 |
* fill-column: 78 |
| 168 |
* End: |
| 169 |
*/ |