[gdb/testsuite] Set remotedir by default in some boards

When doing a gdb_simple_compile, and downloading the resulting exec $obj
to target the result $target_obj may be a relative file path, which may give
problems when trying to do:
...
remote_exec target $target_obj
...

Fix/workaround this on some target boards by setting remotedir by default, and
add a corresponding test in gdb.testsuite/board-sanity.exp.

This doesn't work for host/target board local-remote-host-native, so xfail this.

Tested on x86_64-linux.
This commit is contained in:
Tom de Vries
2023-03-17 16:06:39 +01:00
parent 0eb0e08287
commit 3741934fdb
3 changed files with 75 additions and 14 deletions

View File

@@ -37,22 +37,35 @@ if { [info exists REMOTE_TARGET_USERNAME] } {
}
set_board_info hostname localhost
# Handle separate test account.
if { [board_info $board username] != $env(USER) } {
# We're pretending that some local user account is remote target.
# Make things a bit more realistic by restricting file permissions.
save_vars {rsh_cmd res} {
set rsh_cmd \
[join \
[list \
[board_info $board rsh_prog] \
-l [board_info $board username] \
[board_info $board hostname]]]
# Make sure remote target can't see files on build.
remote_exec build "chmod go-rx $objdir"
# Handle separate test account.
if { [board_info $board username] != $env(USER) } {
# We're pretending that some local user account is remote target.
# Make things a bit more realistic by restricting file permissions.
# Make sure build can't see files on remote target. We can't use
# remote_exec target, because we're in the middle of parsing the
# target board.
remote_exec build \
"[board_info $board rsh_prog] \
-l [board_info $board username] \
[board_info $board hostname] \
chmod go-rx ."
# Make sure remote target can't see files on build.
remote_exec build "chmod go-rx $objdir"
# Make sure build can't see files on remote target. We can't use
# remote_exec target, because we're in the middle of parsing the
# target board.
remote_exec build $rsh_cmd chmod go-rx ."
}
# Set remotedir by default, to force remote_download target to give an
# absolute file name.
set res [remote_exec build $rsh_cmd pwd]
if { [lindex $res 0] != 0 } {
error "Couldn't set remotedir using pwd"
}
set_board_info remotedir [string trim [lindex $res 1]]
}
proc ${board}_file { dest op args } {

View File

@@ -45,6 +45,22 @@ set_board_info rcp_prog /usr/bin/scp
# Some remote machines don't have writable home directories.
if [info exists REMOTE_TMPDIR] {
set_board_info remotedir $REMOTE_TMPDIR
} else {
# Set remotedir by default, to force remote_download target to give an
# absolute file name.
save_vars {rsh_cmd res} {
set rsh_cmd \
[join \
[list \
[board_info $board rsh_prog] \
-l [board_info $board username] \
[board_info $board hostname]]]
set res [remote_exec build $rsh_cmd pwd]
if { [lindex $res 0] != 0 } {
error "Couldn't set remotedir using pwd"
}
set_board_info remotedir [string trim [lindex $res 1]]
}
}
if [info exists GDBSERVER] {

View File

@@ -120,3 +120,35 @@ foreach_with_prefix remote {host target} {
test_remote $remote $host_is_target
}
}
proc_with_prefix gdb_simple_compile_and_run {} {
set src {
int main() {
return 0;
}
}
set test "compile"
if {![gdb_simple_compile board-sanity $src executable]} {
fail $test
return
}
pass $test
set target_obj [gdb_remote_download target $obj]
set result [remote_exec target $target_obj]
set status [lindex $result 0]
set output [lindex $result 1]
if { [host_info name] == "local-remote-host-native"
&& [target_info name] == "local-remote-host-native" } {
# Setting remotedir on this board has effect on both host and
# target, and it seems to broken for host. Xfail this for now.
setup_xfail *-*-*
}
gdb_assert { $status == 0 && $output == "" }
remote_file build delete $obj
}
gdb_simple_compile_and_run