Commit | Line | Data |
---|---|---|
88b9d363 | 1 | # Copyright (C) 2010-2022 Free Software Foundation, Inc. |
ed3ef339 DE |
2 | |
3 | # This program is free software; you can redistribute it and/or modify | |
4 | # it under the terms of the GNU General Public License as published by | |
5 | # the Free Software Foundation; either version 3 of the License, or | |
6 | # (at your option) any later version. | |
7 | # | |
8 | # This program is distributed in the hope that it will be useful, | |
9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 | # GNU General Public License for more details. | |
12 | # | |
13 | # You should have received a copy of the GNU General Public License | |
14 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
15 | ||
16 | # This file is part of the GDB testsuite. | |
17 | # It tests the Guile symbol table support. | |
18 | ||
19 | load_lib gdb-guile.exp | |
20 | ||
21 | standard_testfile scm-symtab.c scm-symtab-2.c | |
22 | ||
5b362f04 | 23 | if {[prepare_for_testing "failed to prepare" $testfile \ |
ed3ef339 DE |
24 | [list $srcfile $srcfile2] debug]} { |
25 | return | |
26 | } | |
27 | ||
28 | # Skip all tests if Guile scripting is not enabled. | |
29 | if { [skip_guile_tests] } { continue } | |
30 | ||
31 | if ![gdb_guile_runto_main] { | |
32 | return | |
33 | } | |
34 | ||
6e4e3fe1 TV |
35 | set debug_types [debug_types] |
36 | ||
ed3ef339 DE |
37 | # Setup and get the symbol table. |
38 | set line_no [gdb_get_line_number "Block break here."] | |
39 | gdb_breakpoint $line_no | |
40 | gdb_continue_to_breakpoint "Block break here." | |
41 | gdb_scm_test_silent_cmd "guile (define frame (selected-frame))" \ | |
42 | "get frame" | |
43 | gdb_scm_test_silent_cmd "guile (define sal (frame-sal frame))" \ | |
44 | "get sal" | |
45 | gdb_scm_test_silent_cmd "guile (define symtab (sal-symtab sal))" \ | |
46 | "get symtab" | |
47 | gdb_scm_test_silent_cmd "guile (define global-block (symtab-global-block symtab))" \ | |
48 | "get global block" | |
49 | gdb_scm_test_silent_cmd "guile (define static-block (symtab-static-block symtab))" \ | |
50 | "get static block" | |
51 | ||
52 | gdb_scm_test_silent_cmd "guile (define global-symbols (map symbol-name (block-symbols global-block)))" \ | |
53 | "get global symbol names" | |
54 | gdb_scm_test_silent_cmd "guile (define static-symbols (map symbol-name (block-symbols static-block)))" \ | |
55 | "get static symbol names" | |
56 | gdb_scm_test_silent_cmd "guile (define global-isymbols '()) (define static-isymbols '())" \ | |
57 | "set up iterated symbol name lists" | |
58 | # TODO: iterated symbols | |
59 | gdb_scm_test_silent_cmd "step" "Step to the next line" | |
60 | gdb_scm_test_silent_cmd "guile (define new-pc (sal-pc (frame-sal (selected-frame))))" \ | |
61 | "get new pc" | |
62 | ||
63 | # Test sal. | |
64 | gdb_test "guile (print (sal-symtab sal))" \ | |
65 | ".*gdb.guile/scm-symtab.c.*" "Test sal-symtab" | |
66 | gdb_test "guile (print (sal-pc sal))" \ | |
67 | "${decimal}" "test sal-pc" | |
68 | gdb_test "guile (print (= (sal-last sal) (- new-pc 1)))" \ | |
69 | "#t" "test sal-last" | |
70 | gdb_test "guile (print (sal-line sal))" \ | |
71 | "$line_no" "test sal-line" | |
72 | gdb_test "guile (print (sal-valid? sal))" \ | |
73 | "#t" "test sal-valid?" | |
74 | ||
75 | # Test eq? on symtabs. | |
76 | gdb_scm_test_silent_cmd "guile (define sal1 (frame-sal frame))" \ | |
77 | "get sal1" | |
78 | gdb_scm_test_silent_cmd "guile (define sal2 (frame-sal (frame-older frame)))" \ | |
79 | "get sal2" | |
80 | gdb_test "guile (print (eq? symtab (sal-symtab sal1)))" \ | |
81 | "= #t" "test eq? of equal symtabs" | |
82 | gdb_test "guile (print (eq? symtab (sal-symtab sal2)))" \ | |
83 | "= #t" "test eq? of equal symtabs from different sals" | |
84 | gdb_test "guile (print (eq? symtab (symbol-symtab (lookup-global-symbol \"func1\"))))" \ | |
85 | "= #f" "test eq? of not-equal symtabs" | |
86 | ||
87 | # Test symbol table. | |
88 | gdb_test "guile (print (symtab-filename symtab))" \ | |
89 | ".*gdb.guile/scm-symtab.c.*" "test symtab-filename" | |
90 | gdb_test "guile (print (symtab-objfile symtab))" \ | |
91 | "#<gdb:objfile .*scm-symtab>" "test symtab-objfile" | |
92 | gdb_test "guile (print (symtab-fullname symtab))" \ | |
93 | "testsuite/gdb.guile/scm-symtab.c.*" "test symtab-fullname" | |
94 | gdb_test "guile (print (symtab-valid? symtab))" \ | |
95 | "#t" "test symtab-valid?" | |
96 | gdb_test "guile (print (->bool (member \"qq\" global-symbols)))" \ | |
97 | "#t" "test qq in global symbols" | |
98 | gdb_test "guile (print (->bool (member \"func\" global-symbols)))" \ | |
99 | "#t" "test func in global symbols" | |
100 | gdb_test "guile (print (->bool (member \"main\" global-symbols)))" \ | |
101 | "#t" "test main in global symbols" | |
102 | gdb_test "guile (print (->bool (member \"int\" static-symbols)))" \ | |
103 | "#t" "test int in static symbols" | |
104 | gdb_test "guile (print (->bool (member \"char\" static-symbols)))" \ | |
105 | "#t" "test char in static symbols" | |
6e4e3fe1 TV |
106 | gdb_test_multiple \ |
107 | "guile (print (->bool (member \"simple_struct\" static-symbols)))" \ | |
108 | "test simple_struct in static symbols" { | |
109 | -re -wrap "#t" { | |
110 | pass $gdb_test_name | |
111 | } | |
112 | -re -wrap "#f" { | |
113 | if { $debug_types } { | |
114 | # Xfail for PR gcc/90232. | |
115 | xfail $gdb_test_name | |
116 | } else { | |
117 | fail $gdb_test_name | |
118 | } | |
119 | } | |
120 | } | |
ed3ef339 DE |
121 | |
122 | # Test is_valid when the objfile is unloaded. This must be the last | |
123 | # test as it unloads the object file in GDB. | |
124 | gdb_unload | |
125 | gdb_test "guile (print (sal-valid? sal))" \ | |
126 | "#f" "test sal-valid? after unloading" | |
127 | gdb_test "guile (print (symtab-valid? symtab))" \ | |
128 | "#f" "test symtab-valid? after unloading" | |
129 | ||
130 | gdb_test_no_output "guile (set! sal #f)" \ | |
131 | "test sal destructor" | |
132 | gdb_test_no_output "guile (set! symtab #f)" \ | |
133 | "test symtab destructor" | |
134 | gdb_test_no_output "guile (gc)" "GC to trigger destructors" | |
135 | ||
136 | # Start with a fresh gdb. | |
137 | clean_restart ${testfile} | |
138 | ||
139 | # Test find-pc-line. | |
140 | # The following tests require execution. | |
141 | ||
142 | if ![gdb_guile_runto_main] { | |
143 | return | |
144 | } | |
145 | ||
146 | runto [gdb_get_line_number "Break at func2 call site."] | |
147 | ||
148 | gdb_scm_test_silent_cmd "guile (define line (sal-line (frame-sal (selected-frame))))" \ | |
149 | "get line number of func2 call site" | |
150 | gdb_test "guile (print (= (sal-line (find-pc-line (frame-pc (selected-frame)))) line))" \ | |
151 | "#t" "test find-pc-line at func2 call site" | |
152 | ||
153 | gdb_scm_test_silent_cmd "step" "step into func2" | |
154 | gdb_scm_test_silent_cmd "up" "step out of func2" | |
155 | ||
156 | gdb_test "guile (print (> (sal-line (find-pc-line (frame-pc (selected-frame)))) line))" \ | |
157 | "#t" "test find-pc-line with resume address" |