Debian Codegraph @

test/debug.scm

raw
1 ;; Test to access debug information.
2 ;;
3 ;; NB: The format of information these test acquires from the running VM
4 ;; is not fixed yet; they may change at any time as VM evolves.
5
6 (use gauche.test)
7 (use scheme.list)
8 (use util.match)
9
10 (test-start "debug features")
11
12 (test-section "stack trace")
13
14 ;; Test that stack trace isn't corrupted by the change of stack
15 ;; boundary handling in 0.9.1
16
17 ;; These functions shouldn't be in let, since doing so makes
18 ;; them optimized away.
19
20 (define (ra x) (ra (rb x)) #f)
21 (define (rb x) (if (rc x) (rb x) (rb x)))
22 (define (rc x) ((with-module gauche.internal %apply-rec) rd x) #f) ;cross C stack boundary
23 (define (rd x) (list 3 (re x)))
24 (define (re x) (* 7 ((with-module gauche.internal %apply-rec) rf x) 9))
25 (define (rf x) (cons 8 (rz x)))
26 (define (rz x) (x (vm-get-stack-trace-lite)))
27
28 (test* "trace crossing C stack boundary"
29 '(rz rf re rd rc rb ra)
30 (filter-map (match-lambda
31 [(('with-module 'gauche.internal '%apply-rec) fn 'x) fn]
32 [((? symbol? fn) 'x) fn]
33 [_ #f])
34 (call/cc (^x (ra x) #f))))
35
36
37 (test-section "source location track")
38
39 ;; source info of quoted literals
40 ;; https://github.com/shirok/Gauche/issues/847
41 (test* "source info of quoted literals" #t
42 (let1 s (debug-source-info '(a b c))
43 (and (pair? s)
44 (string? (car s))
45 (#/debug\.scm$/ (car s))
46 (integer? (cadr s)))))
47
48 (test-section "packing debug-info")
49
50 (use gauche.vm.debug-info)
51 (test-module 'gauche.vm.debug-info)
52
53 (use util.isomorph)
54 (use gauche.cgen.unit)
55
56 (define (test-debug-info data :optional (msg #f))
57 (test* (or msg (write-to-string data write-shared))
58 data
59 (let* ([unit (make <cgen-unit>)]
60 [bv (encode-debug-info unit data)])
61 (decode-debug-info bv (get-debug-info-const-vector unit)))
62 isomorphic?))
63
64 (test-debug-info 1)
65 (test-debug-info 'abc)
66 (test-debug-info '(a b () c))
67 (test-debug-info '#0=(a b . #0#))
68 (test-debug-info '#0=(a b #0#))
69 (test-debug-info '(a #1=(b) #1#))
70 (test-debug-info '(a #1=(b) (#1#)))
71 (test-debug-info '(a #1=(b) . #1#))
72 (test-debug-info '#0=(1 . #1=(2 #2=(3) #0# #1# . #2#)))
73
74 (let1 xs (make-list 234 0)
75 (test-debug-info `(12345 123456789 123456789012345 ,@xs #0=(1234567) . #0#)
76 "big data"))
77
78 (test-end)