run copyright.sh for 2011.
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / unload.exp
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
19 if $tracelevel then {
20 strace $tracelevel
21 }
22
23 #
24 # test running programs
25 #
26
27 if {[skip_shlib_tests]} {
28 return 0
29 }
30
31 set testfile "unload"
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}]
49
50 if [get_compiler_info ${binfile}] {
51 return -1
52 }
53
54 set lib_opts debug
55 set exec_opts [list debug shlib_load additional_flags=-DSHLIB_NAME\=\"${lib_dlopen}\" additional_flags=-DSHLIB_NAME2\=\"${lib_dlopen2}\"]
56
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."
61 return -1
62 }
63
64 # Start with a fresh gdb.
65
66 gdb_exit
67 gdb_start
68 gdb_reinitialize_dir $srcdir/$subdir
69 gdb_load ${binfile}
70 gdb_load_shlibs $lib_sl $lib_sl2
71
72 if [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
81 gdb_breakpoint "shrfunc1" allow-pending
82 gdb_breakpoint "shrfunc2" allow-pending
83
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"
89
90 set unloadshr_line [gdb_get_line_number "unloadshr break" ${libsrcfile}]
91
92 gdb_run_cmd
93 gdb_test "" \
94 "Breakpoint 1, shrfunc1 \\\(x=1\\\).*${libsrcfile}:$unloadshr_line.*" \
95 "running program"
96
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"
102
103 gdb_breakpoint "$testfile.c:[gdb_get_line_number "y-set-1" $testfile.c]" temporary
104
105 gdb_test "continue" \
106 "Continuing.*warning: Temporarily disabling breakpoints for.*${lib_syms}.*y-set-1.*" \
107 "continuing to unloaded libfile"
108
109 gdb_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
115 gdb_run_cmd
116 gdb_test "" \
117 "Breakpoint 1, shrfunc1 \\\(x=1\\\).*${libsrcfile}:$unloadshr_line.*" \
118 "rerun to shared library breakpoint"
119
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"
125
126 gdb_breakpoint "$testfile.c:[gdb_get_line_number "y-set-1" $testfile.c]" temporary
127
128 gdb_test "continue" \
129 "Continuing.*warning: Temporarily disabling breakpoints for.*${lib_syms}.*y-set-1.*" \
130 "continuing to unloaded libfile"
131
132 set unloadshr_line2 [gdb_get_line_number "unloadshr2 break" ${libsrcfile2}]
133
134 gdb_test "continue" \
135 "Breakpoint 2, shrfunc2 \\\(x=2\\\).*${libsrcfile2}:$unloadshr_line2\r\n.*" \
136 "continue to shrfunc2"
137
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"
144
145 gdb_breakpoint "$testfile.c:[gdb_get_line_number "y-set-2" $testfile.c]"
146
147 gdb_test "continue" \
148 "Continuing.*warning: Temporarily disabling breakpoints for.*${lib_syms2}.*y-set-2.*" \
149 "continuing to unloaded libfile2"
150
151 gdb_test "print y" " = 200" "print y from libfile2"
This page took 0.035928 seconds and 4 git commands to generate.