/[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.33 - (hide annotations)
Mon May 17 10:07:27 1993 UTC (20 years, 11 months ago) by ram
Branch: MAIN
Changes since 1.32: +2 -2 lines
Fix comment.
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.33 "$Header: /tiger/var/lib/cvsroots/cmucl/src/compiler/debug-dump.lisp,v 1.33 1993/05/17 10:07:27 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     (let ((name (file-info-name x))
296     (res (make-debug-source
297     :from :file
298 ram 1.11 :comment (file-info-comment x)
299 wlott 1.1 :created (file-info-write-date x)
300     :compiled (source-info-start-time info)
301     :source-root (file-info-source-root x)
302 ram 1.6 :start-positions
303 ram 1.18 (coerce-to-smallest-eltype
304     (file-info-positions x)))))
305 wlott 1.27 (cond ((simple-string-p name)
306 wlott 1.1 (setf (debug-source-name res) name))
307     (t
308     (setf (debug-source-from res) name)
309 ram 1.19 (setf (debug-source-name res)
310     (coerce (file-info-forms x) 'simple-vector))))
311 wlott 1.1 res))
312     (source-info-files info)))
313    
314    
315 ram 1.3 ;;; COERCE-TO-SMALLEST-ELTYPE -- Internal
316     ;;;
317     ;;; Given an arbirtary sequence, coerce it to an unsigned vector if
318     ;;; possible.
319     ;;;
320     (defun coerce-to-smallest-eltype (seq)
321 ram 1.18 (declare (type sequence seq))
322 ram 1.3 (let ((max 0))
323 ram 1.18 (declare (type (or index null) max))
324 ram 1.3 (macrolet ((frob ()
325 ram 1.18 '(if (and (typep val 'index) max)
326 ram 1.3 (when (> val max)
327     (setq max val))
328     (setq max nil))))
329     (if (listp seq)
330 ram 1.6 (dolist (val seq)
331 ram 1.3 (frob))
332     (dotimes (i (length seq))
333     (let ((val (aref seq i)))
334     (frob)))))
335    
336     (if max
337 ram 1.10 (coerce seq `(simple-array (integer 0 ,max)))
338 ram 1.3 (coerce seq 'simple-vector))))
339    
340    
341 ram 1.15 ;;;; Variables:
342 ram 1.3
343 ram 1.2 ;;; TN-SC-OFFSET -- Internal
344 wlott 1.1 ;;;
345 ram 1.2 ;;; Return a SC-OFFSET describing TN's location.
346 wlott 1.1 ;;;
347 ram 1.2 (defun tn-sc-offset (tn)
348     (declare (type tn tn))
349     (make-sc-offset (sc-number (tn-sc tn))
350     (tn-offset tn)))
351 wlott 1.1
352    
353 ram 1.3 ;;; DUMP-1-VARIABLE -- Internal
354 ram 1.2 ;;;
355     ;;; Dump info to represent Var's location being TN. ID is an integer that
356     ;;; makes Var's name unique in the function. Buffer is the vector we stick the
357 ram 1.22 ;;; result in. If Minimal is true, we suppress name dumping, and set the
358     ;;; minimal flag.
359 ram 1.2 ;;;
360 ram 1.16 ;;; The debug-variable is only marked as always-live if the TN is
361     ;;; environment live and is an argument. If a :debug-environment TN, then we
362     ;;; also exclude set variables, since the variable is not guranteed to be live
363     ;;; everywhere in that case.
364     ;;;
365 ram 1.22 (defun dump-1-variable (fun var tn id minimal buffer)
366     (declare (type lambda-var var) (type (or tn null) tn) (type index id)
367 ram 1.15 (type clambda fun))
368 ram 1.2 (let* ((name (leaf-name var))
369     (package (symbol-package name))
370     (package-p (and package (not (eq package *package*))))
371 ram 1.22 (save-tn (and tn (tn-save-tn tn)))
372     (kind (and tn (tn-kind tn)))
373 ram 1.2 (flags 0))
374 ram 1.18 (declare (type index flags))
375 ram 1.22 (cond (minimal
376     (setq flags (logior flags compiled-debug-variable-minimal-p))
377     (unless tn
378     (setq flags (logior flags compiled-debug-variable-deleted-p))))
379     (t
380     (unless package
381     (setq flags (logior flags compiled-debug-variable-uninterned)))
382     (when package-p
383     (setq flags (logior flags compiled-debug-variable-packaged)))))
384 ram 1.16 (when (and (or (eq kind :environment)
385     (and (eq kind :debug-environment)
386     (null (basic-var-sets var))))
387 ram 1.18 (not (gethash tn (ir2-component-spilled-tns
388     (component-info *compile-component*))))
389 ram 1.15 (eq (lambda-var-home var) fun))
390 ram 1.8 (setq flags (logior flags compiled-debug-variable-environment-live)))
391 ram 1.2 (when save-tn
392 ram 1.8 (setq flags (logior flags compiled-debug-variable-save-loc-p)))
393 ram 1.22 (unless (or (zerop id) minimal)
394 ram 1.8 (setq flags (logior flags compiled-debug-variable-id-p)))
395 ram 1.2 (vector-push-extend flags buffer)
396 ram 1.22 (unless minimal
397     (write-var-string (symbol-name name) buffer)
398     (when package-p
399     (write-var-string (package-name package) buffer))
400     (unless (zerop id)
401     (write-var-integer id buffer)))
402     (if tn
403     (write-var-integer (tn-sc-offset tn) buffer)
404     (assert minimal))
405 ram 1.2 (when save-tn
406     (write-var-integer (tn-sc-offset save-tn) buffer)))
407     (undefined-value))
408    
409    
410 wlott 1.1 ;;; COMPUTE-VARIABLES -- Internal
411     ;;;
412     ;;; Return a vector suitable for use as the DEBUG-FUNCTION-VARIABLES of Fun.
413 ram 1.2 ;;; Level is the current DEBUG-INFO quality. Var-Locs is a hashtable in which
414     ;;; we enter the translation from LAMBDA-VARS to the relative position of that
415     ;;; variable's location in the resulting vector.
416 wlott 1.1 ;;;
417 ram 1.2 (defun compute-variables (fun level var-locs)
418 wlott 1.1 (declare (type clambda fun) (type hash-table var-locs))
419 ram 1.2 (collect ((vars))
420     (labels ((frob-leaf (leaf tn gensym-p)
421 wlott 1.1 (let ((name (leaf-name leaf)))
422 ram 1.20 (when (and name (leaf-refs leaf) (tn-offset tn)
423 ram 1.2 (or gensym-p (symbol-package name)))
424     (vars (cons leaf tn)))))
425     (frob-lambda (x gensym-p)
426     (dolist (leaf (lambda-vars x))
427     (frob-leaf leaf (leaf-info leaf) gensym-p))))
428     (frob-lambda fun t)
429     (when (>= level 2)
430     (dolist (x (ir2-environment-environment
431     (environment-info (lambda-environment fun))))
432     (let ((thing (car x)))
433     (when (lambda-var-p thing)
434     (frob-leaf thing (cdr x) (= level 3)))))
435    
436     (dolist (let (lambda-lets fun))
437 ram 1.6 (frob-lambda let (= level 3)))))
438 wlott 1.1
439 ram 1.2 (setf (fill-pointer *byte-buffer*) 0)
440     (let ((sorted (sort (vars) #'string<
441     :key #'(lambda (x)
442     (symbol-name (leaf-name (car x))))))
443     (prev-name nil)
444     (id 0)
445     (i 0))
446 ram 1.18 (declare (type (or simple-string null) prev-name)
447     (type index id i))
448 ram 1.2 (dolist (x sorted)
449     (let* ((var (car x))
450     (name (symbol-name (leaf-name var))))
451     (cond ((and prev-name (string= prev-name name))
452     (incf id))
453     (t
454     (setq id 0 prev-name name)))
455 ram 1.22 (dump-1-variable fun var (cdr x) id nil *byte-buffer*)
456 ram 1.3 (setf (gethash var var-locs) i))
457 ram 1.2 (incf i)))
458 wlott 1.1
459 ram 1.2 (copy-seq *byte-buffer*)))
460 wlott 1.1
461 ram 1.2
462 ram 1.22 ;;; COMPUTE-MINIMAL-VARIABLES -- Internal
463     ;;;
464     ;;; Dump out the arguments to Fun in the minimal variable format.
465     ;;;
466     (defun compute-minimal-variables (fun)
467     (declare (type clambda fun))
468     (setf (fill-pointer *byte-buffer*) 0)
469     (dolist (var (lambda-vars fun))
470     (dump-1-variable fun var (leaf-info var) 0 t *byte-buffer*))
471     (copy-seq *byte-buffer*))
472    
473    
474 ram 1.2 ;;; DEBUG-LOCATION-FOR -- Internal
475     ;;;
476     ;;; Return Var's relative position in the function's variables (determined
477 ram 1.8 ;;; from the Var-Locs hashtable.) If Var is deleted, the return DELETED.
478 ram 1.2 ;;;
479     (defun debug-location-for (var var-locs)
480 ram 1.7 (declare (type lambda-var var) (type hash-table var-locs))
481 ram 1.2 (let ((res (gethash var var-locs)))
482 ram 1.8 (cond (res)
483     (t
484 ram 1.20 (assert (or (null (leaf-refs var))
485     (not (tn-offset (leaf-info var)))))
486 ram 1.8 'deleted))))
487 ram 1.2
488 ram 1.3
489     ;;;; Arguments/returns:
490 ram 1.2
491 wlott 1.1 ;;; COMPUTE-ARGUMENTS -- Internal
492     ;;;
493     ;;; Return a vector to be used as the COMPILED-DEBUG-FUNCTION-ARGUMENTS for
494     ;;; Fun. If fun is the MAIN-ENTRY for an optional dispatch, then look at the
495     ;;; ARGLIST to determine the syntax, otherwise pretend all arguments are fixed.
496     ;;;
497     ;;; ### This assumption breaks down in EPs other than the main-entry, since
498     ;;; they may or may not have supplied-p vars, etc.
499     ;;;
500     (defun compute-arguments (fun var-locs)
501     (declare (type clambda fun) (type hash-table var-locs))
502     (collect ((res))
503     (let ((od (lambda-optional-dispatch fun)))
504     (if (and od (eq (optional-dispatch-main-entry od) fun))
505 ram 1.12 (let ((actual-vars (lambda-vars fun))
506     (saw-optional nil))
507 wlott 1.1 (dolist (arg (optional-dispatch-arglist od))
508     (let ((info (lambda-var-arg-info arg))
509     (actual (pop actual-vars)))
510     (cond (info
511     (case (arg-info-kind info)
512     (:keyword
513     (res (arg-info-keyword info)))
514     (:rest
515 ram 1.12 (res 'rest-arg))
516     (:optional
517     (unless saw-optional
518     (res 'optional-args)
519     (setq saw-optional t))))
520 wlott 1.1 (res (debug-location-for actual var-locs))
521     (when (arg-info-supplied-p info)
522     (res 'supplied-p)
523     (res (debug-location-for (pop actual-vars) var-locs))))
524     (t
525     (res (debug-location-for actual var-locs)))))))
526     (dolist (var (lambda-vars fun))
527     (res (debug-location-for var var-locs)))))
528    
529 ram 1.3 (coerce-to-smallest-eltype (res))))
530 wlott 1.1
531    
532     ;;; COMPUTE-DEBUG-RETURNS -- Internal
533     ;;;
534 ram 1.8 ;;; Return a vector of SC offsets describing Fun's return locations. (Must
535     ;;; be known values return...)
536 wlott 1.1 ;;;
537     (defun compute-debug-returns (fun)
538 ram 1.3 (coerce-to-smallest-eltype
539     (mapcar #'(lambda (loc)
540     (tn-sc-offset loc))
541     (return-info-locations (tail-set-info (lambda-tail-set fun))))))
542 wlott 1.1
543 ram 1.3
544 ram 1.22 ;;;; Debug functions:
545    
546     ;;; DFUN-FROM-FUN -- Internal
547     ;;;
548     ;;; Return a C-D-F structure with all the mandatory slots filled in.
549     ;;;
550     (defun dfun-from-fun (fun)
551     (declare (type clambda fun))
552     (let* ((2env (environment-info (lambda-environment fun)))
553     (dispatch (lambda-optional-dispatch fun))
554     (main-p (and dispatch
555     (eq fun (optional-dispatch-main-entry dispatch)))))
556     (make-compiled-debug-function
557     :name (cond ((leaf-name fun))
558     ((let ((ef (functional-entry-function
559     fun)))
560     (and ef (leaf-name ef))))
561     ((and main-p (leaf-name dispatch)))
562     (t
563     (component-name
564     (block-component (node-block (lambda-bind fun))))))
565     :kind (if main-p nil (functional-kind fun))
566     :return-pc (tn-sc-offset (ir2-environment-return-pc 2env))
567     :old-fp (tn-sc-offset (ir2-environment-old-fp 2env))
568     :start-pc (label-position (ir2-environment-environment-start 2env))
569     :elsewhere-pc (label-position (ir2-environment-elsewhere-start 2env)))))
570    
571    
572     ;;; COMPUTE-1-DEBUG-FUNCTION -- Internal
573     ;;;
574     ;;; Return a complete C-D-F structure for Fun. This involves determining
575     ;;; the DEBUG-INFO level and filling in optional slots as appropriate.
576     ;;;
577     (defun compute-1-debug-function (fun var-locs)
578     (declare (type clambda fun) (type hash-table var-locs))
579     (let* ((dfun (dfun-from-fun fun))
580 ram 1.32 (actual-level
581     (cookie-debug (lexenv-cookie (node-lexenv (lambda-bind fun)))))
582     (level (if *collect-dynamic-statistics*
583     (max actual-level 2)
584     actual-level)))
585 ram 1.22 (cond ((zerop level))
586     ((and (<= level 1)
587     (let ((od (lambda-optional-dispatch fun)))
588     (or (not od)
589     (not (eq (optional-dispatch-main-entry od) fun)))))
590     (setf (compiled-debug-function-variables dfun)
591     (compute-minimal-variables fun))
592     (setf (compiled-debug-function-arguments dfun) :minimal))
593     (t
594 ram 1.24 (setf (compiled-debug-function-variables dfun)
595     (compute-variables fun level var-locs))
596     (setf (compiled-debug-function-arguments dfun)
597     (compute-arguments fun var-locs))))
598 ram 1.22
599     (when (>= level 2)
600     (multiple-value-bind (blocks tlf-num)
601     (compute-debug-blocks fun var-locs)
602     (setf (compiled-debug-function-tlf-number dfun) tlf-num)
603     (setf (compiled-debug-function-blocks dfun) blocks)))
604    
605     (if (external-entry-point-p fun)
606     (setf (compiled-debug-function-returns dfun) :standard)
607 ram 1.26 (let ((info (tail-set-info (lambda-tail-set fun))))
608     (when info
609     (cond ((eq (return-info-kind info) :unknown)
610     (setf (compiled-debug-function-returns dfun)
611     :standard))
612     ((/= level 0)
613     (setf (compiled-debug-function-returns dfun)
614     (compute-debug-returns fun)))))))
615 ram 1.22 dfun))
616    
617    
618     ;;;; Minimal debug functions:
619    
620     ;;; DEBUG-FUNCTION-MINIMAL-P -- Internal
621     ;;;
622     ;;; Return true if Dfun can be represented as a minimal debug function.
623     ;;; Dfun is a cons (<start offset> . C-D-F).
624     ;;;
625     (defun debug-function-minimal-p (dfun)
626     (declare (type cons dfun))
627     (let ((dfun (cdr dfun)))
628     (and (member (compiled-debug-function-arguments dfun) '(:minimal nil))
629     (null (compiled-debug-function-blocks dfun)))))
630    
631    
632     ;;; DUMP-1-MINIMAL-DFUN -- Internal
633     ;;;
634     ;;; Dump a packed binary representation of a Dfun into *byte-buffer*.
635     ;;; Prev-Start and Start are the byte offsets in the code where the previous
636     ;;; function started and where this one starts. Prev-Elsewhere is the previous
637     ;;; function's elsewhere PC.
638     ;;;
639     (defun dump-1-minimal-dfun (dfun prev-start start prev-elsewhere)
640     (declare (type compiled-debug-function dfun)
641     (type index prev-start start prev-elsewhere))
642     (let* ((name (compiled-debug-function-name dfun))
643     (setf-p (and (consp name) (eq (car name) 'setf)
644     (consp (cdr name)) (symbolp (cadr name))))
645     (base-name (if setf-p (cadr name) name))
646     (pkg (when (symbolp base-name)
647     (symbol-package base-name)))
648     (name-rep
649     (cond ((stringp base-name)
650     minimal-debug-function-name-component)
651     ((not pkg)
652     minimal-debug-function-name-uninterned)
653     ((eq pkg *package*)
654     minimal-debug-function-name-symbol)
655     (t
656     minimal-debug-function-name-packaged))))
657     (assert (or (atom name) setf-p))
658     (let ((options 0))
659     (setf (ldb minimal-debug-function-name-style-byte options) name-rep)
660     (setf (ldb minimal-debug-function-kind-byte options)
661     (position (compiled-debug-function-kind dfun)
662     minimal-debug-function-kinds))
663     (setf (ldb minimal-debug-function-returns-byte options)
664     (etypecase (compiled-debug-function-returns dfun)
665     ((member :standard) minimal-debug-function-returns-standard)
666     ((member :fixed) minimal-debug-function-returns-fixed)
667     (vector minimal-debug-function-returns-specified)))
668     (vector-push-extend options *byte-buffer*))
669    
670     (let ((flags 0))
671     (when setf-p
672     (setq flags (logior flags minimal-debug-function-setf-bit)))
673     (when (compiled-debug-function-nfp dfun)
674     (setq flags (logior flags minimal-debug-function-nfp-bit)))
675     (when (compiled-debug-function-variables dfun)
676     (setq flags (logior flags minimal-debug-function-variables-bit)))
677     (vector-push-extend flags *byte-buffer*))
678    
679     (when (eql name-rep minimal-debug-function-name-packaged)
680     (write-var-string (package-name pkg) *byte-buffer*))
681     (unless (stringp base-name)
682     (write-var-string (symbol-name base-name) *byte-buffer*))
683    
684     (let ((vars (compiled-debug-function-variables dfun)))
685     (when vars
686     (let ((len (length vars)))
687     (write-var-integer len *byte-buffer*)
688     (dotimes (i len)
689     (vector-push-extend (aref vars i) *byte-buffer*)))))
690    
691     (let ((returns (compiled-debug-function-returns dfun)))
692     (when (vectorp returns)
693     (let ((len (length returns)))
694     (write-var-integer len *byte-buffer*)
695     (dotimes (i len)
696     (write-var-integer (aref returns i) *byte-buffer*)))))
697    
698     (write-var-integer (compiled-debug-function-return-pc dfun)
699     *byte-buffer*)
700     (write-var-integer (compiled-debug-function-old-fp dfun)
701     *byte-buffer*)
702     (when (compiled-debug-function-nfp dfun)
703     (write-var-integer (compiled-debug-function-nfp dfun)
704     *byte-buffer*))
705     (write-var-integer (- start prev-start) *byte-buffer*)
706     (write-var-integer (- (compiled-debug-function-start-pc dfun) start)
707     *byte-buffer*)
708     (write-var-integer (- (compiled-debug-function-elsewhere-pc dfun)
709     prev-elsewhere)
710     *byte-buffer*)))
711    
712    
713     ;;; COMPUTE-MINIMAL-DEBUG-FUNCTIONS -- Internal
714     ;;;
715     ;;; Return a byte-vector holding all the debug functions for a component in
716     ;;; the packed binary minimal-debug-function format.
717     ;;;
718     (defun compute-minimal-debug-functions (dfuns)
719     (declare (list dfuns))
720     (setf (fill-pointer *byte-buffer*) 0)
721     (let ((prev-start 0)
722     (prev-elsewhere 0))
723     (dolist (dfun dfuns)
724     (let ((start (car dfun))
725     (elsewhere (compiled-debug-function-elsewhere-pc (cdr dfun))))
726     (dump-1-minimal-dfun (cdr dfun) prev-start start prev-elsewhere)
727     (setq prev-start start prev-elsewhere elsewhere))))
728     (copy-seq *byte-buffer*))
729    
730    
731     ;;;; Full component dumping:
732    
733     ;;; COMPUTE-DEBUG-FUNCTION-MAP -- Internal
734     ;;;
735     ;;; Compute the full form (simple-vector) function map.
736     ;;;
737     (defun compute-debug-function-map (sorted)
738     (declare (list sorted))
739     (let* ((len (1- (* (length sorted) 2)))
740     (funs-vec (make-array len)))
741     (do ((i -1 (+ i 2))
742     (sorted sorted (cdr sorted)))
743     ((= i len))
744     (declare (fixnum i))
745     (let ((dfun (car sorted)))
746     (unless (minusp i)
747     (setf (svref funs-vec i) (car dfun)))
748     (setf (svref funs-vec (1+ i)) (cdr dfun))))
749     funs-vec))
750    
751    
752 wlott 1.1 ;;; DEBUG-INFO-FOR-COMPONENT -- Interface
753     ;;;
754 ram 1.22 ;;; Return a debug-info structure describing component. This has to be
755     ;;; called after assembly so that source map information is available.
756     ;;;
757 wlott 1.17 (defun debug-info-for-component (component)
758     (declare (type component component))
759 ram 1.18 (let ((res (make-compiled-debug-info :name (component-name component)
760 ram 1.2 :package (package-name *package*))))
761 wlott 1.1 (collect ((dfuns))
762 ram 1.22 (let ((var-locs (make-hash-table :test #'eq))
763     (*byte-buffer*
764     (make-array 10 :element-type '(unsigned-byte 8)
765     :fill-pointer 0 :adjustable t)))
766 wlott 1.1 (dolist (fun (component-lambdas component))
767     (clrhash var-locs)
768 ram 1.22 (dfuns (cons (label-position
769     (block-label (node-block (lambda-bind fun))))
770 ram 1.23 (compute-1-debug-function fun var-locs))))
771    
772     (let ((sorted (sort (dfuns) #'< :key #'car)))
773     (setf (compiled-debug-info-function-map res)
774     (if (every #'debug-function-minimal-p sorted)
775     (compute-minimal-debug-functions sorted)
776     (compute-debug-function-map sorted))))))
777 wlott 1.1
778     res))

  ViewVC Help
Powered by ViewVC 1.1.5