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

  ViewVC Help
Powered by ViewVC 1.1.5