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
;
55 fprintf(stderr
, "fatal error encountered in SBCL pid %d",getpid());
56 #if defined(LISP_FEATURE_SB_THREAD)
57 fprintf(stderr
, "(tid %lu)", (unsigned long) thread_self());
60 fprintf(stderr
, ":\n");
62 vfprintf(stderr
, fmt
, ap
);
65 fprintf(stderr
, "\n");
68 fprintf(stderr
, "Argh! lossage_handler() returned, total confusion..\n");
72 /* internal error handler for when the Lisp error system doesn't exist
74 * FIXME: Shouldn't error output go to stderr instead of stdout? (Alas,
75 * this'd require changes in a number of things like brief_print(..),
76 * or I'd have changed it immediately.) */
78 describe_internal_error(os_context_t
*context
)
80 unsigned char *ptr
= arch_internal_error_arguments(context
);
81 int len
, scoffset
, sc
, offset
, ch
;
84 printf("internal error #%d\n", *ptr
++);
89 if (scoffset
== 253) {
93 else if (scoffset
== 254) {
94 scoffset
= ptr
[0] + ptr
[1]*256;
98 else if (scoffset
== 255) {
99 scoffset
= ptr
[0] + (ptr
[1]<<8) + (ptr
[2]<<16) + (ptr
[3]<<24);
103 sc
= scoffset
& 0x1f;
104 offset
= scoffset
>> 5;
106 printf(" SC: %d, Offset: %d", sc
, offset
);
109 case sc_DescriptorReg
:
111 brief_print(*os_context_register_addr(context
, offset
));
114 case sc_CharacterReg
:
115 ch
= *os_context_register_addr(context
, offset
);
116 #ifdef LISP_FEATURE_X86
122 case '\n': printf("\t'\\n'\n"); break;
123 case '\b': printf("\t'\\b'\n"); break;
124 case '\t': printf("\t'\\t'\n"); break;
125 case '\r': printf("\t'\\r'\n"); break;
127 if (ch
< 32 || ch
> 127)
128 printf("\\%03o", ch
);
130 printf("\t'%c'\n", ch
);
135 #ifdef sc_WordPointerReg
136 case sc_WordPointerReg
:
138 printf("\t0x%08lx\n", (unsigned long) *os_context_register_addr(context
, offset
));
141 printf("\t%ld\n", (long) *os_context_register_addr(context
, offset
));
144 printf("\t%lu\n", (unsigned long) *os_context_register_addr(context
, offset
));
146 #ifdef sc_SingleFloatReg
147 case sc_SingleFloatReg
:
148 printf("\t%g\n", *(float *)&context
->sc_fpregs
[offset
]);
151 #ifdef sc_DoubleFloatReg
152 case sc_DoubleFloatReg
:
153 printf("\t%g\n", *(double *)&context
->sc_fpregs
[offset
]);
163 /* utility routines used by miscellaneous pieces of code */
165 lispobj
debug_print(lispobj string
)
167 /* This is a kludge. It's not actually safe - in general - to use
168 %primitive print on the alpha, because it skips half of the
169 number stack setup that should usually be done on a function
170 call, so the called routine (i.e. this one) ends up being able
171 to overwrite local variables in the caller. Rather than fix
172 this everywhere that %primitive print is used (it's only a
173 debugging aid anyway) we just guarantee our safety by putting
174 an unused buffer on the stack before doing anything else
177 fprintf(stderr
, "%s\n",
178 (char *)(((struct vector
*)native_pointer(string
))->data
));
179 /* shut GCC up about not using this, because that's the point.. */