/[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.48 - (hide annotations)
Fri Jan 22 13:36:06 2010 UTC (4 years, 2 months ago) by rtoy
Branch: MAIN
Changes since 1.47: +3 -2 lines
Fix handling of debug sources.  When trying to read the source form
from the source file, the file is opened using the default external
format.  This is not right if the file was compiled using a different
external format, and we try to read it using the default format.

compiler/debug-dump.lisp:
o Set the INFO slot to the external format used to source files.

code/debug-info.lisp:
o Add comment that the INFO slot contains the external format for
  :FILES.  (It was previously unused.)

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

  ViewVC Help
Powered by ViewVC 1.1.5