Commit | Line | Data |
---|---|---|
618f726f | 1 | # Copyright 2013-2016 Free Software Foundation, Inc. |
b903e17e DE |
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 solib-search-path, and in the case of solib-svr4.c whether l_addr_p | |
17 | # is properly reset when the path is changed. | |
18 | ||
19 | if {[is_remote target] || [skip_shlib_tests]} { | |
5b362f04 | 20 | untested "skipping remote target and shared library tests" |
b903e17e DE |
21 | return -1 |
22 | } | |
23 | ||
24 | # This is required by gdb_compile_shlib. | |
25 | if {[get_compiler_info]} { | |
26 | warning "Could not get compiler info" | |
5b362f04 | 27 | untested "no compiler info" |
b903e17e DE |
28 | return 1 |
29 | } | |
30 | ||
31 | # Build "wrong" and "right" versions of the libraries in separate directories. | |
32 | set wrong_lib_subdir "solib-search-wrong" | |
33 | set right_lib_subdir "solib-search-right" | |
34 | ||
35 | # First library file. | |
36 | set libname1 "solib-search-lib1" | |
37 | set srcfile1_lib ${srcdir}/${subdir}/${libname1}.c | |
08b3fe69 TT |
38 | set wrong_binfile1_lib \ |
39 | [standard_output_file ${wrong_lib_subdir}/${libname1}.so] | |
40 | set right_binfile1_lib \ | |
41 | [standard_output_file ${right_lib_subdir}/${libname1}.so] | |
b903e17e DE |
42 | # Second library file. |
43 | set libname2 "solib-search-lib2" | |
44 | set srcfile2_lib ${srcdir}/${subdir}/${libname2}.c | |
08b3fe69 TT |
45 | set wrong_binfile2_lib \ |
46 | [standard_output_file ${wrong_lib_subdir}/${libname2}.so] | |
47 | set right_binfile2_lib \ | |
48 | [standard_output_file ${right_lib_subdir}/${libname2}.so] | |
b903e17e DE |
49 | # Link with the library that lives here. |
50 | # This is so that we can replace what gdb sees with the wrong copy, | |
51 | # and then tell gdb to use the right copy that lives someplace else. | |
08b3fe69 TT |
52 | set binfile1_lib [standard_output_file ${libname1}.so] |
53 | set binfile2_lib [standard_output_file ${libname2}.so] | |
b903e17e DE |
54 | |
55 | set lib_flags [list debug ldflags=-Wl,-Bsymbolic] | |
56 | set wrong_lib_flags "$lib_flags additional_flags=-DARRAY_SIZE=1" | |
57 | set right_lib_flags "$lib_flags additional_flags=-DARRAY_SIZE=8192 -DRIGHT" | |
58 | ||
59 | # Binary file. | |
08b3fe69 | 60 | standard_testfile .c |
b903e17e DE |
61 | set bin_flags [list debug shlib=${binfile1_lib} shlib=${binfile2_lib}] |
62 | ||
08b3fe69 TT |
63 | remote_exec build "rm -rf [standard_output_file ${wrong_lib_subdir}]" |
64 | remote_exec build "rm -rf [standard_output_file ${right_lib_subdir}]" | |
65 | remote_exec build "mkdir [standard_output_file ${wrong_lib_subdir}]" | |
66 | remote_exec build "mkdir [standard_output_file ${right_lib_subdir}]" | |
b903e17e DE |
67 | |
68 | if { [gdb_compile_shlib ${srcfile1_lib} ${wrong_binfile1_lib} $wrong_lib_flags] != "" | |
69 | || [gdb_compile_shlib ${srcfile2_lib} ${wrong_binfile2_lib} $wrong_lib_flags] != "" | |
70 | || [gdb_compile_shlib ${srcfile1_lib} ${right_binfile1_lib} $right_lib_flags] != "" | |
71 | || [gdb_compile_shlib ${srcfile2_lib} ${right_binfile2_lib} $right_lib_flags] != "" } { | |
84c93cd5 | 72 | untested "failed to compile shared library" |
b903e17e DE |
73 | return -1 |
74 | } | |
75 | ||
76 | # Build the test binary using the right copies of the libraries. | |
77 | remote_exec build "ln -sf ${right_lib_subdir}/${libname1}.so ${binfile1_lib}" | |
78 | remote_exec build "ln -sf ${right_lib_subdir}/${libname2}.so ${binfile2_lib}" | |
08b3fe69 TT |
79 | if { [gdb_compile $srcdir/$subdir/${srcfile} ${binfile} \ |
80 | executable $bin_flags] != "" } { | |
84c93cd5 | 81 | untested "failed to compile" |
b903e17e DE |
82 | return -1 |
83 | } | |
84 | ||
85 | clean_restart $testfile | |
86 | ||
87 | if { ![runto_main] } { | |
bc6c7af4 | 88 | fail "can't run to main" |
b903e17e DE |
89 | return |
90 | } | |
91 | ||
92 | gdb_breakpoint "break_here" | |
93 | gdb_continue "break_here" | |
94 | ||
08b3fe69 | 95 | set corefile [standard_output_file solib-search.core] |
b903e17e DE |
96 | set core_supported [gdb_gcore_cmd "$corefile" "save a corefile"] |
97 | ||
98 | if {!$core_supported} { | |
99 | return -1 | |
100 | } | |
101 | ||
102 | # Before we restart gdb, replace the libs with the "wrong" ones. | |
103 | remote_exec build "ln -sf ${wrong_lib_subdir}/${libname1}.so ${binfile1_lib}" | |
104 | remote_exec build "ln -sf ${wrong_lib_subdir}/${libname2}.so ${binfile2_lib}" | |
105 | ||
106 | clean_restart $testfile | |
107 | ||
108 | set core_loaded [gdb_core_cmd $corefile "re-load generated corefile"] | |
109 | if { $core_loaded == -1 } { | |
110 | # No use proceeding from here. | |
111 | return | |
112 | } | |
113 | ||
114 | proc test_backtrace { expect_fail } { | |
115 | global gdb_prompt | |
116 | ||
117 | set count 0 | |
118 | set total_expected 5 | |
119 | ||
120 | if { $expect_fail } { | |
121 | set testname "backtrace (with wrong libs)" | |
122 | } else { | |
123 | set testname "backtrace (with right libs)" | |
124 | } | |
125 | # N.B. The order of the tests here is important. | |
126 | # We need to count each function in the backtrace, and expect matches | |
127 | # the first one it finds. | |
128 | gdb_test_multiple "backtrace" $testname { | |
129 | -re "\[^\r\n\]* in lib2_func4 \[^\r\n\]*" { | |
130 | incr count | |
131 | exp_continue | |
132 | } | |
133 | -re "\[^\r\n\]* in lib1_func3 \[^\r\n\]*" { | |
134 | incr count | |
135 | exp_continue | |
136 | } | |
137 | -re "\[^\r\n\]* in lib2_func2 \[^\r\n\]*" { | |
138 | incr count | |
139 | exp_continue | |
140 | } | |
141 | -re "\[^\r\n\]* in lib1_func1 \[^\r\n\]*" { | |
142 | incr count | |
143 | exp_continue | |
144 | } | |
145 | -re "\[^\r\n\]* in main \[^\r\n\]*" { | |
146 | incr count | |
147 | exp_continue | |
148 | } | |
149 | -re "\[\r\n\]$gdb_prompt $" { | |
150 | pass "$testname (data collection)" | |
151 | } | |
152 | } | |
153 | ||
154 | set fail 0 | |
155 | if { $expect_fail } { | |
156 | # If the backtrace output is correct the test isn't sufficiently | |
157 | # testing what it should. | |
158 | if { $count == $total_expected } { | |
159 | set fail 1 | |
160 | } | |
161 | } else { | |
162 | if { $count != $total_expected } { | |
163 | set fail 1 | |
164 | } | |
165 | } | |
166 | if { $fail } { | |
167 | fail $testname | |
168 | } else { | |
169 | pass $testname | |
170 | } | |
171 | } | |
172 | ||
173 | # Verify the backtrace is messed up. | |
174 | test_backtrace 1 | |
175 | ||
176 | # Remove the copies gdb currently sees: the absolute path is encoded in | |
177 | # the core file and we want gdb to find the right copies elsewhere. | |
178 | remote_exec build "rm -f ${binfile1_lib}" | |
179 | remote_exec build "rm -f ${binfile2_lib}" | |
180 | # Set solib-search-path to use the correct copies of libraries. | |
08b3fe69 | 181 | gdb_test "set solib-search-path [standard_output_file ${right_lib_subdir}]" \ |
5e4c3ac4 TT |
182 | "" \ |
183 | "set solib-search-path" | |
b903e17e DE |
184 | |
185 | # Verify gdb has properly updated the location of the libraries. | |
186 | test_backtrace 0 | |
187 | gdb_test "p lib1_size" " = 8192" | |
188 | gdb_test "p lib2_size" " = 8192" | |
189 |