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