/[slime]/slime/swank-cmucl.lisp
ViewVC logotype

Contents of /slime/swank-cmucl.lisp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.215 - (show annotations)
Tue Nov 3 18:22:58 2009 UTC (4 years, 5 months ago) by heller
Branch: MAIN
Changes since 1.214: +95 -10 lines
Ask gdb for source lines of foreign functions.

* swank-cmucl.lisp (frame-source-location): Handle foreign
frames with gdb.
(frame-ip): Handle bogus frames (on x86)
(disassemble-frame): Use gdb for foreign frames.
(foreign-frame-p, foreign-frame-source-location): New functions.
(gdb-command, gdb-exec, parse-gdb-line-info, read-word)
(whitespacep, with-temporary-file, call/temporary-file): New
helpers.
1 ;;; -*- indent-tabs-mode: nil; outline-regexp: ";;;;+" -*-
2 ;;;
3 ;;; License: Public Domain
4 ;;;
5 ;;;; Introduction
6 ;;;
7 ;;; This is the CMUCL implementation of the `swank-backend' package.
8
9 (in-package :swank-backend)
10
11 (import-swank-mop-symbols :pcl '(:slot-definition-documentation))
12
13 (defun swank-mop:slot-definition-documentation (slot)
14 (documentation slot t))
15
16 ;;;; "Hot fixes"
17 ;;;
18 ;;; Here are necessary bugfixes to the oldest supported version of
19 ;;; CMUCL (currently 18e). Any fixes placed here should also be
20 ;;; submitted to the `cmucl-imp' mailing list and confirmed as
21 ;;; good. When a new release is made that includes the fixes we should
22 ;;; promptly delete them from here. It is enough to be compatible with
23 ;;; the latest release.
24
25 (in-package :lisp)
26
27 ;;; `READ-SEQUENCE' with large sequences has problems in 18e. This new
28 ;;; definition works better.
29
30 #-cmu19
31 (progn
32 (let ((s (find-symbol (string :*enable-package-locked-errors*) :lisp)))
33 (when s
34 (setf (symbol-value s) nil)))
35
36 (defun read-into-simple-string (s stream start end)
37 (declare (type simple-string s))
38 (declare (type stream stream))
39 (declare (type index start end))
40 (unless (subtypep (stream-element-type stream) 'character)
41 (error 'type-error
42 :datum (read-char stream nil #\Null)
43 :expected-type (stream-element-type stream)
44 :format-control "Trying to read characters from a binary stream."))
45 ;; Let's go as low level as it seems reasonable.
46 (let* ((numbytes (- end start))
47 (total-bytes 0))
48 ;; read-n-bytes may return fewer bytes than requested, so we need
49 ;; to keep trying.
50 (loop while (plusp numbytes) do
51 (let ((bytes-read (system:read-n-bytes stream s start numbytes nil)))
52 (when (zerop bytes-read)
53 (return-from read-into-simple-string total-bytes))
54 (incf total-bytes bytes-read)
55 (incf start bytes-read)
56 (decf numbytes bytes-read)))
57 total-bytes))
58
59 (let ((s (find-symbol (string :*enable-package-locked-errors*) :lisp)))
60 (when s
61 (setf (symbol-value s) t)))
62
63 )
64
65 (in-package :swank-backend)
66
67
68 ;;;; TCP server
69 ;;;
70 ;;; In CMUCL we support all communication styles. By default we use
71 ;;; `:SIGIO' because it is the most responsive, but it's somewhat
72 ;;; dangerous: CMUCL is not in general "signal safe", and you don't
73 ;;; know for sure what you'll be interrupting. Both `:FD-HANDLER' and
74 ;;; `:SPAWN' are reasonable alternatives.
75
76 (defimplementation preferred-communication-style ()
77 :sigio)
78
79 #-(or darwin mips)
80 (defimplementation create-socket (host port)
81 (let* ((addr (resolve-hostname host))
82 (addr (if (not (find-symbol "SOCKET-ERROR" :ext))
83 (ext:htonl addr)
84 addr)))
85 (ext:create-inet-listener port :stream :reuse-address t :host addr)))
86
87 ;; There seems to be a bug in create-inet-listener on Mac/OSX and Irix.
88 #+(or darwin mips)
89 (defimplementation create-socket (host port)
90 (declare (ignore host))
91 (ext:create-inet-listener port :stream :reuse-address t))
92
93 (defimplementation local-port (socket)
94 (nth-value 1 (ext::get-socket-host-and-port (socket-fd socket))))
95
96 (defimplementation close-socket (socket)
97 (let ((fd (socket-fd socket)))
98 (sys:invalidate-descriptor fd)
99 (ext:close-socket fd)))
100
101 (defimplementation accept-connection (socket &key
102 external-format buffering timeout)
103 (declare (ignore timeout))
104 (make-socket-io-stream (ext:accept-tcp-connection socket)
105 (or buffering :full)
106 (or external-format :iso-8859-1)))
107
108 ;;;;; Sockets
109
110 (defun socket-fd (socket)
111 "Return the filedescriptor for the socket represented by SOCKET."
112 (etypecase socket
113 (fixnum socket)
114 (sys:fd-stream (sys:fd-stream-fd socket))))
115
116 (defun resolve-hostname (hostname)
117 "Return the IP address of HOSTNAME as an integer (in host byte-order)."
118 (let ((hostent (ext:lookup-host-entry hostname)))
119 (car (ext:host-entry-addr-list hostent))))
120
121 (defvar *external-format-to-coding-system*
122 '((:iso-8859-1
123 "latin-1" "latin-1-unix" "iso-latin-1-unix"
124 "iso-8859-1" "iso-8859-1-unix")
125 #+unicode
126 (:utf-8 "utf-8" "utf-8-unix")))
127
128 (defimplementation find-external-format (coding-system)
129 (car (rassoc-if (lambda (x) (member coding-system x :test #'equal))
130 *external-format-to-coding-system*)))
131
132 (defun make-socket-io-stream (fd buffering external-format)
133 "Create a new input/output fd-stream for FD."
134 #-unicode(declare (ignore external-format))
135 (sys:make-fd-stream fd :input t :output t :element-type 'base-char
136 :buffering buffering
137 #+unicode :external-format
138 #+unicode external-format))
139
140 ;;;;; Signal-driven I/O
141
142 (defimplementation install-sigint-handler (function)
143 (sys:enable-interrupt :sigint (lambda (signal code scp)
144 (declare (ignore signal code scp))
145 (funcall function))))
146
147 (defvar *sigio-handlers* '()
148 "List of (key . function) pairs.
149 All functions are called on SIGIO, and the key is used for removing
150 specific functions.")
151
152 (defun set-sigio-handler ()
153 (sys:enable-interrupt :sigio (lambda (signal code scp)
154 (sigio-handler signal code scp))))
155
156 (defun sigio-handler (signal code scp)
157 (declare (ignore signal code scp))
158 (mapc #'funcall (mapcar #'cdr *sigio-handlers*)))
159
160 (defun fcntl (fd command arg)
161 "fcntl(2) - manipulate a file descriptor."
162 (multiple-value-bind (ok error) (unix:unix-fcntl fd command arg)
163 (cond (ok)
164 (t (error "fcntl: ~A" (unix:get-unix-error-msg error))))))
165
166 (defimplementation add-sigio-handler (socket fn)
167 (set-sigio-handler)
168 (let ((fd (socket-fd socket)))
169 (fcntl fd unix:f-setown (unix:unix-getpid))
170 (let ((old-flags (fcntl fd unix:f-getfl 0)))
171 (fcntl fd unix:f-setfl (logior old-flags unix:fasync)))
172 (assert (not (assoc fd *sigio-handlers*)))
173 (push (cons fd fn) *sigio-handlers*)))
174
175 (defimplementation remove-sigio-handlers (socket)
176 (let ((fd (socket-fd socket)))
177 (when (assoc fd *sigio-handlers*)
178 (setf *sigio-handlers* (remove fd *sigio-handlers* :key #'car))
179 (let ((old-flags (fcntl fd unix:f-getfl 0)))
180 (fcntl fd unix:f-setfl (logandc2 old-flags unix:fasync)))
181 (sys:invalidate-descriptor fd))
182 (assert (not (assoc fd *sigio-handlers*)))
183 (when (null *sigio-handlers*)
184 (sys:default-interrupt :sigio))))
185
186 ;;;;; SERVE-EVENT
187
188 (defimplementation add-fd-handler (socket fn)
189 (let ((fd (socket-fd socket)))
190 (sys:add-fd-handler fd :input (lambda (_) _ (funcall fn)))))
191
192 (defimplementation remove-fd-handlers (socket)
193 (sys:invalidate-descriptor (socket-fd socket)))
194
195 (defimplementation wait-for-input (streams &optional timeout)
196 (assert (member timeout '(nil t)))
197 (loop
198 (let ((ready (remove-if-not #'listen streams)))
199 (when ready (return ready)))
200 (when timeout (return nil))
201 (multiple-value-bind (in out) (make-pipe)
202 (let* ((f (constantly t))
203 (handlers (loop for s in (cons in (mapcar #'to-fd-stream streams))
204 collect (add-one-shot-handler s f))))
205 (unwind-protect
206 (let ((*interrupt-queued-handler* (lambda ()
207 (write-char #\! out))))
208 (when (check-slime-interrupts) (return :interrupt))
209 (sys:serve-event))
210 (mapc #'sys:remove-fd-handler handlers)
211 (close in)
212 (close out))))))
213
214 (defun to-fd-stream (stream)
215 (etypecase stream
216 (sys:fd-stream stream)
217 (synonym-stream
218 (to-fd-stream
219 (symbol-value (synonym-stream-symbol stream))))
220 (two-way-stream
221 (to-fd-stream (two-way-stream-input-stream stream)))))
222
223 (defun add-one-shot-handler (stream function)
224 (let (handler)
225 (setq handler (sys:add-fd-handler (sys:fd-stream-fd stream) :input
226 (lambda (fd)
227 (declare (ignore fd))
228 (sys:remove-fd-handler handler)
229 (funcall function stream))))))
230
231 (defun make-pipe ()
232 (multiple-value-bind (in out) (unix:unix-pipe)
233 (values (sys:make-fd-stream in :input t :buffering :none)
234 (sys:make-fd-stream out :output t :buffering :none))))
235
236
237 ;;;; Stream handling
238 ;;; XXX: How come we don't use Gray streams in CMUCL too? -luke (15/May/2004)
239
240 (defimplementation make-output-stream (write-string)
241 (make-slime-output-stream write-string))
242
243 (defimplementation make-input-stream (read-string)
244 (make-slime-input-stream read-string))
245
246 (defstruct (slime-output-stream
247 (:include lisp::lisp-stream
248 (lisp::misc #'sos/misc)
249 (lisp::out #'sos/write-char)
250 (lisp::sout #'sos/write-string))
251 (:conc-name sos.)
252 (:print-function %print-slime-output-stream)
253 (:constructor make-slime-output-stream (output-fn)))
254 (output-fn nil :type function)
255 (buffer (make-string 4000) :type string)
256 (index 0 :type kernel:index)
257 (column 0 :type kernel:index))
258
259 (defun %print-slime-output-stream (s stream d)
260 (declare (ignore d))
261 (print-unreadable-object (s stream :type t :identity t)))
262
263 (defun sos/write-char (stream char)
264 (let ((pending-output nil))
265 (system:without-interrupts
266 (let ((buffer (sos.buffer stream))
267 (index (sos.index stream)))
268 (setf (schar buffer index) char)
269 (setf (sos.index stream) (1+ index))
270 (incf (sos.column stream))
271 (when (char= #\newline char)
272 (setf (sos.column stream) 0)
273 #+(or)(setq pending-output (sos/reset-buffer stream))
274 )
275 (when (= index (1- (length buffer)))
276 (setq pending-output (sos/reset-buffer stream)))))
277 (when pending-output
278 (funcall (sos.output-fn stream) pending-output)))
279 char)
280
281 (defun sos/write-string (stream string start end)
282 (loop for i from start below end
283 do (sos/write-char stream (aref string i))))
284
285 (defun sos/flush (stream)
286 (let ((string (sos/reset-buffer stream)))
287 (when string
288 (funcall (sos.output-fn stream) string))
289 nil))
290
291 (defun sos/reset-buffer (stream)
292 (system:without-interrupts
293 (let ((end (sos.index stream)))
294 (unless (zerop end)
295 (prog1 (subseq (sos.buffer stream) 0 end)
296 (setf (sos.index stream) 0))))))
297
298 (defun sos/misc (stream operation &optional arg1 arg2)
299 (declare (ignore arg1 arg2))
300 (case operation
301 ((:force-output :finish-output) (sos/flush stream))
302 (:charpos (sos.column stream))
303 (:line-length 75)
304 (:file-position nil)
305 (:element-type 'base-char)
306 (:get-command nil)
307 (:close nil)
308 (t (format *terminal-io* "~&~Astream: ~S~%" stream operation))))
309
310 (defstruct (slime-input-stream
311 (:include string-stream
312 (lisp::in #'sis/in)
313 (lisp::misc #'sis/misc))
314 (:conc-name sis.)
315 (:print-function %print-slime-output-stream)
316 (:constructor make-slime-input-stream (input-fn)))
317 (input-fn nil :type function)
318 (buffer "" :type string)
319 (index 0 :type kernel:index))
320
321 (defun sis/in (stream eof-errorp eof-value)
322 (let ((index (sis.index stream))
323 (buffer (sis.buffer stream)))
324 (when (= index (length buffer))
325 (let ((string (funcall (sis.input-fn stream))))
326 (cond ((zerop (length string))
327 (return-from sis/in
328 (if eof-errorp
329 (error (make-condition 'end-of-file :stream stream))
330 eof-value)))
331 (t
332 (setf buffer string)
333 (setf (sis.buffer stream) buffer)
334 (setf index 0)))))
335 (prog1 (aref buffer index)
336 (setf (sis.index stream) (1+ index)))))
337
338 (defun sis/misc (stream operation &optional arg1 arg2)
339 (declare (ignore arg2))
340 (ecase operation
341 (:file-position nil)
342 (:file-length nil)
343 (:unread (setf (aref (sis.buffer stream)
344 (decf (sis.index stream)))
345 arg1))
346 (:clear-input
347 (setf (sis.index stream) 0
348 (sis.buffer stream) ""))
349 (:listen (< (sis.index stream) (length (sis.buffer stream))))
350 (:charpos nil)
351 (:line-length nil)
352 (:get-command nil)
353 (:element-type 'base-char)
354 (:close nil)
355 (:interactive-p t)))
356
357
358 ;;;; Compilation Commands
359
360 (defvar *previous-compiler-condition* nil
361 "Used to detect duplicates.")
362
363 (defvar *previous-context* nil
364 "Previous compiler error context.")
365
366 (defvar *buffer-name* nil
367 "The name of the Emacs buffer we are compiling from.
368 NIL if we aren't compiling from a buffer.")
369
370 (defvar *buffer-start-position* nil)
371 (defvar *buffer-substring* nil)
372
373 (defimplementation call-with-compilation-hooks (function)
374 (let ((*previous-compiler-condition* nil)
375 (*previous-context* nil)
376 (*print-readably* nil))
377 (handler-bind ((c::compiler-error #'handle-notification-condition)
378 (c::style-warning #'handle-notification-condition)
379 (c::warning #'handle-notification-condition))
380 (funcall function))))
381
382 (defimplementation swank-compile-file (input-file output-file
383 load-p external-format)
384 (declare (ignore external-format))
385 (clear-xref-info input-file)
386 (with-compilation-hooks ()
387 (let ((*buffer-name* nil)
388 (ext:*ignore-extra-close-parentheses* nil))
389 (multiple-value-bind (output-file warnings-p failure-p)
390 (compile-file input-file :output-file output-file)
391 (values output-file warnings-p
392 (or failure-p
393 (when load-p
394 ;; Cache the latest source file for definition-finding.
395 (source-cache-get input-file
396 (file-write-date input-file))
397 (not (load output-file)))))))))
398
399 (defimplementation swank-compile-string (string &key buffer position filename
400 policy)
401 (declare (ignore filename policy))
402 (with-compilation-hooks ()
403 (let ((*buffer-name* buffer)
404 (*buffer-start-position* position)
405 (*buffer-substring* string)
406 (source-info (list :emacs-buffer buffer
407 :emacs-buffer-offset position
408 :emacs-buffer-string string)))
409 (with-input-from-string (stream string)
410 (let ((failurep (ext:compile-from-stream stream :source-info
411 source-info)))
412 (not failurep))))))
413
414
415 ;;;;; Trapping notes
416 ;;;
417 ;;; We intercept conditions from the compiler and resignal them as
418 ;;; `SWANK:COMPILER-CONDITION's.
419
420 (defun handle-notification-condition (condition)
421 "Handle a condition caused by a compiler warning."
422 (unless (eq condition *previous-compiler-condition*)
423 (let ((context (c::find-error-context nil)))
424 (setq *previous-compiler-condition* condition)
425 (setq *previous-context* context)
426 (signal-compiler-condition condition context))))
427
428 (defun signal-compiler-condition (condition context)
429 (signal (make-condition
430 'compiler-condition
431 :original-condition condition
432 :severity (severity-for-emacs condition)
433 :message (compiler-condition-message condition)
434 :source-context (compiler-error-context context)
435 :location (if (read-error-p condition)
436 (read-error-location condition)
437 (compiler-note-location context)))))
438
439 (defun severity-for-emacs (condition)
440 "Return the severity of CONDITION."
441 (etypecase condition
442 ((satisfies read-error-p) :read-error)
443 (c::compiler-error :error)
444 (c::style-warning :note)
445 (c::warning :warning)))
446
447 (defun read-error-p (condition)
448 (eq (type-of condition) 'c::compiler-read-error))
449
450 (defun compiler-condition-message (condition)
451 "Briefly describe a compiler error for Emacs.
452 When Emacs presents the message it already has the source popped up
453 and the source form highlighted. This makes much of the information in
454 the error-context redundant."
455 (princ-to-string condition))
456
457 (defun compiler-error-context (error-context)
458 "Describe context information for Emacs."
459 (declare (type (or c::compiler-error-context null) error-context))
460 (multiple-value-bind (enclosing source)
461 (if error-context
462 (values (c::compiler-error-context-enclosing-source error-context)
463 (c::compiler-error-context-source error-context)))
464 (if (or enclosing source)
465 (format nil "~@[--> ~{~<~%--> ~1:;~A ~>~}~%~]~
466 ~@[==>~{~&~A~}~]"
467 enclosing source))))
468
469 (defun read-error-location (condition)
470 (let* ((finfo (car (c::source-info-current-file c::*source-info*)))
471 (file (c::file-info-name finfo))
472 (pos (c::compiler-read-error-position condition)))
473 (cond ((and (eq file :stream) *buffer-name*)
474 (make-location (list :buffer *buffer-name*)
475 (list :offset *buffer-start-position* pos)))
476 ((and (pathnamep file) (not *buffer-name*))
477 (make-location (list :file (unix-truename file))
478 (list :position (1+ pos))))
479 (t (break)))))
480
481 (defun compiler-note-location (context)
482 "Derive the location of a complier message from its context.
483 Return a `location' record, or (:error REASON) on failure."
484 (if (null context)
485 (note-error-location)
486 (with-struct (c::compiler-error-context- file-name
487 original-source
488 original-source-path) context
489 (or (locate-compiler-note file-name original-source
490 (reverse original-source-path))
491 (note-error-location)))))
492
493 (defun note-error-location ()
494 "Pseudo-location for notes that can't be located."
495 (cond (*compile-file-truename*
496 (make-location (list :file (unix-truename *compile-file-truename*))
497 (list :eof)))
498 (*buffer-name*
499 (make-location (list :buffer *buffer-name*)
500 (list :position *buffer-start-position*)))
501 (t (list :error "No error location available."))))
502
503 (defun locate-compiler-note (file source source-path)
504 (cond ((and (eq file :stream) *buffer-name*)
505 ;; Compiling from a buffer
506 (make-location (list :buffer *buffer-name*)
507 (list :offset *buffer-start-position*
508 (source-path-string-position
509 source-path *buffer-substring*))))
510 ((and (pathnamep file) (null *buffer-name*))
511 ;; Compiling from a file
512 (make-location (list :file (unix-truename file))
513 (list :position (1+ (source-path-file-position
514 source-path file)))))
515 ((and (eq file :lisp) (stringp source))
516 ;; No location known, but we have the source form.
517 ;; XXX How is this case triggered? -luke (16/May/2004)
518 ;; This can happen if the compiler needs to expand a macro
519 ;; but the macro-expander is not yet compiled. Calling the
520 ;; (interpreted) macro-expander triggers IR1 conversion of
521 ;; the lambda expression for the expander and invokes the
522 ;; compiler recursively.
523 (make-location (list :source-form source)
524 (list :position 1)))))
525
526 (defun unix-truename (pathname)
527 (ext:unix-namestring (truename pathname)))
528
529
530 ;;;; XREF
531 ;;;
532 ;;; Cross-reference support is based on the standard CMUCL `XREF'
533 ;;; package. This package has some caveats: XREF information is
534 ;;; recorded during compilation and not preserved in fasl files, and
535 ;;; XREF recording is disabled by default. Redefining functions can
536 ;;; also cause duplicate references to accumulate, but
537 ;;; `swank-compile-file' will automatically clear out any old records
538 ;;; from the same filename.
539 ;;;
540 ;;; To enable XREF recording, set `c:*record-xref-info*' to true. To
541 ;;; clear out the XREF database call `xref:init-xref-database'.
542
543 (defmacro defxref (name function)
544 `(defimplementation ,name (name)
545 (xref-results (,function name))))
546
547 (defxref who-calls xref:who-calls)
548 (defxref who-references xref:who-references)
549 (defxref who-binds xref:who-binds)
550 (defxref who-sets xref:who-sets)
551
552 ;;; More types of XREF information were added since 18e:
553 ;;;
554 #+cmu19
555 (progn
556 (defxref who-macroexpands xref:who-macroexpands)
557 ;; XXX
558 (defimplementation who-specializes (symbol)
559 (let* ((methods (xref::who-specializes (find-class symbol)))
560 (locations (mapcar #'method-location methods)))
561 (mapcar #'list methods locations))))
562
563 (defun xref-results (contexts)
564 (mapcar (lambda (xref)
565 (list (xref:xref-context-name xref)
566 (resolve-xref-location xref)))
567 contexts))
568
569 (defun resolve-xref-location (xref)
570 (let ((name (xref:xref-context-name xref))
571 (file (xref:xref-context-file xref))
572 (source-path (xref:xref-context-source-path xref)))
573 (cond ((and file source-path)
574 (let ((position (source-path-file-position source-path file)))
575 (make-location (list :file (unix-truename file))
576 (list :position (1+ position)))))
577 (file
578 (make-location (list :file (unix-truename file))
579 (list :function-name (string name))))
580 (t
581 `(:error ,(format nil "Unknown source location: ~S ~S ~S "
582 name file source-path))))))
583
584 (defun clear-xref-info (namestring)
585 "Clear XREF notes pertaining to NAMESTRING.
586 This is a workaround for a CMUCL bug: XREF records are cumulative."
587 (when c:*record-xref-info*
588 (let ((filename (truename namestring)))
589 (dolist (db (list xref::*who-calls*
590 #+cmu19 xref::*who-is-called*
591 #+cmu19 xref::*who-macroexpands*
592 xref::*who-references*
593 xref::*who-binds*
594 xref::*who-sets*))
595 (maphash (lambda (target contexts)
596 ;; XXX update during traversal?
597 (setf (gethash target db)
598 (delete filename contexts
599 :key #'xref:xref-context-file
600 :test #'equalp)))
601 db)))))
602
603
604 ;;;; Find callers and callees
605 ;;;
606 ;;; Find callers and callees by looking at the constant pool of
607 ;;; compiled code objects. We assume every fdefn object in the
608 ;;; constant pool corresponds to a call to that function. A better
609 ;;; strategy would be to use the disassembler to find actual
610 ;;; call-sites.
611
612 (labels ((make-stack () (make-array 100 :fill-pointer 0 :adjustable t))
613 (map-cpool (code fun)
614 (declare (type kernel:code-component code) (type function fun))
615 (loop for i from vm:code-constants-offset
616 below (kernel:get-header-data code)
617 do (funcall fun (kernel:code-header-ref code i))))
618
619 (callees (fun)
620 (let ((callees (make-stack)))
621 (map-cpool (vm::find-code-object fun)
622 (lambda (o)
623 (when (kernel:fdefn-p o)
624 (vector-push-extend (kernel:fdefn-function o)
625 callees))))
626 (coerce callees 'list)))
627
628 (callers (fun)
629 (declare (function fun))
630 (let ((callers (make-stack)))
631 (ext:gc :full t)
632 ;; scan :dynamic first to avoid the need for even more gcing
633 (dolist (space '(:dynamic :read-only :static))
634 (vm::map-allocated-objects
635 (lambda (obj header size)
636 (declare (type fixnum header) (ignore size))
637 (when (= vm:code-header-type header)
638 (map-cpool obj
639 (lambda (c)
640 (when (and (kernel:fdefn-p c)
641 (eq (kernel:fdefn-function c) fun))
642 (vector-push-extend obj callers))))))
643 space)
644 (ext:gc))
645 (coerce callers 'list)))
646
647 (entry-points (code)
648 (loop for entry = (kernel:%code-entry-points code)
649 then (kernel::%function-next entry)
650 while entry
651 collect entry))
652
653 (guess-main-entry-point (entry-points)
654 (or (find-if (lambda (fun)
655 (ext:valid-function-name-p
656 (kernel:%function-name fun)))
657 entry-points)
658 (car entry-points)))
659
660 (fun-dspec (fun)
661 (list (kernel:%function-name fun) (function-location fun)))
662
663 (code-dspec (code)
664 (let ((eps (entry-points code))
665 (di (kernel:%code-debug-info code)))
666 (cond (eps (fun-dspec (guess-main-entry-point eps)))
667 (di (list (c::debug-info-name di)
668 (debug-info-function-name-location di)))
669 (t (list (princ-to-string code)
670 `(:error "No src-loc available")))))))
671 (declare (inline map-cpool))
672
673 (defimplementation list-callers (symbol)
674 (mapcar #'code-dspec (callers (coerce symbol 'function) )))
675
676 (defimplementation list-callees (symbol)
677 (mapcar #'fun-dspec (callees symbol))))
678
679 (defun test-list-callers (count)
680 (let ((funsyms '()))
681 (do-all-symbols (s)
682 (when (and (fboundp s)
683 (functionp (symbol-function s))
684 (not (macro-function s))
685 (not (special-operator-p s)))
686 (push s funsyms)))
687 (let ((len (length funsyms)))
688 (dotimes (i count)
689 (let ((sym (nth (random len) funsyms)))
690 (format t "~s -> ~a~%" sym (mapcar #'car (list-callers sym))))))))
691
692 ;; (test-list-callers 100)
693
694
695 ;;;; Resolving source locations
696 ;;;
697 ;;; Our mission here is to "resolve" references to code locations into
698 ;;; actual file/buffer names and character positions. The references
699 ;;; we work from come out of the compiler's statically-generated debug
700 ;;; information, such as `code-location''s and `debug-source''s. For
701 ;;; more details, see the "Debugger Programmer's Interface" section of
702 ;;; the CMUCL manual.
703 ;;;
704 ;;; The first step is usually to find the corresponding "source-path"
705 ;;; for the location. Once we have the source-path we can pull up the
706 ;;; source file and `READ' our way through to the right position. The
707 ;;; main source-code groveling work is done in
708 ;;; `swank-source-path-parser.lisp'.
709
710 (defvar *debug-definition-finding* nil
711 "When true don't handle errors while looking for definitions.
712 This is useful when debugging the definition-finding code.")
713
714 (defvar *source-snippet-size* 256
715 "Maximum number of characters in a snippet of source code.
716 Snippets at the beginning of definitions are used to tell Emacs what
717 the definitions looks like, so that it can accurately find them by
718 text search.")
719
720 (defmacro safe-definition-finding (&body body)
721 "Execute BODY and return the source-location it returns.
722 If an error occurs and `*debug-definition-finding*' is false, then
723 return an error pseudo-location.
724
725 The second return value is NIL if no error occurs, otherwise it is the
726 condition object."
727 `(flet ((body () ,@body))
728 (if *debug-definition-finding*
729 (body)
730 (handler-case (values (progn ,@body) nil)
731 (error (c) (values `(:error ,(trim-whitespace (princ-to-string c)))
732 c))))))
733
734 (defun trim-whitespace (string)
735 (string-trim #(#\newline #\space #\tab) string))
736
737 (defun code-location-source-location (code-location)
738 "Safe wrapper around `code-location-from-source-location'."
739 (safe-definition-finding
740 (source-location-from-code-location code-location)))
741
742 (defun source-location-from-code-location (code-location)
743 "Return the source location for CODE-LOCATION."
744 (let ((debug-fun (di:code-location-debug-function code-location)))
745 (when (di::bogus-debug-function-p debug-fun)
746 ;; Those lousy cheapskates! They've put in a bogus debug source
747 ;; because the code was compiled at a low debug setting.
748 (error "Bogus debug function: ~A" debug-fun)))
749 (let* ((debug-source (di:code-location-debug-source code-location))
750 (from (di:debug-source-from debug-source))
751 (name (di:debug-source-name debug-source)))
752 (ecase from
753 (:file
754 (location-in-file name code-location debug-source))
755 (:stream
756 (location-in-stream code-location debug-source))
757 (:lisp
758 ;; The location comes from a form passed to `compile'.
759 ;; The best we can do is return the form itself for printing.
760 (make-location
761 (list :source-form (with-output-to-string (*standard-output*)
762 (debug::print-code-location-source-form
763 code-location 100 t)))
764 (list :position 1))))))
765
766 (defun location-in-file (filename code-location debug-source)
767 "Resolve the source location for CODE-LOCATION in FILENAME."
768 (let* ((code-date (di:debug-source-created debug-source))
769 (source-code (get-source-code filename code-date)))
770 (with-input-from-string (s source-code)
771 (make-location (list :file (unix-truename filename))
772 (list :position (1+ (code-location-stream-position
773 code-location s)))
774 `(:snippet ,(read-snippet s))))))
775
776 (defun location-in-stream (code-location debug-source)
777 "Resolve the source location for a CODE-LOCATION from a stream.
778 This only succeeds if the code was compiled from an Emacs buffer."
779 (unless (debug-source-info-from-emacs-buffer-p debug-source)
780 (error "The code is compiled from a non-SLIME stream."))
781 (let* ((info (c::debug-source-info debug-source))
782 (string (getf info :emacs-buffer-string))
783 (position (code-location-string-offset
784 code-location
785 string)))
786 (make-location
787 (list :buffer (getf info :emacs-buffer))
788 (list :offset (getf info :emacs-buffer-offset) position)
789 (list :snippet (with-input-from-string (s string)
790 (file-position s position)
791 (read-snippet s))))))
792
793 ;;;;; Function-name locations
794 ;;;
795 (defun debug-info-function-name-location (debug-info)
796 "Return a function-name source-location for DEBUG-INFO.
797 Function-name source-locations are a fallback for when precise
798 positions aren't available."
799 (with-struct (c::debug-info- (fname name) source) debug-info
800 (with-struct (c::debug-source- info from name) (car source)
801 (ecase from
802 (:file
803 (make-location (list :file (namestring (truename name)))
804 (list :function-name (string fname))))
805 (:stream
806 (assert (debug-source-info-from-emacs-buffer-p (car source)))
807 (make-location (list :buffer (getf info :emacs-buffer))
808 (list :function-name (string fname))))
809 (:lisp
810 (make-location (list :source-form (princ-to-string (aref name 0)))
811 (list :position 1)))))))
812
813 (defun debug-source-info-from-emacs-buffer-p (debug-source)
814 "Does the `info' slot of DEBUG-SOURCE contain an Emacs buffer location?
815 This is true for functions that were compiled directly from buffers."
816 (info-from-emacs-buffer-p (c::debug-source-info debug-source)))
817
818 (defun info-from-emacs-buffer-p (info)
819 (and info
820 (consp info)
821 (eq :emacs-buffer (car info))))
822
823
824 ;;;;; Groveling source-code for positions
825
826 (defun code-location-stream-position (code-location stream)
827 "Return the byte offset of CODE-LOCATION in STREAM. Extract the
828 toplevel-form-number and form-number from CODE-LOCATION and use that
829 to find the position of the corresponding form.
830
831 Finish with STREAM positioned at the start of the code location."
832 (let* ((location (debug::maybe-block-start-location code-location))
833 (tlf-offset (di:code-location-top-level-form-offset location))
834 (form-number (di:code-location-form-number location)))
835 (let ((pos (form-number-stream-position tlf-offset form-number stream)))
836 (file-position stream pos)
837 pos)))
838
839 (defun form-number-stream-position (tlf-number form-number stream)
840 "Return the starting character position of a form in STREAM.
841 TLF-NUMBER is the top-level-form number.
842 FORM-NUMBER is an index into a source-path table for the TLF."
843 (multiple-value-bind (tlf position-map) (read-source-form tlf-number stream)
844 (let* ((path-table (di:form-number-translations tlf 0))
845 (source-path
846 (if (<= (length path-table) form-number) ; source out of sync?
847 (list 0) ; should probably signal a condition
848 (reverse (cdr (aref path-table form-number))))))
849 (source-path-source-position source-path tlf position-map))))
850
851 (defun code-location-string-offset (code-location string)
852 "Return the byte offset of CODE-LOCATION in STRING.
853 See CODE-LOCATION-STREAM-POSITION."
854 (with-input-from-string (s string)
855 (code-location-stream-position code-location s)))
856
857
858 ;;;; Finding definitions
859
860 ;;; There are a great many different types of definition for us to
861 ;;; find. We search for definitions of every kind and return them in a
862 ;;; list.
863
864 (defimplementation find-definitions (name)
865 (append (function-definitions name)
866 (setf-definitions name)
867 (variable-definitions name)
868 (class-definitions name)
869 (type-definitions name)
870 (compiler-macro-definitions name)
871 (source-transform-definitions name)
872 (function-info-definitions name)
873 (ir1-translator-definitions name)))
874
875 ;;;;; Functions, macros, generic functions, methods
876 ;;;
877 ;;; We make extensive use of the compile-time debug information that
878 ;;; CMUCL records, in particular "debug functions" and "code
879 ;;; locations." Refer to the "Debugger Programmer's Interface" section
880 ;;; of the CMUCL manual for more details.
881
882 (defun function-definitions (name)
883 "Return definitions for NAME in the \"function namespace\", i.e.,
884 regular functions, generic functions, methods and macros.
885 NAME can any valid function name (e.g, (setf car))."
886 (let ((macro? (and (symbolp name) (macro-function name)))
887 (special? (and (symbolp name) (special-operator-p name)))
888 (function? (and (ext:valid-function-name-p name)
889 (ext:info :function :definition name)
890 (if (symbolp name) (fboundp name) t))))
891 (cond (macro?
892 (list `((defmacro ,name)
893 ,(function-location (macro-function name)))))
894 (special?
895 (list `((:special-operator ,name)
896 (:error ,(format nil "Special operator: ~S" name)))))
897 (function?
898 (let ((function (fdefinition name)))
899 (if (genericp function)
900 (generic-function-definitions name function)
901 (list (list `(function ,name)
902 (function-location function)))))))))
903
904 ;;;;;; Ordinary (non-generic/macro/special) functions
905 ;;;
906 ;;; First we test if FUNCTION is a closure created by defstruct, and
907 ;;; if so extract the defstruct-description (`dd') from the closure
908 ;;; and find the constructor for the struct. Defstruct creates a
909 ;;; defun for the default constructor and we use that as an
910 ;;; approximation to the source location of the defstruct.
911 ;;;
912 ;;; For an ordinary function we return the source location of the
913 ;;; first code-location we find.
914 ;;;
915 (defun function-location (function)
916 "Return the source location for FUNCTION."
917 (cond ((struct-closure-p function)
918 (struct-closure-location function))
919 ((c::byte-function-or-closure-p function)
920 (byte-function-location function))
921 (t
922 (compiled-function-location function))))
923
924 (defun compiled-function-location (function)
925 "Return the location of a regular compiled function."
926 (multiple-value-bind (code-location error)
927 (safe-definition-finding (function-first-code-location function))
928 (cond (error (list :error (princ-to-string error)))
929 (t (code-location-source-location code-location)))))
930
931 (defun function-first-code-location (function)
932 "Return the first code-location we can find for FUNCTION."
933 (and (function-has-debug-function-p function)
934 (di:debug-function-start-location
935 (di:function-debug-function function))))
936
937 (defun function-has-debug-function-p (function)
938 (di:function-debug-function function))
939
940 (defun function-code-object= (closure function)
941 (and (eq (vm::find-code-object closure)
942 (vm::find-code-object function))
943 (not (eq closure function))))
944
945 (defun byte-function-location (fun)
946 "Return the location of the byte-compiled function FUN."
947 (etypecase fun
948 ((or c::hairy-byte-function c::simple-byte-function)
949 (let* ((di (kernel:%code-debug-info (c::byte-function-component fun))))
950 (if di
951 (debug-info-function-name-location di)
952 `(:error
953 ,(format nil "Byte-function without debug-info: ~a" fun)))))
954 (c::byte-closure
955 (byte-function-location (c::byte-closure-function fun)))))
956
957 ;;; Here we deal with structure accessors. Note that `dd' is a
958 ;;; "defstruct descriptor" structure in CMUCL. A `dd' describes a
959 ;;; `defstruct''d structure.
960
961 (defun struct-closure-p (function)
962 "Is FUNCTION a closure created by defstruct?"
963 (or (function-code-object= function #'kernel::structure-slot-accessor)
964 (function-code-object= function #'kernel::structure-slot-setter)
965 (function-code-object= function #'kernel::%defstruct)))
966
967 (defun struct-closure-location (function)
968 "Return the location of the structure that FUNCTION belongs to."
969 (assert (struct-closure-p function))
970 (safe-definition-finding
971 (dd-location (struct-closure-dd function))))
972
973 (defun struct-closure-dd (function)
974 "Return the defstruct-definition (dd) of FUNCTION."
975 (assert (= (kernel:get-type function) vm:closure-header-type))
976 (flet ((find-layout (function)
977 (sys:find-if-in-closure
978 (lambda (x)
979 (let ((value (if (di::indirect-value-cell-p x)
980 (c:value-cell-ref x)
981 x)))
982 (when (kernel::layout-p value)
983 (return-from find-layout value))))
984 function)))
985 (kernel:layout-info (find-layout function))))
986
987 (defun dd-location (dd)
988 "Return the location of a `defstruct'."
989 ;; Find the location in a constructor.
990 (function-location (struct-constructor dd)))
991
992 (defun struct-constructor (dd)
993 "Return a constructor function from a defstruct definition.
994 Signal an error if no constructor can be found."
995 (let ((constructor (or (kernel:dd-default-constructor dd)
996 (car (kernel::dd-constructors dd)))))
997 (when (or (null constructor)
998 (and (consp constructor) (null (car constructor))))
999 (error "Cannot find structure's constructor: ~S"
1000 (kernel::dd-name dd)))
1001 (coerce (if (consp constructor) (first constructor) constructor)
1002 'function)))
1003
1004 ;;;;;; Generic functions and methods
1005
1006 (defun generic-function-definitions (name function)
1007 "Return the definitions of a generic function and its methods."
1008 (cons (list `(defgeneric ,name) (gf-location function))
1009 (gf-method-definitions function)))
1010
1011 (defun gf-location (gf)
1012 "Return the location of the generic function GF."
1013 (definition-source-location gf (pcl::generic-function-name gf)))
1014
1015 (defun gf-method-definitions (gf)
1016 "Return the locations of all methods of the generic function GF."
1017 (mapcar #'method-definition (pcl::generic-function-methods gf)))
1018
1019 (defun method-definition (method)
1020 (list (method-dspec method)
1021 (method-location method)))
1022
1023 (defun method-dspec (method)
1024 "Return a human-readable \"definition specifier\" for METHOD."
1025 (let* ((gf (pcl:method-generic-function method))
1026 (name (pcl:generic-function-name gf))
1027 (specializers (pcl:method-specializers method))
1028 (qualifiers (pcl:method-qualifiers method)))
1029 `(method ,name ,@qualifiers ,(pcl::unparse-specializers specializers))))
1030
1031 ;; XXX maybe special case setters/getters
1032 (defun method-location (method)
1033 (function-location (or (pcl::method-fast-function method)
1034 (pcl:method-function method))))
1035
1036 (defun genericp (fn)
1037 (typep fn 'generic-function))
1038
1039 ;;;;;; Types and classes
1040
1041 (defun type-definitions (name)
1042 "Return `deftype' locations for type NAME."
1043 (maybe-make-definition (ext:info :type :expander name) 'deftype name))
1044
1045 (defun maybe-make-definition (function kind name)
1046 "If FUNCTION is non-nil then return its definition location."
1047 (if function
1048 (list (list `(,kind ,name) (function-location function)))))
1049
1050 (defun class-definitions (name)
1051 "Return the definition locations for the class called NAME."
1052 (if (symbolp name)
1053 (let ((class (kernel::find-class name nil)))
1054 (etypecase class
1055 (null '())
1056 (kernel::structure-class
1057 (list (list `(defstruct ,name) (dd-location (find-dd name)))))
1058 #+(or)
1059 (conditions::condition-class
1060 (list (list `(define-condition ,name)
1061 (condition-class-location class))))
1062 (kernel::standard-class
1063 (list (list `(defclass ,name)
1064 (class-location (find-class name)))))
1065 ((or kernel::built-in-class
1066 conditions::condition-class
1067 kernel:funcallable-structure-class)
1068 (list (list `(kernel::define-type-class ,name)
1069 `(:error
1070 ,(format nil "No source info for ~A" name)))))))))
1071
1072 (defun class-location (class)
1073 "Return the `defclass' location for CLASS."
1074 (definition-source-location class (pcl:class-name class)))
1075
1076 (defun find-dd (name)
1077 "Find the defstruct-definition by the name of its structure-class."
1078 (let ((layout (ext:info :type :compiler-layout name)))
1079 (if layout
1080 (kernel:layout-info layout))))
1081
1082 (defun condition-class-location (class)
1083 (let ((slots (conditions::condition-class-slots class))
1084 (name (conditions::condition-class-name class)))
1085 (cond ((null slots)
1086 `(:error ,(format nil "No location info for condition: ~A" name)))
1087 (t
1088 ;; Find the class via one of its slot-reader methods.
1089 (let* ((slot (first slots))
1090 (gf (fdefinition
1091 (first (conditions::condition-slot-readers slot)))))
1092 (method-location
1093 (first
1094 (pcl:compute-applicable-methods-using-classes
1095 gf (list (find-class name))))))))))
1096
1097 (defun make-name-in-file-location (file string)
1098 (multiple-value-bind (filename c)
1099 (ignore-errors
1100 (unix-truename (merge-pathnames (make-pathname :type "lisp")
1101 file)))
1102 (cond (filename (make-location `(:file ,filename)
1103 `(:function-name ,(string string))))
1104 (t (list :error (princ-to-string c))))))
1105
1106 (defun source-location-form-numbers (location)
1107 (c::decode-form-numbers (c::form-numbers-form-numbers location)))
1108
1109 (defun source-location-tlf-number (location)
1110 (nth-value 0 (source-location-form-numbers location)))
1111
1112 (defun source-location-form-number (location)
1113 (nth-value 1 (source-location-form-numbers location)))
1114
1115 (defun resolve-file-source-location (location)
1116 (let ((filename (c::file-source-location-pathname location))
1117 (tlf-number (source-location-tlf-number location))
1118 (form-number (source-location-form-number location)))
1119 (with-open-file (s filename)
1120 (let ((pos (form-number-stream-position tlf-number form-number s)))
1121 (make-location `(:file ,(unix-truename filename))
1122 `(:position ,(1+ pos)))))))
1123
1124 (defun resolve-stream-source-location (location)
1125 (let ((info (c::stream-source-location-user-info location))
1126 (tlf-number (source-location-tlf-number location))
1127 (form-number (source-location-form-number location)))
1128 ;; XXX duplication in frame-source-location
1129 (assert (info-from-emacs-buffer-p info))
1130 (destructuring-bind (&key emacs-buffer emacs-buffer-string
1131 emacs-buffer-offset) info
1132 (with-input-from-string (s emacs-buffer-string)
1133 (let ((pos (form-number-stream-position tlf-number form-number s)))
1134 (make-location `(:buffer ,emacs-buffer)
1135 `(:offset ,emacs-buffer-offset ,pos)))))))
1136
1137 ;; XXX predicates for 18e backward compatibilty. Remove them when
1138 ;; we're 19a only.
1139 (defun file-source-location-p (object)
1140 (when (fboundp 'c::file-source-location-p)
1141 (c::file-source-location-p object)))
1142
1143 (defun stream-source-location-p (object)
1144 (when (fboundp 'c::stream-source-location-p)
1145 (c::stream-source-location-p object)))
1146
1147 (defun source-location-p (object)
1148 (or (file-source-location-p object)
1149 (stream-source-location-p object)))
1150
1151 (defun resolve-source-location (location)
1152 (etypecase location
1153 ((satisfies file-source-location-p)
1154 (resolve-file-source-location location))
1155 ((satisfies stream-source-location-p)
1156 (resolve-stream-source-location location))))
1157
1158 (defun definition-source-location (object name)
1159 (let ((source (pcl::definition-source object)))
1160 (etypecase source
1161 (null
1162 `(:error ,(format nil "No source info for: ~A" object)))
1163 ((satisfies source-location-p)
1164 (resolve-source-location source))
1165 (pathname
1166 (make-name-in-file-location source name))
1167 (cons
1168 (destructuring-bind ((dg name) pathname) source
1169 (declare (ignore dg))
1170 (etypecase pathname
1171 (pathname (make-name-in-file-location pathname (string name)))
1172 (null `(:error ,(format nil "Cannot resolve: ~S" source)))))))))
1173
1174 (defun setf-definitions (name)
1175 (let ((function (or (ext:info :setf :inverse name)
1176 (ext:info :setf :expander name)
1177 (and (symbolp name)
1178 (fboundp `(setf ,name))
1179 (fdefinition `(setf ,name))))))
1180 (if function
1181 (list (list `(setf ,name)
1182 (function-location (coerce function 'function)))))))
1183
1184
1185 (defun variable-location (symbol)
1186 (multiple-value-bind (location foundp)
1187 ;; XXX for 18e compatibilty. rewrite this when we drop 18e
1188 ;; support.
1189 (ignore-errors (eval `(ext:info :source-location :defvar ',symbol)))
1190 (if (and foundp location)
1191 (resolve-source-location location)
1192 `(:error ,(format nil "No source info for variable ~S" symbol)))))
1193
1194 (defun variable-definitions (name)
1195 (if (symbolp name)
1196 (multiple-value-bind (kind recorded-p) (ext:info :variable :kind name)
1197 (if recorded-p
1198 (list (list `(variable ,kind ,name)
1199 (variable-location name)))))))
1200
1201 (defun compiler-macro-definitions (symbol)
1202 (maybe-make-definition (compiler-macro-function symbol)
1203 'define-compiler-macro
1204 symbol))
1205
1206 (defun source-transform-definitions (name)
1207 (maybe-make-definition (ext:info :function :source-transform name)
1208 'c:def-source-transform
1209 name))
1210
1211 (defun function-info-definitions (name)
1212 (let ((info (ext:info :function :info name)))
1213 (if info
1214 (append (loop for transform in (c::function-info-transforms info)
1215 collect (list `(c:deftransform ,name
1216 ,(c::type-specifier
1217 (c::transform-type transform)))
1218 (function-location (c::transform-function
1219 transform))))
1220 (maybe-make-definition (c::function-info-derive-type info)
1221 'c::derive-type name)
1222 (maybe-make-definition (c::function-info-optimizer info)
1223 'c::optimizer name)
1224 (maybe-make-definition (c::function-info-ltn-annotate info)
1225 'c::ltn-annotate name)
1226 (maybe-make-definition (c::function-info-ir2-convert info)
1227 'c::ir2-convert name)
1228 (loop for template in (c::function-info-templates info)
1229 collect (list `(c::vop ,(c::template-name template))
1230 (function-location
1231 (c::vop-info-generator-function
1232 template))))))))
1233
1234 (defun ir1-translator-definitions (name)
1235 (maybe-make-definition (ext:info :function :ir1-convert name)
1236 'c:def-ir1-translator name))
1237
1238
1239 ;;;; Documentation.
1240
1241 (defimplementation describe-symbol-for-emacs (symbol)
1242 (let ((result '()))
1243 (flet ((doc (kind)
1244 (or (documentation symbol kind) :not-documented))
1245 (maybe-push (property value)
1246 (when value
1247 (setf result (list* property value result)))))
1248 (maybe-push
1249 :variable (multiple-value-bind (kind recorded-p)
1250 (ext:info variable kind symbol)
1251 (declare (ignore kind))
1252 (if (or (boundp symbol) recorded-p)
1253 (doc 'variable))))
1254 (when (fboundp symbol)
1255 (maybe-push
1256 (cond ((macro-function symbol) :macro)
1257 ((special-operator-p symbol) :special-operator)
1258 ((genericp (fdefinition symbol)) :generic-function)
1259 (t :function))
1260 (doc 'function)))
1261 (maybe-push
1262 :setf (if (or (ext:info setf inverse symbol)
1263 (ext:info setf expander symbol))
1264 (doc 'setf)))
1265 (maybe-push
1266 :type (if (ext:info type kind symbol)
1267 (doc 'type)))
1268 (maybe-push
1269 :class (if (find-class symbol nil)
1270 (doc 'class)))
1271 (maybe-push
1272 :alien-type (if (not (eq (ext:info alien-type kind symbol) :unknown))
1273 (doc 'alien-type)))
1274 (maybe-push
1275 :alien-struct (if (ext:info alien-type struct symbol)
1276 (doc nil)))
1277 (maybe-push
1278 :alien-union (if (ext:info alien-type union symbol)
1279 (doc nil)))
1280 (maybe-push
1281 :alien-enum (if (ext:info alien-type enum symbol)
1282 (doc nil)))
1283 result)))
1284
1285 (defimplementation describe-definition (symbol namespace)
1286 (describe (ecase namespace
1287 (:variable
1288 symbol)
1289 ((:function :generic-function)
1290 (symbol-function symbol))
1291 (:setf
1292 (or (ext:info setf inverse symbol)
1293 (ext:info setf expander symbol)))
1294 (:type
1295 (kernel:values-specifier-type symbol))
1296 (:class
1297 (find-class symbol))
1298 (:alien-struct
1299 (ext:info :alien-type :struct symbol))
1300 (:alien-union
1301 (ext:info :alien-type :union symbol))
1302 (:alien-enum
1303 (ext:info :alien-type :enum symbol))
1304 (:alien-type
1305 (ecase (ext:info :alien-type :kind symbol)
1306 (:primitive
1307 (let ((alien::*values-type-okay* t))
1308 (funcall (ext:info :alien-type :translator symbol)
1309 (list symbol))))
1310 ((:defined)
1311 (ext:info :alien-type :definition symbol))
1312 (:unknown :unkown))))))
1313
1314 ;;;;; Argument lists
1315
1316 (defimplementation arglist (fun)
1317 (etypecase fun
1318 (function (function-arglist fun))
1319 (symbol (function-arglist (or (macro-function fun)
1320 (symbol-function fun))))))
1321
1322 (defun function-arglist (fun)
1323 (let ((arglist
1324 (cond ((eval:interpreted-function-p fun)
1325 (eval:interpreted-function-arglist fun))
1326 ((pcl::generic-function-p fun)
1327 (pcl:generic-function-lambda-list fun))
1328 ((c::byte-function-or-closure-p fun)
1329 (byte-code-function-arglist fun))
1330 ((kernel:%function-arglist (kernel:%function-self fun))
1331 (handler-case (read-arglist fun)
1332 (error () :not-available)))
1333 ;; this should work both for compiled-debug-function
1334 ;; and for interpreted-debug-function
1335 (t
1336 (handler-case (debug-function-arglist
1337 (di::function-debug-function fun))
1338 (di:unhandled-condition () :not-available))))))
1339 (check-type arglist (or list (member :not-available)))
1340 arglist))
1341
1342 (defimplementation function-name (function)
1343 (cond ((eval:interpreted-function-p function)
1344 (eval:interpreted-function-name function))
1345 ((pcl::generic-function-p function)
1346 (pcl::generic-function-name function))
1347 ((c::byte-function-or-closure-p function)
1348 (c::byte-function-name function))
1349 (t (kernel:%function-name (kernel:%function-self function)))))
1350
1351 ;;; A simple case: the arglist is available as a string that we can
1352 ;;; `read'.
1353
1354 (defun read-arglist (fn)
1355 "Parse the arglist-string of the function object FN."
1356 (let ((string (kernel:%function-arglist
1357 (kernel:%function-self fn)))
1358 (package (find-package
1359 (c::compiled-debug-info-package
1360 (kernel:%code-debug-info
1361 (vm::find-code-object fn))))))
1362 (with-standard-io-syntax
1363 (let ((*package* (or package *package*)))
1364 (read-from-string string)))))
1365
1366 ;;; A harder case: an approximate arglist is derived from available
1367 ;;; debugging information.
1368
1369 (defun debug-function-arglist (debug-function)
1370 "Derive the argument list of DEBUG-FUNCTION from debug info."
1371 (let ((args (di::debug-function-lambda-list debug-function))
1372 (required '())
1373 (optional '())
1374 (rest '())
1375 (key '()))
1376 ;; collect the names of debug-vars
1377 (dolist (arg args)
1378 (etypecase arg
1379 (di::debug-variable
1380 (push (di::debug-variable-symbol arg) required))
1381 ((member :deleted)
1382 (push ':deleted required))
1383 (cons
1384 (ecase (car arg)
1385 (:keyword
1386 (push (second arg) key))
1387 (:optional
1388 (push (debug-variable-symbol-or-deleted (second arg)) optional))
1389 (:rest
1390 (push (debug-variable-symbol-or-deleted (second arg)) rest))))))
1391 ;; intersperse lambda keywords as needed
1392 (append (nreverse required)
1393 (if optional (cons '&optional (nreverse optional)))
1394 (if rest (cons '&rest (nreverse rest)))
1395 (if key (cons '&key (nreverse key))))))
1396
1397 (defun debug-variable-symbol-or-deleted (var)
1398 (etypecase var
1399 (di:debug-variable
1400 (di::debug-variable-symbol var))
1401 ((member :deleted)
1402 '#:deleted)))
1403
1404 (defun symbol-debug-function-arglist (fname)
1405 "Return FNAME's debug-function-arglist and %function-arglist.
1406 A utility for debugging DEBUG-FUNCTION-ARGLIST."
1407 (let ((fn (fdefinition fname)))
1408 (values (debug-function-arglist (di::function-debug-function fn))
1409 (kernel:%function-arglist (kernel:%function-self fn)))))
1410
1411 ;;; Deriving arglists for byte-compiled functions:
1412 ;;;
1413 (defun byte-code-function-arglist (fn)
1414 ;; There doesn't seem to be much arglist information around for
1415 ;; byte-code functions. Use the arg-count and return something like
1416 ;; (arg0 arg1 ...)
1417 (etypecase fn
1418 (c::simple-byte-function
1419 (loop for i from 0 below (c::simple-byte-function-num-args fn)
1420 collect (make-arg-symbol i)))
1421 (c::hairy-byte-function
1422 (hairy-byte-function-arglist fn))
1423 (c::byte-closure
1424 (byte-code-function-arglist (c::byte-closure-function fn)))))
1425
1426 (defun make-arg-symbol (i)
1427 (make-symbol (format nil "~A~D" (string 'arg) i)))
1428
1429 ;;; A "hairy" byte-function is one that takes a variable number of
1430 ;;; arguments. `hairy-byte-function' is a type from the bytecode
1431 ;;; interpreter.
1432 ;;;
1433 (defun hairy-byte-function-arglist (fn)
1434 (let ((counter -1))
1435 (flet ((next-arg () (make-arg-symbol (incf counter))))
1436 (with-struct (c::hairy-byte-function- min-args max-args rest-arg-p
1437 keywords-p keywords) fn
1438 (let ((arglist '())
1439 (optional (- max-args min-args)))
1440 ;; XXX isn't there a better way to write this?
1441 ;; (Looks fine to me. -luke)
1442 (dotimes (i min-args)
1443 (push (next-arg) arglist))
1444 (when (plusp optional)
1445 (push '&optional arglist)
1446 (dotimes (i optional)
1447 (push (next-arg) arglist)))
1448 (when rest-arg-p
1449 (push '&rest arglist)
1450 (push (next-arg) arglist))
1451 (when keywords-p
1452 (push '&key arglist)
1453 (loop for (key _ __) in keywords
1454 do (push key arglist))
1455 (when (eq keywords-p :allow-others)
1456 (push '&allow-other-keys arglist)))
1457 (nreverse arglist))))))
1458
1459
1460 ;;;; Miscellaneous.
1461
1462 (defimplementation macroexpand-all (form)
1463 (walker:macroexpand-all form))
1464
1465 (defimplementation compiler-macroexpand-1 (form &optional env)
1466 (ext:compiler-macroexpand-1 form env))
1467
1468 (defimplementation compiler-macroexpand (form &optional env)
1469 (ext:compiler-macroexpand form env))
1470
1471 (defimplementation set-default-directory (directory)
1472 (setf (ext:default-directory) (namestring directory))
1473 ;; Setting *default-pathname-defaults* to an absolute directory
1474 ;; makes the behavior of MERGE-PATHNAMES a bit more intuitive.
1475 (setf *default-pathname-defaults* (pathname (ext:default-directory)))
1476 (default-directory))
1477
1478 (defimplementation default-directory ()
1479 (namestring (ext:default-directory)))
1480
1481 (defimplementation getpid ()
1482 (unix:unix-getpid))
1483
1484 (defimplementation lisp-implementation-type-name ()
1485 "cmucl")
1486
1487 (defimplementation quit-lisp ()
1488 (ext::quit))
1489
1490 ;;; source-path-{stream,file,string,etc}-position moved into
1491 ;;; swank-source-path-parser
1492
1493
1494 ;;;; Debugging
1495
1496 (defvar *sldb-stack-top*)
1497
1498 (defimplementation call-with-debugging-environment (debugger-loop-fn)
1499 (unix:unix-sigsetmask 0)
1500 (let* ((*sldb-stack-top* (or debug:*stack-top-hint* (di:top-frame)))
1501 (debug:*stack-top-hint* nil)
1502 (kernel:*current-level* 0))
1503 (handler-bind ((di::unhandled-condition
1504 (lambda (condition)
1505 (error (make-condition
1506 'sldb-condition
1507 :original-condition condition)))))
1508 (unwind-protect
1509 (progn
1510 #+(or)(sys:scrub-control-stack)
1511 (funcall debugger-loop-fn))
1512 #+(or)(sys:scrub-control-stack)
1513 ))))
1514
1515 (defun frame-down (frame)
1516 (handler-case (di:frame-down frame)
1517 (di:no-debug-info () nil)))
1518
1519 (defun nth-frame (index)
1520 (do ((frame *sldb-stack-top* (frame-down frame))
1521 (i index (1- i)))
1522 ((zerop i) frame)))
1523
1524 (defimplementation compute-backtrace (start end)
1525 (let ((end (or end most-positive-fixnum)))
1526 (loop for f = (nth-frame start) then (frame-down f)
1527 for i from start below end
1528 while f collect f)))
1529
1530 (defimplementation print-frame (frame stream)
1531 (let ((*standard-output* stream))
1532 (handler-case
1533 (debug::print-frame-call frame :verbosity 1 :number nil)
1534 (error (e)
1535 (ignore-errors (princ e stream))))))
1536
1537 (defimplementation frame-source-location (index)
1538 (let ((frame (nth-frame index)))
1539 (cond ((foreign-frame-p frame) (foreign-frame-source-location frame))
1540 ((code-location-source-location (di:frame-code-location frame))))))
1541
1542 (defimplementation eval-in-frame (form index)
1543 (di:eval-in-frame (nth-frame index) form))
1544
1545 (defun frame-debug-vars (frame)
1546 "Return a vector of debug-variables in frame."
1547 (let ((loc (di:frame-code-location frame)))
1548 (remove-if
1549 (lambda (v)
1550 (not (eq (di:debug-variable-validity v loc) :valid)))
1551 (di::debug-function-debug-variables (di:frame-debug-function frame)))))
1552
1553 (defun debug-var-value (var frame)
1554 (let* ((loc (di:frame-code-location frame))
1555 (validity (di:debug-variable-validity var loc)))
1556 (ecase validity
1557 (:valid (di:debug-variable-value var frame))
1558 ((:invalid :unknown) (make-symbol (string validity))))))
1559
1560 (defimplementation frame-locals (index)
1561 (let ((frame (nth-frame index)))
1562 (loop for v across (frame-debug-vars frame)
1563 collect (list :name (di:debug-variable-symbol v)
1564 :id (di:debug-variable-id v)
1565 :value (debug-var-value v frame)))))
1566
1567 (defimplementation frame-var-value (frame var)
1568 (let* ((frame (nth-frame frame))
1569 (dvar (aref (frame-debug-vars frame) var)))
1570 (debug-var-value dvar frame)))
1571
1572 (defimplementation frame-catch-tags (index)
1573 (mapcar #'car (di:frame-catches (nth-frame index))))
1574
1575 (defimplementation return-from-frame (index form)
1576 (let ((sym (find-symbol (string 'find-debug-tag-for-frame)
1577 :debug-internals)))
1578 (if sym
1579 (let* ((frame (nth-frame index))
1580 (probe (funcall sym frame)))
1581 (cond (probe (throw (car probe) (eval-in-frame form index)))
1582 (t (format nil "Cannot return from frame: ~S" frame))))
1583 "return-from-frame is not implemented in this version of CMUCL.")))
1584
1585 (defimplementation activate-stepping (frame)
1586 (set-step-breakpoints (nth-frame frame)))
1587
1588 (defimplementation sldb-break-on-return (frame)
1589 (break-on-return (nth-frame frame)))
1590
1591 ;;; We set the breakpoint in the caller which might be a bit confusing.
1592 ;;;
1593 (defun break-on-return (frame)
1594 (let* ((caller (di:frame-down frame))
1595 (cl (di:frame-code-location caller)))
1596 (flet ((hook (frame bp)
1597 (when (frame-pointer= frame caller)
1598 (di:delete-breakpoint bp)
1599 (signal-breakpoint bp frame))))
1600 (let* ((info (ecase (di:code-location-kind cl)
1601 ((:single-value-return :unknown-return) nil)
1602 (:known-return (debug-function-returns
1603 (di:frame-debug-function frame)))))
1604 (bp (di:make-breakpoint #'hook cl :kind :code-location
1605 :info info)))
1606 (di:activate-breakpoint bp)
1607 `(:ok ,(format nil "Set breakpoint in ~A" caller))))))
1608
1609 (defun frame-pointer= (frame1 frame2)
1610 "Return true if the frame pointers of FRAME1 and FRAME2 are the same."
1611 (sys:sap= (di::frame-pointer frame1) (di::frame-pointer frame2)))
1612
1613 ;;; The PC in escaped frames at a single-return-value point is
1614 ;;; actually vm:single-value-return-byte-offset bytes after the
1615 ;;; position given in the debug info. Here we try to recognize such
1616 ;;; cases.
1617 ;;;
1618 (defun next-code-locations (frame code-location)
1619 "Like `debug::next-code-locations' but be careful in escaped frames."
1620 (let ((next (debug::next-code-locations code-location)))
1621 (flet ((adjust-pc ()
1622 (let ((cl (di::copy-compiled-code-location code-location)))
1623 (incf (di::compiled-code-location-pc cl)
1624 vm:single-value-return-byte-offset)
1625 cl)))
1626 (cond ((and (di::compiled-frame-escaped frame)
1627 (eq (di:code-location-kind code-location)
1628 :single-value-return)
1629 (= (length next) 1)
1630 (di:code-location= (car next) (adjust-pc)))
1631 (debug::next-code-locations (car next)))
1632 (t
1633 next)))))
1634
1635 (defun set-step-breakpoints (frame)
1636 (let ((cl (di:frame-code-location frame)))
1637 (when (di:debug-block-elsewhere-p (di:code-location-debug-block cl))
1638 (error "Cannot step in elsewhere code"))
1639 (let* ((debug::*bad-code-location-types*
1640 (remove :call-site debug::*bad-code-location-types*))
1641 (next (next-code-locations frame cl)))
1642 (cond (next
1643 (let ((steppoints '()))
1644 (flet ((hook (bp-frame bp)
1645 (signal-breakpoint bp bp-frame)
1646 (mapc #'di:delete-breakpoint steppoints)))
1647 (dolist (code-location next)
1648 (let ((bp (di:make-breakpoint #'hook code-location
1649 :kind :code-location)))
1650 (di:activate-breakpoint bp)
1651 (push bp steppoints))))))
1652 (t
1653 (break-on-return frame))))))
1654
1655
1656 ;; XXX the return values at return breakpoints should be passed to the
1657 ;; user hooks. debug-int.lisp should be changed to do this cleanly.
1658
1659 ;;; The sigcontext and the PC for a breakpoint invocation are not
1660 ;;; passed to user hook functions, but we need them to extract return
1661 ;;; values. So we advice di::handle-breakpoint and bind the values to
1662 ;;; special variables.
1663 ;;;
1664 (defvar *breakpoint-sigcontext*)
1665 (defvar *breakpoint-pc*)
1666
1667 ;; XXX don't break old versions without fwrappers. Remove this one day.
1668 #+#.(cl:if (cl:find-package :fwrappers) '(and) '(or))
1669 (progn
1670 (fwrappers:define-fwrapper bind-breakpoint-sigcontext (offset c sigcontext)
1671 (let ((*breakpoint-sigcontext* sigcontext)
1672 (*breakpoint-pc* offset))
1673 (fwrappers:call-next-function)))
1674 (fwrappers:set-fwrappers 'di::handle-breakpoint '())
1675 (fwrappers:fwrap 'di::handle-breakpoint #'bind-breakpoint-sigcontext))
1676
1677 (defun sigcontext-object (sc index)
1678 "Extract the lisp object in sigcontext SC at offset INDEX."
1679 (kernel:make-lisp-obj (vm:sigcontext-register sc index)))
1680
1681 (defun known-return-point-values (sigcontext sc-offsets)
1682 (let ((fp (system:int-sap (vm:sigcontext-register sigcontext
1683 vm::cfp-offset))))
1684 (system:without-gcing
1685 (loop for sc-offset across sc-offsets
1686 collect (di::sub-access-debug-var-slot fp sc-offset sigcontext)))))
1687
1688 ;;; CMUCL returns the first few values in registers and the rest on
1689 ;;; the stack. In the multiple value case, the number of values is
1690 ;;; stored in a dedicated register. The values of the registers can be
1691 ;;; accessed in the sigcontext for the breakpoint. There are 3 kinds
1692 ;;; of return conventions: :single-value-return, :unknown-return, and
1693 ;;; :known-return.
1694 ;;;
1695 ;;; The :single-value-return convention returns the value in a
1696 ;;; register without setting the nargs registers.
1697 ;;;
1698 ;;; The :unknown-return variant is used for multiple values. A
1699 ;;; :unknown-return point consists actually of 2 breakpoints: one for
1700 ;;; the single value case and one for the general case. The single
1701 ;;; value breakpoint comes vm:single-value-return-byte-offset after
1702 ;;; the multiple value breakpoint.
1703 ;;;
1704 ;;; The :known-return convention is used by local functions.
1705 ;;; :known-return is currently not supported because we don't know
1706 ;;; where the values are passed.
1707 ;;;
1708 (defun breakpoint-values (breakpoint)
1709 "Return the list of return values for a return point."
1710 (flet ((1st (sc) (sigcontext-object sc (car vm::register-arg-offsets))))
1711 (let ((sc (locally (declare (optimize (speed 0)))
1712 (alien:sap-alien *breakpoint-sigcontext* (* unix:sigcontext))))
1713 (cl (di:breakpoint-what breakpoint)))
1714 (ecase (di:code-location-kind cl)
1715 (:single-value-return
1716 (list (1st sc)))
1717 (:known-return
1718 (let ((info (di:breakpoint-info breakpoint)))
1719 (if (vectorp info)
1720 (known-return-point-values sc info)
1721 (progn
1722 ;;(break)
1723 (list "<<known-return convention not supported>>" info)))))
1724 (:unknown-return
1725 (let ((mv-return-pc (di::compiled-code-location-pc cl)))
1726 (if (= mv-return-pc *breakpoint-pc*)
1727 (mv-function-end-breakpoint-values sc)
1728 (list (1st sc)))))))))
1729
1730 ;; XXX: di::get-function-end-breakpoint-values takes 2 arguments in
1731 ;; newer versions of CMUCL (after ~March 2005).
1732 (defun mv-function-end-breakpoint-values (sigcontext)
1733 (let ((sym (find-symbol "FUNCTION-END-BREAKPOINT-VALUES/STANDARD" :di)))
1734 (cond (sym (funcall sym sigcontext))
1735 (t (funcall 'di::get-function-end-breakpoint-values sigcontext)))))
1736
1737 (defun debug-function-returns (debug-fun)
1738 "Return the return style of DEBUG-FUN."
1739 (let* ((cdfun (di::compiled-debug-function-compiler-debug-fun debug-fun)))
1740 (c::compiled-debug-function-returns cdfun)))
1741
1742 (define-condition breakpoint (simple-condition)
1743 ((message :initarg :message :reader breakpoint.message)
1744 (values :initarg :values :reader breakpoint.values))
1745 (:report (lambda (c stream) (princ (breakpoint.message c) stream))))
1746
1747 (defimplementation condition-extras (condition)
1748 (typecase condition
1749 (breakpoint
1750 ;; pop up the source buffer
1751 `((:show-frame-source 0)))
1752 (t '())))
1753
1754 (defun signal-breakpoint (breakpoint frame)
1755 "Signal a breakpoint condition for BREAKPOINT in FRAME.
1756 Try to create a informative message."
1757 (flet ((brk (values fstring &rest args)
1758 (let ((msg (apply #'format nil fstring args))
1759 (debug:*stack-top-hint* frame))
1760 (break 'breakpoint :message msg :values values))))
1761 (with-struct (di::breakpoint- kind what) breakpoint
1762 (case kind
1763 (:code-location
1764 (case (di:code-location-kind what)
1765 ((:single-value-return :known-return :unknown-return)
1766 (let ((values (breakpoint-values breakpoint)))
1767 (brk values "Return value: ~{~S ~}" values)))
1768 (t
1769 #+(or)
1770 (when (eq (di:code-location-kind what) :call-site)
1771 (call-site-function breakpoint frame))
1772 (brk nil "Breakpoint: ~S ~S"
1773 (di:code-location-kind what)
1774 (di::compiled-code-location-pc what)))))
1775 (:function-start
1776 (brk nil "Function start breakpoint"))
1777 (t (brk nil "Breakpoint: ~A in ~A" breakpoint frame))))))
1778
1779 (defimplementation sldb-break-at-start (fname)
1780 (let ((debug-fun (di:function-debug-function (coerce fname 'function))))
1781 (cond ((not debug-fun)
1782 `(:error ,(format nil "~S has no debug-function" fname)))
1783 (t
1784 (flet ((hook (frame bp &optional args cookie)
1785 (declare (ignore args cookie))
1786 (signal-breakpoint bp frame)))
1787 (let ((bp (di:make-breakpoint #'hook debug-fun
1788 :kind :function-start)))
1789 (di:activate-breakpoint bp)
1790 `(:ok ,(format nil "Set breakpoint in ~S" fname))))))))
1791
1792 (defun frame-cfp (frame)
1793 "Return the Control-Stack-Frame-Pointer for FRAME."
1794 (etypecase frame
1795 (di::compiled-frame (di::frame-pointer frame))
1796 ((or di::interpreted-frame null) -1)))
1797
1798 (defun frame-ip (frame)
1799 "Return the (absolute) instruction pointer and the relative pc of FRAME."
1800 (if (not frame)
1801 -1
1802 (let ((debug-fun (di::frame-debug-function frame)))
1803 (etypecase debug-fun
1804 (di::compiled-debug-function
1805 (let* ((code-loc (di:frame-code-location frame))
1806 (component (di::compiled-debug-function-component debug-fun))
1807 (pc (di::compiled-code-location-pc code-loc))
1808 (ip (sys:without-gcing
1809 (sys:sap-int
1810 (sys:sap+ (kernel:code-instructions component) pc)))))
1811 (values ip pc)))
1812 (di::interpreted-debug-function -1)
1813 (di::bogus-debug-function
1814 #-x86 -1
1815 #+x86
1816 (let ((fp (di::frame-pointer (di:frame-up frame))))
1817 (multiple-value-bind (ra ofp) (di::x86-call-context fp)
1818 (declare (ignore ofp))
1819 (values ra 0))))))))
1820
1821 (defun frame-registers (frame)
1822 "Return the lisp registers CSP, CFP, IP, OCFP, LRA for FRAME-NUMBER."
1823 (let* ((cfp (frame-cfp frame))
1824 (csp (frame-cfp (di::frame-up frame)))
1825 (ip (frame-ip frame))
1826 (ocfp (frame-cfp (di::frame-down frame)))
1827 (lra (frame-ip (di::frame-down frame))))
1828 (values csp cfp ip ocfp lra)))
1829
1830 (defun print-frame-registers (frame-number)
1831 (let ((frame (di::frame-real-frame (nth-frame frame-number))))
1832 (flet ((fixnum (p) (etypecase p
1833 (integer p)
1834 (sys:system-area-pointer (sys:sap-int p)))))
1835 (apply #'format t "~
1836 ~8X Stack Pointer
1837 ~8X Frame Pointer
1838 ~8X Instruction Pointer
1839 ~8X Saved Frame Pointer
1840 ~8X Saved Instruction Pointer~%" (mapcar #'fixnum
1841 (multiple-value-list (frame-registers frame)))))))
1842
1843 (defvar *gdb-program-name* "/usr/bin/gdb")
1844
1845 (defimplementation disassemble-frame (frame-number)
1846 (print-frame-registers frame-number)
1847 (terpri)
1848 (let* ((frame (di::frame-real-frame (nth-frame frame-number)))
1849 (debug-fun (di::frame-debug-function frame)))
1850 (etypecase debug-fun
1851 (di::compiled-debug-function
1852 (let* ((component (di::compiled-debug-function-component debug-fun))
1853 (fun (di:debug-function-function debug-fun)))
1854 (if fun
1855 (disassemble fun)
1856 (disassem:disassemble-code-component component))))
1857 (di::bogus-debug-function
1858 (cond ((probe-file *gdb-program-name*)
1859 (let ((ip (sys:sap-int (frame-ip frame))))
1860 (princ (gdb-command "disas 0x~x" ip))))
1861 (t
1862 (format t "~%[Disassembling bogus frames not implemented]")))))))
1863
1864 (defmacro with-temporary-file ((stream filename) &body body)
1865 `(call/temporary-file (lambda (,stream ,filename) . ,body)))
1866
1867 (defun call/temporary-file (fun)
1868 (let ((name (system::pick-temporary-file-name)))
1869 (unwind-protect
1870 (with-open-file (stream name :direction :output :if-exists :supersede)
1871 (funcall fun stream name))
1872 (delete-file name))))
1873
1874 (defun gdb-command (format-string &rest args)
1875 (let ((str (gdb-exec (format nil "attach ~d~%~a~%detach"
1876 (getpid)
1877 (apply #'format nil format-string args)))))
1878 (subseq str (1+ (position #\newline str)))))
1879
1880 (defun gdb-exec (cmd)
1881 (with-temporary-file (file filename)
1882 (write-string cmd file)
1883 (force-output file)
1884 (let* ((output (make-string-output-stream))
1885 (proc (ext:run-program "gdb" `("-batch" "-x" ,filename)
1886 :wait t
1887 :output output)))
1888 (assert (eq (ext:process-status proc) :exited))
1889 (assert (eq (ext:process-exit-code proc) 0))
1890 (get-output-stream-string output))))
1891
1892 (defun foreign-frame-p (frame)
1893 #-x86 nil
1894 #+x86 (let ((ip (frame-ip frame)))
1895 (and (sys:system-area-pointer-p ip)
1896 (multiple-value-bind (pc code)
1897 (di::compute-lra-data-from-pc ip)
1898 (declare (ignore pc))
1899 (not code)))))
1900
1901 (defun foreign-frame-source-location (frame)
1902 (let ((ip (sys:sap-int (frame-ip frame))))
1903 (cond ((probe-file *gdb-program-name*)
1904 (parse-gdb-line-info (gdb-command "info line *0x~x" ip)))
1905 (t `(:error "no srcloc available for ~a" frame)))))
1906
1907 ;; The output of gdb looks like:
1908 ;; Line 215 of "../../src/lisp/x86-assem.S"
1909 ;; starts at address 0x805318c <Ldone+11>
1910 ;; and ends at 0x805318e <Ldone+13>.
1911 ;; The ../../ are fixed up with the "target:" search list which might
1912 ;; be wrong sometimes.
1913 (defun parse-gdb-line-info (string)
1914 (with-input-from-string (*standard-input* string)
1915 (let ((w1 (read-word)))
1916 (cond ((equal w1 "Line")
1917 (let ((line (read-word)))
1918 (assert (equal (read-word) "of"))
1919 (let ((file (read-word)))
1920 (make-location (list :file
1921 (unix-truename
1922 (merge-pathnames
1923 (read-from-string file)
1924 (format nil "~a/lisp/"
1925 (unix-truename "target:")))))
1926 (list :line (parse-integer line))))))
1927 (t `(:error ,string))))))
1928
1929 (defun read-word (&optional (stream *standard-input*))
1930 (peek-char t stream)
1931 (concatenate 'string (loop until (whitespacep (peek-char nil stream))
1932 collect (read-char stream))))
1933
1934 (defun whitespacep (char)
1935 (member char '(#\space #\newline)))
1936
1937
1938 ;;;; Inspecting
1939
1940 (defconstant +lowtag-symbols+
1941 '(vm:even-fixnum-type
1942 vm:function-pointer-type
1943 vm:other-immediate-0-type
1944 vm:list-pointer-type
1945 vm:odd-fixnum-type
1946 vm:instance-pointer-type
1947 vm:other-immediate-1-type
1948 vm:other-pointer-type)
1949 "Names of the constants that specify type tags.
1950 The `symbol-value' of each element is a type tag.")
1951
1952 (defconstant +header-type-symbols+
1953 (labels ((suffixp (suffix string)
1954 (and (>= (length string) (length suffix))
1955 (string= string suffix :start1 (- (length string)
1956 (length suffix)))))
1957 (header-type-symbol-p (x)
1958 (and (suffixp "-TYPE" (symbol-name x))
1959 (not (member x +lowtag-symbols+))
1960 (boundp x)
1961 (typep (symbol-value x) 'fixnum))))
1962 (remove-if-not #'header-type-symbol-p
1963 (append (apropos-list "-TYPE" "VM")
1964 (apropos-list "-TYPE" "BIGNUM"))))
1965 "A list of names of the type codes in boxed objects.")
1966
1967 (defimplementation describe-primitive-type (object)
1968 (with-output-to-string (*standard-output*)
1969 (let* ((lowtag (kernel:get-lowtag object))
1970 (lowtag-symbol (find lowtag +lowtag-symbols+ :key #'symbol-value)))
1971 (format t "lowtag: ~A" lowtag-symbol)
1972 (when (member lowtag (list vm:other-pointer-type
1973 vm:function-pointer-type
1974 vm:other-immediate-0-type
1975 vm:other-immediate-1-type
1976 ))
1977 (let* ((type (kernel:get-type object))
1978 (type-symbol (find type +header-type-symbols+
1979 :key #'symbol-value)))
1980 (format t ", type: ~A" type-symbol))))))
1981
1982 (defmethod emacs-inspect ((o t))
1983 (cond ((di::indirect-value-cell-p o)
1984 `("Value: " (:value ,(c:value-cell-ref o))))
1985 ((alien::alien-value-p o)
1986 (inspect-alien-value o))
1987 (t
1988 (cmucl-inspect o))))
1989
1990 (defun cmucl-inspect (o)
1991 (destructuring-bind (text labeledp . parts) (inspect::describe-parts o)
1992 (list* (format nil "~A~%" text)
1993 (if labeledp
1994 (loop for (label . value) in parts
1995 append (label-value-line label value))
1996 (loop for value in parts for i from 0
1997 append (label-value-line i value))))))
1998
1999 (defmethod emacs-inspect ((o function))
2000 (let ((header (kernel:get-type o)))
2001 (cond ((= header vm:function-header-type)
2002 (append (label-value-line*
2003 ("Self" (kernel:%function-self o))
2004 ("Next" (kernel:%function-next o))
2005 ("Name" (kernel:%function-name o))
2006 ("Arglist" (kernel:%function-arglist o))
2007 ("Type" (kernel:%function-type o))
2008 ("Code" (kernel:function-code-header o)))
2009 (list
2010 (with-output-to-string (s)
2011 (disassem:disassemble-function o :stream s)))))
2012 ((= header vm:closure-header-type)
2013 (list* (format nil "~A is a closure.~%" o)
2014 (append
2015 (label-value-line "Function" (kernel:%closure-function o))
2016 `("Environment:" (:newline))
2017 (loop for i from 0 below (1- (kernel:get-closure-length o))
2018 append (label-value-line
2019 i (kernel:%closure-index-ref o i))))))
2020 ((eval::interpreted-function-p o)
2021 (cmucl-inspect o))
2022 (t
2023 (call-next-method)))))
2024
2025 (defmethod emacs-inspect ((o kernel:funcallable-instance))
2026 (append (label-value-line*
2027 (:function (kernel:%funcallable-instance-function o))
2028 (:lexenv (kernel:%funcallable-instance-lexenv o))
2029 (:layout (kernel:%funcallable-instance-layout o)))
2030 (cmucl-inspect o)))
2031
2032 (defmethod emacs-inspect ((o kernel:code-component))
2033 (append
2034 (label-value-line*
2035 ("code-size" (kernel:%code-code-size o))
2036 ("entry-points" (kernel:%code-entry-points o))
2037 ("debug-info" (kernel:%code-debug-info o))
2038 ("trace-table-offset" (kernel:code-header-ref
2039 o vm:code-trace-table-offset-slot)))
2040 `("Constants:" (:newline))
2041 (loop for i from vm:code-constants-offset
2042 below (kernel:get-header-data o)
2043 append (label-value-line i (kernel:code-header-ref o i)))
2044 `("Code:"
2045 (:newline)
2046 , (with-output-to-string (*standard-output*)
2047 (cond ((c::compiled-debug-info-p (kernel:%code-debug-info o))
2048 (disassem:disassemble-code-component o))
2049 ((or
2050 (c::debug-info-p (kernel:%code-debug-info o))
2051 (consp (kernel:code-header-ref
2052 o vm:code-trace-table-offset-slot)))
2053 (c:disassem-byte-component o))
2054 (t
2055 (disassem:disassemble-memory
2056 (disassem::align
2057 (+ (logandc2 (kernel:get-lisp-obj-address o)
2058 vm:lowtag-mask)
2059 (* vm:code-constants-offset vm:word-bytes))
2060 (ash 1 vm:lowtag-bits))
2061 (ash (kernel:%code-code-size o) vm:word-shift))))))))
2062
2063 (defmethod emacs-inspect ((o kernel:fdefn))
2064 (label-value-line*
2065 ("name" (kernel:fdefn-name o))
2066 ("function" (kernel:fdefn-function o))
2067 ("raw-addr" (sys:sap-ref-32
2068 (sys:int-sap (kernel:get-lisp-obj-address o))
2069 (* vm:fdefn-raw-addr-slot vm:word-bytes)))))
2070
2071 #+(or)
2072 (defmethod emacs-inspect ((o array))
2073 (if (typep o 'simple-array)
2074 (call-next-method)
2075 (label-value-line*
2076 (:header (describe-primitive-type o))
2077 (:rank (array-rank o))
2078 (:fill-pointer (kernel:%array-fill-pointer o))
2079 (:fill-pointer-p (kernel:%array-fill-pointer-p o))
2080 (:elements (kernel:%array-available-elements o))
2081 (:data (kernel:%array-data-vector o))
2082 (:displacement (kernel:%array-displacement o))
2083 (:displaced-p (kernel:%array-displaced-p o))
2084 (:dimensions (array-dimensions o)))))
2085
2086 (defmethod emacs-inspect ((o simple-vector))
2087 (append
2088 (label-value-line*
2089 (:header (describe-primitive-type o))
2090 (:length (c::vector-length o)))
2091 (loop for i below (length o)
2092 append (label-value-line i (aref o i)))))
2093
2094 (defun inspect-alien-record (alien)
2095 (with-struct (alien::alien-value- sap type) alien
2096 (with-struct (alien::alien-record-type- kind name fields) type
2097 (append
2098 (label-value-line*
2099 (:sap sap)
2100 (:kind kind)
2101 (:name name))
2102 (loop for field in fields
2103 append (let ((slot (alien::alien-record-field-name field)))
2104 (declare (optimize (speed 0)))
2105 (label-value-line slot (alien:slot alien slot))))))))
2106
2107 (defun inspect-alien-pointer (alien)
2108 (with-struct (alien::alien-value- sap type) alien
2109 (label-value-line*
2110 (:sap sap)
2111 (:type type)
2112 (:to (alien::deref alien)))))
2113
2114 (defun inspect-alien-value (alien)
2115 (typecase (alien::alien-value-type alien)
2116 (alien::alien-record-type (inspect-alien-record alien))
2117 (alien::alien-pointer-type (inspect-alien-pointer alien))
2118 (t (cmucl-inspect alien))))
2119
2120 ;;;; Profiling
2121 (defimplementation profile (fname)
2122 (eval `(profile:profile ,fname)))
2123
2124 (defimplementation unprofile (fname)
2125 (eval `(profile:unprofile ,fname)))
2126
2127 (defimplementation unprofile-all ()
2128 (eval `(profile:unprofile))
2129 "All functions unprofiled.")
2130
2131 (defimplementation profile-report ()
2132 (eval `(profile:report-time)))
2133
2134 (defimplementation profile-reset ()
2135 (eval `(profile:reset-time))
2136 "Reset profiling counters.")
2137
2138 (defimplementation profiled-functions ()
2139 profile:*timed-functions*)
2140
2141 (defimplementation profile-package (package callers methods)
2142 (profile:profile-all :package package
2143 :callers-p callers
2144 #-cmu18e :methods #-cmu18e methods))
2145
2146
2147 ;;;; Multiprocessing
2148
2149 #+mp
2150 (progn
2151 (defimplementation initialize-multiprocessing (continuation)
2152 (mp::init-multi-processing)
2153 (mp:make-process continuation :name "swank")
2154 ;; Threads magic: this never returns! But top-level becomes
2155 ;; available again.
2156 (unless mp::*idle-process*
2157 (mp::startup-idle-and-top-level-loops)))
2158
2159 (defimplementation spawn (fn &key name)
2160 (mp:make-process fn :name (or name "Anonymous")))
2161
2162 (defvar *thread-id-counter* 0)
2163
2164 (defimplementation thread-id (thread)
2165 (or (getf (mp:process-property-list thread) 'id)
2166 (setf (getf (mp:process-property-list thread) 'id)
2167 (incf *thread-id-counter*))))
2168
2169 (defimplementation find-thread (id)
2170 (find id (all-threads)
2171 :key (lambda (p) (getf (mp:process-property-list p) 'id))))
2172
2173 (defimplementation thread-name (thread)
2174 (mp:process-name thread))
2175
2176 (defimplementation thread-status (thread)
2177 (mp:process-whostate thread))
2178
2179 (defimplementation current-thread ()
2180 mp:*current-process*)
2181
2182 (defimplementation all-threads ()
2183 (copy-list mp:*all-processes*))
2184
2185 (defimplementation interrupt-thread (thread fn)
2186 (mp:process-interrupt thread fn))
2187
2188 (defimplementation kill-thread (thread)
2189 (mp:destroy-process thread))
2190
2191 (defvar *mailbox-lock* (mp:make-lock "mailbox lock"))
2192
2193 (defstruct (mailbox (:conc-name mailbox.))
2194 (mutex (mp:make-lock "process mailbox"))
2195 (queue '() :type list))
2196
2197 (defun mailbox (thread)
2198 "Return THREAD's mailbox."
2199 (mp:with-lock-held (*mailbox-lock*)
2200 (or (getf (mp:process-property-list thread) 'mailbox)
2201 (setf (getf (mp:process-property-list thread) 'mailbox)
2202 (make-mailbox)))))
2203
2204 (defimplementation send (thread message)
2205 (check-slime-interrupts)
2206 (let* ((mbox (mailbox thread)))
2207 (mp:with-lock-held ((mailbox.mutex mbox))
2208 (setf (mailbox.queue mbox)
2209 (nconc (mailbox.queue mbox) (list message))))))
2210
2211 (defimplementation receive-if (test &optional timeout)
2212 (let ((mbox (mailbox mp:*current-process*)))
2213 (assert (or (not timeout) (eq timeout t)))
2214 (loop
2215 (check-slime-interrupts)
2216 (mp:with-lock-held ((mailbox.mutex mbox))
2217 (let* ((q (mailbox.queue mbox))
2218 (tail (member-if test q)))
2219 (when tail
2220 (setf (mailbox.queue mbox)
2221 (nconc (ldiff q tail) (cdr tail)))
2222 (return (car tail)))))
2223 (when (eq timeout t) (return (values nil t)))
2224 (mp:process-wait-with-timeout
2225 "receive-if" 0.5
2226 (lambda () (some test (mailbox.queue mbox)))))))
2227
2228
2229 ) ;; #+mp
2230
2231
2232
2233 ;;;; GC hooks
2234 ;;;
2235 ;;; Display GC messages in the echo area to avoid cluttering the
2236 ;;; normal output.
2237 ;;;
2238
2239 ;; this should probably not be here, but where else?
2240 (defun background-message (message)
2241 (funcall (find-symbol (string :background-message) :swank)
2242 message))
2243
2244 (defun print-bytes (nbytes &optional stream)
2245 "Print the number NBYTES to STREAM in KB, MB, or GB units."
2246 (let ((names '((0 bytes) (10 kb) (20 mb) (30 gb) (40 tb) (50 eb))))
2247 (multiple-value-bind (power name)
2248 (loop for ((p1 n1) (p2 n2)) on names
2249 while n2 do
2250 (when (<= (expt 2 p1) nbytes (1- (expt 2 p2)))
2251 (return (values p1 n1))))
2252 (cond (name
2253 (format stream "~,1F ~A" (/ nbytes (expt 2 power)) name))
2254 (t
2255 (format stream "~:D bytes" nbytes))))))
2256
2257 (defconstant gc-generations 6)
2258
2259 #+gencgc
2260 (defun generation-stats ()
2261 "Return a string describing the size distribution among the generations."
2262 (let* ((alloc (loop for i below gc-generations
2263 collect (lisp::gencgc-stats i)))
2264 (sum (coerce (reduce #'+ alloc) 'float)))
2265 (format nil "~{~3F~^/~}"
2266 (mapcar (lambda (size) (/ size sum))
2267 alloc))))
2268
2269 (defvar *gc-start-time* 0)
2270
2271 (defun pre-gc-hook (bytes-in-use)
2272 (setq *gc-start-time* (get-internal-real-time))
2273 (let ((msg (format nil "[Commencing GC with ~A in use.]"
2274 (print-bytes bytes-in-use))))
2275 (background-message msg)))
2276
2277 (defun post-gc-hook (bytes-retained bytes-freed trigger)
2278 (declare (ignore trigger))
2279 (let* ((seconds (/ (- (get-internal-real-time) *gc-start-time*)
2280 internal-time-units-per-second))
2281 (msg (format nil "[GC done. ~A freed ~A retained ~A ~4F sec]"
2282 (print-bytes bytes-freed)
2283 (print-bytes bytes-retained)
2284 #+gencgc(generation-stats)
2285 #-gencgc""
2286 seconds)))
2287 (background-message msg)))
2288
2289 (defun install-gc-hooks ()
2290 (setq ext:*gc-notify-before* #'pre-gc-hook)
2291 (setq ext:*gc-notify-after* #'post-gc-hook))
2292
2293 (defun remove-gc-hooks ()
2294 (setq ext:*gc-notify-before* #'lisp::default-gc-notify-before)
2295 (setq ext:*gc-notify-after* #'lisp::default-gc-notify-after))
2296
2297 (defvar *install-gc-hooks* t
2298 "If non-nil install GC hooks")
2299
2300 (defimplementation emacs-connected ()
2301 (when *install-gc-hooks*
2302 (install-gc-hooks)))
2303
2304 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2305 ;;Trace implementations
2306 ;;In CMUCL, we have:
2307 ;; (trace <name>)
2308 ;; (trace (method <name> <qualifier>? (<specializer>+)))
2309 ;; (trace :methods t '<name>) ;;to trace all methods of the gf <name>
2310 ;; <name> can be a normal name or a (setf name)
2311
2312 (defun tracedp (spec)
2313 (member spec (eval '(trace)) :test #'equal))
2314
2315 (defun toggle-trace-aux (spec &rest options)
2316 (cond ((tracedp spec)
2317 (eval `(untrace ,spec))
2318 (format nil "~S is now untraced." spec))
2319 (t
2320 (eval `(trace ,spec ,@options))
2321 (format nil "~S is now traced." spec))))
2322
2323 (defimplementation toggle-trace (spec)
2324 (ecase (car spec)
2325 ((setf)
2326 (toggle-trace-aux spec))
2327 ((:defgeneric)
2328 (let ((name (second spec)))
2329 (toggle-trace-aux name :methods name)))
2330 ((:defmethod)
2331 (cond ((fboundp `(method ,@(cdr spec)))
2332 (toggle-trace-aux `(method ,(cdr spec))))
2333 ;; Man, is this ugly
2334 ((fboundp `(pcl::fast-method ,@(cdr spec)))
2335 (toggle-trace-aux `(pcl::fast-method ,@(cdr spec))))
2336 (t
2337 (error 'undefined-function :name (cdr spec)))))
2338 ((:call)
2339 (destructuring-bind (caller callee) (cdr spec)
2340 (toggle-trace-aux (process-fspec callee)
2341 :wherein (list (process-fspec caller)))))
2342 ;; doesn't work properly
2343 ;; ((:labels :flet) (toggle-trace-aux (process-fspec spec)))
2344 ))
2345
2346 (defun process-fspec (fspec)
2347 (cond ((consp fspec)
2348 (ecase (first fspec)
2349 ((:defun :defgeneric) (second fspec))
2350 ((:defmethod)
2351 `(method ,(second fspec) ,@(third fspec) ,(fourth fspec)))
2352 ((:labels) `(labels ,(third fspec) ,(process-fspec (second fspec))))
2353 ((:flet) `(flet ,(third fspec) ,(process-fspec (second fspec))))))
2354 (t
2355 fspec)))
2356
2357 ;;; Weak datastructures
2358
2359 (defimplementation make-weak-key-hash-table (&rest args)
2360 (apply #'make-hash-table :weak-p t args))
2361
2362
2363 ;;; Save image
2364
2365 (defimplementation save-image (filename &optional restart-function)
2366 (multiple-value-bind (pid error) (unix:unix-fork)
2367 (when (not pid) (error "fork: ~A" (unix:get-unix-error-msg error)))
2368 (cond ((= pid 0)
2369 (let ((args `(,filename
2370 ,@(if restart-function
2371 `((:init-function ,restart-function))))))
2372 (apply #'ext:save-lisp args)))
2373 (t
2374 (let ((status (waitpid pid)))
2375 (destructuring-bind (&key exited? status &allow-other-keys) status
2376 (assert (and exited? (equal status 0)) ()
2377 "Invalid exit status: ~a" status)))))))
2378
2379 (defun waitpid (pid)
2380 (alien:with-alien ((status c-call:int))
2381 (let ((code (alien:alien-funcall
2382 (alien:extern-alien
2383 waitpid (alien:function c-call:int c-call:int
2384 (* c-call:int) c-call:int))
2385 pid (alien:addr status) 0)))
2386 (cond ((= code -1) (error "waitpid: ~A" (unix:get-unix-error-msg)))
2387 (t (assert (= code pid))
2388 (decode-wait-status status))))))
2389
2390 (defun decode-wait-status (status)
2391 (let ((output (with-output-to-string (s)
2392 (call-program (list (process-status-program)
2393 (format nil "~d" status))
2394 :output s))))
2395 (read-from-string output)))
2396
2397 (defun call-program (args &key output)
2398 (destructuring-bind (program &rest args) args
2399 (let ((process (ext:run-program program args :output output)))
2400 (when (not program) (error "fork failed"))
2401 (unless (and (eq (ext:process-status process) :exited)
2402 (= (ext:process-exit-code process) 0))
2403 (error "Non-zero exit status")))))
2404
2405 (defvar *process-status-program* nil)
2406
2407 (defun process-status-program ()
2408 (or *process-status-program*
2409 (setq *process-status-program*
2410 (compile-process-status-program))))
2411
2412 (defun compile-process-status-program ()
2413 (let ((infile (system::pick-temporary-file-name
2414 "/tmp/process-status~d~c.c")))
2415 (with-open-file (stream infile :direction :output :if-exists :supersede)
2416 (format stream "
2417 #include <stdio.h>
2418 #include <stdlib.h>
2419 #include <sys/types.h>
2420 #include <sys/wait.h>
2421 #include <assert.h>
2422
2423 #define FLAG(value) (value ? \"t\" : \"nil\")
2424
2425 int main (int argc, char** argv) {
2426 assert (argc == 2);
2427 {
2428 char* endptr = NULL;
2429 char* arg = argv[1];
2430 long int status = strtol (arg, &endptr, 10);
2431 assert (endptr != arg && *endptr == '\\0');
2432 printf (\"(:exited? %s :status %d :signal? %s :signal %d :coredump? %s\"
2433 \" :stopped? %s :stopsig %d)\\n\",
2434 FLAG(WIFEXITED(status)), WEXITSTATUS(status),
2435 FLAG(WIFSIGNALED(status)), WTERMSIG(status),
2436 FLAG(WCOREDUMP(status)),
2437 FLAG(WIFSTOPPED(status)), WSTOPSIG(status));
2438 fflush (NULL);
2439 return 0;
2440 }
2441 }
2442 ")
2443 (finish-output stream))
2444 (let* ((outfile (system::pick-temporary-file-name))
2445 (args (list "cc" "-o" outfile infile)))
2446 (warn "Running cc: ~{~a ~}~%" args)
2447 (call-program args :output t)
2448 (delete-file infile)
2449 outfile)))
2450
2451 ;; (save-image "/tmp/x.core")
2452
2453 ;; Local Variables:
2454 ;; pbook-heading-regexp: "^;;;\\(;+\\)"
2455 ;; pbook-commentary-regexp: "^;;;\\($\\|[^;]\\)"
2456 ;; End:

  ViewVC Help
Powered by ViewVC 1.1.5