[PATCH 5/57][Arm][GAS] Add support for MVE instructions: vmull{b,t}
[binutils-gdb.git] / gdb / testsuite / gdb.base / solib-search.exp
blobfd4d45e0fd68ad84d218c397613fa760a724a7e3
1 # Copyright 2013-2019 Free Software Foundation, Inc.
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.
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.
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/>.
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.
19 if {[is_remote target] || [skip_shlib_tests]} {
20     untested "skipping remote target and shared library tests"
21     return -1
24 # This is required by gdb_compile_shlib.
25 if {[get_compiler_info]} {
26     warning "Could not get compiler info"
27     untested "no compiler info"
28     return 1
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"
35 # First library file.
36 set libname1 "solib-search-lib1"
37 set srcfile1_lib ${srcdir}/${subdir}/${libname1}.c
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]
42 # Second library file.
43 set libname2 "solib-search-lib2"
44 set srcfile2_lib ${srcdir}/${subdir}/${libname2}.c
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]
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.
52 set binfile1_lib [standard_output_file ${libname1}.so]
53 set binfile2_lib [standard_output_file ${libname2}.so]
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"
59 # Binary file.
60 standard_testfile .c
61 set bin_flags [list debug shlib=${binfile1_lib} shlib=${binfile2_lib}]
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}]"
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] != "" } {
72     untested "failed to compile shared library"
73     return -1
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}"
79 if { [gdb_compile $srcdir/$subdir/${srcfile} ${binfile} \
80           executable $bin_flags] != "" } {
81     untested "failed to compile"
82     return -1
85 clean_restart $testfile
87 if { ![runto_main] } {
88     fail "can't run to main"
89     return
92 gdb_breakpoint "break_here"
93 gdb_continue "break_here"
95 set corefile [standard_output_file solib-search.core]
96 set core_supported [gdb_gcore_cmd "$corefile" "save a corefile"]
98 if {!$core_supported} {
99   return -1
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}"
106 clean_restart $testfile
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
114 proc test_backtrace { expect_fail } {
115     global gdb_prompt
117     set count 0
118     set total_expected 5
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     }
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     }
173 # Verify the backtrace is messed up.
174 test_backtrace 1
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.
181 gdb_test "set solib-search-path [standard_output_file ${right_lib_subdir}]" \
182     "" \
183     "set solib-search-path"
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"