1# Copyright 2007-2023 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 connecting and disconnecting at shared library events. 17 18if {[skip_shlib_tests]} { 19 return 0 20} 21 22set gdbserver_reconnect_p 1 23if { [info proc gdb_reconnect] == "" } { 24 return 0 25} 26 27set testfile solib-disc 28set libfile so-disc-shr 29set srcfile ${testfile}.c 30set binfile [standard_output_file ${testfile}] 31 32set libsrc "${srcdir}/${subdir}/${libfile}.c" 33set libname "${libfile}.so" 34set libobj [standard_output_file ${libname}] 35set execsrc "${srcdir}/${subdir}/${srcfile}" 36set lib_dlopen [shlib_target_file ${libname}] 37set lib_syms [shlib_symbol_file ${libname}] 38 39remote_exec build "rm -f ${binfile}" 40 41set exec_opts [list debug shlib_load additional_flags=-DSHLIB_NAME=\"${lib_dlopen}\"] 42 43if { [gdb_compile_shlib $libsrc $libobj {debug}] != "" 44 || [gdb_compile $execsrc ${binfile} executable $exec_opts] != "" } { 45 return -1 46} 47 48gdb_exit 49gdb_start 50gdb_reinitialize_dir $srcdir/$subdir 51gdb_load ${binfile} 52gdb_load_shlib $libobj 53 54if {![runto_main]} { 55 return 0 56} 57 58gdb_test_no_output "set stop-on-solib-events 1" 59 60gdb_test "continue" "Stopped due to shared library event.*" "continue to load" 61 62set msg "save \$pc after load" 63set saved_pc "" 64gdb_test_multiple "print/x \$pc" $msg { 65 -re "\\\$$decimal = (\[^\r\n\]*)\r\n$gdb_prompt $" { 66 set saved_pc $expect_out(1,string) 67 pass $msg 68 } 69} 70 71gdb_test "disconnect" "Ending remote debugging\\." "disconnect after load" 72if { [gdb_reconnect] == 0 } { 73 pass "reconnect after load" 74} else { 75 fail "reconnect after load" 76 return 0 77} 78 79gdb_test "print/x \$pc" "\\\$$decimal = $saved_pc" "check \$pc after load" 80 81 82gdb_test "continue" "Stopped due to shared library event.*" "continue to unload" 83 84set msg "save \$pc after unload" 85set saved_pc "" 86gdb_test_multiple "print/x \$pc" $msg { 87 -re "\\\$$decimal = (\[^\r\n\]*)\r\n$gdb_prompt $" { 88 set saved_pc $expect_out(1,string) 89 pass $msg 90 } 91} 92 93gdb_test "disconnect" "Ending remote debugging\\." "disconnect after unload" 94if { [gdb_reconnect] == 0 } { 95 pass "reconnect after unload" 96} else { 97 fail "reconnect after unload" 98 return 0 99} 100 101gdb_test "print/x \$pc" "\\\$$decimal = $saved_pc" "check \$pc after unload" 102