]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.base/solib-display.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / solib-display.exp
1 # Copyright 2009-2024 Free Software Foundation, Inc.
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
31 require allow_shlib_tests
32
33 # This test is currently not supported for stub targets, because it uses the
34 # start command (through gdb_start_cmd). In theory, it could be changed to
35 # use something else (kill + gdb_run_cmd with a manual breakpoint at main).
36 # However, when we try that with the native-gdbserver board, we see that the
37 # test fails and gdb outputs this upon connection:
38 #
39 # warning: Unable to display "a_global": No symbol "a_global" in current context.
40 # warning: Unable to display "b_global": No symbol "b_global" in current context.
41 # warning: Unable to display "c_global": No symbol "c_global" in current context.
42 #
43 # This is because the initial stop is done before the shared libraries are
44 # loaded.
45
46 require !use_gdb_stub
47
48 # Library file.
49 set libname "solib-display-lib"
50 set srcfile_lib ${srcdir}/${subdir}/${libname}.c
51 set binfile_lib [standard_output_file ${libname}.so]
52 set lib_flags {}
53 # Binary file.
54 set testfile "solib-display-main"
55 set srcfile ${srcdir}/${subdir}/${testfile}.c
56 set executable ${testfile}
57 set binfile [standard_output_file ${executable}]
58 set bin_flags [list debug shlib=${binfile_lib}]
59
60 # SEP must be last for the possible `unsupported' error path.
61 foreach libsepdebug {NO IN SEP} { with_test_prefix "$libsepdebug" {
62
63 set sep_lib_flags $lib_flags
64 if {$libsepdebug != "NO"} {
65 lappend sep_lib_flags {debug}
66 }
67 if { [gdb_compile_shlib ${srcfile_lib} ${binfile_lib} $sep_lib_flags] != ""
68 || [gdb_compile ${srcfile} ${binfile} executable $bin_flags] != "" } {
69 untested "failed to compile"
70 return -1
71 }
72
73 if {$libsepdebug == "SEP"} {
74 if {[gdb_gnu_strip_debug $binfile_lib] != 0} {
75 unsupported "could not split debug of $binfile_lib."
76 return
77 } else {
78 pass "split solib"
79 }
80 }
81
82 clean_restart $executable
83
84 if {![runto_main]} {
85 return 0
86 }
87
88 gdb_test "display (int) a_global" "1: \\(int\\) a_global = 41"
89 gdb_test "display (int) b_global" "2: \\(int\\) b_global = 42"
90 gdb_test "display (int) c_global" "3: \\(int\\) c_global = 43"
91
92 if { [gdb_start_cmd] < 0 } {
93 fail "can't run to main (2)"
94 continue
95 }
96
97 gdb_test "" [multi_line \
98 "1: \\(int\\) a_global = 41" \
99 "2: \\(int\\) b_global = 42" \
100 "3: \\(int\\) c_global = 43" \
101 ] "after rerun"
102
103 # Now rebuild the library without b_global
104 if { [gdb_compile_shlib ${srcfile_lib} ${binfile_lib} \
105 "$sep_lib_flags additional_flags=-DNO_B_GLOBAL"] != ""} {
106 fail "can't rebuild $binfile_lib"
107 }
108
109 if {$libsepdebug == "SEP"} {
110 set test "split solib second time"
111 if {[gdb_gnu_strip_debug $binfile_lib] != 0} {
112 fail $test
113 continue
114 } else {
115 pass $test
116 }
117 }
118
119 if { [gdb_start_cmd] < 0 } {
120 fail "can't run to main (3)"
121 continue
122 }
123
124
125 gdb_test "" [multi_line \
126 "1: \\(int\\) a_global = 41" \
127 "warning: .*b_global.*" \
128 "3: \\(int\\) c_global = 43" \
129 ] "after rerun (2)"
130
131 # Now verify that displays which are not in the shared library
132 # are not cleared permaturely.
133
134 gdb_test "break [gdb_get_line_number "break here" ${testfile}.c]" \
135 ".*Breakpoint.* at .*"
136
137 gdb_test "continue"
138 gdb_test "display main_global" "4: main_global = 44"
139 gdb_test "display a_local" "5: a_local = 45"
140 gdb_test "display a_static" "6: a_static = 46"
141
142 if { [gdb_start_cmd] < 0 } {
143 fail "can't run to main (4)"
144 continue
145 }
146
147 gdb_test "" "6: a_static = 46\\r\\n4: main_global = 44\\r\\n.*"
148 gdb_test "continue" [multi_line \
149 "4: main_global = 44" \
150 "5: a_local = 45" \
151 "6: a_static = 46" \
152 ] "continue two"
153 }}