]> Git Repo - binutils.git/blame - gdb/testsuite/gdb.base/sym-file.exp
Automatic date update in version.in
[binutils.git] / gdb / testsuite / gdb.base / sym-file.exp
CommitLineData
4a94e368 1# Copyright 2013-2022 Free Software Foundation, Inc.
681f229a
NB
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# Test adding and removing a symbol file dynamically:
17# 1) Run to gdb_add_symbol_file in $srcfile.
18# 2) Set a pending breakpoint at bar in $srcfile3.
2d1baf52 19# 3) Load the library's symbols using 'add-symbol-file'.
681f229a
NB
20# 4) 'info files' must display ${lib_basename}.
21# 5) Continue to bar in $srcfile3.
22# 6) Set a breakpoint at foo in $srcfile3.
23# 7) Continue to foo in $srcfile3.
24# 8) Set a breakpoint at gdb_remove_symbol_file.
25# 9) Continue to gdb_remove_symbol_file in $srcfile.
2d1baf52 26# 10) Remove the library's symbols using 'remove-symbol-file'.
681f229a
NB
27# 11) 'info files' must not display ${lib_basename}, anymore.
28# 12) Check that the breakpoints at foo and bar are pending.
29# 13) Check that the execution can continue without error.
08351840 30# 14) Regression test for a stale breakpoints bug.
681f229a
NB
31
32if {![is_elf_target]} {
33 return 0
34}
35
36if [skip_shlib_tests] {
37 return 0
38}
39
681f229a
NB
40set target_size TARGET_UNKNOWN
41if {[is_lp64_target]} {
42 set target_size TARGET_LP64
43} elseif {[is_ilp32_target]} {
44 set target_size TARGET_ILP32
45} else {
46 return 0
47}
48
49set main_basename sym-file-main
50set loader_basename sym-file-loader
51set lib_basename sym-file-lib
52
53standard_testfile $main_basename.c $loader_basename.c $lib_basename.c
54
55set libsrc "${srcdir}/${subdir}/${srcfile3}"
2d1baf52
PA
56set lib_so [standard_output_file ${lib_basename}.so]
57set lib_syms [shlib_symbol_file ${lib_so}]
58set lib_dlopen [shlib_target_file ${lib_basename}.so]
59
681f229a 60set exec_opts [list debug "additional_flags= -I$srcdir/../../include/ -D$target_size\
2d1baf52 61 -DSHLIB_NAME\\=\"$lib_dlopen\""]
681f229a 62
2d1baf52 63if {[gdb_compile_shlib $libsrc $lib_so {debug}] != ""} {
5b362f04 64 untested "failed to compile shared library"
681f229a
NB
65 return
66}
67
5b362f04 68if {[prepare_for_testing "failed to prepare" $binfile "$srcfile $srcfile2" $exec_opts]} {
681f229a
NB
69 return
70}
71
d9019901 72gdb_load_shlib ${lib_so}
2d1baf52 73
65a33d75 74if {![runto_main]} {
2d1baf52 75 return
681f229a
NB
76}
77
2d1baf52
PA
78# 1) Run to gdb_add_symbol_file in $srcfile for adding the library's
79# symbols.
80gdb_breakpoint gdb_add_symbol_file
81gdb_continue_to_breakpoint gdb_add_symbol_file
82
681f229a
NB
83# 2) Set a pending breakpoint at bar in $srcfile3.
84set result [gdb_breakpoint bar allow-pending]
65a33d75 85if {!$result} {
681f229a
NB
86 return
87}
88
2d1baf52
PA
89# 3) Add the library's symbols using 'add-symbol-file'.
90set result [gdb_test "add-symbol-file ${lib_syms} addr" \
3453e7e4 91 "Reading symbols from .*${lib_syms}\\.\\.\\." \
7dd6df01 92 "add-symbol-file ${lib_basename}.so addr" \
681f229a
NB
93 "add symbol table from file \".*${lib_basename}\\.so\"\
94 at.*\\(y or n\\) " \
95 "y"]
65a33d75 96if {$result != 0} {
681f229a
NB
97 return
98}
99
100# 4) 'info files' must display $srcfile3.
101gdb_test "info files" \
102 "^(?=(.*${lib_basename})).*" \
103 "info files must display ${lib_basename}"
104
105# 5) Continue to bar in $srcfile3 to ensure that the breakpoint
106# was bound correctly after adding $shilb_name.
107set lnum_bar [gdb_get_line_number "break at bar" $srcfile3]
108gdb_continue_to_breakpoint bar ".*${lib_basename}\\.c:$lnum_bar.*"
109
110# 6) Set a breakpoint at foo in $srcfile3.
111set result [gdb_breakpoint foo]
65a33d75 112if {!$result} {
681f229a
NB
113 return
114}
115
116# 7) Continue to foo in $srcfile3 to ensure that the breakpoint
117# was bound correctly.
118set lnum_foo [gdb_get_line_number "break at foo" $srcfile3]
119gdb_continue_to_breakpoint foo ".*${lib_basename}\\.c:$lnum_foo.*"
120
121# 8) Set a breakpoint at gdb_remove_symbol_file in $srcfile for
2d1baf52 122# removing the library's symbols.
681f229a 123set result [gdb_breakpoint gdb_remove_symbol_file]
65a33d75 124if {!$result} {
681f229a
NB
125 return
126}
127
128# 9) Continue to gdb_remove_symbol_file in $srcfile.
129gdb_continue_to_breakpoint gdb_remove_symbol_file
130
2d1baf52 131# 10) Remove the library's symbols using 'remove-symbol-file'.
681f229a
NB
132set result [gdb_test "remove-symbol-file -a addr" \
133 ""\
134 "remove-symbol-file -a addr" \
135 "Remove symbol table from file \".*${lib_basename}\\.so\"\\?\
136.*\\(y or n\\) " \
137 "y"]
65a33d75 138if {$result != 0} {
681f229a
NB
139 return
140}
141
142# 11) 'info files' must not display ${lib_basename}, anymore.
143gdb_test "info files" \
144 "^(?!(.*${lib_basename})).*" \
145 "info files must not display ${lib_basename}"
146
2d1baf52
PA
147# 12) Check that the breakpoints at foo and bar are pending after
148# removing the library's symbols.
149gdb_test "info breakpoints 3" \
681f229a 150 ".*PENDING.*" \
7dd6df01 151 "breakpoint at foo is pending"
681f229a 152
2d1baf52 153gdb_test "info breakpoints 4" \
681f229a 154 ".*PENDING.*" \
7dd6df01 155 "breakpoint at bar is pending"
681f229a
NB
156
157# 13) Check that the execution can continue without error.
08351840
PA
158set lnum_reload [gdb_get_line_number "reload lib here"]
159gdb_breakpoint $lnum_reload
160gdb_continue_to_breakpoint reload ".*${srcfile}:$lnum_reload.*"
161
162# 14) Regression test for a stale breakpoints bug. Check whether
163# unloading symbols manually without the program actually unloading
164# the library, when breakpoints are inserted doesn't leave stale
165# breakpoints behind.
166with_test_prefix "stale bkpts" {
167 # Force breakpoints always inserted.
168 gdb_test_no_output "set breakpoint always-inserted on"
169
170 # Get past the library reload.
171 gdb_continue_to_breakpoint gdb_add_symbol_file
172
173 # Load the library's symbols.
174 gdb_test "add-symbol-file ${lib_syms} addr" \
3453e7e4 175 "Reading symbols from .*${lib_syms}\\.\\.\\." \
08351840
PA
176 "add-symbol-file ${lib_basename}.so addr" \
177 "add symbol table from file \".*${lib_syms}\"\
178at.*\\(y or n\\) " \
179 "y"
180
181 # Set a breakpoint at baz, in the library.
182 gdb_breakpoint baz
183
184 gdb_test "info breakpoints 7" ".*y.*0x.*in baz.*" \
185 "breakpoint at baz is resolved"
186
187 # Unload symbols manually without the program actually unloading
188 # the library.
189 gdb_test "remove-symbol-file -a addr" \
190 "" \
191 "remove-symbol-file -a addr" \
192 "Remove symbol table from file \".*${lib_basename}\\.so\"\\?\
193.*\\(y or n\\) " \
194 "y"
195
196 gdb_test "info breakpoints 7" ".*PENDING.*" \
197 "breakpoint at baz is pending"
198
199 # Check that execution can continue without error. If GDB leaves
200 # breakpoints behind, we'll get back a spurious SIGTRAP.
201 set lnum_end [gdb_get_line_number "end here"]
202 gdb_breakpoint $lnum_end
203 gdb_continue_to_breakpoint "end here" ".*end here.*"
204}
This page took 2.786662 seconds and 4 git commands to generate.