1# Copyright 1997, 1998, 1999, 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. It verifies GDB's 32# ability to catch loads and unloads of shared libraries. 33# 34 35#setup_xfail "*-*-*" 36#clear_xfail "hppa*-*-*hpux*" 37if {![istarget "hppa*-*-hpux*"]} { 38 return 0 39} 40 41set testfile "solib" 42set srcfile ${testfile}.c 43set binfile ${objdir}/${subdir}/${testfile} 44 45# build the first test case 46if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } { 47 untested solib.exp 48 return -1 49} 50 51if [get_compiler_info ${binfile}] { 52 return -1 53} 54 55# Build the shared libraries this test case needs. 56# 57#cd ${subdir} 58#remote_exec build "$CC -g +z -c ${testfile}1.c -o ${testfile}1.o" 59#remote_exec build "$CC -g +z -c ${testfile}2.c -o ${testfile}2.o" 60 61if {$gcc_compiled == 0} { 62 if [istarget "hppa*-hp-hpux*"] then { 63 set additional_flags "additional_flags=+z" 64 } else { 65 # don't know what the compiler is... 66 set additional_flags "" 67 } 68} else { 69 set additional_flags "additional_flags=-fpic" 70} 71 72if {[gdb_compile "${srcdir}/${subdir}/${testfile}1.c" "${binfile}1.o" object [list debug $additional_flags]] != ""} { 73 perror "Couldn't compile ${testfile}1.c" 74 #return -1 75} 76if {[gdb_compile "${srcdir}/${subdir}/${testfile}2.c" "${binfile}2.o" object [list debug, $additional_flags]] != ""} { 77 perror "Couldn't compile ${testfile}2.c" 78 #return -1 79} 80 81if [istarget "hppa*-*-hpux*"] { 82 remote_exec build "ld -b ${binfile}1.o -o ${binfile}1.sl" 83 remote_exec build "ld -b ${binfile}2.o -o ${binfile}2.sl" 84} else { 85 set additional_flags "additional_flags=-shared" 86 gdb_compile "${binfile}1.o" "${binfile}1.sl" executable [list debug $additional_flags] 87 gdb_compile "${binfile}2.o" "${binfile}2.sl" executable [list debug $additional_flags] 88} 89 90# Build a version where the main program is in a shared library. For 91# testing an indirect call made in a shared library. 92 93if {[gdb_compile "${srcdir}/${subdir}/${testfile}.c" "${binfile}_sl.o" object [list debug $additional_flags]] != ""} { 94 perror "Couldn't compile ${testfile}.c for ${binfile}_sl.o" 95 #return -1 96} 97 98if { [istarget "hppa*-*-hpux*"] } { 99 remote_exec build "ld -b ${binfile}_sl.o -o ${binfile}_sl.sl" 100} else { 101 set additional_flags "additional_flags=-shared" 102 gdb_compile "${binfile}_sl.o" "${binfile}_sl.sl" executable [list debug $additional_flags] 103} 104 105if { [istarget "hppa*-*-hpux*"] } { 106 set additional_flags "-Wl,-u,main" 107 if { [gdb_compile "${binfile}_sl.sl" "${binfile}_sl" executable [list debug $additional_flags]] != "" } { 108 untested solib.exp 109 return -1 110 } 111} else { 112 # FIXME: need to fill this part in for non-HP build 113} 114 115#cd .. 116 117# Start with a fresh gdb 118 119gdb_exit 120gdb_start 121gdb_reinitialize_dir $srcdir/$subdir 122gdb_load ${binfile} 123 124# This program manually loads and unloads SOM shared libraries, via calls 125# to shl_load and shl_unload. 126# 127if ![runto_main] then { fail "catch load/unload tests suppressed" } 128 129# Verify that we complain if the user tells us to catch something we 130# don't understand. 131# 132send_gdb "catch a_cold\n" 133gdb_expect { 134 -re "Unknown event kind specified for catch.*$gdb_prompt $"\ 135 {pass "bogus catch kind is disallowed"} 136 -re "$gdb_prompt $"\ 137 {fail "bogus catch kind is disallowed"} 138 timeout {fail "(timeout) bogus catch kind is disallowed"} 139} 140 141# Verify that we can set a generic catchpoint on shlib loads. I.e., that 142# we can catch any shlib load, without specifying the name. 143# 144send_gdb "catch load\n" 145gdb_expect { 146 -re "Catchpoint \[0-9\]* .load <any library>.*$gdb_prompt $"\ 147 {pass "set generic catch load"} 148 -re "$gdb_prompt $"\ 149 {fail "set generic catch load"} 150 timeout {fail "(timeout) set generic catch load"} 151} 152 153send_gdb "continue\n" 154gdb_expect { 155 -re "Catchpoint \[0-9\] .loaded gdb.base/solib1.sl.*$gdb_prompt $"\ 156 {pass "caught generic solib load"} 157 -re "$gdb_prompt $"\ 158 {fail "caught generic solib load"} 159 timeout {fail "(timeout) caught generic solib load"} 160} 161 162# Set a breakpoint on the line following the shl_load call, and 163# continue. 164# 165# ??rehrauer: It appears that we can't just say "finish" from here; 166# GDB is getting confused by the dld's presense on the stack. 167# 168send_gdb "break 27\n" 169gdb_expect { 170 -re "Breakpoint \[0-9\]* at.*$gdb_prompt $"\ 171 {pass "set break after shl_load"} 172 -re "$gdb_prompt $"\ 173 {fail "set break after shl_load"} 174 timeout {fail "(timeout) set break after shl_load"} 175} 176 177send_gdb "continue\n" 178gdb_expect { 179 -re "Breakpoint \[0-9\]*, main .. at .*solib.c:27.*$gdb_prompt $"\ 180 {pass "continue after generic catch load"} 181 -re "$gdb_prompt $"\ 182 {fail "continue after generic catch load"} 183 timeout {fail "(timeout) continue after generic catch load"} 184} 185 186# Step over the call to shl_findsym. 187# 188# ??rehrauer: In theory, since the call to shl_load asked for 189# immediate binding of the shlib's symbols, and since the 190# shlib's symbols should have been auto-loaded, we ought to 191# be able to set a breakpoint on solib_main now. However, 192# that seems not to be the case. Dunno why for sure; perhaps 193# the breakpoint wants to be set on an import stub in the 194# main program for solib_main? There wouldn't be one, in 195# this case... 196# 197send_gdb "next\n" 198gdb_expect { 199 -re "$gdb_prompt $"\ 200 {pass "step over shl_findsym"} 201 timeout {fail "(timeout) step over shl_findsym"} 202} 203 204# Verify that we can catch an unload of any library. 205# 206send_gdb "catch unload\n" 207gdb_expect { 208 -re "Catchpoint \[0-9\]* .unload <any library>.*$gdb_prompt $"\ 209 {pass "set generic catch unload"} 210 -re "$gdb_prompt $"\ 211 {fail "set generic catch unload"} 212 timeout {fail "(timeout) set generic catch load"} 213} 214 215send_gdb "continue\n" 216gdb_expect { 217 -re "Catchpoint \[0-9\] .unloaded gdb.base/solib1.sl.*$gdb_prompt $"\ 218 {pass "caught generic solib unload"} 219 -re "$gdb_prompt $"\ 220 {fail "caught generic solib unload"} 221 timeout {fail "(timeout) caught generic solib unload"} 222} 223 224# Verify that we can catch a load of a specific library. (Delete 225# all the other catchpoints first, so that the generic catchpoints 226# we've previously set don't trigger.) 227# 228send_gdb "delete\n" 229gdb_expect { 230 -re "Delete all breakpoints.*y or n.*"\ 231 {send_gdb "y\n" 232 gdb_expect { 233 -re "$gdb_prompt $"\ 234 {pass "delete all catchpoints"} 235 timeout {fail "(timeout) delete all catchpoints"} 236 } 237 } 238 -re "$gdb_prompt $"\ 239 {fail "delete all catchpoints"} 240 timeout {fail "(timeout) delete all catchpoints"} 241} 242 243send_gdb "catch load gdb.base/solib2.sl\n" 244gdb_expect { 245 -re "Catchpoint \[0-9\]* .load gdb.base/solib2.sl.*$gdb_prompt $"\ 246 {pass "set specific catch load"} 247 -re "$gdb_prompt $"\ 248 {fail "set specific catch load"} 249 timeout {fail "(timeout) set specific catch load"} 250} 251 252send_gdb "continue\n" 253gdb_expect { 254 -re "Catchpoint \[0-9\] .loaded gdb.base/solib2.sl.*$gdb_prompt $"\ 255 {pass "caught specific solib load"} 256 -re "$gdb_prompt $"\ 257 {fail "caught specific solib load"} 258 timeout {fail "(timeout) caught specific solib load"} 259} 260 261# Verify that we can catch an unload of a specific library. 262# 263send_gdb "catch unload gdb.base/solib2.sl\n" 264gdb_expect { 265 -re "Catchpoint \[0-9\]* .unload gdb.base/solib2.sl.*$gdb_prompt $"\ 266 {pass "set specific catch unload"} 267 -re "$gdb_prompt $"\ 268 {fail "set specific catch unload"} 269 timeout {fail "(timeout) set specific catch unload"} 270} 271 272send_gdb "continue\n" 273gdb_expect { 274 -re "Catchpoint \[0-9\] .unloaded gdb.base/solib2.sl.*$gdb_prompt $"\ 275 {pass "caught specific solib unload"} 276 -re "$gdb_prompt $"\ 277 {fail "caught specific solib unload"} 278 timeout {fail "(timeout) caught specific solib unload"} 279} 280 281# Verify that we can set a catchpoint on a specific library that 282# happens not to be loaded by the program. And, that this catchpoint 283# won't trigger inappropriately when other shlibs are loaded. 284# 285send_gdb "break 55\n" 286gdb_expect { 287 -re "Breakpoint \[0-9\]* at.*$gdb_prompt $"\ 288 {pass "set break on shl_unload"} 289 -re "$gdb_prompt $"\ 290 {fail "set break on shl_unload"} 291 timeout {fail "(timeout) set break on shl_unload"} 292} 293 294send_gdb "break 58\n" 295gdb_expect { 296 -re "Breakpoint \[0-9\]* at.*$gdb_prompt $"\ 297 {pass "set break after shl_unload"} 298 -re "$gdb_prompt $"\ 299 {fail "set break after shl_unload"} 300 timeout {fail "(timeout) set break after shl_unload"} 301} 302 303send_gdb "catch load foobar.sl\n" 304gdb_expect { 305 -re "Catchpoint \[0-9\]* .load foobar.sl.*$gdb_prompt $"\ 306 {pass "set specific catch load for nonloaded shlib"} 307 -re "$gdb_prompt $"\ 308 {fail "set specific catch load for nonloaded shlib"} 309 timeout {fail "(timeout) set specific catch load for nonloaded shlib"} 310} 311 312send_gdb "catch unload foobar.sl\n" 313gdb_expect { 314 -re "Catchpoint \[0-9\]* .unload foobar.sl.*$gdb_prompt $"\ 315 {pass "set specific catch unload for nonloaded shlib"} 316 -re "$gdb_prompt $"\ 317 {fail "set specific catch unload for nonloaded shlib"} 318 timeout {fail "(timeout) set specific catch unload for nonloaded shlib"} 319} 320 321send_gdb "continue\n" 322gdb_expect { 323 -re "Breakpoint \[0-9\]*.*$gdb_prompt $"\ 324 {pass "specific catch load doesn't trigger inappropriately"} 325 -re "$gdb_prompt $"\ 326 {fail "specific catch load doesn't trigger inappropriately"} 327 timeout {fail "(timeout) specific catch load doesn't trigger inappropriately"} 328} 329 330send_gdb "continue\n" 331gdb_expect { 332 -re "Breakpoint \[0-9\]*.*$gdb_prompt $"\ 333 {pass "specific catch unload doesn't trigger inappropriately"} 334 -re "$gdb_prompt $"\ 335 {fail "specific catch unload doesn't trigger inappropriately"} 336 timeout {fail "(timeout) specific catch unload doesn't trigger inappropriately"} 337} 338 339# ??rehrauer: There ought to be testpoints here that verify that 340# load/unload catchpoints can use conditionals, can be temporary, 341# self-disabling, etc etc. 342# 343 344gdb_exit 345 346# 347# Test stepping into an indirect call in a shared library. 348# 349 350gdb_start 351gdb_load ${binfile}_sl 352gdb_test "break main" ".*deferred. at .main..*" "break on main" 353gdb_test "run" ".*Breakpoint.*main.*solib.c.*" "hit breakpoint at main" 354gdb_test "break 45" "Breakpoint.*solib.c, line 45.*" "break on indirect call" 355gdb_test "continue" "Continuing.*solib.c:45.*" \ 356 "continue to break on indirect call" 357gdb_test "step" "solib_main.*solib1.c:17.*return arg.arg.*" \ 358 "step into indirect call from a shared library" 359gdb_exit 360 361return 0 362