0.9.16.38:
[sbcl.git] / src / compiler / debug-dump.lisp
1 ;;;; stuff that creates debugger information from the compiler's
2 ;;;; internal data structures
3
4 ;;;; This software is part of the SBCL system. See the README file for
5 ;;;; more information.
6 ;;;;
7 ;;;; This software is derived from the CMU CL system, which was
8 ;;;; written at Carnegie Mellon University and released into the
9 ;;;; public domain. The software is in the public domain and is
10 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
11 ;;;; files for more information.
12
13 (in-package "SB!C")
14
15 (deftype byte-buffer () '(vector (unsigned-byte 8)))
16 (defvar *byte-buffer*)
17 (declaim (type byte-buffer *byte-buffer*))
18 \f
19 ;;;; debug blocks
20
21 (deftype location-kind ()
22   '(member :unknown-return :known-return :internal-error :non-local-exit
23            :block-start :call-site :single-value-return :non-local-entry
24            :step-before-vop))
25
26 ;;; The LOCATION-INFO structure holds the information what we need
27 ;;; about locations which code generation decided were "interesting".
28 (defstruct (location-info
29             (:constructor make-location-info (kind label vop))
30             (:copier nil))
31   ;; The kind of location noted.
32   (kind nil :type location-kind)
33   ;; The label pointing to the interesting code location.
34   (label nil :type (or label index null))
35   ;; The VOP that emitted this location (for node, save-set, ir2-block, etc.)
36   (vop nil :type vop))
37
38 ;;; This is called during code generation in places where there is an
39 ;;; "interesting" location: someplace where we are likely to end up
40 ;;; in the debugger, and thus want debug info.
41 (defun note-debug-location (vop label kind)
42   (declare (type vop vop) (type (or label null) label)
43            (type location-kind kind))
44   (let ((location (make-location-info kind label vop)))
45     (setf (ir2-block-locations (vop-block vop))
46           (nconc (ir2-block-locations (vop-block vop))
47                  (list location)))
48     location))
49
50 #!-sb-fluid (declaim (inline ir2-block-physenv))
51 (defun ir2-block-physenv (2block)
52   (declare (type ir2-block 2block))
53   (block-physenv (ir2-block-block 2block)))
54
55 ;;; Given a local conflicts vector and an IR2 block to represent the
56 ;;; set of live TNs, and the VAR-LOCS hash-table representing the
57 ;;; variables dumped, compute a bit-vector representing the set of
58 ;;; live variables. If the TN is environment-live, we only mark it as
59 ;;; live when it is in scope at NODE.
60 (defun compute-live-vars (live node block var-locs vop)
61   (declare (type ir2-block block) (type local-tn-bit-vector live)
62            (type hash-table var-locs) (type node node)
63            (type (or vop null) vop))
64   (let ((res (make-array (logandc2 (+ (hash-table-count var-locs) 7) 7)
65                          :element-type 'bit
66                          :initial-element 0))
67         (spilled (gethash vop
68                           (ir2-component-spilled-vops
69                            (component-info *component-being-compiled*)))))
70     (do-live-tns (tn live block)
71       (let ((leaf (tn-leaf tn)))
72         (when (and (lambda-var-p leaf)
73                    (or (not (member (tn-kind tn)
74                                     '(:environment :debug-environment)))
75                        (rassoc leaf (lexenv-vars (node-lexenv node))))
76                    (or (null spilled)
77                        (not (member tn spilled))))
78           (let ((num (gethash leaf var-locs)))
79             (when num
80               (setf (sbit res num) 1))))))
81     res))
82
83 ;;; The PC for the location most recently dumped.
84 (defvar *previous-location*)
85 (declaim (type index *previous-location*))
86
87 ;;; Dump a compiled debug-location into *BYTE-BUFFER* that describes
88 ;;; the code/source map and live info. If true, VOP is the VOP
89 ;;; associated with this location, for use in determining whether TNs
90 ;;; are spilled.
91 (defun dump-1-location (node block kind tlf-num label live var-locs vop)
92   (declare (type node node) (type ir2-block block)
93            (type (or null local-tn-bit-vector) live)
94            (type (or label index) label)
95            (type location-kind kind) (type (or index null) tlf-num)
96            (type hash-table var-locs) (type (or vop null) vop))
97
98   (vector-push-extend
99    (dpb (position-or-lose kind *compiled-code-location-kinds*)
100         compiled-code-location-kind-byte
101         0)
102    *byte-buffer*)
103
104   (let ((loc (if (fixnump label) label (label-position label))))
105     (write-var-integer (- loc *previous-location*) *byte-buffer*)
106     (setq *previous-location* loc))
107
108   (let ((path (node-source-path node)))
109     (unless tlf-num
110       (write-var-integer (source-path-tlf-number path) *byte-buffer*))
111     (write-var-integer (source-path-form-number path) *byte-buffer*))
112
113   (if live
114       (write-packed-bit-vector (compute-live-vars live node block var-locs vop)
115                                *byte-buffer*)
116       (write-packed-bit-vector
117        (make-array (logandc2 (+ (hash-table-count var-locs) 7) 7)
118                    :initial-element 0
119                    :element-type 'bit)
120        *byte-buffer*))
121
122   (write-var-string (or (and (typep node 'combination)
123                              (combination-step-info node))
124                         "")
125                     *byte-buffer*)
126   (values))
127
128 ;;; Extract context info from a Location-Info structure and use it to
129 ;;; dump a compiled code-location.
130 (defun dump-location-from-info (loc tlf-num var-locs)
131   (declare (type location-info loc) (type (or index null) tlf-num)
132            (type hash-table var-locs))
133   (let ((vop (location-info-vop loc)))
134     (dump-1-location (vop-node vop)
135                      (vop-block vop)
136                      (location-info-kind loc)
137                      tlf-num
138                      (location-info-label loc)
139                      (vop-save-set vop)
140                      var-locs
141                      vop))
142   (values))
143
144 ;;; Scan all the blocks, determining if all locations are in the same
145 ;;; TLF, and returning it or NIL.
146 (defun find-tlf-number (fun)
147   (declare (type clambda fun))
148   (let ((res (source-path-tlf-number (node-source-path (lambda-bind fun)))))
149     (declare (type (or index null) res))
150     (do-physenv-ir2-blocks (2block (lambda-physenv fun))
151       (let ((block (ir2-block-block 2block)))
152         (when (eq (block-info block) 2block)
153           (unless (eql (source-path-tlf-number
154                         (node-source-path
155                          (block-start-node block)))
156                        res)
157             (setq res nil)))
158
159         (dolist (loc (ir2-block-locations 2block))
160           (unless (eql (source-path-tlf-number
161                         (node-source-path
162                          (vop-node (location-info-vop loc))))
163                        res)
164             (setq res nil)))))
165     res))
166
167 ;;; Dump out the number of locations and the locations for Block.
168 (defun dump-block-locations (block locations tlf-num var-locs)
169   (declare (type cblock block) (list locations))
170   (if (and locations
171            (eq (location-info-kind (first locations))
172                :non-local-entry))
173       (write-var-integer (length locations) *byte-buffer*)
174       (let ((2block (block-info block)))
175         (write-var-integer (+ (length locations) 1) *byte-buffer*)
176         (dump-1-location (block-start-node block)
177                          2block :block-start tlf-num
178                          (ir2-block-%label 2block)
179                          (ir2-block-live-out 2block)
180                          var-locs
181                          nil)))
182   (dolist (loc locations)
183     (dump-location-from-info loc tlf-num var-locs))
184   (values))
185
186 ;;; Dump the successors of Block, being careful not to fly into space
187 ;;; on weird successors.
188 (defun dump-block-successors (block physenv)
189   (declare (type cblock block) (type physenv physenv))
190   (let* ((tail (component-tail (block-component block)))
191          (succ (block-succ block))
192          (valid-succ
193           (if (and succ
194                    (or (eq (car succ) tail)
195                        (not (eq (block-physenv (car succ)) physenv))))
196               ()
197               succ)))
198     (vector-push-extend
199      (dpb (length valid-succ) compiled-debug-block-nsucc-byte 0)
200      *byte-buffer*)
201     (let ((base (block-number
202                  (node-block
203                   (lambda-bind (physenv-lambda physenv))))))
204       (dolist (b valid-succ)
205         (write-var-integer
206          (the index (- (block-number b) base))
207          *byte-buffer*))))
208   (values))
209
210 ;;; Return a vector and an integer (or null) suitable for use as the
211 ;;; BLOCKS and TLF-NUMBER in FUN's DEBUG-FUN. This requires two
212 ;;; passes to compute:
213 ;;; -- Scan all blocks, dumping the header and successors followed
214 ;;;    by all the non-elsewhere locations.
215 ;;; -- Dump the elsewhere block header and all the elsewhere
216 ;;;    locations (if any.)
217 (defun compute-debug-blocks (fun var-locs)
218   (declare (type clambda fun) (type hash-table var-locs))
219   (setf (fill-pointer *byte-buffer*) 0)
220   (let ((*previous-location* 0)
221         (tlf-num (find-tlf-number fun))
222         (physenv (lambda-physenv fun))
223         (prev-locs nil)
224         (prev-block nil))
225     (collect ((elsewhere))
226       (do-physenv-ir2-blocks (2block physenv)
227         (let ((block (ir2-block-block 2block)))
228           (when (eq (block-info block) 2block)
229             (when prev-block
230               (dump-block-locations prev-block prev-locs tlf-num var-locs))
231             (setq prev-block block  prev-locs ())
232             (dump-block-successors block physenv)))
233
234         (collect ((here prev-locs))
235           (dolist (loc (ir2-block-locations 2block))
236             (if (label-elsewhere-p (location-info-label loc))
237                 (elsewhere loc)
238                 (here loc)))
239           (setq prev-locs (here))))
240
241       (dump-block-locations prev-block prev-locs tlf-num var-locs)
242
243       (when (elsewhere)
244         (vector-push-extend compiled-debug-block-elsewhere-p *byte-buffer*)
245         (write-var-integer (length (elsewhere)) *byte-buffer*)
246         (dolist (loc (elsewhere))
247           (dump-location-from-info loc tlf-num var-locs))))
248
249     (values (copy-seq *byte-buffer*) tlf-num)))
250 \f
251 ;;; Return DEBUG-SOURCE structure containing information derived from
252 ;;; INFO.
253 (defun debug-source-for-info (info)
254   (declare (type source-info info))
255   (let* ((file-info (source-info-file-info info))
256          (res (make-debug-source
257                :from :file
258                :created (file-info-write-date file-info)
259                :compiled (source-info-start-time info)
260                :source-root (file-info-source-root file-info)
261                :start-positions (coerce-to-smallest-eltype
262                                  (file-info-positions file-info))))
263          (name (file-info-name file-info)))
264     (etypecase name
265       ((member :lisp)
266        (setf (debug-source-from res) name
267              (debug-source-name res) (file-info-forms file-info)))
268       (pathname
269        (setf (debug-source-name res)
270              (make-file-info-namestring name file-info))))
271     res))
272
273 ;;; Given an arbitrary sequence, coerce it to an unsigned vector if
274 ;;; possible. Ordinarily we coerce it to the smallest specialized
275 ;;; vector we can. However, we also have a special hack for
276 ;;; cross-compiling at bootstrap time, when arbitrarily-specialized
277 ;;; vectors aren't fully supported: in that case, we coerce it only to
278 ;;; a vector whose element size is an integer multiple of output byte
279 ;;; size.
280 (defun coerce-to-smallest-eltype (seq)
281   (let ((maxoid 0))
282     (flet ((frob (x)
283              (if (typep x 'unsigned-byte)
284                  (when (>= x maxoid)
285                    (setf maxoid x))
286                  (return-from coerce-to-smallest-eltype
287                    (coerce seq 'simple-vector)))))
288       (if (listp seq)
289           (dolist (i seq)
290             (frob i))
291           (dovector (i seq)
292             (frob i)))
293       (let ((specializer `(unsigned-byte
294                            ,(etypecase maxoid
295                               ((unsigned-byte 8) 8)
296                               ((unsigned-byte 16) 16)
297                               ((unsigned-byte 32) 32)))))
298         ;; cross-compilers beware! It would be possible for the
299         ;; upgraded-array-element-type of (UNSIGNED-BYTE 16) to be
300         ;; (SIGNED-BYTE 17) or (UNSIGNED-BYTE 23), and this is
301         ;; completely valid by ANSI.  However, the cross-compiler
302         ;; doesn't know how to dump (in practice) anything but the
303         ;; above three specialized array types, so make it break here
304         ;; if this is violated.
305         #+sb-xc-host
306         (aver
307          ;; not SB!XC:UPGRADED-ARRAY-ELEMENT-TYPE, because we are
308          ;; worried about whether the host's implementation of arrays.
309          (let ((uaet (upgraded-array-element-type specializer)))
310            (dolist (et '((unsigned-byte 8)
311                          (unsigned-byte 16)
312                          (unsigned-byte 32))
313                     nil)
314              (when (and (subtypep et uaet) (subtypep uaet et))
315                (return t)))))
316         (coerce seq `(simple-array ,specializer (*)))))))
317 \f
318 ;;;; variables
319
320 ;;; Return a SC-OFFSET describing TN's location.
321 (defun tn-sc-offset (tn)
322   (declare (type tn tn))
323   (make-sc-offset (sc-number (tn-sc tn))
324                   (tn-offset tn)))
325
326 ;;; Dump info to represent VAR's location being TN. ID is an integer
327 ;;; that makes VAR's name unique in the function. BUFFER is the vector
328 ;;; we stick the result in. If MINIMAL, we suppress name dumping, and
329 ;;; set the minimal flag.
330 ;;;
331 ;;; The DEBUG-VAR is only marked as always-live if the TN is
332 ;;; environment live and is an argument. If a :DEBUG-ENVIRONMENT TN,
333 ;;; then we also exclude set variables, since the variable is not
334 ;;; guaranteed to be live everywhere in that case.
335 (defun dump-1-var (fun var tn id minimal buffer)
336   (declare (type lambda-var var) (type (or tn null) tn) (type index id)
337            (type clambda fun))
338   (let* ((name (leaf-debug-name var))
339          (save-tn (and tn (tn-save-tn tn)))
340          (kind (and tn (tn-kind tn)))
341          (flags 0))
342     (declare (type index flags))
343     (when minimal
344       (setq flags (logior flags compiled-debug-var-minimal-p))
345       (unless (and tn (tn-offset tn))
346         (setq flags (logior flags compiled-debug-var-deleted-p))))
347     (when (and (or (eq kind :environment)
348                    (and (eq kind :debug-environment)
349                         (null (basic-var-sets var))))
350                (not (gethash tn (ir2-component-spilled-tns
351                                  (component-info *component-being-compiled*))))
352                (eq (lambda-var-home var) fun))
353       (setq flags (logior flags compiled-debug-var-environment-live)))
354     (when save-tn
355       (setq flags (logior flags compiled-debug-var-save-loc-p)))
356     (unless (or (zerop id) minimal)
357       (setq flags (logior flags compiled-debug-var-id-p)))
358     (vector-push-extend flags buffer)
359     (unless minimal
360       (vector-push-extend name buffer)
361       (unless (zerop id)
362         (vector-push-extend id buffer)))
363     (if (and tn (tn-offset tn))
364         (vector-push-extend (tn-sc-offset tn) buffer)
365         (aver minimal))
366     (when save-tn
367       (vector-push-extend (tn-sc-offset save-tn) buffer)))
368   (values))
369
370 ;;; Return a vector suitable for use as the DEBUG-FUN-VARS
371 ;;; of FUN. LEVEL is the current DEBUG-INFO quality. VAR-LOCS is a
372 ;;; hash table in which we enter the translation from LAMBDA-VARS to
373 ;;; the relative position of that variable's location in the resulting
374 ;;; vector.
375 (defun compute-vars (fun level var-locs)
376   (declare (type clambda fun) (type hash-table var-locs))
377   (collect ((vars))
378     (labels ((frob-leaf (leaf tn gensym-p)
379                (let ((name (leaf-debug-name leaf)))
380                  (when (and name (leaf-refs leaf) (tn-offset tn)
381                             (or gensym-p (symbol-package name)))
382                    (vars (cons leaf tn)))))
383              (frob-lambda (x gensym-p)
384                (dolist (leaf (lambda-vars x))
385                  (frob-leaf leaf (leaf-info leaf) gensym-p))))
386       (frob-lambda fun t)
387       (when (>= level 2)
388         (dolist (x (ir2-physenv-closure (physenv-info (lambda-physenv fun))))
389           (let ((thing (car x)))
390             (when (lambda-var-p thing)
391               (frob-leaf thing (cdr x) (= level 3)))))
392
393         (dolist (let (lambda-lets fun))
394           (frob-lambda let (= level 3)))))
395
396     (let ((sorted (sort (vars) #'string<
397                         :key (lambda (x)
398                                (symbol-name (leaf-debug-name (car x))))))
399           (prev-name nil)
400           (id 0)
401           (i 0)
402           (buffer (make-array 0 :fill-pointer 0 :adjustable t)))
403       (declare (type (or simple-string null) prev-name)
404                (type index id i))
405       (dolist (x sorted)
406         (let* ((var (car x))
407                (name (symbol-name (leaf-debug-name var))))
408           (cond ((and prev-name (string= prev-name name))
409                  (incf id))
410                 (t
411                  (setq id 0  prev-name name)))
412           (dump-1-var fun var (cdr x) id nil buffer)
413           (setf (gethash var var-locs) i))
414         (incf i))
415       (coerce buffer 'simple-vector))))
416
417 ;;; Return a vector suitable for use as the DEBUG-FUN-VARS of
418 ;;; FUN, representing the arguments to FUN in minimal variable format.
419 (defun compute-minimal-vars (fun)
420   (declare (type clambda fun))
421   (let ((buffer (make-array 0 :fill-pointer 0 :adjustable t)))
422     (dolist (var (lambda-vars fun))
423       (dump-1-var fun var (leaf-info var) 0 t buffer))
424     (coerce buffer 'simple-vector)))
425
426 ;;; Return VAR's relative position in the function's variables (determined
427 ;;; from the VAR-LOCS hashtable).  If VAR is deleted, then return DELETED.
428 (defun debug-location-for (var var-locs)
429   (declare (type lambda-var var) (type hash-table var-locs))
430   (let ((res (gethash var var-locs)))
431     (cond (res)
432           (t
433            (aver (or (null (leaf-refs var))
434                      (not (tn-offset (leaf-info var)))))
435            'deleted))))
436 \f
437 ;;;; arguments/returns
438
439 ;;; Return a vector to be used as the COMPILED-DEBUG-FUN-ARGS for FUN.
440 ;;; If FUN is the MAIN-ENTRY for an optional dispatch, then look at
441 ;;; the ARGLIST to determine the syntax, otherwise pretend all
442 ;;; arguments are fixed.
443 ;;;
444 ;;; ### This assumption breaks down in EPs other than the main-entry,
445 ;;; since they may or may not have supplied-p vars, etc.
446 (defun compute-args (fun var-locs)
447   (declare (type clambda fun) (type hash-table var-locs))
448   (collect ((res))
449     (let ((od (lambda-optional-dispatch fun)))
450       (if (and od (eq (optional-dispatch-main-entry od) fun))
451           (let ((actual-vars (lambda-vars fun))
452                 (saw-optional nil))
453             (dolist (arg (optional-dispatch-arglist od))
454               (let ((info (lambda-var-arg-info arg))
455                     (actual (pop actual-vars)))
456                 (cond (info
457                        (case (arg-info-kind info)
458                          (:keyword
459                           (res (arg-info-key info)))
460                          (:rest
461                           (res 'rest-arg))
462                          (:more-context
463                           (res 'more-arg))
464                          (:optional
465                           (unless saw-optional
466                             (res 'optional-args)
467                             (setq saw-optional t))))
468                        (res (debug-location-for actual var-locs))
469                        (when (arg-info-supplied-p info)
470                          (res 'supplied-p)
471                          (res (debug-location-for (pop actual-vars) var-locs))))
472                       (t
473                        (res (debug-location-for actual var-locs)))))))
474           (dolist (var (lambda-vars fun))
475             (res (debug-location-for var var-locs)))))
476
477     (coerce-to-smallest-eltype (res))))
478
479 ;;; Return a vector of SC offsets describing FUN's return locations.
480 ;;; (Must be known values return...)
481 (defun compute-debug-returns (fun)
482   (coerce-to-smallest-eltype
483    (mapcar (lambda (loc)
484              (tn-sc-offset loc))
485            (return-info-locations (tail-set-info (lambda-tail-set fun))))))
486 \f
487 ;;;; debug functions
488
489 ;;; Return a C-D-F structure with all the mandatory slots filled in.
490 (defun dfun-from-fun (fun)
491   (declare (type clambda fun))
492   (let* ((2env (physenv-info (lambda-physenv fun)))
493          (dispatch (lambda-optional-dispatch fun))
494          (main-p (and dispatch
495                       (eq fun (optional-dispatch-main-entry dispatch)))))
496     (make-compiled-debug-fun
497      :name (leaf-debug-name fun)
498      :kind (if main-p nil (functional-kind fun))
499      :return-pc (tn-sc-offset (ir2-physenv-return-pc 2env))
500      :old-fp (tn-sc-offset (ir2-physenv-old-fp 2env))
501      :start-pc (label-position (ir2-physenv-environment-start 2env))
502      :elsewhere-pc (label-position (ir2-physenv-elsewhere-start 2env)))))
503
504 ;;; Return a complete C-D-F structure for FUN. This involves
505 ;;; determining the DEBUG-INFO level and filling in optional slots as
506 ;;; appropriate.
507 (defun compute-1-debug-fun (fun var-locs)
508   (declare (type clambda fun) (type hash-table var-locs))
509   (let* ((dfun (dfun-from-fun fun))
510          (actual-level (policy (lambda-bind fun) compute-debug-fun))
511          (level (if #!+sb-dyncount *collect-dynamic-statistics*
512                     #!-sb-dyncount nil
513                     (max actual-level 2)
514                     actual-level)))
515     (cond ((zerop level))
516           ((and (<= level 1)
517                 (let ((od (lambda-optional-dispatch fun)))
518                   (or (not od)
519                       (not (eq (optional-dispatch-main-entry od) fun)))))
520            (setf (compiled-debug-fun-vars dfun)
521                  (compute-minimal-vars fun))
522            (setf (compiled-debug-fun-arguments dfun) :minimal))
523           (t
524            (setf (compiled-debug-fun-vars dfun)
525                  (compute-vars fun level var-locs))
526            (setf (compiled-debug-fun-arguments dfun)
527                  (compute-args fun var-locs))))
528
529     (if (>= level 2)
530         (multiple-value-bind (blocks tlf-num)
531             (compute-debug-blocks fun var-locs)
532           (setf (compiled-debug-fun-tlf-number dfun) tlf-num)
533           (setf (compiled-debug-fun-blocks dfun) blocks))
534         (setf (compiled-debug-fun-tlf-number dfun) (find-tlf-number fun)))
535
536     (if (xep-p fun)
537         (setf (compiled-debug-fun-returns dfun) :standard)
538         (let ((info (tail-set-info (lambda-tail-set fun))))
539           (when info
540             (cond ((eq (return-info-kind info) :unknown)
541                    (setf (compiled-debug-fun-returns dfun)
542                          :standard))
543                   ((/= level 0)
544                    (setf (compiled-debug-fun-returns dfun)
545                          (compute-debug-returns fun)))))))
546     dfun))
547 \f
548 ;;;; full component dumping
549
550 ;;; Compute the full form (simple-vector) function map.
551 (defun compute-debug-fun-map (sorted)
552   (declare (list sorted))
553   (let* ((len (1- (* (length sorted) 2)))
554          (funs-vec (make-array len)))
555     (do ((i -1 (+ i 2))
556          (sorted sorted (cdr sorted)))
557         ((= i len))
558       (declare (fixnum i))
559       (let ((dfun (car sorted)))
560         (unless (minusp i)
561           (setf (svref funs-vec i) (car dfun)))
562         (setf (svref funs-vec (1+ i)) (cdr dfun))))
563     funs-vec))
564
565 ;;; Return a DEBUG-INFO structure describing COMPONENT. This has to be
566 ;;; called after assembly so that source map information is available.
567 (defun debug-info-for-component (component)
568   (declare (type component component))
569   (let ((dfuns nil)
570         (var-locs (make-hash-table :test 'eq))
571         (*byte-buffer* (make-array 10
572                                    :element-type '(unsigned-byte 8)
573                                    :fill-pointer 0
574                                    :adjustable t)))
575     (dolist (lambda (component-lambdas component))
576       (clrhash var-locs)
577       (push (cons (label-position (block-label (lambda-block lambda)))
578                   (compute-1-debug-fun lambda var-locs))
579             dfuns))
580     (let* ((sorted (sort dfuns #'< :key #'car))
581            (fun-map (compute-debug-fun-map sorted)))
582       (make-compiled-debug-info :name (component-name component)
583                                 :fun-map fun-map))))
584 \f
585 ;;; Write BITS out to BYTE-BUFFER in backend byte order. The length of
586 ;;; BITS must be evenly divisible by eight.
587 (defun write-packed-bit-vector (bits byte-buffer)
588   (declare (type simple-bit-vector bits) (type byte-buffer byte-buffer))
589
590   ;; Enforce constraint from CMU-CL-era comment.
591   (aver (zerop (mod (length bits) 8)))
592
593   (multiple-value-bind (initial step done)
594       (ecase *backend-byte-order*
595         (:little-endian (values 0  1  8))
596         (:big-endian    (values 7 -1 -1)))
597     (let ((shift initial)
598           (byte 0))
599       (dotimes (i (length bits))
600         (let ((int (aref bits i)))
601           (setf byte (logior byte (ash int shift)))
602           (incf shift step))
603         (when (= shift done)
604           (vector-push-extend byte byte-buffer)
605           (setf shift initial
606                 byte 0)))
607       (unless (= shift initial)
608         (vector-push-extend byte byte-buffer))))
609   (values))