[gdb/testsuite] Handle remotedir in remote_upload
authorTom de Vries <tdevries@suse.de>
Mon, 20 Mar 2023 16:06:49 +0000 (17:06 +0100)
committerTom de Vries <tdevries@suse.de>
Mon, 20 Mar 2023 16:06:49 +0000 (17:06 +0100)
Dejagnu's remotedir implementation has support in remote_exec and
remote_download, but not remote_upload.

Consider the following scenario:
- downloading an executable to target,
- running it,
- uploading a file produced by the executable
while assuming remote target user remote-target with homedir
/home/remote-target and remotedir set to /home/remote-target/tmp.

Concretely, it looks like this:
...
 # binfile == "$outputs/gdb.abc/a.out"
 set target_binfile [remote_download target $binfile]
 # target_binfile == "/home/remote-target/tmp/a.out"
 remote_exec target $target_binfile
 # Running $target_binfile produced /home/remote-target/tmp/result.txt.
 set result [remote_upload target /home/remote-target/tmp/result.txt \
                 $outputs/gdb.abc/result.txt]
 # result == $outputs/gdb.abc/result.txt.
...

Add a remote_upload implementation that also handles remotedir in lib/gdb.exp,
overriding dejagnu's remote_upload, such that we can simplify the
remote_upload call to:
...
 set result [remote_upload target result.txt $outputs/gdb.abc/result.txt]
...

Tested on x86_64-linux.

PR testsuite/30250
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30250

gdb/testsuite/gdb.testsuite/board-sanity.exp
gdb/testsuite/lib/gdb.exp

index d6402262f602ac97501ae21c4e65cb496128b996..eb19db8699b958a152cec34392cef8810b7351bd 100644 (file)
@@ -77,9 +77,7 @@ proc test_remote { remote host_is_target } {
        }
 
     with_test_prefix copy-from-remote {
-       # Note: we're using $remote_file here instead of $file, otherwise
-       # this breaks with board_info remotedir.
-       set build_file [remote_upload $remote $remote_file]
+       set build_file [remote_upload $remote $file]
        gdb_assert { [string equal [file tail $build_file] $file] == 1 } \
            "remote_upload returns valid value"
        
index 86a05156e0a0fcd0c727e5b68fce5b10fc73ebf8..111a158e7ce63d41d33709db20e4b4f24295509a 100644 (file)
@@ -5917,6 +5917,21 @@ proc gdb_touch_execfile { binfile } {
     }
 }
 
+# Override of dejagnu's remote_upload, which doesn't handle remotedir.
+
+rename remote_upload dejagnu_remote_upload
+proc remote_upload { dest srcfile args } {
+    if { [is_remote $dest] && [board_info $dest exists remotedir] } {
+       set remotedir [board_info $dest remotedir]
+       if { ![string match "$remotedir*" $srcfile] } {
+           # Use hardcoded '/' as separator, as in dejagnu's remote_download.
+           set srcfile $remotedir/$srcfile
+       }
+    }
+
+    return [dejagnu_remote_upload $dest $srcfile {*}$args]
+}
+
 # Like remote_download but provides a gdb-specific behavior.
 #
 # If the destination board is remote, the local file FROMFILE is transferred as