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