Commit | Line | Data |
---|---|---|
88b9d363 | 1 | # Copyright 2010-2022 Free Software Foundation, Inc. |
0c5bf5a9 JK |
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 | # In some cases gdbserver cannot find the DT_DEBUG library list on its own and | |
17 | # it needs to fall back to GDB solib-svr4.c look up via symbols from the main | |
18 | # executable. | |
19 | # gdbserver :1234 ld-linux-x86-64.so.2 /bin/prog | |
20 | # gdb /bin/prog | |
21 | # (gdb) target remote ... | |
22 | ||
23 | load_lib gdbserver-support.exp | |
24 | load_lib prelink-support.exp | |
25 | ||
26 | if {[skip_gdbserver_tests] || [skip_shlib_tests]} { | |
27 | return | |
28 | } | |
29 | ||
b0963d73 | 30 | standard_testfile solib-list-main.c |
0c5bf5a9 | 31 | set srclibfile ${testfile}-lib.c |
b0963d73 | 32 | set binlibfile [standard_output_file ${testfile}.so] |
0c5bf5a9 | 33 | |
4c93b1db | 34 | if { [get_compiler_info] |
f48e22e3 SM |
35 | || [gdb_compile_shlib "${srcdir}/${subdir}/${srclibfile}" "${binlibfile}" {debug}] != "" |
36 | || [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable "shlib=${binlibfile}"] != "" } { | |
84c93cd5 | 37 | untested "failed to compile" |
0c5bf5a9 JK |
38 | return -1 |
39 | } | |
40 | ||
41 | set interp_system [section_get ${binfile} .interp] | |
42 | verbose -log "system interpreter is: $interp_system" | |
43 | ||
44 | foreach nonstop { 0 1 } { with_test_prefix "non-stop $nonstop" { | |
8dc558a0 SM |
45 | save_vars { GDBFLAGS } { |
46 | # If GDB and GDBserver are both running locally, set the sysroot to avoid | |
47 | # reading files via the remote protocol. | |
48 | if { ![is_remote host] && ![is_remote target] } { | |
49 | set GDBFLAGS "$GDBFLAGS -ex \"set sysroot\"" | |
50 | } | |
51 | ||
52 | clean_restart | |
53 | } | |
54 | ||
d9019901 | 55 | gdb_load_shlib ${binlibfile} |
0c5bf5a9 | 56 | |
f48e22e3 SM |
57 | set remote_binfile [gdb_remote_download target $binfile] |
58 | ||
59 | # When testing remote, the file path we receive may be only the file name, | |
60 | # "solib-list". ld-linux doesn't seem to be able to find the file when | |
61 | # passing just the file name, it wants either the absolute path or a | |
62 | # relative path with at least one directory component. Calling readlink on | |
63 | # the target to get the full path will make it happy. | |
64 | set remote_binfile [lindex [remote_exec target "readlink -f $remote_binfile"] 1] | |
65 | ||
0c5bf5a9 JK |
66 | # Make sure we're disconnected, in case we're testing with an |
67 | # extended-remote board, therefore already connected. | |
68 | gdb_test "disconnect" ".*" | |
69 | ||
70 | gdb_test "set non-stop $nonstop" | |
0c5bf5a9 JK |
71 | |
72 | # It is required for the non-stop mode, GDB would try to step over | |
73 | # _dl_debug_state breakpoint will still only ld.so loaded in gdbserver. | |
74 | # But GDB having symbols from the main executable it would try to use | |
75 | # displaced-stepping buffer at unmapped that time address _start. | |
76 | gdb_test "set displaced-stepping off" | |
096be756 | 77 | |
b1b53fb3 YQ |
78 | # Unset last_loaded_file because we want GDBserver spawn |
79 | # ${interp_system} not ${last_loaded_file}. | |
80 | global last_loaded_file | |
81 | unset -nocomplain last_loaded_file | |
82 | ||
096be756 PA |
83 | # Note we pass ${interp_system}, the program gdbserver spawns, as |
84 | # argument here, instead of using gdb_load, because we don't want | |
85 | # to download the interpreter to the target (it's already there) | |
86 | # or to the test output directory. | |
f48e22e3 | 87 | set res [gdbserver_spawn "${interp_system} ${remote_binfile}"] |
0c5bf5a9 JK |
88 | set gdbserver_protocol [lindex $res 0] |
89 | set gdbserver_gdbport [lindex $res 1] | |
90 | ||
91 | # Load BINFILE after gdbserver_spawn (so that gdbserver executes ld.so) | |
92 | # but before "target remote" below so that qSymbol data get already | |
93 | # initialized from BINFILE (and not from ld.so first needing a change to | |
94 | # BINFILE later). | |
3453e7e4 | 95 | gdb_test "file ${binfile}" {Reading symbols from .*\.\.\..*} "file binfile" \ |
0c5bf5a9 JK |
96 | {(Are you sure you want to change the file|Load new symbol table from ".*")\? \(y or n\) } "y" |
97 | ||
98 | set test "target $gdbserver_protocol" | |
6b9374f1 | 99 | set ok 0 |
b0237c0e | 100 | set new_symbol_table 0 |
0c5bf5a9 | 101 | gdb_test_multiple "target $gdbserver_protocol $gdbserver_gdbport" $test { |
6b9374f1 TV |
102 | -re "Remote debugging using" { |
103 | set ok 1 | |
104 | exp_continue | |
105 | } | |
106 | -re {.*Load new symbol table from ".*"\? \(y or n\) } { | |
b0237c0e | 107 | set new_symbol_table 1 |
6b9374f1 TV |
108 | send_gdb "y\n" answer |
109 | exp_continue | |
110 | } | |
111 | -re ".*\r\n$gdb_prompt " { | |
0c5bf5a9 | 112 | # Do not anchor end, there may be more output in non-stop mode. |
6b9374f1 TV |
113 | if ($ok) { |
114 | pass $test | |
115 | } else { | |
116 | fail $test | |
117 | } | |
0c5bf5a9 JK |
118 | } |
119 | } | |
b0237c0e | 120 | gdb_assert {$new_symbol_table == 1} |
0c5bf5a9 | 121 | |
0c5bf5a9 JK |
122 | gdb_test "continue" "Program received signal SIGUSR1, .*" |
123 | gdb_test "sharedlibrary" ".*" | |
124 | gdb_test "p libvar" " = 23" | |
125 | }} |