redesign exiting SBCL
[sbcl.git] / tests / debug.impure.lisp
1 ;;;; This file is for testing debugging functionality, using
2 ;;;; test machinery which might have side effects (e.g.
3 ;;;; executing DEFUN).
4
5 ;;;; This software is part of the SBCL system. See the README file for
6 ;;;; more information.
7 ;;;;
8 ;;;; While most of SBCL is derived from the CMU CL system, the test
9 ;;;; files (like this one) were written from scratch after the fork
10 ;;;; from CMU CL.
11 ;;;;
12 ;;;; This software is in the public domain and is provided with
13 ;;;; absolutely no warranty. See the COPYING and CREDITS files for
14 ;;;; more information.
15
16 (cl:in-package :cl-user)
17
18 ;;; The debugger doesn't have any native knowledge of the interpreter
19 (when (eq sb-ext:*evaluator-mode* :interpret)
20   (sb-ext:exit :code 104))
21
22 \f
23 ;;;; Check that we get debug arglists right.
24
25 (defvar *p* (namestring *load-truename*))
26
27 ;;; FIXME: This should use some get-argslist like functionality that
28 ;;; we actually export.
29 ;;;
30 ;;; Return the debug arglist of the function object FUN as a list, or
31 ;;; punt with :UNKNOWN.
32 (defun get-arglist (fun)
33   (declare (type function fun))
34   ;; The Lisp-level type FUNCTION can conceal a multitude of sins..
35   (case (sb-kernel:widetag-of fun)
36     (#.sb-vm:simple-fun-header-widetag
37       (sb-kernel:%simple-fun-arglist fun))
38     (#.sb-vm:closure-header-widetag (get-arglist
39                                      (sb-kernel:%closure-fun fun)))
40     ;; In code/describe.lisp, ll. 227 (%describe-fun), we use a scheme
41     ;; like above, and it seems to work. -- MNA 2001-06-12
42     ;;
43     ;; (There might be other cases with arglist info also.
44     ;; SIMPLE-FUN-HEADER-WIDETAG and CLOSURE-HEADER-WIDETAG just
45     ;; happen to be the two case that I had my nose rubbed in when
46     ;; debugging a GC problem caused by applying %SIMPLE-FUN-ARGLIST to
47     ;; a closure. -- WHN 2001-06-05)
48     (t
49      #+sb-eval
50      (if (typep fun 'sb-eval::interpreted-function)
51          (sb-eval::interpreted-function-lambda-list fun)
52          :unknown)
53      #-sb-eval
54      :unknown)))
55
56 (defun zoop (zeep &key beep)
57   blurp)
58 (assert (equal (get-arglist #'zoop) '(zeep &key beep)))
59
60 ;;; Check some predefined functions too.
61 ;;;
62 ;;; (We don't know exactly what the arguments are, e.g. the first
63 ;;; argument of PRINT might be SB-IMPL::OBJECT or SB-KERNEL::OBJ or
64 ;;; whatever. But we do know the general structure that a correct
65 ;;; answer should have, so we can safely do a lot of checks.)
66 (with-test (:name :predefined-functions-1)
67   (destructuring-bind (object-sym &optional-sym stream-sym) (get-arglist #'print)
68     (assert (symbolp object-sym))
69     (assert (eql &optional-sym '&optional))
70     (assert (symbolp stream-sym))))
71 (with-test (:name :predefined-functions-2)
72   (destructuring-bind (dest-sym control-sym &rest-sym format-args-sym)
73       (get-arglist #'format)
74     (assert (symbolp dest-sym))
75     (assert (symbolp control-sym))
76     (assert (eql &rest-sym '&rest))
77     (assert (symbolp format-args-sym))))
78
79 ;;; Check for backtraces generally being correct.  Ensure that the
80 ;;; actual backtrace finishes (doesn't signal any errors on its own),
81 ;;; and that it contains the frames we expect, doesn't contain any
82 ;;; "bogus stack frame"s, and contains the appropriate toplevel call
83 ;;; and hasn't been cut off anywhere.
84 (defun verify-backtrace (test-function frame-specs &key (allow-stunted nil))
85   (labels ((args-equal (want real)
86              (cond ((eq '&rest (car want))
87                     t)
88                    ((endp want)
89                     (endp real))
90                    ((or (eq '? (car want)) (equal (car want) (car real)))
91                     (args-equal (cdr want) (cdr real)))
92                    (t
93                     nil))))
94     (let ((result nil))
95       (block outer-handler
96         (handler-bind
97             ((error (lambda (condition)
98                       ;; find the part of the backtrace we're interested in
99                       (let* ((full-backtrace (sb-debug:backtrace-as-list))
100                              (backtrace (member (caar frame-specs) full-backtrace
101                                                 :key #'car
102                                                 :test #'equal)))
103
104                         (setf result condition)
105
106                         (unless backtrace
107                           (format t "~&//~S not in backtrace:~%   ~S~%"
108                                   (caar frame-specs)
109                                   full-backtrace)
110                           (setf result nil))
111                         ;; check that we have all the frames we wanted
112                         (mapcar
113                          (lambda (spec frame)
114                            (unless (or (not spec)
115                                        (and (equal (car spec) (car frame))
116                                             (args-equal (cdr spec)
117                                                         (cdr frame))))
118                              (print (list :wanted spec :got frame))
119                              (setf result nil)))
120                          frame-specs
121                          backtrace)
122
123                         ;; Make sure the backtrace isn't stunted in
124                         ;; any way.  (Depends on running in the main
125                         ;; thread.) FIXME: On Windows we get two
126                         ;; extra foreign frames below regular frames.
127                         (unless (find '(sb-impl::toplevel-init) backtrace
128                                       :test #'equal)
129                           (print (list :backtrace-stunted backtrace))
130                           (setf result nil))
131                         (return-from outer-handler)))))
132           (funcall test-function)))
133       result)))
134
135 (defvar *undefined-function-frame*
136   ;; bug 353
137   '("undefined function"))
138
139 ;;; Test for "undefined function" (undefined_tramp) working properly.
140 ;;; Try it with and without tail call elimination, since they can have
141 ;;; different effects.  (Specifically, if undefined_tramp is incorrect
142 ;;; a stunted stack can result from the tail call variant.)
143 (flet ((optimized ()
144          (declare (optimize (speed 2) (debug 1))) ; tail call elimination
145          (#:undefined-function 42))
146        (not-optimized ()
147          (declare (optimize (speed 1) (debug 2))) ; no tail call elimination
148          (#:undefined-function 42))
149        (test (fun)
150          (declare (optimize (speed 1) (debug 2))) ; no tail call elimination
151          (funcall fun)))
152
153   (with-test (:name (:undefined-function :bug-346)
154                     ;; Failures on ALPHA, SPARC, MIPS, and probably
155                     ;; HPPA are due to not having a full and valid
156                     ;; stack frame for the undefined function frame.
157                     ;; See PPC undefined_tramp for details.
158               :fails-on '(or :alpha :sparc :mips
159                           (and :x86-64 :freebsd)))
160     (assert (verify-backtrace
161              (lambda () (test #'optimized))
162              (list *undefined-function-frame*
163                    (list `(flet test :in ,*p*) #'optimized)))))
164
165   ;; bug 353: This test fails at least most of the time for x86/linux
166   ;; ca. 0.8.20.16. -- WHN
167   (with-test (:name (:undefined-function :bug-353))
168     (assert (verify-backtrace
169              (lambda () (test #'not-optimized))
170              (list *undefined-function-frame*
171                    (list `(flet not-optimized :in ,*p*))
172                    (list `(flet test :in ,*p*) #'not-optimized))))))
173
174 (with-test (:name :backtrace-interrupted-condition-wait
175             :skipped-on '(not :sb-thread)
176                   ;; For some unfathomable reason the backtrace becomes
177                   ;; stunted on Darwin, ending at _sigtramp, when we add
178                   ;; :TIMEOUT NIL to the frame we expect. If we leave it out,
179                   ;; the backtrace is fine -- but the test fails. I can only
180                   ;; boggle right now.
181             :fails-on '(or (and :x86 :linux) :darwin))
182   (let ((m (sb-thread:make-mutex))
183         (q (sb-thread:make-waitqueue)))
184     (assert (verify-backtrace
185             (lambda ()
186               (sb-thread:with-mutex (m)
187                 (handler-bind ((timeout (lambda (c)
188                                           (error "foo"))))
189                   (with-timeout 0.1
190                     (sb-thread:condition-wait q m)))))
191             `((sb-thread:condition-wait ,q ,m :timeout nil))))))
192
193 ;;; Division by zero was a common error on PPC. It depended on the
194 ;;; return function either being before INTEGER-/-INTEGER in memory,
195 ;;; or more than MOST-POSITIVE-FIXNUM bytes ahead. It also depends on
196 ;;; INTEGER-/-INTEGER calling SIGNED-TRUNCATE. I believe Raymond Toy
197 ;;; says that the Sparc backend (at least for CMUCL) inlines this, so
198 ;;; if SBCL does the same this test is probably not good for the
199 ;;; Sparc.
200 ;;;
201 ;;; Disabling tail call elimination on this will probably ensure that
202 ;;; the return value (to the flet or the enclosing top level form) is
203 ;;; more than MOST-POSITIVE-FIXNUM with the current spaces on OS X.
204 ;;; Enabling it might catch other problems, so do it anyway.
205 (flet ((optimized ()
206          (declare (optimize (speed 2) (debug 1))) ; tail call elimination
207          (/ 42 0))
208        (not-optimized ()
209          (declare (optimize (speed 1) (debug 2))) ; no tail call elimination
210          (/ 42 0))
211        (test (fun)
212          (declare (optimize (speed 1) (debug 2))) ; no tail call elimination
213          (funcall fun)))
214   (with-test (:name (:divide-by-zero :bug-346)
215               :fails-on :alpha)  ; bug 346
216     (assert (verify-backtrace (lambda () (test #'optimized))
217                               (list '(/ 42 &rest)
218                                     (list `(flet test :in ,*p*) #'optimized)))))
219   (with-test (:name (:divide-by-zero :bug-356)
220               :fails-on :alpha)  ; bug 356
221     (assert (verify-backtrace (lambda () (test #'not-optimized))
222                               (list '(/ 42 &rest)
223                                     `((flet not-optimized :in ,*p*))
224                                     (list `(flet test :in ,*p*) #'not-optimized))))))
225
226 (with-test (:name (:throw :no-such-tag)
227             :fails-on '(or
228                         (and :sparc :linux)
229                         :alpha
230                         :mips))
231   (progn
232     (defun throw-test ()
233       (throw 'no-such-tag t))
234     (assert (verify-backtrace #'throw-test '((throw-test))))))
235
236 (defun bug-308926 (x)
237   (let ((v "foo"))
238     (flet ((bar (z)
239              (oops v z)
240              (oops z v)))
241       (bar x)
242       (bar v))))
243
244 (with-test (:name :bug-308926)
245   (assert (verify-backtrace (lambda () (bug-308926 13))
246                             '(((flet bar :in bug-308926) 13)
247                               (bug-308926 &rest t)))))
248
249 ;;; test entry point handling in backtraces
250
251 (defun oops ()
252   (error "oops"))
253
254 (with-test (:name :xep-too-many-arguments)
255   (assert (verify-backtrace (lambda () (oops 1 2 3 4 5 6))
256                             '((oops ? ? ? ? ? ?)))))
257
258 (defmacro defbt (n ll &body body)
259   `(progn
260      ;; normal debug info
261      (defun ,(intern (format nil "BT.~A.1" n)) ,ll
262        ,@body)
263      ;; no arguments saved
264      (defun ,(intern (format nil "BT.~A.2" n)) ,ll
265        (declare (optimize (debug 1) (speed 3)))
266        ,@body)
267      ;; no lambda-list saved
268      (defun ,(intern (format nil "BT.~A.3" n)) ,ll
269        (declare (optimize (debug 0)))
270        ,@body)))
271
272 (defbt 1 (&key key)
273   (list key))
274
275 (defbt 2 (x)
276   (list x))
277
278 (defbt 3 (&key (key (oops)))
279   (list key))
280
281 ;;; ERROR instead of OOPS so that tail call elimination doesn't happen
282 (defbt 4 (&optional opt)
283   (list (error "error")))
284
285 (defbt 5 (&optional (opt (oops)))
286   (list opt))
287
288 (defmacro with-details (bool &body body)
289   `(let ((sb-debug:*show-entry-point-details* ,bool))
290      ,@body))
291
292 (defun bug-354 (x)
293   (error "XEPs in backtraces: ~S" x))
294
295 (with-test (:name :bug-354)
296   (with-details t
297     (assert (not (verify-backtrace (lambda () (bug-354 354))
298                                    '((bug-354 &rest)
299                                      ((sb-c::tl-xep bug-354) &rest))))))
300   (assert (verify-backtrace (lambda () (bug-354 354)) '((bug-354 354)))))
301
302 ;;; FIXME: This test really should be broken into smaller pieces
303 (with-test (:name (:backtrace :tl-xep))
304   (with-details t
305     (assert (verify-backtrace #'namestring
306                               '(((sb-c::tl-xep namestring) 0 ?)))))
307   (with-details nil
308     (assert (verify-backtrace #'namestring
309                               '((namestring))))))
310
311 (with-test (:name (:backtrace :more-processor))
312   (with-details t
313     (assert (verify-backtrace (lambda () (bt.1.1 :key))
314                               '(((sb-c::&more-processor bt.1.1) &rest))))
315     (assert (verify-backtrace (lambda () (bt.1.2 :key))
316                               '(((sb-c::&more-processor bt.1.2) &rest))))
317     (assert (verify-backtrace (lambda () (bt.1.3 :key))
318                               '(((sb-c::&more-processor bt.1.3) &rest)))))
319   (with-details nil
320     (assert (verify-backtrace (lambda () (bt.1.1 :key))
321                               '((bt.1.1 :key))))
322     (assert (verify-backtrace (lambda () (bt.1.2 :key))
323                               '((bt.1.2 &rest))))
324     (assert (verify-backtrace (lambda () (bt.1.3 :key))
325                               '((bt.1.3 &rest))))))
326
327 (with-test (:name (:backtrace :xep))
328   (with-details t
329     (assert (verify-backtrace #'bt.2.1
330                               '(((sb-c::xep bt.2.1) 0 ?))))
331     (assert (verify-backtrace #'bt.2.2
332                               '(((sb-c::xep bt.2.2) &rest))))
333     (assert (verify-backtrace #'bt.2.3
334                               '(((sb-c::xep bt.2.3) &rest)))))
335   (with-details nil
336     (assert (verify-backtrace #'bt.2.1
337                               '((bt.2.1))))
338     (assert (verify-backtrace #'bt.2.2
339                               '((bt.2.2 &rest))))
340     (assert (verify-backtrace #'bt.2.3
341                               '((bt.2.3 &rest))))))
342
343 (with-test (:name (:backtrace :varargs-entry))
344   (with-details t
345     (assert (verify-backtrace #'bt.3.1
346                               '(((sb-c::varargs-entry bt.3.1) :key nil))))
347     (assert (verify-backtrace #'bt.3.2
348                               '(((sb-c::varargs-entry bt.3.2) :key ?))))
349     (assert (verify-backtrace #'bt.3.3
350                               '(((sb-c::varargs-entry bt.3.3) &rest)))))
351   (with-details nil
352     (assert (verify-backtrace #'bt.3.1
353                               '((bt.3.1 :key nil))))
354     (assert (verify-backtrace #'bt.3.2
355                               '((bt.3.2 :key ?))))
356     (assert (verify-backtrace #'bt.3.3
357                               '((bt.3.3 &rest))))))
358
359 (with-test (:name (:backtrace :hairy-args-processor))
360   (with-details t
361     (assert (verify-backtrace #'bt.4.1
362                               '(((sb-c::hairy-arg-processor bt.4.1) ?))))
363     (assert (verify-backtrace #'bt.4.2
364                               '(((sb-c::hairy-arg-processor bt.4.2) ?))))
365     (assert (verify-backtrace #'bt.4.3
366                               '(((sb-c::hairy-arg-processor bt.4.3) &rest)))))
367   (with-details nil
368     (assert (verify-backtrace #'bt.4.1
369                               '((bt.4.1 ?))))
370     (assert (verify-backtrace #'bt.4.2
371                               '((bt.4.2 ?))))
372     (assert (verify-backtrace #'bt.4.3
373                               '((bt.4.3 &rest))))))
374
375
376 (with-test (:name (:backtrace :optional-processor))
377   (with-details t
378     (assert (verify-backtrace #'bt.5.1
379                               '(((sb-c::&optional-processor bt.5.1)))))
380     (assert (verify-backtrace #'bt.5.2
381                               '(((sb-c::&optional-processor bt.5.2) &rest))))
382     (assert (verify-backtrace #'bt.5.3
383                               '(((sb-c::&optional-processor bt.5.3) &rest)))))
384   (with-details nil
385     (assert (verify-backtrace #'bt.5.1
386                               '((bt.5.1))))
387     (assert (verify-backtrace #'bt.5.2
388                               '((bt.5.2 &rest))))
389     (assert (verify-backtrace #'bt.5.3
390                               '((bt.5.3 &rest))))))
391
392 (write-line "//compile nil")
393 (defvar *compile-nil-error* (compile nil '(lambda (x) (cons (when x (error "oops")) nil))))
394 (defvar *compile-nil-non-tc* (compile nil '(lambda (y) (cons (funcall *compile-nil-error* y) nil))))
395 (with-test (:name (:compile nil))
396   (assert (verify-backtrace (lambda () (funcall *compile-nil-non-tc* 13))
397                             `(((lambda (x) :in ,*p*) 13)
398                               ((lambda (y) :in ,*p*) 13)))))
399
400 (with-test (:name :clos-slot-typecheckfun-named)
401   (assert
402    (verify-backtrace
403     (lambda ()
404       (eval `(locally (declare (optimize safety))
405                (defclass clos-typecheck-test ()
406                  ((slot :type fixnum)))
407                (setf (slot-value (make-instance 'clos-typecheck-test) 'slot) t))))
408     '(((sb-pcl::slot-typecheck fixnum) t)))))
409
410 (with-test (:name :clos-emf-named)
411   (assert
412    (verify-backtrace
413     (lambda ()
414       (eval `(progn
415                (defmethod clos-emf-named-test ((x symbol)) x)
416                (defmethod clos-emf-named-test :before (x) (assert x))
417                (clos-emf-named-test nil))))
418     '(((sb-pcl::emf clos-emf-named-test) ? ? nil)))))
419
420 (with-test (:name :bug-310173)
421   (flet ((make-fun (n)
422            (let* ((names '(a b))
423                   (req (loop repeat n collect (pop names))))
424              (compile nil
425                       `(lambda (,@req &rest rest)
426                          (let ((* *)) ; no tail-call
427                            (apply '/ ,@req rest)))))))
428     (assert
429      (verify-backtrace (lambda ()
430                          (funcall (make-fun 0) 10 11 0))
431                        `((sb-kernel:two-arg-/ 10/11 0)
432                          (/ 10 11 0)
433                          ((lambda (&rest rest) :in ,*p*) 10 11 0))))
434     (assert
435      (verify-backtrace (lambda ()
436                          (funcall (make-fun 1) 10 11 0))
437                        `((sb-kernel:two-arg-/ 10/11 0)
438                          (/ 10 11 0)
439                          ((lambda (a &rest rest) :in ,*p*) 10 11 0))))
440     (assert
441      (verify-backtrace (lambda ()
442                          (funcall (make-fun 2) 10 11 0))
443                        `((sb-kernel:two-arg-/ 10/11 0)
444                          (/ 10 11 0)
445                          ((lambda (a b &rest rest) :in ,*p*) 10 11 0))))))
446
447 ;;;; test TRACE
448
449 (defun trace-this ()
450   'ok)
451
452 (defun trace-fact (n)
453   (if (zerop n)
454       1
455       (* n (trace-fact (1- n)))))
456
457 (with-test (:name (trace :simple))
458   (let ((out (with-output-to-string (*trace-output*)
459                (trace trace-this)
460                (assert (eq 'ok (trace-this)))
461                (untrace))))
462     (assert (search "TRACE-THIS" out))
463     (assert (search "returned OK" out))))
464
465 ;;; bug 379
466 ;;; This is not a WITH-TEST :FAILS-ON PPC DARWIN since there are
467 ;;; suspicions that the breakpoint trace might corrupt the whole image
468 ;;; on that platform.
469 (with-test (:name (trace :encapsulate nil)
470             :fails-on '(or (and :ppc (not :linux)) :sparc :mips)
471             :broken-on '(or :darwin :sunos))
472   (let ((out (with-output-to-string (*trace-output*)
473                (trace trace-this :encapsulate nil)
474                (assert (eq 'ok (trace-this)))
475                (untrace))))
476     (assert (search "TRACE-THIS" out))
477     (assert (search "returned OK" out))))
478
479 (with-test (:name (trace-recursive :encapsulate nil)
480             :fails-on '(or (and :ppc (not :linux)) :sparc :mips :sunos)
481             :broken-on '(or :darwin (and :x86 :sunos)))
482   (let ((out (with-output-to-string (*trace-output*)
483                (trace trace-fact :encapsulate nil)
484                (assert (= 120 (trace-fact 5)))
485                (untrace))))
486     (assert (search "TRACE-FACT" out))
487     (assert (search "returned 1" out))
488     (assert (search "returned 120" out))))
489
490 (defun trace-and-fmakunbound-this (x)
491   x)
492
493 (with-test (:name :bug-667657)
494   (trace trace-and-fmakunbound-this)
495   (fmakunbound 'trace-and-fmakunbound-this)
496   (untrace)
497   (assert (not (trace))))
498
499 (with-test (:name :bug-414)
500   (handler-bind ((warning #'error))
501     (load (compile-file "bug-414.lisp"))
502     (disassemble 'bug-414)))
503
504 (with-test (:name :bug-310175 :fails-on '(not :stack-allocatable-lists))
505   ;; KLUDGE: Not all DX-enabled platforms DX CONS, and the compiler
506   ;; transforms two-arg-LIST* (and one-arg-LIST) to CONS.  Therefore,
507   ;; use two-arg-LIST, which should get through to VOP LIST, and thus
508   ;; stack-allocate on a predictable set of machines.
509   (let ((dx-arg (list t t)))
510     (declare (dynamic-extent dx-arg))
511     (flet ((dx-arg-backtrace (x)
512              (declare (optimize (debug 2)))
513              (prog1 (sb-debug:backtrace-as-list 10)
514                (assert (sb-debug::stack-allocated-p x)))))
515       (declare (notinline dx-arg-backtrace))
516       (assert (member-if (lambda (frame)
517                            (and (consp frame)
518                                 (consp (car frame))
519                                 (equal '(flet dx-arg-backtrace :in) (butlast (car frame)))
520                                 (notany #'sb-debug::stack-allocated-p (cdr frame))))
521                          (dx-arg-backtrace dx-arg))))))
522
523 (with-test (:name :bug-795245)
524   (assert
525    (eq :ok
526        (catch 'done
527          (handler-bind
528              ((error (lambda (e)
529                        (declare (ignore e))
530                        (handler-case
531                            (sb-debug:backtrace 100 (make-broadcast-stream))
532                          (error ()
533                            (throw 'done :error))
534                          (:no-error ()
535                            (throw 'done :ok))))))
536            (apply '/= nil 1 2 nil))))))
537
538 ;;;; test infinite error protection
539
540 (defmacro nest-errors (n-levels error-form)
541   (if (< 0 n-levels)
542       `(handler-bind ((error (lambda (condition)
543                                (declare (ignore condition))
544                                ,error-form)))
545         (nest-errors ,(1- n-levels) ,error-form))
546       error-form))
547
548 (defun erroring-debugger-hook (condition old-debugger-hook)
549   (let ((*debugger-hook* old-debugger-hook))
550     (format t "recursive condition: ~A~%" condition) (force-output)
551     (error "recursive condition: ~A" condition)))
552
553 (defun test-inifinite-error-protection ()
554   ;; after 50 successful throws to SB-IMPL::TOPLEVEL-CATCHER sbcl used
555   ;; to halt, it produces so much garbage that's hard to suppress that
556   ;; it is tested only once
557   (write-line "--HARMLESS BUT ALARMING BACKTRACE COMING UP--")
558   (let ((*debugger-hook* #'erroring-debugger-hook))
559     (loop repeat 1 do
560           (let ((error-counter 0)
561                 (*terminal-io* (make-broadcast-stream)))
562             (assert
563              (not (eq
564                    :normal-exit
565                    (catch 'sb-impl::toplevel-catcher
566                      (nest-errors 20 (error "infinite error ~s"
567                                             (incf error-counter)))
568                      :normal-exit)))))))
569   (write-line "--END OF H-B-A-B--"))
570
571 (with-test (:name infinite-error-protection)
572   (enable-debugger)
573   (test-inifinite-error-protection))
574
575 (with-test (:name (infinite-error-protection :thread)
576                   :skipped-on '(not :sb-thread))
577   (enable-debugger)
578   (let ((thread (sb-thread:make-thread #'test-inifinite-error-protection)))
579     (loop while (sb-thread:thread-alive-p thread))))
580
581 ;; unconditional, in case either previous left it enabled
582 (disable-debugger)
583 \f
584 ;;;; test some limitations of MAKE-LISP-OBJ
585
586 ;;; Older GENCGC systems had a bug in the pointer validation used by
587 ;;; MAKE-LISP-OBJ that made SIMPLE-FUN objects always fail to
588 ;;; validate.
589 (with-test (:name (make-lisp-obj :simple-funs))
590   (sb-sys:without-gcing
591     (assert (eq #'identity
592                 (sb-kernel:make-lisp-obj
593                  (sb-kernel:get-lisp-obj-address
594                   #'identity))))))
595
596 ;;; Older CHENEYGC systems didn't perform any real pointer validity
597 ;;; checks beyond "is this pointer to somewhere in heap space".
598 (with-test (:name (make-lisp-obj :pointer-validation))
599   ;; Fun and games: We need to test MAKE-LISP-OBJ with a known-bogus
600   ;; address, but we also need the GC to not pitch a fit if it sees an
601   ;; object with said bogus address.  Thus, construct our known-bogus
602   ;; object within an area of unboxed storage (a vector) in static
603   ;; space.  We'll make it a simple object, (CONS 0 0), which has an
604   ;; in-memory representation of two consecutive zero words.  We
605   ;; allocate a three-word vector so that we can guarantee a
606   ;; double-word aligned double-word of zeros no matter what happens
607   ;; with the vector-data-offset (currently double-word aligned).
608   (let* ((memory (sb-int:make-static-vector 3 :element-type `(unsigned-byte ,sb-vm:n-word-bits)
609                                             :initial-element 0))
610          (vector-data-address (sb-sys:sap-int (sb-kernel::vector-sap memory)))
611          (object-base-address (logandc2 (+ vector-data-address sb-vm:lowtag-mask) sb-vm:lowtag-mask))
612          (object-tagged-address (+ object-base-address sb-vm:list-pointer-lowtag)))
613     (multiple-value-bind
614           (object valid-p)
615         (sb-kernel:make-lisp-obj object-tagged-address nil)
616       (assert (not valid-p)))))
617
618 (write-line "/debug.impure.lisp done")