1#   Copyright 2003, 2004, 2005, 2007, 2008, 2009, 2010, 2011
2#   Free Software Foundation, Inc.
3
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.
8#
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.
13#
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/>.
16
17# This file was created by Jeff Johnston. (jjohnstn@redhat.com)
18
19if $tracelevel then {
20    strace $tracelevel
21}
22
23#
24# test running programs
25#
26
27if {[skip_shlib_tests]} {
28    return 0
29}
30
31set testfile "unload"
32set libfile "unloadshr"
33set libfile2 "unloadshr2"
34set libname "${libfile}.sl"
35set libname2 "${libfile2}.sl"
36set libsrcfile ${libfile}.c
37set libsrcfile2 ${libfile2}.c
38set srcfile $srcdir/$subdir/$testfile.c
39set binfile $objdir/$subdir/$testfile
40set shlibdir ${objdir}/${subdir}
41set libsrc  $srcdir/$subdir/$libfile.c
42set libsrc2  $srcdir/$subdir/$libfile2.c
43set lib_sl  $objdir/$subdir/$libname
44set lib_sl2  $objdir/$subdir/$libname2
45set lib_dlopen [shlib_target_file ${libname}]
46set lib_dlopen2 [shlib_target_file ${libname2}]
47set lib_syms [shlib_symbol_file ${libname}]
48set lib_syms2 [shlib_symbol_file ${libname2}]
49
50if [get_compiler_info ${binfile}] {
51    return -1
52}
53
54set lib_opts debug
55set exec_opts [list debug shlib_load additional_flags=-DSHLIB_NAME\=\"${lib_dlopen}\" additional_flags=-DSHLIB_NAME2\=\"${lib_dlopen2}\"]
56
57if { [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."
61    return -1
62}
63
64# Start with a fresh gdb.
65
66gdb_exit
67gdb_start
68gdb_reinitialize_dir $srcdir/$subdir
69gdb_load ${binfile}
70gdb_load_shlibs $lib_sl $lib_sl2
71
72if [target_info exists gdb_stub] {
73    gdb_step_for_stub;
74}
75
76#
77# Test setting a breakpoint in a dynamically loaded library which is
78# manually loaded and unloaded
79#
80
81gdb_breakpoint "shrfunc1" allow-pending
82gdb_breakpoint "shrfunc2" allow-pending
83
84gdb_test "info break" \
85    "Num     Type\[ \]+Disp Enb Address\[ \]+What\r?
861\[\t \]+breakpoint     keep y *<PENDING> *shrfunc1\r?
872\[\t \]+breakpoint     keep y *<PENDING> *shrfunc2" \
88"pending breakpoint info before run"
89
90set unloadshr_line [gdb_get_line_number "unloadshr break" ${libsrcfile}]
91
92gdb_run_cmd
93gdb_test "" \
94"Breakpoint 1, shrfunc1 \\\(x=1\\\).*${libsrcfile}:$unloadshr_line.*" \
95"running program"
96
97gdb_test "info break" \
98    "Num     Type\[ \]+Disp Enb Address\[ \]+What\r?
991\[\t \]+breakpoint     keep y *0x\[0-9a-f\]+ *in shrfunc1 at .*
1002\[\t \]+breakpoint     keep y *<PENDING> *shrfunc2.*" \
101"pending breakpoint info on first run at shrfunc1"
102
103gdb_breakpoint "$testfile.c:[gdb_get_line_number "y-set-1" $testfile.c]" temporary
104
105gdb_test "continue" \
106"Continuing.*warning: Temporarily disabling breakpoints for.*${lib_syms}.*y-set-1.*" \
107"continuing to unloaded libfile"
108
109gdb_test "print y" " = 10" "print y from libfile"
110
111#
112# Try to rerun program and verify that shared breakpoint is reset properly
113#
114
115gdb_run_cmd
116gdb_test "" \
117"Breakpoint 1, shrfunc1 \\\(x=1\\\).*${libsrcfile}:$unloadshr_line.*" \
118"rerun to shared library breakpoint"
119
120gdb_test "info break" \
121    "Num     Type\[ \]+Disp Enb Address\[ \]+What\r?
1221\[\t \]+breakpoint     keep y *0x\[0-9a-f\]+ *in shrfunc1 at .*
1232\[\t \]+breakpoint     keep y *<PENDING> *shrfunc2.*" \
124"pending breakpoint info on second run at shrfunc1"
125
126gdb_breakpoint "$testfile.c:[gdb_get_line_number "y-set-1" $testfile.c]" temporary
127
128gdb_test "continue" \
129"Continuing.*warning: Temporarily disabling breakpoints for.*${lib_syms}.*y-set-1.*" \
130"continuing to unloaded libfile"
131
132set unloadshr_line2 [gdb_get_line_number "unloadshr2 break" ${libsrcfile2}]
133
134gdb_test "continue" \
135"Breakpoint 2, shrfunc2 \\\(x=2\\\).*${libsrcfile2}:$unloadshr_line2\r\n.*" \
136"continue to shrfunc2"
137
138gdb_test "info break" \
139    "Num     Type\[ \]+Disp Enb Address\[ \]+What\r?
1401\[\t \]+breakpoint     keep y *<PENDING> *shrfunc1\r?
141\[\t \]+breakpoint already hit \[0-9\]+ (time|times)\r?
1422\[\t \]+breakpoint     keep y *0x\[0-9a-f\]+ *in shrfunc2 at .*" \
143"pending breakpoint info on second run at shrfunc2"
144
145gdb_breakpoint "$testfile.c:[gdb_get_line_number "y-set-2" $testfile.c]"
146
147gdb_test "continue" \
148"Continuing.*warning: Temporarily disabling breakpoints for.*${lib_syms2}.*y-set-2.*" \
149"continuing to unloaded libfile2"
150
151gdb_test "print y" " = 200" "print y from libfile2"
152