Automatic Copyright Year update after running gdb/copyright.py
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / solib-display.exp
CommitLineData
88b9d363 1# Copyright 2009-2022 Free Software Foundation, Inc.
a3247a22
PP
2# This program is free software; you can redistribute it and/or modify
3# it under the terms of the GNU General Public License as published by
4# the Free Software Foundation; either version 3 of the License, or
5# (at your option) any later version.
6#
7# This program is distributed in the hope that it will be useful,
8# but WITHOUT ANY WARRANTY; without even the implied warranty of
9# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10# GNU General Public License for more details.
11#
12# You should have received a copy of the GNU General Public License
13# along with this program. If not, see <http://www.gnu.org/licenses/>.
14#
15# Contributed by Paul Pluzhnikov <ppluzhnikov@google.com>
16#
17
18# This test case verifies that if a display is active on a variable
19# which belongs in a shared library, and that shared library is
20# reloaded (e.g. due to re-execution of the program), GDB will continue
21# to display it (gdb-6.8 crashed under this scenario).
22
23# Also test that a display of variable which is currently present in
24# a shared library, but disappears before re-run, doesn't cause GDB
25# difficulties, and that it continues to display other variables.
26
27# Finally, test that displays which refer to main executable
28# (and thus aren't affected by shared library unloading) are not
29# disabled prematurely.
30
02e370d9
SM
31if { [skip_shlib_tests] } {
32 return 0
33}
34
35# This test is currently not supported for stub targets, because it uses the
36# start command (through gdb_start_cmd). In theory, it could be changed to
37# use something else (kill + gdb_run_cmd with a manual breakpoint at main).
38# However, when we try that with the native-gdbserver board, we see that the
39# test fails and gdb outputs this upon connection:
40#
41# warning: Unable to display "a_global": No symbol "a_global" in current context.
42# warning: Unable to display "b_global": No symbol "b_global" in current context.
43# warning: Unable to display "c_global": No symbol "c_global" in current context.
44#
45# This is because the initial stop is done before the shared libraries are
46# loaded.
47
48if { [use_gdb_stub] } {
a3247a22
PP
49 return 0
50}
51
52# Library file.
53set libname "solib-display-lib"
54set srcfile_lib ${srcdir}/${subdir}/${libname}.c
0ab77f5f 55set binfile_lib [standard_output_file ${libname}.so]
c0201579 56set lib_flags {}
a3247a22
PP
57# Binary file.
58set testfile "solib-display-main"
59set srcfile ${srcdir}/${subdir}/${testfile}.c
4d836c09 60set executable ${testfile}
0ab77f5f 61set binfile [standard_output_file ${executable}]
a3247a22
PP
62set bin_flags [list debug shlib=${binfile_lib}]
63
4c93b1db 64if [get_compiler_info] {
a3247a22
PP
65 return -1
66}
67
c0201579 68# SEP must be last for the possible `unsupported' error path.
0f4d39d5 69foreach libsepdebug {NO IN SEP} { with_test_prefix "$libsepdebug" {
c0201579
JK
70
71 set sep_lib_flags $lib_flags
72 if {$libsepdebug != "NO"} {
73 lappend sep_lib_flags {debug}
74 }
75 if { [gdb_compile_shlib ${srcfile_lib} ${binfile_lib} $sep_lib_flags] != ""
76 || [gdb_compile ${srcfile} ${binfile} executable $bin_flags] != "" } {
84c93cd5 77 untested "failed to compile"
c0201579
JK
78 return -1
79 }
80
81 if {$libsepdebug == "SEP"} {
82 if {[gdb_gnu_strip_debug $binfile_lib] != 0} {
bc6c7af4 83 unsupported "could not split debug of $binfile_lib."
c0201579
JK
84 return
85 } else {
86 pass "split solib"
87 }
88 }
89
90 clean_restart $executable
91
92 if ![runto_main] then {
bc6c7af4 93 fail "can't run to main"
c0201579
JK
94 return 0
95 }
96
46a4882b
PA
97 gdb_test "display (int) a_global" "1: \\(int\\) a_global = 41"
98 gdb_test "display (int) b_global" "2: \\(int\\) b_global = 42"
99 gdb_test "display (int) c_global" "3: \\(int\\) c_global = 43"
c0201579
JK
100
101 if { [gdb_start_cmd] < 0 } {
bc6c7af4 102 fail "can't run to main (2)"
c0201579
JK
103 continue
104 }
105
62147a22 106 gdb_test "" [multi_line \
46a4882b
PA
107 "1: \\(int\\) a_global = 41" \
108 "2: \\(int\\) b_global = 42" \
109 "3: \\(int\\) c_global = 43" \
62147a22 110 ] "after rerun"
c0201579
JK
111
112 # Now rebuild the library without b_global
113 if { [gdb_compile_shlib ${srcfile_lib} ${binfile_lib} \
114 "$sep_lib_flags additional_flags=-DNO_B_GLOBAL"] != ""} {
bc6c7af4 115 fail "can't rebuild $binfile_lib"
c0201579
JK
116 }
117
118 if {$libsepdebug == "SEP"} {
119 set test "split solib second time"
120 if {[gdb_gnu_strip_debug $binfile_lib] != 0} {
121 fail $test
122 continue
123 } else {
124 pass $test
125 }
126 }
127
128 if { [gdb_start_cmd] < 0 } {
bc6c7af4 129 fail "can't run to main (3)"
c0201579
JK
130 continue
131 }
132
62147a22
PA
133
134 gdb_test "" [multi_line \
46a4882b 135 "1: \\(int\\) a_global = 41" \
62147a22 136 "warning: .*b_global.*" \
46a4882b 137 "3: \\(int\\) c_global = 43" \
62147a22 138 ] "after rerun (2)"
c0201579
JK
139
140 # Now verify that displays which are not in the shared library
141 # are not cleared permaturely.
142
143 gdb_test "break [gdb_get_line_number "break here" ${testfile}.c]" \
144 ".*Breakpoint.* at .*"
145
146 gdb_test "continue"
147 gdb_test "display main_global" "4: main_global = 44"
148 gdb_test "display a_local" "5: a_local = 45"
149 gdb_test "display a_static" "6: a_static = 46"
150
151 if { [gdb_start_cmd] < 0 } {
bc6c7af4 152 fail "can't run to main (4)"
c0201579
JK
153 continue
154 }
155
156 gdb_test "" "6: a_static = 46\\r\\n4: main_global = 44\\r\\n.*"
157 gdb_test "break [gdb_get_line_number "break here" ${testfile}.c]" \
158 ".*Breakpoint.* at .*"
62147a22
PA
159 gdb_test "continue" [multi_line \
160 "4: main_global = 44" \
161 "5: a_local = 45" \
162 "6: a_static = 46" \
163 ]
6a5870ce 164}}
This page took 1.940629 seconds and 4 git commands to generate.