Automatic Copyright Year update after running gdb/copyright.py
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / jit-elf-so.exp
1 # Copyright 2011-2022 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 # The same tests as in jit.exp, but loading JITer itself from a shared
17 # library.
18
19 if {[skip_shlib_tests]} {
20 untested "skipping shared library tests"
21 return -1
22 }
23
24 if {[get_compiler_info]} {
25 untested "could not get compiler info"
26 return 1
27 }
28
29 load_lib jit-elf-helpers.exp
30
31 # Increase this to see more detail.
32 set test_verbose 0
33
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
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} {
56 global main_loader_srcfile main_loader_binfile main_loader_basename
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
66 }
67
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]
78 with_test_prefix "one_jit_test-$count" {
79 global test_verbose
80 global main_loader_binfile main_loader_srcfile
81 global main_solib_binfile main_solib_srcfile
82
83 clean_restart $main_loader_binfile
84 gdb_load_shlib $main_solib_binfile
85
86 # This is just to help debugging when things fail
87 if {$test_verbose > 0} {
88 gdb_test "set debug jit 1"
89 }
90
91 if { ![runto_main] } {
92 fail "can't run to main"
93 return
94 }
95
96 gdb_breakpoint [gdb_get_line_number "break here before-dlopen" \
97 $main_loader_srcfile]
98 gdb_continue_to_breakpoint "break here before-dlopen"
99 gdb_test_no_output "set var jit_libname = \"$main_solib_binfile\"" \
100 "setting library name"
101
102 gdb_breakpoint [gdb_get_line_number "break here after-dlopen" \
103 $main_loader_srcfile]
104 gdb_continue_to_breakpoint "break here after-dlopen"
105
106 set line [gdb_get_line_number {break here 0} $main_solib_srcfile]
107 gdb_breakpoint "$main_solib_srcfile:$line"
108 gdb_continue_to_breakpoint "break here 0"
109
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 }
119
120 set line [gdb_get_line_number {break here 1} $main_solib_srcfile]
121 gdb_breakpoint "$main_solib_srcfile:$line"
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
127 if {$test_verbose > 0} {
128 gdb_test "maintenance print objfiles"
129 gdb_test "maintenance info break"
130 }
131
132 set line [gdb_get_line_number {break here 2} $main_solib_srcfile]
133 gdb_breakpoint "$main_solib_srcfile:$line"
134 gdb_continue_to_breakpoint "break here 2"
135
136 # All jit librares must have been unregistered
137 gdb_test "info function jit_function" \
138 "All functions matching regular expression \"jit_function\":" \
139 "info function jit_function after unregistration"
140 }
141 }
142
143 # Compile the main code (which loads the JIT objects) as a shared library.
144 if { [compile_jit_elf_main_as_so $main_solib_srcfile $main_solib_binfile \
145 {additional_flags="-DMAIN=jit_dl_main"}] < 0 } {
146 return
147 }
148
149 # Compile the "real" main for this test.
150 if { [compile_jit_dlmain {shlib_load}] < 0 } {
151 return
152 }
153
154 # Compile two shared libraries to use as JIT objects.
155 set jit_solibs_target [compile_and_download_n_jit_so \
156 $jit_solib_basename $jit_solib_srcfile 2]
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 }
This page took 0.033928 seconds and 4 git commands to generate.