blob: f9a661a9359093a8f0a85c2f522991dc1ac73f7e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
|
# Copyright 2013-2019 Free Software Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. */
# Test adding and removing a symbol file dynamically:
# 1) Run to gdb_add_symbol_file in $srcfile.
# 2) Set a pending breakpoint at bar in $srcfile3.
# 3) Load the library's symbols using 'add-symbol-file'.
# 4) 'info files' must display ${lib_basename}.
# 5) Continue to bar in $srcfile3.
# 6) Set a breakpoint at foo in $srcfile3.
# 7) Continue to foo in $srcfile3.
# 8) Set a breakpoint at gdb_remove_symbol_file.
# 9) Continue to gdb_remove_symbol_file in $srcfile.
# 10) Remove the library's symbols using 'remove-symbol-file'.
# 11) 'info files' must not display ${lib_basename}, anymore.
# 12) Check that the breakpoints at foo and bar are pending.
# 13) Check that the execution can continue without error.
# 14) Regression test for a stale breakpoints bug.
if {![is_elf_target]} {
return 0
}
if [skip_shlib_tests] {
return 0
}
set target_size TARGET_UNKNOWN
if {[is_lp64_target]} {
set target_size TARGET_LP64
} elseif {[is_ilp32_target]} {
set target_size TARGET_ILP32
} else {
return 0
}
set main_basename sym-file-main
set loader_basename sym-file-loader
set lib_basename sym-file-lib
standard_testfile $main_basename.c $loader_basename.c $lib_basename.c
set libsrc "${srcdir}/${subdir}/${srcfile3}"
set lib_so [standard_output_file ${lib_basename}.so]
set lib_syms [shlib_symbol_file ${lib_so}]
set lib_dlopen [shlib_target_file ${lib_basename}.so]
set exec_opts [list debug "additional_flags= -I$srcdir/../../include/ -D$target_size\
-DSHLIB_NAME\\=\"$lib_dlopen\""]
if [get_compiler_info] {
return -1
}
if {[gdb_compile_shlib $libsrc $lib_so {debug}] != ""} {
untested "failed to compile shared library"
return
}
if {[prepare_for_testing "failed to prepare" $binfile "$srcfile $srcfile2" $exec_opts]} {
return
}
gdb_load_shlib ${lib_so}
if ![runto_main] then {
fail "can't run to main"
return
}
# 1) Run to gdb_add_symbol_file in $srcfile for adding the library's
# symbols.
gdb_breakpoint gdb_add_symbol_file
gdb_continue_to_breakpoint gdb_add_symbol_file
# 2) Set a pending breakpoint at bar in $srcfile3.
set result [gdb_breakpoint bar allow-pending]
if {!$result} then {
return
}
# 3) Add the library's symbols using 'add-symbol-file'.
set result [gdb_test "add-symbol-file ${lib_syms} addr" \
"Reading symbols from .*${lib_syms}\\.\\.\\." \
"add-symbol-file ${lib_basename}.so addr" \
"add symbol table from file \".*${lib_basename}\\.so\"\
at.*\\(y or n\\) " \
"y"]
if {$result != 0} then {
return
}
# 4) 'info files' must display $srcfile3.
gdb_test "info files" \
"^(?=(.*${lib_basename})).*" \
"info files must display ${lib_basename}"
# 5) Continue to bar in $srcfile3 to ensure that the breakpoint
# was bound correctly after adding $shilb_name.
set lnum_bar [gdb_get_line_number "break at bar" $srcfile3]
gdb_continue_to_breakpoint bar ".*${lib_basename}\\.c:$lnum_bar.*"
# 6) Set a breakpoint at foo in $srcfile3.
set result [gdb_breakpoint foo]
if {!$result} then {
return
}
# 7) Continue to foo in $srcfile3 to ensure that the breakpoint
# was bound correctly.
set lnum_foo [gdb_get_line_number "break at foo" $srcfile3]
gdb_continue_to_breakpoint foo ".*${lib_basename}\\.c:$lnum_foo.*"
# 8) Set a breakpoint at gdb_remove_symbol_file in $srcfile for
# removing the library's symbols.
set result [gdb_breakpoint gdb_remove_symbol_file]
if {!$result} then {
return
}
# 9) Continue to gdb_remove_symbol_file in $srcfile.
gdb_continue_to_breakpoint gdb_remove_symbol_file
# 10) Remove the library's symbols using 'remove-symbol-file'.
set result [gdb_test "remove-symbol-file -a addr" \
""\
"remove-symbol-file -a addr" \
"Remove symbol table from file \".*${lib_basename}\\.so\"\\?\
.*\\(y or n\\) " \
"y"]
if {$result != 0} then {
return
}
# 11) 'info files' must not display ${lib_basename}, anymore.
gdb_test "info files" \
"^(?!(.*${lib_basename})).*" \
"info files must not display ${lib_basename}"
# 12) Check that the breakpoints at foo and bar are pending after
# removing the library's symbols.
gdb_test "info breakpoints 3" \
".*PENDING.*" \
"breakpoint at foo is pending"
gdb_test "info breakpoints 4" \
".*PENDING.*" \
"breakpoint at bar is pending"
# 13) Check that the execution can continue without error.
set lnum_reload [gdb_get_line_number "reload lib here"]
gdb_breakpoint $lnum_reload
gdb_continue_to_breakpoint reload ".*${srcfile}:$lnum_reload.*"
# 14) Regression test for a stale breakpoints bug. Check whether
# unloading symbols manually without the program actually unloading
# the library, when breakpoints are inserted doesn't leave stale
# breakpoints behind.
with_test_prefix "stale bkpts" {
# Force breakpoints always inserted.
gdb_test_no_output "set breakpoint always-inserted on"
# Get past the library reload.
gdb_continue_to_breakpoint gdb_add_symbol_file
# Load the library's symbols.
gdb_test "add-symbol-file ${lib_syms} addr" \
"Reading symbols from .*${lib_syms}\\.\\.\\." \
"add-symbol-file ${lib_basename}.so addr" \
"add symbol table from file \".*${lib_syms}\"\
at.*\\(y or n\\) " \
"y"
# Set a breakpoint at baz, in the library.
gdb_breakpoint baz
gdb_test "info breakpoints 7" ".*y.*0x.*in baz.*" \
"breakpoint at baz is resolved"
# Unload symbols manually without the program actually unloading
# the library.
gdb_test "remove-symbol-file -a addr" \
"" \
"remove-symbol-file -a addr" \
"Remove symbol table from file \".*${lib_basename}\\.so\"\\?\
.*\\(y or n\\) " \
"y"
gdb_test "info breakpoints 7" ".*PENDING.*" \
"breakpoint at baz is pending"
# Check that execution can continue without error. If GDB leaves
# breakpoints behind, we'll get back a spurious SIGTRAP.
set lnum_end [gdb_get_line_number "end here"]
gdb_breakpoint $lnum_end
gdb_continue_to_breakpoint "end here" ".*end here.*"
}
|