PR gdb/15827
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / sym-file.exp
CommitLineData
ecd75fc8 1# Copyright 2013-2014 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.
30
31if {![is_elf_target]} {
32 return 0
33}
34
35if [skip_shlib_tests] {
36 return 0
37}
38
681f229a
NB
39set target_size TARGET_UNKNOWN
40if {[is_lp64_target]} {
41 set target_size TARGET_LP64
42} elseif {[is_ilp32_target]} {
43 set target_size TARGET_ILP32
44} else {
45 return 0
46}
47
48set main_basename sym-file-main
49set loader_basename sym-file-loader
50set lib_basename sym-file-lib
51
52standard_testfile $main_basename.c $loader_basename.c $lib_basename.c
53
54set libsrc "${srcdir}/${subdir}/${srcfile3}"
2d1baf52
PA
55set lib_so [standard_output_file ${lib_basename}.so]
56set lib_syms [shlib_symbol_file ${lib_so}]
57set lib_dlopen [shlib_target_file ${lib_basename}.so]
58
681f229a 59set exec_opts [list debug "additional_flags= -I$srcdir/../../include/ -D$target_size\
2d1baf52 60 -DSHLIB_NAME\\=\"$lib_dlopen\""]
681f229a
NB
61
62if [get_compiler_info] {
63 return -1
64}
65
2d1baf52 66if {[gdb_compile_shlib $libsrc $lib_so {debug}] != ""} {
681f229a
NB
67 untested ${testfile}
68 return
69}
70
71if {[prepare_for_testing $testfile $binfile "$srcfile $srcfile2" $exec_opts]} {
72 return
73}
74
2d1baf52
PA
75gdb_load_shlibs ${lib_so}
76
77if ![runto_main] then {
78 fail "Can't run to main"
79 return
681f229a
NB
80}
81
2d1baf52
PA
82# 1) Run to gdb_add_symbol_file in $srcfile for adding the library's
83# symbols.
84gdb_breakpoint gdb_add_symbol_file
85gdb_continue_to_breakpoint gdb_add_symbol_file
86
681f229a
NB
87# 2) Set a pending breakpoint at bar in $srcfile3.
88set result [gdb_breakpoint bar allow-pending]
89if {!$result} then {
90 return
91}
92
2d1baf52
PA
93# 3) Add the library's symbols using 'add-symbol-file'.
94set result [gdb_test "add-symbol-file ${lib_syms} addr" \
95 "Reading symbols from .*${lib_syms}\\.\\.\\.done\\." \
7dd6df01 96 "add-symbol-file ${lib_basename}.so addr" \
681f229a
NB
97 "add symbol table from file \".*${lib_basename}\\.so\"\
98 at.*\\(y or n\\) " \
99 "y"]
100if {$result != 0} then {
101 return
102}
103
104# 4) 'info files' must display $srcfile3.
105gdb_test "info files" \
106 "^(?=(.*${lib_basename})).*" \
107 "info files must display ${lib_basename}"
108
109# 5) Continue to bar in $srcfile3 to ensure that the breakpoint
110# was bound correctly after adding $shilb_name.
111set lnum_bar [gdb_get_line_number "break at bar" $srcfile3]
112gdb_continue_to_breakpoint bar ".*${lib_basename}\\.c:$lnum_bar.*"
113
114# 6) Set a breakpoint at foo in $srcfile3.
115set result [gdb_breakpoint foo]
116if {!$result} then {
117 return
118}
119
120# 7) Continue to foo in $srcfile3 to ensure that the breakpoint
121# was bound correctly.
122set lnum_foo [gdb_get_line_number "break at foo" $srcfile3]
123gdb_continue_to_breakpoint foo ".*${lib_basename}\\.c:$lnum_foo.*"
124
125# 8) Set a breakpoint at gdb_remove_symbol_file in $srcfile for
2d1baf52 126# removing the library's symbols.
681f229a
NB
127set result [gdb_breakpoint gdb_remove_symbol_file]
128if {!$result} then {
129 return
130}
131
132# 9) Continue to gdb_remove_symbol_file in $srcfile.
133gdb_continue_to_breakpoint gdb_remove_symbol_file
134
2d1baf52 135# 10) Remove the library's symbols using 'remove-symbol-file'.
681f229a
NB
136set result [gdb_test "remove-symbol-file -a addr" \
137 ""\
138 "remove-symbol-file -a addr" \
139 "Remove symbol table from file \".*${lib_basename}\\.so\"\\?\
140.*\\(y or n\\) " \
141 "y"]
142if {$result != 0} then {
143 return
144}
145
146# 11) 'info files' must not display ${lib_basename}, anymore.
147gdb_test "info files" \
148 "^(?!(.*${lib_basename})).*" \
149 "info files must not display ${lib_basename}"
150
2d1baf52
PA
151# 12) Check that the breakpoints at foo and bar are pending after
152# removing the library's symbols.
153gdb_test "info breakpoints 3" \
681f229a 154 ".*PENDING.*" \
7dd6df01 155 "breakpoint at foo is pending"
681f229a 156
2d1baf52 157gdb_test "info breakpoints 4" \
681f229a 158 ".*PENDING.*" \
7dd6df01 159 "breakpoint at bar is pending"
681f229a
NB
160
161# 13) Check that the execution can continue without error.
162gdb_continue_to_end
This page took 0.095881 seconds and 4 git commands to generate.