From b072645433f83d62a4b7cf857d3d50f0dd7e0c75 Mon Sep 17 00:00:00 2001 From: Tom de Vries Date: Sun, 6 Nov 2022 11:26:23 +0100 Subject: [PATCH 3/3] [gdb/testsuite] Fix gdb.base/print-file-var.exp for remote target --- gdb/testsuite/gdb.base/print-file-var.exp | 6 ++- gdb/testsuite/lib/gdb.exp | 48 +++++++++++++++++------ 2 files changed, 39 insertions(+), 15 deletions(-) diff --git a/gdb/testsuite/gdb.base/print-file-var.exp b/gdb/testsuite/gdb.base/print-file-var.exp index 9abe87d7758..abdbbbfdce4 100644 --- a/gdb/testsuite/gdb.base/print-file-var.exp +++ b/gdb/testsuite/gdb.base/print-file-var.exp @@ -59,8 +59,10 @@ proc test {hidden dlopen version_id_main lang} { set main_opts [list debug $lang] set link_opts [list debug shlib=${libobj1}] + set target_libobj2 [gdb_load_shlib $libobj2 -only-download] + if {$dlopen} { - lappend main_opts "additional_flags=-DSHLIB_NAME=\"$libobj2\"" + lappend main_opts "additional_flags=-DSHLIB_NAME=\"$target_libobj2\"" lappend link_opts "shlib_load" } else { lappend link_opts "shlib=${libobj2}" @@ -79,7 +81,7 @@ proc test {hidden dlopen version_id_main lang} { clean_restart $executable gdb_load_shlib $libobj1 - gdb_load_shlib $libobj2 + gdb_load_shlib $libobj2 -no-download if ![runto_main] { return -1 diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp index e2cda30b95a..5328afb27e8 100644 --- a/gdb/testsuite/lib/gdb.exp +++ b/gdb/testsuite/lib/gdb.exp @@ -5873,24 +5873,46 @@ proc gdb_remote_download {dest fromfile {tofile {}}} { # # Copy the listed library to the target. -proc gdb_load_shlib { file } { +proc gdb_load_shlib { file args } { global gdb_spawn_id - if ![info exists gdb_spawn_id] { - perror "gdb_load_shlib: GDB is not running" + set download 1 + set solib-search-path 1 + parse_args { + {no-download} + {only-download} + } + if { ${no-download} && ${only-download} } { + perror \ + "gdb_load_shlib: Cannot use both -no-download and -only-download" + } + if { ${no-download} } { + set download 0 + } + if { ${only-download} } { + set solib-search-path 0 } - set dest [gdb_remote_download target [shlib_target_file $file]] + set dest "" + if { $download } { + set dest [gdb_remote_download target [shlib_target_file $file]] + } - if {[is_remote target]} { - # If the target is remote, we need to tell gdb where to find the - # libraries. - # - # We could set this even when not testing remotely, but a user - # generally won't set it unless necessary. In order to make the tests - # more like the real-life scenarios, we don't set it for local testing. - gdb_test "set solib-search-path [file dirname $file]" "" \ - "set solib-search-path for [file tail $file]" + if { ${solib-search-path} } { + if ![info exists gdb_spawn_id] { + perror "gdb_load_shlib: GDB is not running" + } + + if {[is_remote target]} { + # If the target is remote, we need to tell gdb where to find the + # libraries. + # + # We could set this even when not testing remotely, but a user + # generally won't set it unless necessary. In order to make the tests + # more like the real-life scenarios, we don't set it for local testing. + gdb_test "set solib-search-path [file dirname $file]" "" \ + "set solib-search-path for [file tail $file]" + } } return $dest -- 2.35.3