dwarf.test 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. ;;;; dwarf.test -*- scheme -*-
  2. ;;;;
  3. ;;;; Copyright 2013, 2021 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. ;; The start of every datum 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. ; ^ 5:4
  39. "'success\n")
  40. ))
  41. (let* ((port (open-input-string prog))
  42. (bv (begin
  43. (set-port-filename! port "foo.scm")
  44. (read-and-compile port #:to 'bytecode))))
  45. (pass-if-equal 'success
  46. ((load-thunk-from-memory bv)))
  47. (pass-if-equal 13 (bar 10))
  48. (let ((source (find-source-for-addr (program-code qux))))
  49. (pass-if-equal "foo.scm" (source-file source))
  50. (pass-if-equal 0 (source-line source))
  51. (pass-if-equal 1 (source-line-for-user source))
  52. (pass-if-equal 0 (source-column source)))
  53. (let ((source (find-source-for-addr (program-code bar))))
  54. (pass-if-equal "foo.scm" (source-file source))
  55. (pass-if-equal 4 (source-line source))
  56. (pass-if-equal 5 (source-line-for-user source))
  57. (pass-if-equal 2 (source-column source)))
  58. (match (find-program-sources (program-code qux))
  59. ((s1 s2 s3)
  60. (pass-if-equal "foo.scm" (source-file s1))
  61. (pass-if-equal 0 (source-line s1))
  62. (pass-if-equal 1 (source-line-for-user s1))
  63. (pass-if-equal 0 (source-column s1))
  64. (pass-if-equal "foo.scm" (source-file s2))
  65. (pass-if-equal 1 (source-line s2))
  66. (pass-if-equal 2 (source-line-for-user s2))
  67. (pass-if-equal 8 (source-column s2))
  68. (pass-if-equal "foo.scm" (source-file s3))
  69. (pass-if-equal 1 (source-line s3))
  70. (pass-if-equal 2 (source-line-for-user s3))
  71. (pass-if-equal 2 (source-column s3)))
  72. (sources
  73. (error "unexpected sources" sources)))
  74. (match (find-program-sources (program-code bar))
  75. ((s1 s2)
  76. (pass-if-equal "foo.scm" (source-file s1))
  77. (pass-if-equal 4 (source-line s1))
  78. (pass-if-equal 5 (source-line-for-user s1))
  79. (pass-if-equal 2 (source-column s1))
  80. (pass-if-equal "foo.scm" (source-file s2))
  81. (pass-if-equal 5 (source-line s2))
  82. (pass-if-equal 6 (source-line-for-user s2))
  83. (pass-if-equal 4 (source-column s2)))
  84. (sources
  85. (error "unexpected sources" sources))))