* hppa.h (pa_opcodes): Use "cX" completer instead of "cx" in fstqx
[external/binutils.git] / gdb / testsuite / gdb.base / unload.exp
1 #   Copyright 2003-2005, 2007-2012 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 # This file was created by Jeff Johnston. (jjohnstn@redhat.com)
17
18 #
19 # test running programs
20 #
21
22 if {[skip_shlib_tests]} {
23     return 0
24 }
25
26 set testfile "unload"
27 set libfile "unloadshr"
28 set libfile2 "unloadshr2"
29 set libname "${libfile}.sl"
30 set libname2 "${libfile2}.sl"
31 set libsrcfile ${libfile}.c
32 set libsrcfile2 ${libfile2}.c
33 set srcfile $srcdir/$subdir/$testfile.c
34 set binfile $objdir/$subdir/$testfile
35 set shlibdir ${objdir}/${subdir}
36 set libsrc  $srcdir/$subdir/$libfile.c
37 set libsrc2  $srcdir/$subdir/$libfile2.c
38 set lib_sl  $objdir/$subdir/$libname
39 set lib_sl2  $objdir/$subdir/$libname2
40 set lib_dlopen [shlib_target_file ${libname}]
41 set lib_dlopen2 [shlib_target_file ${libname2}]
42 set lib_syms [shlib_symbol_file ${libname}]
43 set lib_syms2 [shlib_symbol_file ${libname2}]
44
45 if [get_compiler_info] {
46     return -1
47 }
48
49 set lib_opts debug
50 set exec_opts [list debug shlib_load additional_flags=-DSHLIB_NAME\=\"${lib_dlopen}\" additional_flags=-DSHLIB_NAME2\=\"${lib_dlopen2}\"]
51
52 if { [gdb_compile_shlib $libsrc $lib_sl $lib_opts] != ""
53      || [gdb_compile_shlib $libsrc2 $lib_sl2 $lib_opts] != ""
54      || [gdb_compile $srcfile $binfile executable $exec_opts] != ""} {
55     untested "Couldn't compile $libsrc or $libsrc2 or $srcfile."
56     return -1
57 }
58
59 # Start with a fresh gdb.
60
61 gdb_exit
62 gdb_start
63 gdb_reinitialize_dir $srcdir/$subdir
64 gdb_load ${binfile}
65 gdb_load_shlibs $lib_sl $lib_sl2
66
67 #
68 # Test setting a breakpoint in a dynamically loaded library which is
69 # manually loaded and unloaded
70 #
71
72 gdb_breakpoint "shrfunc1" allow-pending
73 gdb_breakpoint "shrfunc2" allow-pending
74
75 gdb_test "info break" \
76     "Num     Type\[ \]+Disp Enb Address\[ \]+What\r?
77 1\[\t \]+breakpoint     keep y *<PENDING> *shrfunc1\r?
78 2\[\t \]+breakpoint     keep y *<PENDING> *shrfunc2" \
79 "pending breakpoint info before run"
80
81 set unloadshr_line [gdb_get_line_number "unloadshr break" ${libsrcfile}]
82
83 gdb_run_cmd
84 gdb_test "" \
85 "Breakpoint 1, shrfunc1 \\\(x=1\\\).*${libsrcfile}:$unloadshr_line.*" \
86 "running program"
87
88 gdb_test "info break" \
89     "Num     Type\[ \]+Disp Enb Address\[ \]+What\r?
90 1\[\t \]+breakpoint     keep y *0x\[0-9a-f\]+ *in shrfunc1 at .*
91 2\[\t \]+breakpoint     keep y *<PENDING> *shrfunc2.*" \
92 "pending breakpoint info on first run at shrfunc1"
93
94 gdb_breakpoint "$testfile.c:[gdb_get_line_number "y-set-1" $testfile.c]" temporary
95
96 gdb_test "continue" \
97 "Continuing.*warning: Temporarily disabling breakpoints for.*${lib_syms}.*y-set-1.*" \
98 "continuing to unloaded libfile"
99
100 gdb_test "print y" " = 10" "print y from libfile"
101
102 #
103 # Try to rerun program and verify that shared breakpoint is reset properly
104 #
105
106 gdb_run_cmd
107 gdb_test "" \
108 "Breakpoint 1, shrfunc1 \\\(x=1\\\).*${libsrcfile}:$unloadshr_line.*" \
109 "rerun to shared library breakpoint"
110
111 gdb_test "info break" \
112     "Num     Type\[ \]+Disp Enb Address\[ \]+What\r?
113 1\[\t \]+breakpoint     keep y *0x\[0-9a-f\]+ *in shrfunc1 at .*
114 2\[\t \]+breakpoint     keep y *<PENDING> *shrfunc2.*" \
115 "pending breakpoint info on second run at shrfunc1"
116
117 gdb_breakpoint "$testfile.c:[gdb_get_line_number "y-set-1" $testfile.c]" temporary
118
119 gdb_test "continue" \
120 "Continuing.*warning: Temporarily disabling breakpoints for.*${lib_syms}.*y-set-1.*" \
121 "continuing to unloaded libfile"
122
123 set unloadshr_line2 [gdb_get_line_number "unloadshr2 break" ${libsrcfile2}]
124
125 gdb_test "continue" \
126 "Breakpoint 2, shrfunc2 \\\(x=2\\\).*${libsrcfile2}:$unloadshr_line2\r\n.*" \
127 "continue to shrfunc2"
128
129 gdb_test "info break" \
130     "Num     Type\[ \]+Disp Enb Address\[ \]+What\r?
131 1\[\t \]+breakpoint     keep y *<PENDING> *shrfunc1\r?
132 \[\t \]+breakpoint already hit \[0-9\]+ (time|times)\r?
133 2\[\t \]+breakpoint     keep y *0x\[0-9a-f\]+ *in shrfunc2 at .*" \
134 "pending breakpoint info on second run at shrfunc2"
135
136 gdb_breakpoint "$testfile.c:[gdb_get_line_number "y-set-2" $testfile.c]"
137
138 gdb_test "continue" \
139 "Continuing.*warning: Temporarily disabling breakpoints for.*${lib_syms2}.*y-set-2.*" \
140 "continuing to unloaded libfile2"
141
142 gdb_test "print y" " = 200" "print y from libfile2"