debuginfo.scm 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. ; Copyright (c) 1993-2008 by Richard Kelsey and Jonathan Rees. See file COPYING.
  2. ; Reading/writing debugging info
  3. (define (write-debug-info location-info file)
  4. (call-with-output-file file
  5. (lambda (port)
  6. (display "Writing ") (display file) (newline)
  7. (let ((write-table
  8. (lambda (table comment)
  9. (display "; " port) (display comment port) (newline port)
  10. (table-walk (lambda (key datum)
  11. (write (list key datum) port)
  12. (newline port))
  13. table)
  14. (write '- port) (newline port))))
  15. (write-table package-name-table "Package uid -> name")
  16. (write-table location-info "Location uid -> (name . package-uid)"))
  17. (display "; Template uid -> name, parent, env maps" port)
  18. (newline port)
  19. (table-walk (lambda (id data)
  20. ;; Fields: (uid name parent env-maps jump-back-dests source)
  21. (write (list id
  22. (let ((name (debug-data-name data)))
  23. (if (generated? name)
  24. (name->symbol name)
  25. name))
  26. (let ((p (debug-data-parent data)))
  27. ;; we'd like to (note-debug-data! p)
  28. (if (debug-data? p)
  29. (debug-data-uid p)
  30. p))
  31. (debug-data-env-maps data)
  32. (debug-data-jump-back-dests data)
  33. ;; Don't retain source code, right?
  34. )
  35. port)
  36. (newline port))
  37. (debug-data-table))
  38. (write '- port) (newline port))))
  39. (define (read-debug-info file)
  40. (call-with-input-file file
  41. (lambda (port)
  42. (display "Reading ") (display file) (newline)
  43. (let ((read-table
  44. (lambda (table)
  45. (let loop ()
  46. (let ((z (read port)))
  47. (if (pair? z)
  48. (begin (table-set! table
  49. (car z)
  50. (make-immutable! (cadr z)))
  51. ;; (set! *location-uid*
  52. ;; (max *location-uid* (+ (car z) 1)))
  53. (loop))))))))
  54. (read-table package-name-table)
  55. (read-table location-info-table))
  56. (let loop ()
  57. (let ((z (read port)))
  58. (if (pair? z)
  59. (begin ;; (set! *template-uid*
  60. ;; (max *template-uid* (+ (car z) 1)))
  61. (table-set! (debug-data-table)
  62. (car z)
  63. (make-immutable!
  64. (apply make-debug-data
  65. (append z '(())))))
  66. (loop))))))))