1 # Copyright 2003, 2004, 2005, 2007, 2008, 2009, 2010, 2011
2 # Free Software Foundation, Inc.
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 # This file was created by Jeff Johnston. (jjohnstn@redhat.com)
24 # test running programs
27 if {[skip_shlib_tests]} {
32 set libfile "unloadshr"
33 set libfile2 "unloadshr2"
34 set libname "${libfile}.sl"
35 set libname2 "${libfile2}.sl"
36 set libsrcfile ${libfile}.c
37 set libsrcfile2 ${libfile2}.c
38 set srcfile $srcdir/$subdir/$testfile.c
39 set binfile $objdir/$subdir/$testfile
40 set shlibdir ${objdir}/${subdir}
41 set libsrc $srcdir/$subdir/$libfile.c
42 set libsrc2 $srcdir/$subdir/$libfile2.c
43 set lib_sl $objdir/$subdir/$libname
44 set lib_sl2 $objdir/$subdir/$libname2
45 set lib_dlopen [shlib_target_file ${libname}]
46 set lib_dlopen2 [shlib_target_file ${libname2}]
47 set lib_syms [shlib_symbol_file ${libname}]
48 set lib_syms2 [shlib_symbol_file ${libname2}]
50 if [get_compiler_info ${binfile}] {
55 set exec_opts [list debug shlib_load additional_flags=-DSHLIB_NAME\=\"${lib_dlopen}\" additional_flags=-DSHLIB_NAME2\=\"${lib_dlopen2}\"]
57 if { [gdb_compile_shlib $libsrc $lib_sl $lib_opts] != ""
58 || [gdb_compile_shlib $libsrc2 $lib_sl2 $lib_opts] != ""
59 || [gdb_compile $srcfile $binfile executable $exec_opts] != ""} {
60 untested "Couldn't compile $libsrc or $libsrc2 or $srcfile."
64 # Start with a fresh gdb.
68 gdb_reinitialize_dir $srcdir/$subdir
70 gdb_load_shlibs $lib_sl $lib_sl2
72 if [target_info exists gdb_stub] {
77 # Test setting a breakpoint in a dynamically loaded library which is
78 # manually loaded and unloaded
81 gdb_breakpoint "shrfunc1" allow-pending
82 gdb_breakpoint "shrfunc2" allow-pending
84 gdb_test "info break" \
85 "Num Type\[ \]+Disp Enb Address\[ \]+What\r?
86 1\[\t \]+breakpoint keep y *<PENDING> *shrfunc1\r?
87 2\[\t \]+breakpoint keep y *<PENDING> *shrfunc2" \
88 "pending breakpoint info before run"
90 set unloadshr_line [gdb_get_line_number "unloadshr break" ${libsrcfile}]
94 "Breakpoint 1, shrfunc1 \\\(x=1\\\).*${libsrcfile}:$unloadshr_line.*" \
97 gdb_test "info break" \
98 "Num Type\[ \]+Disp Enb Address\[ \]+What\r?
99 1\[\t \]+breakpoint keep y *0x\[0-9a-f\]+ *in shrfunc1 at .*
100 2\[\t \]+breakpoint keep y *<PENDING> *shrfunc2.*" \
101 "pending breakpoint info on first run at shrfunc1"
103 gdb_breakpoint "$testfile.c:[gdb_get_line_number "y-set-1" $testfile.c]" temporary
105 gdb_test "continue" \
106 "Continuing.*warning: Temporarily disabling breakpoints for.*${lib_syms}.*y-set-1.*" \
107 "continuing to unloaded libfile"
109 gdb_test "print y" " = 10" "print y from libfile"
112 # Try to rerun program and verify that shared breakpoint is reset properly
117 "Breakpoint 1, shrfunc1 \\\(x=1\\\).*${libsrcfile}:$unloadshr_line.*" \
118 "rerun to shared library breakpoint"
120 gdb_test "info break" \
121 "Num Type\[ \]+Disp Enb Address\[ \]+What\r?
122 1\[\t \]+breakpoint keep y *0x\[0-9a-f\]+ *in shrfunc1 at .*
123 2\[\t \]+breakpoint keep y *<PENDING> *shrfunc2.*" \
124 "pending breakpoint info on second run at shrfunc1"
126 gdb_breakpoint "$testfile.c:[gdb_get_line_number "y-set-1" $testfile.c]" temporary
128 gdb_test "continue" \
129 "Continuing.*warning: Temporarily disabling breakpoints for.*${lib_syms}.*y-set-1.*" \
130 "continuing to unloaded libfile"
132 set unloadshr_line2 [gdb_get_line_number "unloadshr2 break" ${libsrcfile2}]
134 gdb_test "continue" \
135 "Breakpoint 2, shrfunc2 \\\(x=2\\\).*${libsrcfile2}:$unloadshr_line2\r\n.*" \
136 "continue to shrfunc2"
138 gdb_test "info break" \
139 "Num Type\[ \]+Disp Enb Address\[ \]+What\r?
140 1\[\t \]+breakpoint keep y *<PENDING> *shrfunc1\r?
141 \[\t \]+breakpoint already hit \[0-9\]+ (time|times)\r?
142 2\[\t \]+breakpoint keep y *0x\[0-9a-f\]+ *in shrfunc2 at .*" \
143 "pending breakpoint info on second run at shrfunc2"
145 gdb_breakpoint "$testfile.c:[gdb_get_line_number "y-set-2" $testfile.c]"
147 gdb_test "continue" \
148 "Continuing.*warning: Temporarily disabling breakpoints for.*${lib_syms2}.*y-set-2.*" \
149 "continuing to unloaded libfile2"
151 gdb_test "print y" " = 200" "print y from libfile2"