2 * stuff to handle internal errors
6 * This software is part of the SBCL system. See the README file for
9 * This software is derived from the CMU CL system, which was
10 * written at Carnegie Mellon University and released into the
11 * public domain. The software is in the public domain and is
12 * provided with absolutely no warranty. See the COPYING and CREDITS
13 * files for more information.
28 #include "genesis/static-symbols.h"
29 #include "genesis/vector.h"
33 /* the way that we shut down the system on a fatal error */
36 default_lossage_handler(void)
40 static void (*lossage_handler)(void) = default_lossage_handler;
42 void enable_lossage_handler(void)
44 lossage_handler = monitor_or_something;
46 void disable_lossage_handler(void)
48 lossage_handler = default_lossage_handler;
52 void print_message(char *fmt, va_list ap)
54 fprintf(stderr, " in SBCL pid %d",getpid());
55 #if defined(LISP_FEATURE_SB_THREAD)
56 fprintf(stderr, "(tid %lu)", (unsigned long) thread_self());
59 fprintf(stderr, ":\n");
60 vfprintf(stderr, fmt, ap);
62 fprintf(stderr, "\n");
66 call_lossage_handler() never_returns;
69 call_lossage_handler()
72 fprintf(stderr, "Argh! lossage_handler() returned, total confusion..\n");
80 /* Block signals to prevent other threads, timers and such from
81 * interfering. If only all threads could be stopped somehow. */
82 block_blockable_signals();
83 fprintf(stderr, "fatal error encountered");
85 print_message(fmt, ap);
87 fprintf(stderr, "\n");
89 call_lossage_handler();
92 boolean lose_on_corruption_p = 0;
95 corruption_warning_and_maybe_lose(char *fmt, ...)
99 thread_sigmask(SIG_BLOCK, &blockable_sigset, &oldset);
100 fprintf(stderr, "CORRUPTION WARNING");
102 print_message(fmt, ap);
104 fprintf(stderr, "The integrity of this image is possibly compromised.\n");
105 if (lose_on_corruption_p)
106 fprintf(stderr, "Exiting.\n");
108 fprintf(stderr, "Continuing with fingers crossed.\n");
110 if (lose_on_corruption_p)
111 call_lossage_handler();
113 thread_sigmask(SIG_SETMASK,&oldset,0);
116 /* internal error handler for when the Lisp error system doesn't exist
118 * FIXME: Shouldn't error output go to stderr instead of stdout? (Alas,
119 * this'd require changes in a number of things like brief_print(..),
120 * or I'd have changed it immediately.) */
122 describe_internal_error(os_context_t *context)
124 unsigned char *ptr = arch_internal_error_arguments(context);
125 int len, scoffset, sc, offset, ch;
128 printf("internal error #%d\n", *ptr++);
133 if (scoffset == 253) {
137 else if (scoffset == 254) {
138 scoffset = ptr[0] + ptr[1]*256;
142 else if (scoffset == 255) {
143 scoffset = ptr[0] + (ptr[1]<<8) + (ptr[2]<<16) + (ptr[3]<<24);
147 sc = scoffset & 0x1f;
148 offset = scoffset >> 5;
150 printf(" SC: %d, Offset: %d", sc, offset);
153 case sc_DescriptorReg:
155 brief_print(*os_context_register_addr(context, offset));
158 case sc_CharacterReg:
159 ch = *os_context_register_addr(context, offset);
160 #ifdef LISP_FEATURE_X86
166 case '\n': printf("\t'\\n'\n"); break;
167 case '\b': printf("\t'\\b'\n"); break;
168 case '\t': printf("\t'\\t'\n"); break;
169 case '\r': printf("\t'\\r'\n"); break;
171 if (ch < 32 || ch > 127)
172 printf("\\%03o", ch);
174 printf("\t'%c'\n", ch);
179 #ifdef sc_WordPointerReg
180 case sc_WordPointerReg:
182 printf("\t0x%08lx\n", (unsigned long) *os_context_register_addr(context, offset));
185 printf("\t%ld\n", (long) *os_context_register_addr(context, offset));
188 printf("\t%lu\n", (unsigned long) *os_context_register_addr(context, offset));
190 #ifdef sc_SingleFloatReg
191 case sc_SingleFloatReg:
192 printf("\t%g\n", *(float *)&context->sc_fpregs[offset]);
195 #ifdef sc_DoubleFloatReg
196 case sc_DoubleFloatReg:
197 printf("\t%g\n", *(double *)&context->sc_fpregs[offset]);
207 /* utility routines used by miscellaneous pieces of code */
209 lispobj debug_print(lispobj string)
211 /* This is a kludge. It's not actually safe - in general - to use
212 %primitive print on the alpha, because it skips half of the
213 number stack setup that should usually be done on a function
214 call, so the called routine (i.e. this one) ends up being able
215 to overwrite local variables in the caller. Rather than fix
216 this everywhere that %primitive print is used (it's only a
217 debugging aid anyway) we just guarantee our safety by putting
218 an unused buffer on the stack before doing anything else
221 fprintf(stderr, "%s\n",
222 (char *)(((struct vector *)native_pointer(string))->data));
223 /* shut GCC up about not using this, because that's the point.. */