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