1# Copyright 1997, 1998, 1999, 2000, 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# Please email any bugs, comments, and/or additions to this file to: 17# bug-gdb@prep.ai.mit.edu 18 19if $tracelevel then { 20 strace $tracelevel 21 } 22 23set prms_id 0 24set bug_id 0 25 26# are we on a target board 27if ![isnative] then { 28 return 29} 30 31# This test is presently only valid on HP-UX, since it requires 32# that we use HP-UX-specific compiler & linker options to build 33# the testcase. 34# 35if {! [istarget "hppa*-*-*hpux*"] } { 36 return 37} 38 39set libfile "solib" 40set testfile "so-indr-cl" 41set srcfile ${testfile}.c 42set binfile ${objdir}/${subdir}/${testfile} 43 44if [get_compiler_info ${binfile}] { 45 return -1 46} 47 48# Build the shared libraries this test case needs. 49# 50#cd ${subdir} 51#remote_exec build "$CC -g +z -c ${libfile}1.c -o ${libfile}1.o" 52 53 54if {$hp_cc_compiler || $hp_aCC_compiler} { 55 set additional_flags "additional_flags=+z" 56} else { 57 set additional_flags "additional_flags=-fpic" 58} 59if {[gdb_compile "${srcdir}/${subdir}/${libfile}1.c" "${objdir}/${subdir}/${libfile}1.o" object [list debug $additional_flags]] != ""} { 60 perror "Couldn't compile ${libfile}1.c" 61 return -1 62} 63 64if [istarget "hppa*-hp-hpux*"] then { 65 remote_exec build "ld -b ${objdir}/${subdir}/${libfile}1.o -o ${objdir}/${subdir}/${libfile}1.sl" 66} else { 67 set additional_flags "additional_flags=-shared" 68 gdb_compile "${objdir}/${subdir}/${libfile}1.o" "${objdir}/${subdir}/${libfile}1.sl" executable [list debug $additional_flags] 69} 70 71# Build the test case 72#remote_exec build "$CC -Aa -g ${srcfile} ${libfile}1.sl -o ${binfile}" 73 74 75if {$hp_cc_compiler} { 76 set additional_flags "additional_flags=-Ae" 77} else { 78 set additional_flags "" 79} 80if {[gdb_compile "${srcdir}/${subdir}/${srcfile} ${objdir}/${subdir}/${libfile}1.sl" "${binfile}" executable [list debug $additional_flags]] != ""} { 81 perror "Couldn't build ${binfile}" 82 return -1 83} 84 85#cd .. 86 87# Start with a fresh gdb 88 89gdb_exit 90gdb_start 91gdb_reinitialize_dir $srcdir/$subdir 92gdb_load ${binfile} 93 94# This program implicitly loads SOM shared libraries. We wish to test 95# whether a user can set breakpoints in a shlib before running the 96# program, where the program doesn't directly call the shlib, but 97# indirectly does via passing its address to another function. 98# 99# ??rehrauer: Currently, this doesn't work, but we do catch the case 100# and explicitly disallow it. The reason it fails appears to be that 101# 102# [1] gdb consults only the linker symbol table in this scenario, and 103# [2] For a shlib function that is only indirectly called from the 104# main a.out, there is in the linker symbol table a stub whose 105# address is negative. Possibly this is to be interpreted as 106# an index into the DLT?? 107# 108send_gdb "break solib_main\n" 109gdb_expect { 110 -re "Cannot break on solib_main without a running program.*$gdb_prompt $"\ 111 {pass "break on indirect solib call before running"} 112 -re "Breakpoint.*deferred.*\\(\"solib_main\" was not found.*$gdb_prompt $"\ 113 {pass "break on indirect solib call before running 2"} 114 -re "$gdb_prompt $"\ 115 {fail "break on indirect solib call before running"} 116 timeout {fail "(timeout) break on indirect solib call before running"} 117} 118 119# However, if we do run to the program's main, we then ought to be 120# able to set a breakpoint on the indirectly called function. (Apparently, 121# once the inferior is running, gdb consults the debug info rather than 122# the linker symbol table, and is able to find the correct address.) 123# 124if ![runto_main] then { fail "indirect solib call tests suppressed" } 125 126# Verify that we can step over the first shlib call. 127# 128send_gdb "break solib_main\n" 129gdb_expect { 130 -re ".*\[Bb\]reakpoint \[0-9\]* at 0x\[0-9a-fA-F\]*: file.*${libfile}1.c.*$gdb_prompt $"\ 131 {pass "break on indirect solib call after running"} 132 -re "$gdb_prompt $"\ 133 {fail "break on indirect solib call after running"} 134 timeout {fail "(timeout) break on indirect solib call after running"} 135} 136 137gdb_exit 138return 0 139