dwarf.test 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. ;;;; dwarf.test -*- scheme -*-
  2. ;;;;
  3. ;;;; Copyright 2013 Free Software Foundation, Inc.
  4. ;;;;
  5. ;;;; This library is free software; you can redistribute it and/or
  6. ;;;; modify it under the terms of the GNU Lesser General Public
  7. ;;;; License as published by the Free Software Foundation; either
  8. ;;;; version 3 of the License, or (at your option) any later version.
  9. ;;;;
  10. ;;;; This library is distributed in the hope that it will be useful,
  11. ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. ;;;; Lesser General Public License for more details.
  14. ;;;;
  15. ;;;; You should have received a copy of the GNU Lesser General Public
  16. ;;;; License along with this library; if not, write to the Free Software
  17. ;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  18. (define-module (test-suite test-dwarf)
  19. #:use-module (test-suite lib)
  20. #:use-module (ice-9 match)
  21. #:use-module (system base compile)
  22. #:use-module (system vm debug)
  23. #:use-module (system vm program)
  24. #:use-module (system vm loader))
  25. (define prog
  26. (string-concatenate
  27. ;; Every open parenthesis is a possible source location.
  28. '("(define (qux f)\n"
  29. ;^ 0:0
  30. " (+ 32 (f)))\n"
  31. ; ^1:2 ^1:8
  32. "\n"
  33. "(define bar\n"
  34. ;^ 3;0
  35. " (lambda (a)\n"
  36. ; ^ 4:2
  37. " 13))\n"
  38. "'success\n")
  39. ))
  40. (let* ((port (open-input-string prog))
  41. (bv (begin
  42. (set-port-filename! port "foo.scm")
  43. (read-and-compile port #:to 'bytecode))))
  44. (pass-if-equal 'success
  45. ((load-thunk-from-memory bv)))
  46. (pass-if-equal 13 (bar 10))
  47. (let ((source (find-source-for-addr (program-code qux))))
  48. (pass-if-equal "foo.scm" (source-file source))
  49. (pass-if-equal 0 (source-line source))
  50. (pass-if-equal 1 (source-line-for-user source))
  51. (pass-if-equal 0 (source-column source)))
  52. (let ((source (find-source-for-addr (program-code bar))))
  53. (pass-if-equal "foo.scm" (source-file source))
  54. (pass-if-equal 4 (source-line source))
  55. (pass-if-equal 5 (source-line-for-user source))
  56. (pass-if-equal 2 (source-column source)))
  57. (match (find-program-sources (program-code qux))
  58. ((s1 s2 s3)
  59. (pass-if-equal "foo.scm" (source-file s1))
  60. (pass-if-equal 0 (source-line s1))
  61. (pass-if-equal 1 (source-line-for-user s1))
  62. (pass-if-equal 0 (source-column s1))
  63. (pass-if-equal "foo.scm" (source-file s2))
  64. (pass-if-equal 1 (source-line s2))
  65. (pass-if-equal 2 (source-line-for-user s2))
  66. (pass-if-equal 8 (source-column s2))
  67. (pass-if-equal "foo.scm" (source-file s3))
  68. (pass-if-equal 1 (source-line s3))
  69. (pass-if-equal 2 (source-line-for-user s3))
  70. (pass-if-equal 2 (source-column s3)))
  71. (sources
  72. (error "unexpected sources" sources)))
  73. (match (find-program-sources (program-code bar))
  74. ((source)
  75. (pass-if-equal "foo.scm" (source-file source))
  76. (pass-if-equal 4 (source-line source))
  77. (pass-if-equal 5 (source-line-for-user source))
  78. (pass-if-equal 2 (source-column source)))
  79. (sources
  80. (error "unexpected sources" sources))))