ddata.scm 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. ; Part of Scheme 48 1.9. See file COPYING for notices and license.
  2. ; Authors: Richard Kelsey, Jonathan Rees
  3. ; Stuff moved from segment.scm 6/5/93
  4. ; Some of that stuff moved to state.scm 4/28/95
  5. ; Debug-data records are for communicating information from the
  6. ; compiler to various debugging tools.
  7. ; An environment map has the form
  8. ; #(pc-before pc-after #(name+ ...) offset (env-map ...))
  9. ; where the two pc's delimit the region of code that executes in this
  10. ; environment. The names indicate variables bound at from that stack
  11. ; offset up. A name+ is either a name or a vector of names indicating
  12. ; that the stack holds a vector of values at that point. The list of
  13. ; env-maps is for inferior (deeper) environments.
  14. ; Source is in the form of an a-list mapping pc's used in continuations
  15. ; to pairs of the form (i . expression), indicating that the continuation
  16. ; is returning the value of i'th subexpression in the source expression.
  17. (define-record-type debug-data :debug-data
  18. (make-debug-data uid name parent env-maps jump-back-dests source)
  19. debug-data?
  20. (uid debug-data-uid)
  21. (name debug-data-name)
  22. (parent debug-data-parent)
  23. (env-maps debug-data-env-maps set-debug-data-env-maps!)
  24. (jump-back-dests debug-data-jump-back-dests set-debug-data-jump-back-dests!)
  25. (source debug-data-source set-debug-data-source!))
  26. (define-record-discloser :debug-data
  27. (lambda (dd)
  28. (list 'debug-data (debug-data-uid dd) (debug-data-name dd))))
  29. ; Returns a list of proper lists describing the environment in effect
  30. ; at the given pc with the given template's code vector.
  31. ;
  32. ; Entries in the environment-maps table (one per template) have the form
  33. ; #(#(pc-before pc-after #(var ...) offset (env-map ...)) ...)
  34. ;
  35. ; A PC of #F indicates that the caller wants the environment map for
  36. ; the closure itself, which will be the last thing in the outermost
  37. ; environment map (because that matches where the environment is pushed
  38. ; onto the stack).
  39. ;
  40. ; Cf. procedure (note-environment vars segment) in segment.scm.
  41. (define (debug-data-env-shape dd pc)
  42. (cond ((not (debug-data? dd))
  43. '())
  44. (pc
  45. (let loop ((emaps (debug-data-env-maps dd))
  46. (shape '()))
  47. (if (null? emaps)
  48. shape
  49. (let ((pc-before (vector-ref (car emaps) 0))
  50. (pc-after (vector-ref (car emaps) 1))
  51. (offset (vector-ref (car emaps) 2))
  52. (vars (vector-ref (car emaps) 3))
  53. (more-maps (vector-ref (car emaps) 4)))
  54. (if (and (>= pc pc-before)
  55. (< pc pc-after))
  56. (loop more-maps
  57. (cons (cons offset
  58. (vector->list vars))
  59. shape))
  60. (loop (cdr emaps) shape))))))
  61. ((not (null? (debug-data-env-maps dd)))
  62. (let ((names (vector-ref (car (debug-data-env-maps dd))
  63. 3)))
  64. (if (and names
  65. (< 0 (vector-length names))
  66. (pair? (vector-ref names (- (vector-length names) 1))))
  67. (list (vector-ref names (- (vector-length names) 1)))
  68. '())))
  69. (else
  70. '())))