[c23e4d]: src / code / interr.lisp Maximize Restore History

Download this file

interr.lisp    473 lines (400 with data), 13.7 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
;;;; functions and macros to define and deal with internal errors
;;;; (i.e. problems that can be signaled from assembler code)
;;;; This software is part of the SBCL system. See the README file for
;;;; more information.
;;;;
;;;; This software is derived from the CMU CL system, which was
;;;; written at Carnegie Mellon University and released into the
;;;; public domain. The software is in the public domain and is
;;;; provided with absolutely no warranty. See the COPYING and CREDITS
;;;; files for more information.
(in-package "SB!KERNEL")
;;;; internal errors
(defvar *internal-errors*
#.(map 'vector #'cdr sb!c:*backend-internal-errors*))
(eval-when (:compile-toplevel :execute)
(sb!xc:defmacro deferr (name args &rest body)
(let* ((rest-pos (position '&rest args))
(required (if rest-pos (subseq args 0 rest-pos) args))
(fp (gensym))
(context (gensym))
(sc-offsets (gensym))
(fn-name (symbolicate name "-HANDLER")))
`(progn
;; FIXME: Having a separate full DEFUN for each error doesn't
;; seem to add much value, and it takes a lot of space. Perhaps
;; we could do this dispatch with a big CASE statement instead?
(defun ,fn-name (name ,fp ,context ,sc-offsets)
;; FIXME: It would probably be good to do *STACK-TOP-HINT*
;; tricks to hide this internal error-handling logic from the
;; poor high level user, so his debugger tells him about
;; where his error was detected instead of telling him where
;; he ended up inside the system error-handling logic.
(declare (ignorable name ,fp ,context ,sc-offsets))
(let (,@(let ((offset -1))
(mapcar (lambda (var)
`(,var (sb!di::sub-access-debug-var-slot
,fp
(nth ,(incf offset)
,sc-offsets)
,context)))
required))
,@(when rest-pos
`((,(nth (1+ rest-pos) args)
(mapcar (lambda (sc-offset)
(sb!di::sub-access-debug-var-slot
,fp
sc-offset
,context))
(nthcdr ,rest-pos ,sc-offsets))))))
,@body))
(setf (svref *internal-errors* ,(error-number-or-lose name))
#',fn-name))))
) ; EVAL-WHEN
(deferr unknown-error (&rest args)
(error "unknown error:~{ ~S~})" args))
(deferr object-not-fun-error (object)
(error 'type-error
:datum object
:expected-type 'function))
(deferr object-not-list-error (object)
(error 'type-error
:datum object
:expected-type 'list))
(deferr object-not-bignum-error (object)
(error 'type-error
:datum object
:expected-type 'bignum))
(deferr object-not-ratio-error (object)
(error 'type-error
:datum object
:expected-type 'ratio))
(deferr object-not-single-float-error (object)
(error 'type-error
:datum object
:expected-type 'single-float))
(deferr object-not-double-float-error (object)
(error 'type-error
:datum object
:expected-type 'double-float))
#!+long-float
(deferr object-not-long-float-error (object)
(error 'type-error
:datum object
:expected-type 'long-float))
(deferr object-not-simple-string-error (object)
(error 'type-error
:datum object
:expected-type 'simple-string))
(deferr object-not-fixnum-error (object)
(error 'type-error
:datum object
:expected-type 'fixnum))
(deferr object-not-vector-error (object)
(error 'type-error
:datum object
:expected-type 'vector))
(deferr object-not-string-error (object)
(error 'type-error
:datum object
:expected-type 'string))
(deferr object-not-base-string-error (object)
(error 'type-error
:datum object
:expected-type 'base-string))
(deferr object-not-vector-nil-error (object)
(error 'type-error
:datum object
:expected-type '(vector nil)))
#!+sb-unicode
(deferr object-not-character-string-error (object)
(error 'type-error
:datum object
:expected-type '(vector character)))
(deferr object-not-bit-vector-error (object)
(error 'type-error
:datum object
:expected-type 'bit-vector))
(deferr object-not-array-error (object)
(error 'type-error
:datum object
:expected-type 'array))
(deferr object-not-number-error (object)
(error 'type-error
:datum object
:expected-type 'number))
(deferr object-not-rational-error (object)
(error 'type-error
:datum object
:expected-type 'rational))
(deferr object-not-float-error (object)
(error 'type-error
:datum object
:expected-type 'float))
(deferr object-not-real-error (object)
(error 'type-error
:datum object
:expected-type 'real))
(deferr object-not-integer-error (object)
(error 'type-error
:datum object
:expected-type 'integer))
(deferr object-not-cons-error (object)
(error 'type-error
:datum object
:expected-type 'cons))
(deferr object-not-symbol-error (object)
(error 'type-error
:datum object
:expected-type 'symbol))
(deferr undefined-fun-error (fdefn-or-symbol)
(error 'undefined-function
:name (etypecase fdefn-or-symbol
(symbol fdefn-or-symbol)
(fdefn (fdefn-name fdefn-or-symbol)))))
(deferr invalid-arg-count-error (nargs)
(error 'simple-program-error
:format-control "invalid number of arguments: ~S"
:format-arguments (list nargs)))
(deferr bogus-arg-to-values-list-error (list)
(error 'simple-type-error
:datum list
:expected-type 'list
:format-control
"~@<attempt to use VALUES-LIST on a dotted list: ~2I~_~S~:>"
:format-arguments (list list)))
(deferr unbound-symbol-error (symbol)
(error 'unbound-variable :name symbol))
(deferr object-not-character-error (object)
(error 'type-error
:datum object
:expected-type 'character))
(deferr object-not-sap-error (object)
(error 'type-error
:datum object
:expected-type 'system-area-pointer))
(deferr invalid-unwind-error ()
(error 'simple-control-error
:format-control
"attempt to RETURN-FROM a block or GO to a tag that no longer exists"
))
(deferr unseen-throw-tag-error (tag)
(error 'simple-control-error
:format-control "attempt to THROW to a tag that does not exist: ~S"
:format-arguments (list tag)))
(deferr nil-fun-returned-error (function)
(error 'simple-control-error
:format-control
"A function with declared result type NIL returned:~% ~S"
:format-arguments (list function)))
(deferr nil-array-accessed-error (array)
(error 'nil-array-accessed-error
:datum array :expected-type '(not (array nil))))
(deferr division-by-zero-error (this that)
(error 'division-by-zero
:operation 'division
:operands (list this that)))
(deferr object-not-type-error (object type)
(error (if (and (typep object 'instance)
(layout-invalid (%instance-layout object)))
'layout-invalid
'type-error)
:datum object
:expected-type type))
(deferr layout-invalid-error (object layout)
(error 'layout-invalid
:datum object
:expected-type (layout-classoid layout)))
(deferr odd-key-args-error ()
(error 'simple-program-error
:format-control "odd number of &KEY arguments"))
(deferr unknown-key-arg-error (key-name)
(error 'simple-program-error
:format-control "unknown &KEY argument: ~S"
:format-arguments (list key-name)))
(deferr invalid-array-index-error (array bound index)
(error 'simple-type-error
:format-control
"invalid array index ~W for ~S (should be nonnegative and <~W)"
:format-arguments (list index array bound)
:datum index
:expected-type `(integer 0 (,bound))))
(deferr object-not-simple-array-error (object)
(error 'type-error
:datum object
:expected-type 'simple-array))
(deferr object-not-signed-byte-32-error (object)
(error 'type-error
:datum object
:expected-type '(signed-byte 32)))
(deferr object-not-unsigned-byte-32-error (object)
(error 'type-error
:datum object
:expected-type '(unsigned-byte 32)))
#!+#.(cl:if (cl:= 64 sb!vm:n-word-bits) '(and) '(or))
(deferr object-not-signed-byte-64-error (object)
(error 'type-error
:datum object
:expected-type '(signed-byte 64)))
#!+#.(cl:if (cl:= 64 sb!vm:n-word-bits) '(and) '(or))
(deferr object-not-unsigned-byte-64-error (object)
(error 'type-error
:datum object
:expected-type '(unsigned-byte 64)))
(macrolet
((define-simple-array-internal-errors ()
`(progn
,@(map 'list
(lambda (saetp)
`(deferr ,(symbolicate
"OBJECT-NOT-"
(sb!vm:saetp-primitive-type-name saetp)
"-ERROR")
(object)
(error 'type-error
:datum object
:expected-type '(simple-array
,(sb!vm:saetp-specifier saetp)
(*)))))
sb!vm:*specialized-array-element-type-properties*))))
(define-simple-array-internal-errors))
(deferr object-not-complex-error (object)
(error 'type-error
:datum object
:expected-type 'complex))
(deferr object-not-complex-rational-error (object)
(error 'type-error
:datum object
:expected-type '(complex rational)))
(deferr object-not-complex-single-float-error (object)
(error 'type-error
:datum object
:expected-type '(complex single-float)))
(deferr object-not-complex-double-float-error (object)
(error 'type-error
:datum object
:expected-type '(complex double-float)))
#!+long-float
(deferr object-not-complex-long-float-error (object)
(error 'type-error
:datum object
:expected-type '(complex long-float)))
(deferr object-not-weak-pointer-error (object)
(error 'type-error
:datum object
:expected-type 'weak-pointer))
(deferr object-not-instance-error (object)
(error 'type-error
:datum object
:expected-type 'instance))
(deferr object-not-complex-vector-error (object)
(error 'type-error
:datum object
:expected-type '(and vector (not simple-array))))
;;;; fetching errorful function name
;;; This flag is used to prevent infinite recursive lossage when
;;; we can't find the caller for some reason.
(defvar *finding-name* nil)
(defun find-caller-name-and-frame ()
(if *finding-name*
(values "<error finding caller name -- already finding name>" nil)
(handler-case
(let* ((*finding-name* t)
(frame (sb!di:frame-down (sb!di:frame-down (sb!di:top-frame))))
(name (sb!di:debug-fun-name
(sb!di:frame-debug-fun frame))))
(sb!di:flush-frames-above frame)
(values name frame))
(error ()
(values "<error finding caller name -- trapped error>" nil))
(sb!di:debug-condition ()
(values "<error finding caller name -- trapped debug-condition>"
nil)))))
(defun find-interrupted-name ()
(/show0 "entering FIND-INTERRUPTED-NAME")
(if *finding-name*
(values "<error finding interrupted name -- already finding name>" nil)
(handler-case
(let ((*finding-name* t))
(/show0 "in ordinary case")
(do ((frame (sb!di:top-frame) (sb!di:frame-down frame)))
((null frame)
(/show0 "null frame")
(values "<error finding interrupted name -- null frame>" nil))
(/show0 "at head of DO loop")
(when (and (sb!di::compiled-frame-p frame)
(sb!di::compiled-frame-escaped frame))
(sb!di:flush-frames-above frame)
(/show0 "returning from within DO loop")
(return (values (sb!di:debug-fun-name
(sb!di:frame-debug-fun frame))
frame)))))
(error ()
(/show0 "trapped ERROR")
(values "<error finding interrupted name -- trapped error>" nil))
(sb!di:debug-condition ()
(/show0 "trapped DEBUG-CONDITION")
(values "<error finding interrupted name -- trapped debug-condition>"
nil)))))
;;;; INTERNAL-ERROR signal handler
(defvar *internal-error-args*)
(defun internal-error (context continuable)
(declare (type system-area-pointer context))
(declare (ignore continuable))
(/show0 "entering INTERNAL-ERROR, CONTEXT=..")
(/hexstr context)
(infinite-error-protect
(/show0 "about to bind ALIEN-CONTEXT")
(let ((alien-context (locally
(declare (optimize (inhibit-warnings 3)))
(sb!alien:sap-alien context (* os-context-t)))))
(/show0 "about to bind ERROR-NUMBER and ARGUMENTS")
(multiple-value-bind (error-number arguments)
(sb!vm:internal-error-args alien-context)
;; There's a limit to how much error reporting we can usefully
;; do before initialization is complete, but try to be a little
;; bit helpful before we die.
(/show0 "back from INTERNAL-ERROR-ARGS, ERROR-NUMBER=..")
(/hexstr error-number)
(/show0 "cold/low ARGUMENTS=..")
(/hexstr arguments)
(unless *cold-init-complete-p*
(%primitive print "can't recover from error in cold init, halting")
(%primitive sb!c:halt))
(multiple-value-bind (name sb!debug:*stack-top-hint*)
(find-interrupted-name)
(/show0 "back from FIND-INTERRUPTED-NAME")
(let ((fp (int-sap (sb!vm:context-register alien-context
sb!vm::cfp-offset)))
(handler (and (< -1 error-number (length *internal-errors*))
(svref *internal-errors* error-number))))
(cond ((null handler)
(error 'simple-error
:format-control
"unknown internal error, ~D, args=~S"
:format-arguments
(list error-number
(mapcar (lambda (sc-offset)
(sb!di::sub-access-debug-var-slot
fp sc-offset alien-context))
arguments))))
((not (functionp handler))
(error 'simple-error
:format-control "internal error ~D: ~A; args=~S"
:format-arguments
(list error-number
handler
(mapcar (lambda (sc-offset)
(sb!di::sub-access-debug-var-slot
fp sc-offset alien-context))
arguments))))
(t
(funcall handler name fp alien-context arguments)))))))))
(defun control-stack-exhausted-error ()
(let ((sb!debug:*stack-top-hint* nil))
(infinite-error-protect
(format *error-output*
"Control stack guard page temporarily disabled: proceed with caution~%")
(error 'control-stack-exhausted))))
(defun undefined-alien-error ()
(error 'undefined-alien-error))