]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.base/jit-elf-fork.exp
src-release.sh: Use -T0 for xz compression
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / jit-elf-fork.exp
1 # Copyright 2011-2024 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 fork handling of an inferior that has JIT-ed objfiles.
17
18 require allow_shlib_tests
19
20 load_lib jit-elf-helpers.exp
21
22 # The main code that loads and registers JIT objects.
23 set main_basename "jit-elf-fork-main"
24 set main_srcfile ${srcdir}/${subdir}/${main_basename}.c
25 set main_binfile [standard_output_file ${main_basename}]
26
27 # The shared library that gets loaded as JIT objects.
28 set jit_solib_basename jit-elf-fork-solib
29 set jit_solib_srcfile ${srcdir}/${subdir}/${jit_solib_basename}.c
30
31 # Compile a shared library to use as JIT objects.
32 set jit_solibs_target [compile_and_download_n_jit_so \
33 $jit_solib_basename $jit_solib_srcfile 1]
34 if { $jit_solibs_target == -1 } {
35 return
36 }
37
38 # Compile the main code (which loads the JIT objects).
39 if { [compile_jit_main ${main_srcfile} ${main_binfile} {}] != 0 } {
40 return
41 }
42
43 # Set up for the tests.
44 #
45 # detach-on-fork and follow-fork-mode are the values to use for the GDB
46 # parameters of the same names.
47 #
48 # Upon return, execution is stopped at the breakpoint just after fork. Which
49 # inferiors exist and which inferior is the current one depends on the
50 # parameter.
51 #
52 # The only breakpoint left is one just before the return statement in main, so
53 # that the callers can continue execution until there.
54
55 proc do_setup { detach-on-fork follow-fork-mode } {
56 clean_restart ${::main_binfile}
57
58 gdb_test_no_output "set detach-on-fork ${detach-on-fork}"
59 gdb_test_no_output "set follow-fork-mode ${follow-fork-mode}"
60
61 if { ![runto_main] } {
62 return -1
63 }
64
65 # Poke desired values directly into inferior.
66 gdb_test_no_output "set var argc=2" "forging argc"
67 gdb_test_no_output "set var argv=fake_argv" "forging argv"
68 set jit_solib_target [lindex $::jit_solibs_target 0]
69 gdb_test_no_output "set var argv\[1]=\"${jit_solib_target}\"" {forging argv[1]}
70
71 # Put a breakpoint before the fork, continue there.
72 gdb_breakpoint [gdb_get_line_number "break before fork" $::main_srcfile]
73 gdb_continue_to_breakpoint "continue to before fork" ".*break before fork.*"
74
75 # We should have one JIT object loaded.
76 gdb_test "maint info jit" \
77 [multi_line \
78 "jit_code_entry address\\s+symfile address\\s+symfile size\\s*" \
79 "${::hex}\\s+${::hex}\\s+${::decimal}\\s*"] \
80 "jit-ed objfiles before fork"
81
82 # Put a breakpoint just after the fork, continue there.
83 gdb_breakpoint [gdb_get_line_number "break after fork" $::main_srcfile]
84 gdb_continue_to_breakpoint "continue to after fork" ".*break after fork.*"
85
86 # We should still have one JIT object loaded in whatever inferior we are
87 # currently stopped in, regardless of the mode.
88 gdb_test "maint info jit" \
89 [multi_line \
90 "jit_code_entry address\\s+symfile address\\s+symfile size\\s*" \
91 "${::hex}\\s+${::hex}\\s+${::decimal}\\s*"] \
92 "jit-ed objfiles after fork"
93
94 # Delete our breakpoints.
95 delete_breakpoints
96
97 # Put a breakpoint before return, for the convenience of our callers.
98 gdb_breakpoint [gdb_get_line_number "break before return" $::main_srcfile]
99 }
100
101 proc_with_prefix test_detach_on_fork_off_follow_fork_mode_parent { } {
102 if { [do_setup off parent] == -1 } {
103 return -1
104 }
105
106 # We are stopped in the parent.
107 gdb_test "inferior" "Current inferior is 1.*" "current inferior is parent"
108
109 # Switch to the child, verify there is a JIT-ed objfile.
110 gdb_test "inferior 2" "Switching to inferior 2.*"
111 gdb_test "maint info jit" \
112 [multi_line \
113 "jit_code_entry address\\s+symfile address\\s+symfile size\\s*" \
114 "${::hex}\\s+${::hex}\\s+${::decimal}\\s*"] \
115 "jit-ed objfile in child"
116
117 # Continue child past JIT unload, verify there are no more JIT-ed objfiles.
118 gdb_continue_to_breakpoint "continue to before return - child" ".*break before return.*"
119 gdb_test_no_output "maint info jit" "no more jit-ed objfiles in child"
120
121 # Go back to parent, the JIT-ed objfile should still be there.
122 gdb_test "inferior 1" "Switching to inferior 1.*"
123 gdb_test "maint info jit" \
124 [multi_line \
125 "jit_code_entry address\\s+symfile address\\s+symfile size\\s*" \
126 "${::hex}\\s+${::hex}\\s+${::decimal}\\s*"] \
127 "jit-ed objfile in parent"
128
129 # Continue parent past JIT unload, verify there are no more JIT-ed objfiles.
130 gdb_continue_to_breakpoint "continue to before return - parent" ".*break before return.*"
131 gdb_test_no_output "maint info jit" "no more jit-ed objfiles in parent"
132 }
133
134 proc_with_prefix test_detach_on_fork_off_follow_fork_mode_child { } {
135 if { [do_setup off child] == -1 } {
136 return -1
137 }
138
139 # We are stopped in the child. This is the exact same thing as
140 # test_detach_on_fork_off_follow_fork_mode_parent, except that we are
141 # stopped in the child.
142 gdb_test "inferior" "Current inferior is 2.*" "current inferior is child"
143
144 # Switch to the parent, verify there is a JIT-ed objfile.
145 gdb_test "inferior 1" "Switching to inferior 1.*"
146 gdb_test "maint info jit" \
147 [multi_line \
148 "jit_code_entry address\\s+symfile address\\s+symfile size\\s*" \
149 "${::hex}\\s+${::hex}\\s+${::decimal}\\s*"] \
150 "jit-ed objfile in parent"
151
152 # Continue parent past JIT unload, verify there are no more JIT-ed objfiles.
153 gdb_continue_to_breakpoint "continue to before return - parent" ".*break before return.*"
154 gdb_test_no_output "maint info jit" "no more jit-ed objfiles in parent"
155
156 # Go back to child, the JIT-ed objfile should still be there.
157 gdb_test "inferior 2" "Switching to inferior 2.*"
158 gdb_test "maint info jit" \
159 [multi_line \
160 "jit_code_entry address\\s+symfile address\\s+symfile size\\s*" \
161 "${::hex}\\s+${::hex}\\s+${::decimal}\\s*"] \
162 "jit-ed objfile in child"
163
164 # Continue child past JIT unload, verify there are no more JIT-ed objfiles.
165 gdb_continue_to_breakpoint "continue to before return - child" ".*break before return.*"
166 gdb_test_no_output "maint info jit" "no more jit-ed objfiles in child"
167 }
168
169 proc_with_prefix test_detach_on_fork_on_follow_fork_mode_parent { } {
170 if { [do_setup on parent] == -1 } {
171 return -1
172 }
173
174 # We are stopped in the parent, child is detached.
175 gdb_test "inferior" "Current inferior is 1.*" "current inferior is parent"
176 gdb_test "inferior 2" "Inferior ID 2 not known." "no inferior 2"
177
178 # Continue past JIT unload, verify there are no more JIT-ed objfiles.
179 gdb_continue_to_breakpoint "continue to before return" ".*break before return.*"
180 gdb_test_no_output "maint info jit" "no more jit-ed objfiles"
181 }
182
183 proc_with_prefix test_detach_on_fork_on_follow_fork_mode_child { } {
184 if { [do_setup on child] == -1 } {
185 return -1
186 }
187
188 # We are stopped in the child, parent is detached.
189 gdb_test "inferior" "Current inferior is 2.*" "current inferior is child"
190 gdb_test "inferior 1" "Switching to inferior 1 \\\[<null>\\\].*"
191 gdb_test "inferior 2" "Switching to inferior 2.*"
192
193 # Continue past JIT unload, verify there are no more JIT-ed objfiles.
194 gdb_continue_to_breakpoint "continue to before return" ".*break before return.*"
195 gdb_test_no_output "maint info jit" "no more jit-ed objfiles"
196 }
197
198 test_detach_on_fork_off_follow_fork_mode_parent
199 test_detach_on_fork_off_follow_fork_mode_child
200 test_detach_on_fork_on_follow_fork_mode_parent
201 test_detach_on_fork_on_follow_fork_mode_child