3520c9aec21304683bd2986cbfb3b9ed0ed39ad0
[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:quit :unix-status 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   '(#+(or x86 x86-64) "bogus stack frame"
138     #-(or x86 x86-64) "undefined function"))
139
140 ;;; Test for "undefined function" (undefined_tramp) working properly.
141 ;;; Try it with and without tail call elimination, since they can have
142 ;;; different effects.  (Specifically, if undefined_tramp is incorrect
143 ;;; a stunted stack can result from the tail call variant.)
144 (flet ((optimized ()
145          (declare (optimize (speed 2) (debug 1))) ; tail call elimination
146          (#:undefined-function 42))
147        (not-optimized ()
148          (declare (optimize (speed 1) (debug 2))) ; no tail call elimination
149          (#:undefined-function 42))
150        (test (fun)
151          (declare (optimize (speed 1) (debug 2))) ; no tail call elimination
152          (funcall fun)))
153
154   (with-test (:name (:undefined-function :bug-346)
155               :fails-on '(or :alpha :ppc :sparc :mips
156                           (and :x86-64 :freebsd)))
157     (assert (verify-backtrace
158              (lambda () (test #'optimized))
159              (list *undefined-function-frame*
160                    (list `(flet test :in ,*p*) #'optimized)))))
161
162   ;; bug 353: This test fails at least most of the time for x86/linux
163   ;; ca. 0.8.20.16. -- WHN
164   (with-test (:name (:undefined-function :bug-353)
165               ;; This used to have fewer :fails-on features pre-0.9.16.38,
166               ;; but it turns out that the bug was just being masked by
167               ;; the presence of the IR1 stepper instrumentation (and
168               ;; is thus again failing now that the instrumentation is
169               ;; no more).
170               :fails-on '(or :alpha :mips :ppc))
171     (assert (verify-backtrace
172              (lambda () (test #'not-optimized))
173              (list *undefined-function-frame*
174                    (list `(flet not-optimized :in ,*p*))
175                    (list `(flet test :in ,*p*) #'not-optimized))))))
176
177 (with-test (:name :backtrace-interrupted-condition-wait
178             :skipped-on '(not :sb-thread)
179                   ;; For some unfathomable reason the backtrace becomes
180                   ;; stunted on Darwin, ending at _sigtramp, when we add
181                   ;; :TIMEOUT NIL to the frame we expect. If we leave it out,
182                   ;; the backtrace is fine -- but the test fails. I can only
183                   ;; boggle right now.
184             :fails-on '(or (and :x86 :linux) :darwin))
185   (let ((m (sb-thread:make-mutex))
186         (q (sb-thread:make-waitqueue)))
187     (assert (verify-backtrace
188             (lambda ()
189               (sb-thread:with-mutex (m)
190                 (handler-bind ((timeout (lambda (c)
191                                           (error "foo"))))
192                   (with-timeout 0.1
193                     (sb-thread:condition-wait q m)))))
194             `((sb-thread:condition-wait ,q ,m :timeout nil))))))
195
196 ;;; Division by zero was a common error on PPC. It depended on the
197 ;;; return function either being before INTEGER-/-INTEGER in memory,
198 ;;; or more than MOST-POSITIVE-FIXNUM bytes ahead. It also depends on
199 ;;; INTEGER-/-INTEGER calling SIGNED-TRUNCATE. I believe Raymond Toy
200 ;;; says that the Sparc backend (at least for CMUCL) inlines this, so
201 ;;; if SBCL does the same this test is probably not good for the
202 ;;; Sparc.
203 ;;;
204 ;;; Disabling tail call elimination on this will probably ensure that
205 ;;; the return value (to the flet or the enclosing top level form) is
206 ;;; more than MOST-POSITIVE-FIXNUM with the current spaces on OS X.
207 ;;; Enabling it might catch other problems, so do it anyway.
208 (flet ((optimized ()
209          (declare (optimize (speed 2) (debug 1))) ; tail call elimination
210          (/ 42 0))
211        (not-optimized ()
212          (declare (optimize (speed 1) (debug 2))) ; no tail call elimination
213          (/ 42 0))
214        (test (fun)
215          (declare (optimize (speed 1) (debug 2))) ; no tail call elimination
216          (funcall fun)))
217   (with-test (:name (:divide-by-zero :bug-346)
218               :fails-on :alpha)  ; bug 346
219     (assert (verify-backtrace (lambda () (test #'optimized))
220                               (list '(/ 42 &rest)
221                                     (list `(flet test :in ,*p*) #'optimized)))))
222   (with-test (:name (:divide-by-zero :bug-356)
223               :fails-on :alpha)  ; bug 356
224     (assert (verify-backtrace (lambda () (test #'not-optimized))
225                               (list '(/ 42 &rest)
226                                     `((flet not-optimized :in ,*p*))
227                                     (list `(flet test :in ,*p*) #'not-optimized))))))
228
229 (with-test (:name (:throw :no-such-tag)
230             :fails-on '(or
231                         (and :sparc :linux)
232                         :alpha
233                         :mips))
234   (progn
235     (defun throw-test ()
236       (throw 'no-such-tag t))
237     (assert (verify-backtrace #'throw-test '((throw-test))))))
238
239 ;;; test entry point handling in backtraces
240
241 (defun oops ()
242   (error "oops"))
243
244 (defmacro defbt (n ll &body body)
245   `(progn
246      ;; normal debug info
247      (defun ,(intern (format nil "BT.~A.1" n)) ,ll
248        ,@body)
249      ;; no arguments saved
250      (defun ,(intern (format nil "BT.~A.2" n)) ,ll
251        (declare (optimize (debug 1) (speed 3)))
252        ,@body)
253      ;; no lambda-list saved
254      (defun ,(intern (format nil "BT.~A.3" n)) ,ll
255        (declare (optimize (debug 0)))
256        ,@body)))
257
258 (defbt 1 (&key key)
259   (list key))
260
261 (defbt 2 (x)
262   (list x))
263
264 (defbt 3 (&key (key (oops)))
265   (list key))
266
267 ;;; ERROR instead of OOPS so that tail call elimination doesn't happen
268 (defbt 4 (&optional opt)
269   (list (error "error")))
270
271 (defbt 5 (&optional (opt (oops)))
272   (list opt))
273
274 (defmacro with-details (bool &body body)
275   `(let ((sb-debug:*show-entry-point-details* ,bool))
276      ,@body))
277
278 (defun bug-354 (x)
279   (error "XEPs in backtraces: ~S" x))
280
281 (with-test (:name :bug-354)
282   (with-details t
283     (assert (not (verify-backtrace (lambda () (bug-354 354))
284                                    '((bug-354 &rest)
285                                      ((sb-c::tl-xep bug-354) &rest))))))
286   (assert (verify-backtrace (lambda () (bug-354 354)) '((bug-354 354)))))
287
288 ;;; FIXME: This test really should be broken into smaller pieces
289 (with-test (:name (:backtrace :tl-xep))
290   (with-details t
291     (assert (verify-backtrace #'namestring
292                               '(((sb-c::tl-xep namestring) 0 ?)))))
293   (with-details nil
294     (assert (verify-backtrace #'namestring
295                               '((namestring))))))
296
297 (with-test (:name (:backtrace :more-processor))
298   (with-details t
299     (assert (verify-backtrace (lambda () (bt.1.1 :key))
300                               '(((sb-c::&more-processor bt.1.1) &rest))))
301     (assert (verify-backtrace (lambda () (bt.1.2 :key))
302                               '(((sb-c::&more-processor bt.1.2) &rest))))
303     (assert (verify-backtrace (lambda () (bt.1.3 :key))
304                               '(((sb-c::&more-processor bt.1.3) &rest)))))
305   (with-details nil
306     (assert (verify-backtrace (lambda () (bt.1.1 :key))
307                               '((bt.1.1 :key))))
308     (assert (verify-backtrace (lambda () (bt.1.2 :key))
309                               '((bt.1.2 &rest))))
310     (assert (verify-backtrace (lambda () (bt.1.3 :key))
311                               '((bt.1.3 &rest))))))
312
313 (with-test (:name (:backtrace :xep))
314   (with-details t
315     (assert (verify-backtrace #'bt.2.1
316                               '(((sb-c::xep bt.2.1) 0 ?))))
317     (assert (verify-backtrace #'bt.2.2
318                               '(((sb-c::xep bt.2.2) &rest))))
319     (assert (verify-backtrace #'bt.2.3
320                               '(((sb-c::xep bt.2.3) &rest)))))
321   (with-details nil
322     (assert (verify-backtrace #'bt.2.1
323                               '((bt.2.1))))
324     (assert (verify-backtrace #'bt.2.2
325                               '((bt.2.2 &rest))))
326     (assert (verify-backtrace #'bt.2.3
327                               '((bt.2.3 &rest))))))
328
329 (with-test (:name (:backtrace :varargs-entry))
330   (with-details t
331     (assert (verify-backtrace #'bt.3.1
332                               '(((sb-c::varargs-entry bt.3.1) :key nil))))
333     (assert (verify-backtrace #'bt.3.2
334                               '(((sb-c::varargs-entry bt.3.2) :key ?))))
335     (assert (verify-backtrace #'bt.3.3
336                               '(((sb-c::varargs-entry bt.3.3) &rest)))))
337   (with-details nil
338     (assert (verify-backtrace #'bt.3.1
339                               '((bt.3.1 :key nil))))
340     (assert (verify-backtrace #'bt.3.2
341                               '((bt.3.2 :key ?))))
342     (assert (verify-backtrace #'bt.3.3
343                               '((bt.3.3 &rest))))))
344
345 (with-test (:name (:backtrace :hairy-args-processor))
346   (with-details t
347     (assert (verify-backtrace #'bt.4.1
348                               '(((sb-c::hairy-arg-processor bt.4.1) ?))))
349     (assert (verify-backtrace #'bt.4.2
350                               '(((sb-c::hairy-arg-processor bt.4.2) ?))))
351     (assert (verify-backtrace #'bt.4.3
352                               '(((sb-c::hairy-arg-processor bt.4.3) &rest)))))
353   (with-details nil
354     (assert (verify-backtrace #'bt.4.1
355                               '((bt.4.1 ?))))
356     (assert (verify-backtrace #'bt.4.2
357                               '((bt.4.2 ?))))
358     (assert (verify-backtrace #'bt.4.3
359                               '((bt.4.3 &rest))))))
360
361
362 (with-test (:name (:backtrace :optional-processor))
363   (with-details t
364     (assert (verify-backtrace #'bt.5.1
365                               '(((sb-c::&optional-processor bt.5.1)))))
366     (assert (verify-backtrace #'bt.5.2
367                               '(((sb-c::&optional-processor bt.5.2) &rest))))
368     (assert (verify-backtrace #'bt.5.3
369                               '(((sb-c::&optional-processor bt.5.3) &rest)))))
370   (with-details nil
371     (assert (verify-backtrace #'bt.5.1
372                               '((bt.5.1))))
373     (assert (verify-backtrace #'bt.5.2
374                               '((bt.5.2 &rest))))
375     (assert (verify-backtrace #'bt.5.3
376                               '((bt.5.3 &rest))))))
377
378 (write-line "//compile nil")
379 (defvar *compile-nil-error* (compile nil '(lambda (x) (cons (when x (error "oops")) nil))))
380 (defvar *compile-nil-non-tc* (compile nil '(lambda (y) (cons (funcall *compile-nil-error* y) nil))))
381 (with-test (:name (:compile nil))
382   (assert (verify-backtrace (lambda () (funcall *compile-nil-non-tc* 13))
383                             `(((lambda (x) :in ,*p*) 13)
384                               ((lambda (y) :in ,*p*) 13)))))
385
386 (with-test (:name :clos-slot-typecheckfun-named)
387   (assert
388    (verify-backtrace
389     (lambda ()
390       (eval `(locally (declare (optimize safety))
391                (defclass clos-typecheck-test ()
392                  ((slot :type fixnum)))
393                (setf (slot-value (make-instance 'clos-typecheck-test) 'slot) t))))
394     '(((sb-pcl::slot-typecheck fixnum) t)))))
395
396 (with-test (:name :clos-emf-named)
397   (assert
398    (verify-backtrace
399     (lambda ()
400       (eval `(progn
401                (defmethod clos-emf-named-test ((x symbol)) x)
402                (defmethod clos-emf-named-test :before (x) (assert x))
403                (clos-emf-named-test nil))))
404     '(((sb-pcl::emf clos-emf-named-test) ? ? nil)))))
405
406 (with-test (:name :bug-310173)
407   (flet ((make-fun (n)
408            (let* ((names '(a b))
409                   (req (loop repeat n collect (pop names))))
410              (compile nil
411                       `(lambda (,@req &rest rest)
412                          (let ((* *)) ; no tail-call
413                            (apply '/ ,@req rest)))))))
414     (assert
415      (verify-backtrace (lambda ()
416                          (funcall (make-fun 0) 10 11 0))
417                        `((sb-kernel:two-arg-/ 10/11 0)
418                          (/ 10 11 0)
419                          ((lambda (&rest rest) :in ,*p*) 10 11 0))))
420     (assert
421      (verify-backtrace (lambda ()
422                          (funcall (make-fun 1) 10 11 0))
423                        `((sb-kernel:two-arg-/ 10/11 0)
424                          (/ 10 11 0)
425                          ((lambda (a &rest rest) :in ,*p*) 10 11 0))))
426     (assert
427      (verify-backtrace (lambda ()
428                          (funcall (make-fun 2) 10 11 0))
429                        `((sb-kernel:two-arg-/ 10/11 0)
430                          (/ 10 11 0)
431                          ((lambda (a b &rest rest) :in ,*p*) 10 11 0))))))
432
433 ;;;; test TRACE
434
435 (defun trace-this ()
436   'ok)
437
438 (defun trace-fact (n)
439   (if (zerop n)
440       1
441       (* n (trace-fact (1- n)))))
442
443 (with-test (:name (trace :simple))
444   (let ((out (with-output-to-string (*trace-output*)
445                (trace trace-this)
446                (assert (eq 'ok (trace-this)))
447                (untrace))))
448     (assert (search "TRACE-THIS" out))
449     (assert (search "returned OK" out))))
450
451 ;;; bug 379
452 ;;; This is not a WITH-TEST :FAILS-ON PPC DARWIN since there are
453 ;;; suspicions that the breakpoint trace might corrupt the whole image
454 ;;; on that platform.
455 (with-test (:name (trace :encapsulate nil)
456             :fails-on '(or (and :ppc (not :linux)) :sparc :mips)
457             :broken-on '(or :darwin :sunos))
458   (let ((out (with-output-to-string (*trace-output*)
459                (trace trace-this :encapsulate nil)
460                (assert (eq 'ok (trace-this)))
461                (untrace))))
462     (assert (search "TRACE-THIS" out))
463     (assert (search "returned OK" out))))
464
465 (with-test (:name (trace-recursive :encapsulate nil)
466             :fails-on '(or (and :ppc (not :linux)) :sparc :mips :sunos)
467             :broken-on '(or :darwin (and :x86 :sunos)))
468   (let ((out (with-output-to-string (*trace-output*)
469                (trace trace-fact :encapsulate nil)
470                (assert (= 120 (trace-fact 5)))
471                (untrace))))
472     (assert (search "TRACE-FACT" out))
473     (assert (search "returned 1" out))
474     (assert (search "returned 120" out))))
475
476 (defun trace-and-fmakunbound-this (x)
477   x)
478
479 (with-test (:name :bug-667657)
480   (trace trace-and-fmakunbound-this)
481   (fmakunbound 'trace-and-fmakunbound-this)
482   (untrace)
483   (assert (not (trace))))
484
485 (with-test (:name :bug-414)
486   (handler-bind ((warning #'error))
487     (load (compile-file "bug-414.lisp"))
488     (disassemble 'bug-414)))
489
490 (with-test (:name :bug-310175 :fails-on '(not :stack-allocatable-lists))
491   ;; KLUDGE: Not all DX-enabled platforms DX CONS, and the compiler
492   ;; transforms two-arg-LIST* (and one-arg-LIST) to CONS.  Therefore,
493   ;; use two-arg-LIST, which should get through to VOP LIST, and thus
494   ;; stack-allocate on a predictable set of machines.
495   (let ((dx-arg (list t t)))
496     (declare (dynamic-extent dx-arg))
497     (flet ((dx-arg-backtrace (x)
498              (declare (optimize (debug 2)))
499              (prog1 (sb-debug:backtrace-as-list 10)
500                (assert (sb-debug::stack-allocated-p x)))))
501       (declare (notinline dx-arg-backtrace))
502       (assert (member-if (lambda (frame)
503                            (and (consp frame)
504                                 (consp (car frame))
505                                 (equal '(flet dx-arg-backtrace :in) (butlast (car frame)))
506                                 (notany #'sb-debug::stack-allocated-p (cdr frame))))
507                          (dx-arg-backtrace dx-arg))))))
508
509 (with-test (:name :bug-795245)
510   (assert
511    (eq :ok
512        (catch 'done
513          (handler-bind
514              ((error (lambda (e)
515                        (declare (ignore e))
516                        (handler-case
517                            (sb-debug:backtrace 100 (make-broadcast-stream))
518                          (error ()
519                            (throw 'done :error))
520                          (:no-error ()
521                            (throw 'done :ok))))))
522            (apply '/= nil 1 2 nil))))))
523
524 ;;;; test infinite error protection
525
526 (defmacro nest-errors (n-levels error-form)
527   (if (< 0 n-levels)
528       `(handler-bind ((error (lambda (condition)
529                                (declare (ignore condition))
530                                ,error-form)))
531         (nest-errors ,(1- n-levels) ,error-form))
532       error-form))
533
534 (defun erroring-debugger-hook (condition old-debugger-hook)
535   (let ((*debugger-hook* old-debugger-hook))
536     (format t "recursive condition: ~A~%" condition) (force-output)
537     (error "recursive condition: ~A" condition)))
538
539 (defun test-inifinite-error-protection ()
540   ;; after 50 successful throws to SB-IMPL::TOPLEVEL-CATCHER sbcl used
541   ;; to halt, it produces so much garbage that's hard to suppress that
542   ;; it is tested only once
543   (write-line "--HARMLESS BUT ALARMING BACKTRACE COMING UP--")
544   (let ((*debugger-hook* #'erroring-debugger-hook))
545     (loop repeat 1 do
546           (let ((error-counter 0)
547                 (*terminal-io* (make-broadcast-stream)))
548             (assert
549              (not (eq
550                    :normal-exit
551                    (catch 'sb-impl::toplevel-catcher
552                      (nest-errors 20 (error "infinite error ~s"
553                                             (incf error-counter)))
554                      :normal-exit)))))))
555   (write-line "--END OF H-B-A-B--"))
556
557 (with-test (:name infinite-error-protection)
558   (enable-debugger)
559   (test-inifinite-error-protection))
560
561 (with-test (:name (infinite-error-protection :thread)
562                   :skipped-on '(not :sb-thread))
563   (enable-debugger)
564   (let ((thread (sb-thread:make-thread #'test-inifinite-error-protection)))
565     (loop while (sb-thread:thread-alive-p thread))))
566
567 ;; unconditional, in case either previous left it enabled
568 (disable-debugger)
569 \f
570 ;;;; test some limitations of MAKE-LISP-OBJ
571
572 ;;; Older GENCGC systems had a bug in the pointer validation used by
573 ;;; MAKE-LISP-OBJ that made SIMPLE-FUN objects always fail to
574 ;;; validate.
575 (with-test (:name (make-lisp-obj :simple-funs))
576   (sb-sys:without-gcing
577     (assert (eq #'identity
578                 (sb-kernel:make-lisp-obj
579                  (sb-kernel:get-lisp-obj-address
580                   #'identity))))))
581
582 ;;; Older CHENEYGC systems didn't perform any real pointer validity
583 ;;; checks beyond "is this pointer to somewhere in heap space".
584 (with-test (:name (make-lisp-obj :pointer-validation))
585   ;; Fun and games: We need to test MAKE-LISP-OBJ with a known-bogus
586   ;; address, but we also need the GC to not pitch a fit if it sees an
587   ;; object with said bogus address.  Thus, construct our known-bogus
588   ;; object within an area of unboxed storage (a vector) in static
589   ;; space.  We'll make it a simple object, (CONS 0 0), which has an
590   ;; in-memory representation of two consecutive zero words.  We
591   ;; allocate a three-word vector so that we can guarantee a
592   ;; double-word aligned double-word of zeros no matter what happens
593   ;; with the vector-data-offset (currently double-word aligned).
594   (let* ((memory (sb-int:make-static-vector 3 :element-type `(unsigned-byte ,sb-vm:n-word-bits)
595                                             :initial-element 0))
596          (vector-data-address (sb-sys:sap-int (sb-kernel::vector-sap memory)))
597          (object-base-address (logandc2 (+ vector-data-address sb-vm:lowtag-mask) sb-vm:lowtag-mask))
598          (object-tagged-address (+ object-base-address sb-vm:list-pointer-lowtag)))
599     (multiple-value-bind
600           (object valid-p)
601         (sb-kernel:make-lisp-obj object-tagged-address nil)
602       (assert (not valid-p)))))
603
604 (write-line "/debug.impure.lisp done")