[gdb/syscalls] Sync with strace v6.13
[binutils-gdb.git] / gdb / testsuite / gdb.base / solib-disc.exp
blob280e8de46d20ba2c6329a39df16b8154f443d2b7
1 # Copyright 2007-2024 Free Software Foundation, Inc.
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.
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.
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/>.  */
16 # Test connecting and disconnecting at shared library events.
18 require allow_shlib_tests
20 set gdbserver_reconnect_p 1
21 if { [info proc gdb_reconnect] == "" } {
22     unsupported "requires gdbserver reconnect"
23     return 0
26 set testfile solib-disc
27 set libfile so-disc-shr
28 set srcfile ${testfile}.c
29 set binfile [standard_output_file ${testfile}]
31 set libsrc "${srcdir}/${subdir}/${libfile}.c"
32 set libname "${libfile}.so"
33 set libobj [standard_output_file ${libname}]
34 set execsrc "${srcdir}/${subdir}/${srcfile}"
35 set lib_dlopen [shlib_target_file ${libname}]
36 set lib_syms [shlib_symbol_file ${libname}]
38 remote_exec build "rm -f ${binfile}"
40 set exec_opts [list debug shlib_load additional_flags=-DSHLIB_NAME=\"${lib_dlopen}\"]
42 if { [gdb_compile_shlib $libsrc $libobj {debug}] != ""
43      || [gdb_compile $execsrc ${binfile} executable $exec_opts] != "" } {
44     return -1
47 clean_restart $binfile
48 gdb_load_shlib $libobj
50 if {![runto_main]} {
51     return 0
54 gdb_test_no_output "set stop-on-solib-events 1"
56 gdb_test "continue" "Stopped due to shared library event.*" "continue to load"
58 set msg "save \$pc after load"
59 set saved_pc ""
60 gdb_test_multiple "print/x \$pc" $msg {
61     -re "\\\$$decimal = (\[^\r\n\]*)\r\n$gdb_prompt $" {
62         set saved_pc $expect_out(1,string)
63         pass $msg
64     }
67 gdb_test "disconnect" "Ending remote debugging\\." "disconnect after load"
68 if { [gdb_reconnect] == 0 } {
69     pass "reconnect after load"
70 } else {
71     fail "reconnect after load"
72     return 0
75 gdb_test "print/x \$pc" "\\\$$decimal = $saved_pc" "check \$pc after load"
78 gdb_test "continue" "Stopped due to shared library event.*" "continue to unload"
80 set msg "save \$pc after unload"
81 set saved_pc ""
82 gdb_test_multiple "print/x \$pc" $msg {
83     -re "\\\$$decimal = (\[^\r\n\]*)\r\n$gdb_prompt $" {
84         set saved_pc $expect_out(1,string)
85         pass $msg
86     }
89 gdb_test "disconnect" "Ending remote debugging\\." "disconnect after unload"
90 if { [gdb_reconnect] == 0 } {
91     pass "reconnect after unload"
92 } else {
93     fail "reconnect after unload"
94     return 0
97 gdb_test "print/x \$pc" "\\\$$decimal = $saved_pc" "check \$pc after unload"