1 ;;;; This file is for testing debugging functionality, using
2 ;;;; test machinery which might have side effects (e.g.
5 ;;;; This software is part of the SBCL system. See the README file for
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
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.
16 (cl:in-package :cl-user)
18 ;;;; Check that we get debug arglists right.
20 ;;; Return the debug arglist of the function object FUN as a list, or
21 ;;; punt with :UNKNOWN.
22 (defun get-arglist (fun)
23 (declare (type function fun))
24 ;; The Lisp-level type FUNCTION can conceal a multitude of sins..
25 (case (sb-kernel:widetag-of fun)
26 (#.sb-vm:simple-fun-header-widetag
27 (sb-kernel:%simple-fun-arglist fun))
28 (#.sb-vm:closure-header-widetag (get-arglist
29 (sb-kernel:%closure-fun fun)))
30 ;; In code/describe.lisp, ll. 227 (%describe-fun), we use a scheme
31 ;; like above, and it seems to work. -- MNA 2001-06-12
33 ;; (There might be other cases with arglist info also.
34 ;; SIMPLE-FUN-HEADER-WIDETAG and CLOSURE-HEADER-WIDETAG just
35 ;; happen to be the two case that I had my nose rubbed in when
36 ;; debugging a GC problem caused by applying %SIMPLE-FUN-ARGLIST to
37 ;; a closure. -- WHN 2001-06-05)
40 (defun zoop (zeep &key beep)
42 (assert (equal (get-arglist #'zoop) '(zeep &key beep)))
44 ;;; Check some predefined functions too.
46 ;;; (We don't know exactly what the arguments are, e.g. the first
47 ;;; argument of PRINT might be SB-IMPL::OBJECT or SB-KERNEL::OBJ or
48 ;;; whatever. But we do know the general structure that a correct
49 ;;; answer should have, so we can safely do a lot of checks.)
50 (destructuring-bind (object-sym &optional-sym stream-sym) (get-arglist #'print)
51 (assert (symbolp object-sym))
52 (assert (eql &optional-sym '&optional))
53 (assert (symbolp stream-sym)))
54 (destructuring-bind (dest-sym control-sym &rest-sym format-args-sym)
55 (get-arglist #'format)
56 (assert (symbolp dest-sym))
57 (assert (symbolp control-sym))
58 (assert (eql &rest-sym '&rest))
59 (assert (symbolp format-args-sym)))
61 ;;; Check for backtraces generally being correct. Ensure that the
62 ;;; actual backtrace finishes (doesn't signal any errors on its own),
63 ;;; and that it contains the frames we expect, doesn't contain any
64 ;;; "bogus stack frame"s, and contains the appropriate toplevel call
65 ;;; and hasn't been cut off anywhere.
66 (defun verify-backtrace (test-function frame-name
67 &key (key #'first) (test #'eql)
68 (allow-bogus-frames nil))
73 ((error #'(lambda (condition)
74 (let ((backtrace (ignore-errors
75 (sb-debug:backtrace-as-list))))
76 ;; Make sure we find what we're looking for.
77 (if (member frame-name backtrace :key key :test test)
78 (setf result (list :error condition))
79 (print (list :failed :frame frame-name :backtrace backtrace)))
80 ;; Make sure there's no bogus stack frames
81 ;; unless they're explicitly allowed.
82 (when (and (not allow-bogus-frames)
83 (member "bogus stack frame" backtrace
84 :key #'first :test #'equal))
85 (print 'verify-backtrace-bogus)
87 ;; Make sure the backtrace isn't stunted in
88 ;; any way. (Depends on running in the main
90 (unless (member 'sb-impl::toplevel-init backtrace
91 :key #'first :test #'equal)
92 (print 'verify-backtrace-stunted)
94 (return-from outer-handler))))
95 (funcall test-function)))
96 (values result return-value)))
98 ;;; Test for "undefined function" (undefined_tramp) working properly.
99 ;;; Try it with and without tail call elimination, since they can have
100 ;;; different effects. (Specifically, if undefined_tramp is incorrect
101 ;;; a stunted stack can result from the tail call variant.)
102 #-(or alpha) ; bug 346
104 (declare (optimize (speed 2) (debug 1))) ; tail call elimination
105 (#:undefined-function 42))
107 (declare (optimize (speed 1) (debug 2))) ; no tail call elimination
108 (#:undefined-function 42))
110 (declare (optimize (speed 1) (debug 2))) ; no tail call elimination
112 (dolist (frame '(#-x86 "undefined function" ; bug 353
113 "FLET COMMON-LISP-USER::TEST"))
114 (assert (verify-backtrace (lambda () (test #'optimized)) frame
116 :allow-bogus-frames (or #+x86 t))))
117 (dolist (frame '(#-x86 "undefined function" ; bug 353
118 "FLET COMMON-LISP-USER::NOT-OPTIMIZED"
119 "FLET COMMON-LISP-USER::TEST"))
120 (assert (verify-backtrace (lambda () (test #'not-optimized)) frame
122 :allow-bogus-frames (or #+x86 t)))))
124 ;;; Division by zero was a common error on PPC. It depended on the
125 ;;; return function either being before INTEGER-/-INTEGER in memory,
126 ;;; or more than MOST-POSITIVE-FIXNUM bytes ahead. It also depends on
127 ;;; INTEGER-/-INTEGER calling SIGNED-TRUNCATE. I believe Raymond Toy
128 ;;; says that the Sparc backend (at least for CMUCL) inlines this, so
129 ;;; if SBCL does the same this test is probably not good for the
132 ;;; Disabling tail call elimination on this will probably ensure that
133 ;;; the return value (to the flet or the enclosing top level form) is
134 ;;; more than MOST-POSITIVE-FIXNUM with the current spaces on OS X.
135 ;;; Enabling it might catch other problems, so do it anyway.
138 (flet ((test-function ()
139 (declare (optimize (speed 2) (debug 1))) ; tail call elimination
141 (assert (verify-backtrace #'test-function '/)))
143 (flet ((test-function ()
144 (declare (optimize (speed 1) (debug 2))) ; no tail call elimination
146 (assert (verify-backtrace #'test-function '/))))
148 #-(or alpha) ; bug 61
151 (throw 'no-such-tag t))
152 (assert (verify-backtrace #'throw-test
153 #-(or x86 sparc) 'throw-test
154 #+(or x86 sparc) "XEP for COMMON-LISP-USER::THROW-TEST" ; bug 354
158 (quit :unix-status 104)