Commit | Line | Data |
---|---|---|
3666a048 | 1 | # Copyright 2011-2021 Free Software Foundation, Inc. |
3b2a0cf2 JB |
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 | # The same tests as in jit.exp, but loading JITer itself from a shared | |
17 | # library. | |
18 | ||
3b2a0cf2 | 19 | if {[skip_shlib_tests]} { |
84c93cd5 | 20 | untested "skipping shared library tests" |
3b2a0cf2 JB |
21 | return -1 |
22 | } | |
23 | ||
4c93b1db | 24 | if {[get_compiler_info]} { |
84c93cd5 | 25 | untested "could not get compiler info" |
3b2a0cf2 JB |
26 | return 1 |
27 | } | |
28 | ||
f8012071 MS |
29 | load_lib jit-elf-helpers.exp |
30 | ||
5144dfba TV |
31 | # Increase this to see more detail. |
32 | set test_verbose 0 | |
33 | ||
9a946945 MSG |
34 | # The "real" main of this test, which loads jit-elf-main |
35 | # as a shared library. | |
36 | set main_loader_basename jit-elf-dlmain | |
37 | set main_loader_srcfile ${srcdir}/${subdir}/${main_loader_basename}.c | |
38 | set main_loader_binfile [standard_output_file ${main_loader_basename}] | |
39 | ||
40 | # The main code that loads and registers JIT objects. | |
41 | set main_solib_basename jit-elf-main | |
42 | set main_solib_srcfile ${srcdir}/${subdir}/${main_solib_basename}.c | |
43 | set main_solib_binfile [standard_output_file ${main_solib_basename}.so] | |
44 | ||
45 | # The shared library that gets loaded as JIT objects. | |
46 | set jit_solib_basename jit-elf-solib | |
47 | set jit_solib_srcfile ${srcdir}/${subdir}/${jit_solib_basename}.c | |
48 | ||
9a946945 MSG |
49 | # Compile the testcase shared library loader. |
50 | # | |
51 | # OPTIONS is passed to gdb_compile when compiling the binary. | |
52 | # | |
53 | # On success, return 0. | |
54 | # On failure, return -1. | |
55 | proc compile_jit_dlmain {options} { | |
ff08abb8 | 56 | global main_loader_srcfile main_loader_binfile main_loader_basename |
9a946945 MSG |
57 | set options [concat $options debug] |
58 | ||
59 | if { [gdb_compile ${main_loader_srcfile} ${main_loader_binfile} \ | |
60 | executable $options] != "" } { | |
61 | untested "failed to compile ${main_loader_basename}.c as an executable" | |
62 | return -1 | |
63 | } | |
64 | ||
65 | return 0 | |
3b2a0cf2 JB |
66 | } |
67 | ||
9a946945 MSG |
68 | # Run $main_loader_binfile and load $main_solib_binfile in |
69 | # GDB. Check jit-related debug output and matches `info function` | |
70 | # output for a jit loaded function using MATCH_STR. | |
71 | # | |
72 | # SOLIB_BINFILES_TARGETS is a list of shared libraries to pass | |
73 | # as arguments when running $main_loader_binfile. | |
74 | # MATCH_STR is a regular expression that output of `info function` | |
75 | # must match. | |
76 | proc one_jit_test {solib_binfiles_target match_str} { | |
77 | set count [llength $solib_binfiles_target] | |
0a251e08 | 78 | with_test_prefix "one_jit_test-$count" { |
5144dfba | 79 | global test_verbose |
9a946945 MSG |
80 | global main_loader_binfile main_loader_srcfile |
81 | global main_solib_binfile main_solib_srcfile | |
0a251e08 | 82 | |
9a946945 MSG |
83 | clean_restart $main_loader_binfile |
84 | gdb_load_shlib $main_solib_binfile | |
0a251e08 YQ |
85 | |
86 | # This is just to help debugging when things fail | |
5144dfba | 87 | if {$test_verbose > 0} { |
0a251e08 YQ |
88 | gdb_test "set debug jit 1" |
89 | } | |
90 | ||
91 | if { ![runto_main] } { | |
bc6c7af4 | 92 | fail "can't run to main" |
0a251e08 YQ |
93 | return |
94 | } | |
95 | ||
9a946945 MSG |
96 | gdb_breakpoint [gdb_get_line_number "break here before-dlopen" \ |
97 | $main_loader_srcfile] | |
0a251e08 | 98 | gdb_continue_to_breakpoint "break here before-dlopen" |
9a946945 MSG |
99 | gdb_test_no_output "set var jit_libname = \"$main_solib_binfile\"" \ |
100 | "setting library name" | |
0a251e08 | 101 | |
9a946945 MSG |
102 | gdb_breakpoint [gdb_get_line_number "break here after-dlopen" \ |
103 | $main_loader_srcfile] | |
0a251e08 YQ |
104 | gdb_continue_to_breakpoint "break here after-dlopen" |
105 | ||
9a946945 MSG |
106 | set line [gdb_get_line_number {break here 0} $main_solib_srcfile] |
107 | gdb_breakpoint "$main_solib_srcfile:$line" | |
0a251e08 YQ |
108 | gdb_continue_to_breakpoint "break here 0" |
109 | ||
9a946945 MSG |
110 | # Poke desired values directly into inferior instead of using "set args" |
111 | # because "set args" does not work under gdbserver. | |
112 | gdb_test_no_output "set var argc=[expr $count + 1]" "forging argc" | |
113 | gdb_test_no_output "set var argv=fake_argv" "forging argv" | |
114 | for {set i 1} {$i <= $count} {incr i} { | |
115 | set binfile_target [lindex $solib_binfiles_target [expr $i-1]] | |
116 | gdb_test_no_output "set var argv\[$i\]=\"${binfile_target}\"" \ | |
117 | "forging argv\[$i\]" | |
118 | } | |
0a251e08 | 119 | |
9a946945 MSG |
120 | set line [gdb_get_line_number {break here 1} $main_solib_srcfile] |
121 | gdb_breakpoint "$main_solib_srcfile:$line" | |
0a251e08 YQ |
122 | gdb_continue_to_breakpoint "break here 1" |
123 | ||
124 | gdb_test "info function jit_function" "$match_str" | |
125 | ||
126 | # This is just to help debugging when things fail | |
5144dfba | 127 | if {$test_verbose > 0} { |
0a251e08 YQ |
128 | gdb_test "maintenance print objfiles" |
129 | gdb_test "maintenance info break" | |
130 | } | |
131 | ||
9a946945 MSG |
132 | set line [gdb_get_line_number {break here 2} $main_solib_srcfile] |
133 | gdb_breakpoint "$main_solib_srcfile:$line" | |
0a251e08 | 134 | gdb_continue_to_breakpoint "break here 2" |
9a946945 | 135 | |
0a251e08 YQ |
136 | # All jit librares must have been unregistered |
137 | gdb_test "info function jit_function" \ | |
ebf47080 SM |
138 | "All functions matching regular expression \"jit_function\":" \ |
139 | "info function jit_function after unregistration" | |
3b2a0cf2 | 140 | } |
0a251e08 | 141 | } |
3b2a0cf2 | 142 | |
9a946945 | 143 | # Compile the main code (which loads the JIT objects) as a shared library. |
f8012071 MS |
144 | if { [compile_jit_elf_main_as_so $main_solib_srcfile $main_solib_binfile \ |
145 | {additional_flags="-DMAIN=jit_dl_main"}] < 0 } { | |
9a946945 MSG |
146 | return |
147 | } | |
148 | ||
149 | # Compile the "real" main for this test. | |
150 | if { [compile_jit_dlmain {shlib_load}] < 0 } { | |
151 | return | |
152 | } | |
6571a381 | 153 | |
9a946945 | 154 | # Compile two shared libraries to use as JIT objects. |
f8012071 MS |
155 | set jit_solibs_target [compile_and_download_n_jit_so \ |
156 | $jit_solib_basename $jit_solib_srcfile 2] | |
9a946945 MSG |
157 | if { $jit_solibs_target == -1 } { |
158 | return | |
159 | } | |
160 | ||
161 | one_jit_test [lindex $jit_solibs_target 0] "${hex} jit_function_0001" | |
162 | one_jit_test $jit_solibs_target "${hex} jit_function_0001\[\r\n\]+${hex} jit_function_0002" | |
163 | ||
164 | foreach solib $jit_solibs_target { | |
165 | # We don't intend to load the .so as a JIT debuginfo reader, but we | |
166 | # need some handy file name for a completion test. | |
167 | set input [string range $solib 0 [expr { [string length $solib] - 2 }]] | |
168 | gdb_test \ | |
169 | "complete jit-reader-load [standard_output_file $input]" \ | |
170 | "jit-reader-load $solib" \ | |
171 | "test jit-reader-load filename completion [file tail $solib]" | |
172 | } |