/[cmucl]/src/compiler/debug-dump.lisp
ViewVC logotype

Contents of /src/compiler/debug-dump.lisp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.35 - (hide annotations)
Tue Aug 3 12:56:48 1993 UTC (20 years, 8 months ago) by ram
Branch: MAIN
Changes since 1.34: +2 -2 lines
Typo.
1 wlott 1.1 ;;; -*- Package: C; Log: C.Log -*-
2     ;;;
3     ;;; **********************************************************************
4 ram 1.21 ;;; This code was written as part of the CMU Common Lisp project at
5     ;;; Carnegie Mellon University, and has been placed in the public domain.
6     ;;; If you want to use this code or any part of CMU Common Lisp, please contact
7     ;;; Scott Fahlman or slisp-group@cs.cmu.edu.
8     ;;;
9     (ext:file-comment
10 ram 1.35 "$Header: /tiger/var/lib/cvsroots/cmucl/src/compiler/debug-dump.lisp,v 1.35 1993/08/03 12:56:48 ram Exp $")
11 ram 1.21 ;;;
12 wlott 1.1 ;;; **********************************************************************
13     ;;;
14     ;;; This file contains stuff that creates debugger information from the
15     ;;; compiler's internal data structures.
16     ;;;
17     ;;; Written by Rob MacLachlan
18     ;;;
19 wlott 1.31 (in-package :c)
20 wlott 1.1
21 ram 1.22 (defvar *byte-buffer*)
22     (declaim (type (vector (unsigned-byte 8)) *byte-buffer*))
23 ram 1.2
24 ram 1.3
25     ;;;; Debug blocks:
26 ram 1.2
27 ram 1.3 (deftype location-kind ()
28 ram 1.6 '(member :unknown-return :known-return :internal-error :non-local-exit
29 wlott 1.28 :block-start :call-site :single-value-return :non-local-entry))
30 ram 1.3
31    
32     ;;; The Location-Info structure holds the information what we need about
33     ;;; locations which code generation decided were "interesting".
34     ;;;
35     (defstruct (location-info
36     (:constructor make-location-info (kind label vop)))
37     ;;
38     ;; The kind of location noted.
39     (kind nil :type location-kind)
40     ;;
41     ;; The label pointing to the interesting code location.
42 wlott 1.31 (label nil :type (or label index null))
43 ram 1.3 ;;
44     ;; The VOP that emitted this location (for node, save-set, ir2-block, etc.)
45     (vop nil :type vop))
46    
47     ;;; NOTE-DEBUG-LOCATION -- Interface
48     ;;;
49     ;;; Called during code generation in places where there is an "interesting"
50     ;;; location: some place where we are likely to end up in the debugger, and
51     ;;; thus want debug info.
52     ;;;
53 ram 1.8 (defun note-debug-location (vop label kind)
54 wlott 1.31 (declare (type vop vop) (type (or label null) label)
55 wlott 1.28 (type location-kind kind))
56 wlott 1.31 (let ((location (make-location-info kind label vop)))
57     (setf (ir2-block-locations (vop-block vop))
58     (nconc (ir2-block-locations (vop-block vop))
59     (list location)))
60     location))
61 ram 1.3
62    
63     ;;; IR2-BLOCK-ENVIRONMENT -- Interface
64     ;;;
65     (proclaim '(inline ir2-block-environment))
66     (defun ir2-block-environment (2block)
67     (declare (type ir2-block 2block))
68 ram 1.15 (block-environment (ir2-block-block 2block)))
69 ram 1.3
70    
71     ;;; COMPUTE-LIVE-VARS -- Internal
72     ;;;
73     ;;; Given a local conflicts vector and an IR2 block to represent the set of
74 ram 1.22 ;;; live TNs, and the Var-Locs hash-table representing the variables dumped,
75 ram 1.15 ;;; compute a bit-vector representing the set of live variables. If the TN is
76     ;;; environment-live, we only mark it as live when it is in scope at Node.
77 ram 1.3 ;;;
78 ram 1.18 (defun compute-live-vars (live node block var-locs vop)
79 ram 1.3 (declare (type ir2-block block) (type local-tn-bit-vector live)
80 ram 1.18 (type hash-table var-locs) (type node node)
81     (type (or vop null) vop))
82 ram 1.8 (let ((res (make-array (logandc2 (+ (hash-table-count var-locs) 7) 7)
83 ram 1.3 :element-type 'bit
84 ram 1.18 :initial-element 0))
85     (spilled (gethash vop
86     (ir2-component-spilled-vops
87     (component-info *compile-component*)))))
88 ram 1.3 (do-live-tns (tn live block)
89     (let ((leaf (tn-leaf tn)))
90 ram 1.15 (when (and (lambda-var-p leaf)
91 ram 1.16 (or (not (member (tn-kind tn)
92     '(:environment :debug-environment)))
93 ram 1.18 (rassoc leaf (lexenv-variables (node-lexenv node))))
94     (or (null spilled)
95     (not (member tn spilled))))
96 ram 1.3 (let ((num (gethash leaf var-locs)))
97     (when num
98 ram 1.7 (setf (sbit res num) 1))))))
99     res))
100 ram 1.3
101    
102     ;;; The PC for the location most recently dumped.
103     ;;;
104     (defvar *previous-location*)
105 ram 1.18 (proclaim '(type index *previous-location*))
106 ram 1.3
107     ;;; DUMP-1-LOCATION -- Internal
108     ;;;
109     ;;; Dump a compiled debug-location into *BYTE-BUFFER* that describes the
110 ram 1.18 ;;; code/source map and live info. If true, VOP is the VOP associated with
111     ;;; this location, for use in determining whether TNs are spilled.
112 ram 1.3 ;;;
113 ram 1.18 (defun dump-1-location (node block kind tlf-num label live var-locs vop)
114 ram 1.3 (declare (type node node) (type ir2-block block)
115 wlott 1.30 (type local-tn-bit-vector live)
116     (type (or label index) label)
117 ram 1.6 (type location-kind kind) (type (or index null) tlf-num)
118 ram 1.18 (type hash-table var-locs) (type (or vop null) vop))
119 ram 1.3
120     (vector-push-extend
121 ram 1.8 (dpb (position kind compiled-code-location-kinds)
122     compiled-code-location-kind-byte
123     0)
124 ram 1.3 *byte-buffer*)
125    
126 wlott 1.30 (let ((loc (if (fixnump label) label (label-position label))))
127 ram 1.3 (write-var-integer (- loc *previous-location*) *byte-buffer*)
128     (setq *previous-location* loc))
129 ram 1.15
130     (let ((path (node-source-path node)))
131     (unless tlf-num
132     (write-var-integer (source-path-tlf-number path) *byte-buffer*))
133     (write-var-integer (source-path-form-number path) *byte-buffer*))
134 ram 1.3
135 ram 1.18 (write-packed-bit-vector (compute-live-vars live node block var-locs vop)
136 ram 1.3 *byte-buffer*)
137    
138     (undefined-value))
139    
140    
141     ;;; DUMP-LOCATION-FROM-INFO -- Internal
142     ;;;
143     ;;; Extract context info from a Location-Info structure and use it to dump a
144     ;;; compiled code-location.
145     ;;;
146 ram 1.7 (defun dump-location-from-info (loc tlf-num var-locs)
147     (declare (type location-info loc) (type (or index null) tlf-num)
148     (type hash-table var-locs))
149 ram 1.3 (let ((vop (location-info-vop loc)))
150     (dump-1-location (vop-node vop)
151     (vop-block vop)
152     (location-info-kind loc)
153     tlf-num
154     (location-info-label loc)
155     (vop-save-set vop)
156 ram 1.18 var-locs
157     vop))
158 ram 1.3 (undefined-value))
159    
160    
161 ram 1.32 ;;; FIND-TLF-NUMBER -- Internal
162 ram 1.12 ;;;
163 ram 1.32 ;;; Scan all the blocks, determining if all locations are in the same TLF,
164     ;;; and returing it or NIL.
165 ram 1.12 ;;;
166 ram 1.32 (defun find-tlf-number (fun)
167 ram 1.12 (declare (type clambda fun))
168 ram 1.32 (let ((res (source-path-tlf-number (node-source-path (lambda-bind fun)))))
169     (declare (type (or index null) res))
170 ram 1.12 (do-environment-ir2-blocks (2block (lambda-environment fun))
171     (let ((block (ir2-block-block 2block)))
172     (when (eq (block-info block) 2block)
173 ram 1.15 (unless (eql (source-path-tlf-number
174     (node-source-path
175     (continuation-next
176     (block-start block))))
177 ram 1.12 res)
178     (setq res nil)))
179    
180     (dolist (loc (ir2-block-locations 2block))
181 ram 1.15 (unless (eql (source-path-tlf-number
182     (node-source-path
183     (vop-node (location-info-vop loc))))
184 ram 1.12 res)
185     (setq res nil)))))
186     res))
187    
188    
189     ;;; DUMP-BLOCK-LOCATIONS -- Internal
190     ;;;
191     ;;; Dump out the number of locations and the locations for Block.
192     ;;;
193     (defun dump-block-locations (block locations tlf-num var-locs)
194     (declare (type cblock block) (list locations))
195 wlott 1.28 (if (and locations
196 wlott 1.29 (eq (location-info-kind (first locations))
197 wlott 1.28 :non-local-entry))
198     (write-var-integer (length locations) *byte-buffer*)
199     (let ((2block (block-info block)))
200     (write-var-integer (+ (length locations) 1) *byte-buffer*)
201     (dump-1-location (continuation-next (block-start block))
202     2block :block-start tlf-num
203     (ir2-block-%label 2block)
204     (ir2-block-live-out 2block)
205     var-locs
206     nil)))
207 ram 1.12 (dolist (loc locations)
208     (dump-location-from-info loc tlf-num var-locs))
209     (undefined-value))
210    
211    
212     ;;; DUMP-BLOCK-SUCCESSORS -- Internal
213     ;;;
214     ;;; Dump the successors of Block, being careful not to fly into space on
215     ;;; weird successors.
216     ;;;
217     (defun dump-block-successors (block env)
218     (declare (type cblock block) (type environment env))
219     (let* ((tail (component-tail (block-component block)))
220     (succ (block-succ block))
221     (valid-succ
222     (if (and succ
223     (or (eq (car succ) tail)
224 ram 1.15 (not (eq (block-environment (car succ)) env))))
225 ram 1.12 ()
226     succ)))
227     (vector-push-extend
228     (dpb (length valid-succ) compiled-debug-block-nsucc-byte 0)
229     *byte-buffer*)
230 ram 1.32 (let ((base (block-number
231     (node-block
232     (lambda-bind (environment-function env))))))
233     (dolist (b valid-succ)
234     (write-var-integer
235     (the index (- (block-number b) base))
236     *byte-buffer*))))
237 ram 1.12 (undefined-value))
238    
239    
240 ram 1.3 ;;; COMPUTE-DEBUG-BLOCKS -- Internal
241     ;;;
242     ;;; Return a vector and an integer (or null) suitable for use as the BLOCKS
243 ram 1.33 ;;; and TLF-NUMBER in Fun's debug-function. This requires two passes to
244 ram 1.3 ;;; compute:
245     ;;; -- Scan all blocks, dumping the header and successors followed by all the
246     ;;; non-elsewhere locations.
247 ram 1.8 ;;; -- Dump the elsewhere block header and all the elsewhere locations (if
248     ;;; any.)
249 ram 1.3 ;;;
250     (defun compute-debug-blocks (fun var-locs)
251     (declare (type clambda fun) (type hash-table var-locs))
252     (setf (fill-pointer *byte-buffer*) 0)
253     (let ((*previous-location* 0)
254 ram 1.32 (tlf-num (find-tlf-number fun))
255 ram 1.12 (env (lambda-environment fun))
256     (prev-locs nil)
257     (prev-block nil))
258     (collect ((elsewhere))
259     (do-environment-ir2-blocks (2block env)
260 ram 1.3 (let ((block (ir2-block-block 2block)))
261     (when (eq (block-info block) 2block)
262 ram 1.12 (when prev-block
263     (dump-block-locations prev-block prev-locs tlf-num var-locs))
264     (setq prev-block block prev-locs ())
265     (dump-block-successors block env)))
266    
267     (collect ((here prev-locs))
268 ram 1.3 (dolist (loc (ir2-block-locations 2block))
269 ram 1.12 (if (label-elsewhere-p (location-info-label loc))
270     (elsewhere loc)
271     (here loc)))
272     (setq prev-locs (here))))
273 ram 1.3
274 ram 1.12 (dump-block-locations prev-block prev-locs tlf-num var-locs)
275 ram 1.3
276 ram 1.8 (when (elsewhere)
277     (vector-push-extend compiled-debug-block-elsewhere-p *byte-buffer*)
278     (write-var-integer (length (elsewhere)) *byte-buffer*)
279     (dolist (loc (elsewhere))
280     (dump-location-from-info loc tlf-num var-locs))))
281    
282 ram 1.3 (values (copy-seq *byte-buffer*) tlf-num)))
283    
284    
285 wlott 1.1 ;;; DEBUG-SOURCE-FOR-INFO -- Interface
286     ;;;
287     ;;; Return a list of DEBUG-SOURCE structures containing information derived
288 ram 1.18 ;;; from Info. We always dump the Start-Positions, since it is too hard
289     ;;; figure out whether we need them or not.
290 wlott 1.1 ;;;
291     (defun debug-source-for-info (info)
292     (declare (type source-info info))
293     (assert (not (source-info-current-file info)))
294     (mapcar #'(lambda (x)
295 ram 1.34 (let ((res (make-debug-source
296 wlott 1.1 :from :file
297 ram 1.11 :comment (file-info-comment x)
298 wlott 1.1 :created (file-info-write-date x)
299     :compiled (source-info-start-time info)
300     :source-root (file-info-source-root x)
301 ram 1.6 :start-positions
302 ram 1.18 (coerce-to-smallest-eltype
303 ram 1.34 (file-info-positions x))))
304 ram 1.35 (name (file-info-name x)))
305 ram 1.34 (etypecase name
306     ((member :stream)
307     (setf (debug-source-from res) name)
308     (setf (debug-source-name res)
309     (coerce (file-info-forms x) 'simple-vector)))
310     (pathname
311     (let* ((untruename (file-info-untruename x))
312     (dir (pathname-directory untruename)))
313     (setf (debug-source-name res)
314     (namestring
315     (if (and dir (eq (first dir) :absolute))
316     untruename
317     name))))))
318 wlott 1.1 res))
319     (source-info-files info)))
320    
321    
322 ram 1.3 ;;; COERCE-TO-SMALLEST-ELTYPE -- Internal
323     ;;;
324     ;;; Given an arbirtary sequence, coerce it to an unsigned vector if
325     ;;; possible.
326     ;;;
327     (defun coerce-to-smallest-eltype (seq)
328 ram 1.18 (declare (type sequence seq))
329 ram 1.3 (let ((max 0))
330 ram 1.18 (declare (type (or index null) max))
331 ram 1.3 (macrolet ((frob ()
332 ram 1.18 '(if (and (typep val 'index) max)
333 ram 1.3 (when (> val max)
334     (setq max val))
335     (setq max nil))))
336     (if (listp seq)
337 ram 1.6 (dolist (val seq)
338 ram 1.3 (frob))
339     (dotimes (i (length seq))
340     (let ((val (aref seq i)))
341     (frob)))))
342    
343     (if max
344 ram 1.10 (coerce seq `(simple-array (integer 0 ,max)))
345 ram 1.3 (coerce seq 'simple-vector))))
346    
347    
348 ram 1.15 ;;;; Variables:
349 ram 1.3
350 ram 1.2 ;;; TN-SC-OFFSET -- Internal
351 wlott 1.1 ;;;
352 ram 1.2 ;;; Return a SC-OFFSET describing TN's location.
353 wlott 1.1 ;;;
354 ram 1.2 (defun tn-sc-offset (tn)
355     (declare (type tn tn))
356     (make-sc-offset (sc-number (tn-sc tn))
357     (tn-offset tn)))
358 wlott 1.1
359    
360 ram 1.3 ;;; DUMP-1-VARIABLE -- Internal
361 ram 1.2 ;;;
362     ;;; Dump info to represent Var's location being TN. ID is an integer that
363     ;;; makes Var's name unique in the function. Buffer is the vector we stick the
364 ram 1.22 ;;; result in. If Minimal is true, we suppress name dumping, and set the
365     ;;; minimal flag.
366 ram 1.2 ;;;
367 ram 1.16 ;;; The debug-variable is only marked as always-live if the TN is
368     ;;; environment live and is an argument. If a :debug-environment TN, then we
369     ;;; also exclude set variables, since the variable is not guranteed to be live
370     ;;; everywhere in that case.
371     ;;;
372 ram 1.22 (defun dump-1-variable (fun var tn id minimal buffer)
373     (declare (type lambda-var var) (type (or tn null) tn) (type index id)
374 ram 1.15 (type clambda fun))
375 ram 1.2 (let* ((name (leaf-name var))
376     (package (symbol-package name))
377     (package-p (and package (not (eq package *package*))))
378 ram 1.22 (save-tn (and tn (tn-save-tn tn)))
379     (kind (and tn (tn-kind tn)))
380 ram 1.2 (flags 0))
381 ram 1.18 (declare (type index flags))
382 ram 1.22 (cond (minimal
383     (setq flags (logior flags compiled-debug-variable-minimal-p))
384     (unless tn
385     (setq flags (logior flags compiled-debug-variable-deleted-p))))
386     (t
387     (unless package
388     (setq flags (logior flags compiled-debug-variable-uninterned)))
389     (when package-p
390     (setq flags (logior flags compiled-debug-variable-packaged)))))
391 ram 1.16 (when (and (or (eq kind :environment)
392     (and (eq kind :debug-environment)
393     (null (basic-var-sets var))))
394 ram 1.18 (not (gethash tn (ir2-component-spilled-tns
395     (component-info *compile-component*))))
396 ram 1.15 (eq (lambda-var-home var) fun))
397 ram 1.8 (setq flags (logior flags compiled-debug-variable-environment-live)))
398 ram 1.2 (when save-tn
399 ram 1.8 (setq flags (logior flags compiled-debug-variable-save-loc-p)))
400 ram 1.22 (unless (or (zerop id) minimal)
401 ram 1.8 (setq flags (logior flags compiled-debug-variable-id-p)))
402 ram 1.2 (vector-push-extend flags buffer)
403 ram 1.22 (unless minimal
404     (write-var-string (symbol-name name) buffer)
405     (when package-p
406     (write-var-string (package-name package) buffer))
407     (unless (zerop id)
408     (write-var-integer id buffer)))
409     (if tn
410     (write-var-integer (tn-sc-offset tn) buffer)
411     (assert minimal))
412 ram 1.2 (when save-tn
413     (write-var-integer (tn-sc-offset save-tn) buffer)))
414     (undefined-value))
415    
416    
417 wlott 1.1 ;;; COMPUTE-VARIABLES -- Internal
418     ;;;
419     ;;; Return a vector suitable for use as the DEBUG-FUNCTION-VARIABLES of Fun.
420 ram 1.2 ;;; Level is the current DEBUG-INFO quality. Var-Locs is a hashtable in which
421     ;;; we enter the translation from LAMBDA-VARS to the relative position of that
422     ;;; variable's location in the resulting vector.
423 wlott 1.1 ;;;
424 ram 1.2 (defun compute-variables (fun level var-locs)
425 wlott 1.1 (declare (type clambda fun) (type hash-table var-locs))
426 ram 1.2 (collect ((vars))
427     (labels ((frob-leaf (leaf tn gensym-p)
428 wlott 1.1 (let ((name (leaf-name leaf)))
429 ram 1.20 (when (and name (leaf-refs leaf) (tn-offset tn)
430 ram 1.2 (or gensym-p (symbol-package name)))
431     (vars (cons leaf tn)))))
432     (frob-lambda (x gensym-p)
433     (dolist (leaf (lambda-vars x))
434     (frob-leaf leaf (leaf-info leaf) gensym-p))))
435     (frob-lambda fun t)
436     (when (>= level 2)
437     (dolist (x (ir2-environment-environment
438     (environment-info (lambda-environment fun))))
439     (let ((thing (car x)))
440     (when (lambda-var-p thing)
441     (frob-leaf thing (cdr x) (= level 3)))))
442    
443     (dolist (let (lambda-lets fun))
444 ram 1.6 (frob-lambda let (= level 3)))))
445 wlott 1.1
446 ram 1.2 (setf (fill-pointer *byte-buffer*) 0)
447     (let ((sorted (sort (vars) #'string<
448     :key #'(lambda (x)
449     (symbol-name (leaf-name (car x))))))
450     (prev-name nil)
451     (id 0)
452     (i 0))
453 ram 1.18 (declare (type (or simple-string null) prev-name)
454     (type index id i))
455 ram 1.2 (dolist (x sorted)
456     (let* ((var (car x))
457     (name (symbol-name (leaf-name var))))
458     (cond ((and prev-name (string= prev-name name))
459     (incf id))
460     (t
461     (setq id 0 prev-name name)))
462 ram 1.22 (dump-1-variable fun var (cdr x) id nil *byte-buffer*)
463 ram 1.3 (setf (gethash var var-locs) i))
464 ram 1.2 (incf i)))
465 wlott 1.1
466 ram 1.2 (copy-seq *byte-buffer*)))
467 wlott 1.1
468 ram 1.2
469 ram 1.22 ;;; COMPUTE-MINIMAL-VARIABLES -- Internal
470     ;;;
471     ;;; Dump out the arguments to Fun in the minimal variable format.
472     ;;;
473     (defun compute-minimal-variables (fun)
474     (declare (type clambda fun))
475     (setf (fill-pointer *byte-buffer*) 0)
476     (dolist (var (lambda-vars fun))
477     (dump-1-variable fun var (leaf-info var) 0 t *byte-buffer*))
478     (copy-seq *byte-buffer*))
479    
480    
481 ram 1.2 ;;; DEBUG-LOCATION-FOR -- Internal
482     ;;;
483     ;;; Return Var's relative position in the function's variables (determined
484 ram 1.8 ;;; from the Var-Locs hashtable.) If Var is deleted, the return DELETED.
485 ram 1.2 ;;;
486     (defun debug-location-for (var var-locs)
487 ram 1.7 (declare (type lambda-var var) (type hash-table var-locs))
488 ram 1.2 (let ((res (gethash var var-locs)))
489 ram 1.8 (cond (res)
490     (t
491 ram 1.20 (assert (or (null (leaf-refs var))
492     (not (tn-offset (leaf-info var)))))
493 ram 1.8 'deleted))))
494 ram 1.2
495 ram 1.3
496     ;;;; Arguments/returns:
497 ram 1.2
498 wlott 1.1 ;;; COMPUTE-ARGUMENTS -- Internal
499     ;;;
500     ;;; Return a vector to be used as the COMPILED-DEBUG-FUNCTION-ARGUMENTS for
501     ;;; Fun. If fun is the MAIN-ENTRY for an optional dispatch, then look at the
502     ;;; ARGLIST to determine the syntax, otherwise pretend all arguments are fixed.
503     ;;;
504     ;;; ### This assumption breaks down in EPs other than the main-entry, since
505     ;;; they may or may not have supplied-p vars, etc.
506     ;;;
507     (defun compute-arguments (fun var-locs)
508     (declare (type clambda fun) (type hash-table var-locs))
509     (collect ((res))
510     (let ((od (lambda-optional-dispatch fun)))
511     (if (and od (eq (optional-dispatch-main-entry od) fun))
512 ram 1.12 (let ((actual-vars (lambda-vars fun))
513     (saw-optional nil))
514 wlott 1.1 (dolist (arg (optional-dispatch-arglist od))
515     (let ((info (lambda-var-arg-info arg))
516     (actual (pop actual-vars)))
517     (cond (info
518     (case (arg-info-kind info)
519     (:keyword
520     (res (arg-info-keyword info)))
521     (:rest
522 ram 1.12 (res 'rest-arg))
523     (:optional
524     (unless saw-optional
525     (res 'optional-args)
526     (setq saw-optional t))))
527 wlott 1.1 (res (debug-location-for actual var-locs))
528     (when (arg-info-supplied-p info)
529     (res 'supplied-p)
530     (res (debug-location-for (pop actual-vars) var-locs))))
531     (t
532     (res (debug-location-for actual var-locs)))))))
533     (dolist (var (lambda-vars fun))
534     (res (debug-location-for var var-locs)))))
535    
536 ram 1.3 (coerce-to-smallest-eltype (res))))
537 wlott 1.1
538    
539     ;;; COMPUTE-DEBUG-RETURNS -- Internal
540     ;;;
541 ram 1.8 ;;; Return a vector of SC offsets describing Fun's return locations. (Must
542     ;;; be known values return...)
543 wlott 1.1 ;;;
544     (defun compute-debug-returns (fun)
545 ram 1.3 (coerce-to-smallest-eltype
546     (mapcar #'(lambda (loc)
547     (tn-sc-offset loc))
548     (return-info-locations (tail-set-info (lambda-tail-set fun))))))
549 wlott 1.1
550 ram 1.3
551 ram 1.22 ;;;; Debug functions:
552    
553     ;;; DFUN-FROM-FUN -- Internal
554     ;;;
555     ;;; Return a C-D-F structure with all the mandatory slots filled in.
556     ;;;
557     (defun dfun-from-fun (fun)
558     (declare (type clambda fun))
559     (let* ((2env (environment-info (lambda-environment fun)))
560     (dispatch (lambda-optional-dispatch fun))
561     (main-p (and dispatch
562     (eq fun (optional-dispatch-main-entry dispatch)))))
563     (make-compiled-debug-function
564     :name (cond ((leaf-name fun))
565     ((let ((ef (functional-entry-function
566     fun)))
567     (and ef (leaf-name ef))))
568     ((and main-p (leaf-name dispatch)))
569     (t
570     (component-name
571     (block-component (node-block (lambda-bind fun))))))
572     :kind (if main-p nil (functional-kind fun))
573     :return-pc (tn-sc-offset (ir2-environment-return-pc 2env))
574     :old-fp (tn-sc-offset (ir2-environment-old-fp 2env))
575     :start-pc (label-position (ir2-environment-environment-start 2env))
576     :elsewhere-pc (label-position (ir2-environment-elsewhere-start 2env)))))
577    
578    
579     ;;; COMPUTE-1-DEBUG-FUNCTION -- Internal
580     ;;;
581     ;;; Return a complete C-D-F structure for Fun. This involves determining
582     ;;; the DEBUG-INFO level and filling in optional slots as appropriate.
583     ;;;
584     (defun compute-1-debug-function (fun var-locs)
585     (declare (type clambda fun) (type hash-table var-locs))
586     (let* ((dfun (dfun-from-fun fun))
587 ram 1.32 (actual-level
588     (cookie-debug (lexenv-cookie (node-lexenv (lambda-bind fun)))))
589     (level (if *collect-dynamic-statistics*
590     (max actual-level 2)
591     actual-level)))
592 ram 1.22 (cond ((zerop level))
593     ((and (<= level 1)
594     (let ((od (lambda-optional-dispatch fun)))
595     (or (not od)
596     (not (eq (optional-dispatch-main-entry od) fun)))))
597     (setf (compiled-debug-function-variables dfun)
598     (compute-minimal-variables fun))
599     (setf (compiled-debug-function-arguments dfun) :minimal))
600     (t
601 ram 1.24 (setf (compiled-debug-function-variables dfun)
602     (compute-variables fun level var-locs))
603     (setf (compiled-debug-function-arguments dfun)
604     (compute-arguments fun var-locs))))
605 ram 1.22
606     (when (>= level 2)
607     (multiple-value-bind (blocks tlf-num)
608     (compute-debug-blocks fun var-locs)
609     (setf (compiled-debug-function-tlf-number dfun) tlf-num)
610     (setf (compiled-debug-function-blocks dfun) blocks)))
611    
612     (if (external-entry-point-p fun)
613     (setf (compiled-debug-function-returns dfun) :standard)
614 ram 1.26 (let ((info (tail-set-info (lambda-tail-set fun))))
615     (when info
616     (cond ((eq (return-info-kind info) :unknown)
617     (setf (compiled-debug-function-returns dfun)
618     :standard))
619     ((/= level 0)
620     (setf (compiled-debug-function-returns dfun)
621     (compute-debug-returns fun)))))))
622 ram 1.22 dfun))
623    
624    
625     ;;;; Minimal debug functions:
626    
627     ;;; DEBUG-FUNCTION-MINIMAL-P -- Internal
628     ;;;
629     ;;; Return true if Dfun can be represented as a minimal debug function.
630     ;;; Dfun is a cons (<start offset> . C-D-F).
631     ;;;
632     (defun debug-function-minimal-p (dfun)
633     (declare (type cons dfun))
634     (let ((dfun (cdr dfun)))
635     (and (member (compiled-debug-function-arguments dfun) '(:minimal nil))
636     (null (compiled-debug-function-blocks dfun)))))
637    
638    
639     ;;; DUMP-1-MINIMAL-DFUN -- Internal
640     ;;;
641     ;;; Dump a packed binary representation of a Dfun into *byte-buffer*.
642     ;;; Prev-Start and Start are the byte offsets in the code where the previous
643     ;;; function started and where this one starts. Prev-Elsewhere is the previous
644     ;;; function's elsewhere PC.
645     ;;;
646     (defun dump-1-minimal-dfun (dfun prev-start start prev-elsewhere)
647     (declare (type compiled-debug-function dfun)
648     (type index prev-start start prev-elsewhere))
649     (let* ((name (compiled-debug-function-name dfun))
650     (setf-p (and (consp name) (eq (car name) 'setf)
651     (consp (cdr name)) (symbolp (cadr name))))
652     (base-name (if setf-p (cadr name) name))
653     (pkg (when (symbolp base-name)
654     (symbol-package base-name)))
655     (name-rep
656     (cond ((stringp base-name)
657     minimal-debug-function-name-component)
658     ((not pkg)
659     minimal-debug-function-name-uninterned)
660     ((eq pkg *package*)
661     minimal-debug-function-name-symbol)
662     (t
663     minimal-debug-function-name-packaged))))
664     (assert (or (atom name) setf-p))
665     (let ((options 0))
666     (setf (ldb minimal-debug-function-name-style-byte options) name-rep)
667     (setf (ldb minimal-debug-function-kind-byte options)
668     (position (compiled-debug-function-kind dfun)
669     minimal-debug-function-kinds))
670     (setf (ldb minimal-debug-function-returns-byte options)
671     (etypecase (compiled-debug-function-returns dfun)
672     ((member :standard) minimal-debug-function-returns-standard)
673     ((member :fixed) minimal-debug-function-returns-fixed)
674     (vector minimal-debug-function-returns-specified)))
675     (vector-push-extend options *byte-buffer*))
676    
677     (let ((flags 0))
678     (when setf-p
679     (setq flags (logior flags minimal-debug-function-setf-bit)))
680     (when (compiled-debug-function-nfp dfun)
681     (setq flags (logior flags minimal-debug-function-nfp-bit)))
682     (when (compiled-debug-function-variables dfun)
683     (setq flags (logior flags minimal-debug-function-variables-bit)))
684     (vector-push-extend flags *byte-buffer*))
685    
686     (when (eql name-rep minimal-debug-function-name-packaged)
687     (write-var-string (package-name pkg) *byte-buffer*))
688     (unless (stringp base-name)
689     (write-var-string (symbol-name base-name) *byte-buffer*))
690    
691     (let ((vars (compiled-debug-function-variables dfun)))
692     (when vars
693     (let ((len (length vars)))
694     (write-var-integer len *byte-buffer*)
695     (dotimes (i len)
696     (vector-push-extend (aref vars i) *byte-buffer*)))))
697    
698     (let ((returns (compiled-debug-function-returns dfun)))
699     (when (vectorp returns)
700     (let ((len (length returns)))
701     (write-var-integer len *byte-buffer*)
702     (dotimes (i len)
703     (write-var-integer (aref returns i) *byte-buffer*)))))
704    
705     (write-var-integer (compiled-debug-function-return-pc dfun)
706     *byte-buffer*)
707     (write-var-integer (compiled-debug-function-old-fp dfun)
708     *byte-buffer*)
709     (when (compiled-debug-function-nfp dfun)
710     (write-var-integer (compiled-debug-function-nfp dfun)
711     *byte-buffer*))
712     (write-var-integer (- start prev-start) *byte-buffer*)
713     (write-var-integer (- (compiled-debug-function-start-pc dfun) start)
714     *byte-buffer*)
715     (write-var-integer (- (compiled-debug-function-elsewhere-pc dfun)
716     prev-elsewhere)
717     *byte-buffer*)))
718    
719    
720     ;;; COMPUTE-MINIMAL-DEBUG-FUNCTIONS -- Internal
721     ;;;
722     ;;; Return a byte-vector holding all the debug functions for a component in
723     ;;; the packed binary minimal-debug-function format.
724     ;;;
725     (defun compute-minimal-debug-functions (dfuns)
726     (declare (list dfuns))
727     (setf (fill-pointer *byte-buffer*) 0)
728     (let ((prev-start 0)
729     (prev-elsewhere 0))
730     (dolist (dfun dfuns)
731     (let ((start (car dfun))
732     (elsewhere (compiled-debug-function-elsewhere-pc (cdr dfun))))
733     (dump-1-minimal-dfun (cdr dfun) prev-start start prev-elsewhere)
734     (setq prev-start start prev-elsewhere elsewhere))))
735     (copy-seq *byte-buffer*))
736    
737    
738     ;;;; Full component dumping:
739    
740     ;;; COMPUTE-DEBUG-FUNCTION-MAP -- Internal
741     ;;;
742     ;;; Compute the full form (simple-vector) function map.
743     ;;;
744     (defun compute-debug-function-map (sorted)
745     (declare (list sorted))
746     (let* ((len (1- (* (length sorted) 2)))
747     (funs-vec (make-array len)))
748     (do ((i -1 (+ i 2))
749     (sorted sorted (cdr sorted)))
750     ((= i len))
751     (declare (fixnum i))
752     (let ((dfun (car sorted)))
753     (unless (minusp i)
754     (setf (svref funs-vec i) (car dfun)))
755     (setf (svref funs-vec (1+ i)) (cdr dfun))))
756     funs-vec))
757    
758    
759 wlott 1.1 ;;; DEBUG-INFO-FOR-COMPONENT -- Interface
760     ;;;
761 ram 1.22 ;;; Return a debug-info structure describing component. This has to be
762     ;;; called after assembly so that source map information is available.
763     ;;;
764 wlott 1.17 (defun debug-info-for-component (component)
765     (declare (type component component))
766 ram 1.18 (let ((res (make-compiled-debug-info :name (component-name component)
767 ram 1.2 :package (package-name *package*))))
768 wlott 1.1 (collect ((dfuns))
769 ram 1.22 (let ((var-locs (make-hash-table :test #'eq))
770     (*byte-buffer*
771     (make-array 10 :element-type '(unsigned-byte 8)
772     :fill-pointer 0 :adjustable t)))
773 wlott 1.1 (dolist (fun (component-lambdas component))
774     (clrhash var-locs)
775 ram 1.22 (dfuns (cons (label-position
776     (block-label (node-block (lambda-bind fun))))
777 ram 1.23 (compute-1-debug-function fun var-locs))))
778    
779     (let ((sorted (sort (dfuns) #'< :key #'car)))
780     (setf (compiled-debug-info-function-map res)
781     (if (every #'debug-function-minimal-p sorted)
782     (compute-minimal-debug-functions sorted)
783     (compute-debug-function-map sorted))))))
784 wlott 1.1
785     res))

  ViewVC Help
Powered by ViewVC 1.1.5