]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.base/jit-simple.exp
Update copyright year range in all GDB files
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / jit-simple.exp
1 # Copyright 2012-2018 Free Software Foundation, Inc.
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 # Test re-running an inferior with a JIT descriptor, where the JIT
17 # descriptor changes address between runs.
18 # http://sourceware.org/bugzilla/show_bug.cgi?id=13431
19
20 # Test both the case of the JIT reader being included in the main
21 # program directly, and the case of the JIT reader being split out to
22 # a shared library.
23
24 # For completeness, also test when the JIT descriptor does not change
25 # address between runs.
26
27 if {[skip_shlib_tests]} {
28 untested "skipping shared library tests"
29 return -1
30 }
31
32 standard_testfile
33
34 set libname $testfile-jit
35 set srcfile_lib $srcdir/$subdir/$libname.c
36 set binfile_lib [standard_output_file $libname.so]
37
38 # Build a standalone JIT binary.
39
40 proc build_standalone_jit {{options ""}} {
41 global testfile srcfile binfile
42
43 lappend options "debug"
44
45 if {[build_executable $testfile.exp $testfile $srcfile $options] == -1} {
46 return -1
47 }
48
49 return 0
50 }
51
52 # Build the shared library JIT.
53
54 proc build_shared_jit {{options ""}} {
55 global testfile
56 global srcfile_lib binfile_lib
57
58 lappend options "debug additional_flags=-fPIC"
59 if { [gdb_compile_shlib $srcfile_lib $binfile_lib $options] != "" } {
60 return -1
61 }
62
63 return 0
64 }
65
66 if {[build_standalone_jit] == -1} {
67 untested "failed to compile standalone testcase"
68 return
69 }
70
71 if {[build_shared_jit] == -1} {
72 untested "failed to compile shared library testcase"
73 return
74 }
75
76 # Built the program that loads the JIT library.
77 set srcfile_dl $testfile-dl.c
78 set binfile_dl $binfile-dl
79 set options [list debug shlib=${binfile_lib}]
80 if {[gdb_compile ${srcdir}/${subdir}/${srcfile_dl} $binfile_dl executable \
81 [list debug shlib=$binfile_lib]] == -1 } {
82 untested "failed to compile"
83 return -1
84 }
85
86 # STANDALONE is true when the JIT reader is included directly in the
87 # main program. False when the JIT reader is in a separate shared
88 # library. If CHANGE_ADDR is true, force changing the JIT descriptor
89 # changes address between runs.
90 proc jit_test_reread {standalone change_addr} {
91 global testfile binfile subdir srcfile srcdir binfile_lib binfile_dl
92 global hex
93
94 with_test_prefix "initial run" {
95 if {$standalone} {
96 clean_restart $binfile
97 } else {
98 clean_restart $binfile_dl
99 }
100
101 runto_main
102
103 set addr_before [get_hexadecimal_valueof "&__jit_debug_descriptor" 0 \
104 "get address of __jit_debug_descriptor"]
105
106 gdb_test "maint info breakpoints" \
107 "jit events keep y $hex <__jit_debug_register_code>.*" \
108 "maint info breakpoints shows jit breakpoint"
109 }
110
111 with_test_prefix "second run" {
112 # Ensure that the new executable is at least one second newer
113 # than the old. If the recompilation happens in the same
114 # second, gdb might not reload the executable automatically.
115 sleep 1
116
117 if ${change_addr} {
118 set options "additional_flags=-DSPACER"
119 if {$standalone} {
120 gdb_rename_execfile $binfile ${binfile}x
121 set res [build_standalone_jit $options]
122 } else {
123 gdb_rename_execfile $binfile_lib ${binfile_lib}x
124 set res [build_shared_jit $options]
125 }
126 if { $res == -1 } {
127 fail "recompile"
128 return
129 } else {
130 pass "recompile"
131 }
132 }
133
134 runto_main
135
136 set addr_after [get_hexadecimal_valueof "&__jit_debug_descriptor" 0 \
137 "get address of __jit_debug_descriptor"]
138
139 # This used to crash in the JIT-in-shared-library case:
140 # https://sourceware.org/bugzilla/show_bug.cgi?id=11094
141 gdb_test "maint info breakpoints" \
142 "jit events keep y $hex <__jit_debug_register_code>.*" \
143 "maint info breakpoints shows jit breakpoint"
144 }
145
146 if ${change_addr} {
147 gdb_assert {$addr_before != $addr_after} "address changed"
148 } else {
149 gdb_assert {$addr_before == $addr_after} "address didn't change"
150 }
151 }
152
153 foreach standalone {1 0} {
154 with_test_prefix [expr ($standalone)?"standalone":"shared"] {
155 with_test_prefix "change addr" {
156 jit_test_reread $standalone 1
157 }
158 with_test_prefix "same addr" {
159 jit_test_reread $standalone 0
160 }
161 }
162 }