public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [pushed] [gdb/testsuite] Fix gdb.mi/*.exp with remote-gdbserver-on-localhost
@ 2023-03-07  9:00 Tom de Vries
  0 siblings, 0 replies; only message in thread
From: Tom de Vries @ 2023-03-07  9:00 UTC (permalink / raw)
  To: gdb-patches

When running test-cases gdb.mi/*.exp with target board
remote-gdbserver-on-localhost, we run into a few fails.

Fix these (and make things more similar to the gdb.exp procs) by:
- factoring out mi_load_shlib out of mi_load_shlibs
- making mi_load_shlib use gdb_download_shlib, like
  gdb_load_shlib
- factoring out mi_locate_shlib out of mi_load_shlib
- making mi_locate_shlib check for mi_spawn_id, like
  gdb_locate_shlib
- using gdb_download_shlib and mi_locate_shlib in the test-cases.

Tested on x86_64-linux, with and without target board
remote-gdbserver-on-localhost.
---
 gdb/testsuite/gdb.mi/mi-catch-load.exp        |  4 ++
 .../gdb.mi/mi-var-invalidate-shlib.exp        |  5 ++-
 gdb/testsuite/lib/mi-support.exp              | 40 ++++++++++++++-----
 3 files changed, 36 insertions(+), 13 deletions(-)

diff --git a/gdb/testsuite/gdb.mi/mi-catch-load.exp b/gdb/testsuite/gdb.mi/mi-catch-load.exp
index 842f4b47f1d..9d15e84d5dc 100644
--- a/gdb/testsuite/gdb.mi/mi-catch-load.exp
+++ b/gdb/testsuite/gdb.mi/mi-catch-load.exp
@@ -32,9 +32,12 @@ if { [gdb_compile_shlib "${srcdir}/${subdir}/${srcfile2}" ${binfile2} {debug}] !
     return -1
 }
 
+gdb_download_shlib $binfile2
+
 # test -catch-load
 with_test_prefix "catch-load" {
     mi_clean_restart $binfile
+    mi_locate_shlib $binfile2
     mi_runto_main
 
     mi_gdb_test "111-gdb-set auto-solib-add on" "111\\^done" \
@@ -61,6 +64,7 @@ with_test_prefix "catch-load" {
 # test -catch-unload
 with_test_prefix "catch-unload" {
     mi_clean_restart $binfile
+    mi_locate_shlib $binfile2
     mi_runto_main
 
     mi_gdb_test "111-gdb-set auto-solib-add on" "111\\^done" "auto-solib-add on"
diff --git a/gdb/testsuite/gdb.mi/mi-var-invalidate-shlib.exp b/gdb/testsuite/gdb.mi/mi-var-invalidate-shlib.exp
index 94eccdf63a0..47ac54f7088 100644
--- a/gdb/testsuite/gdb.mi/mi-var-invalidate-shlib.exp
+++ b/gdb/testsuite/gdb.mi/mi-var-invalidate-shlib.exp
@@ -30,8 +30,9 @@ if { [gdb_compile_shlib $srcdir/$subdir/$srcfile2 $shlib_path {debug}] != "" } {
     return -1
 }
 
+set shlib_path_target [gdb_download_shlib $shlib_path]
 
-set opts [list shlib_load debug additional_flags=-DSHLIB_PATH="${shlib_path}"]
+set opts [list shlib_load debug additional_flags=-DSHLIB_PATH="${shlib_path_target}"]
 if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable $opts] != "" } {
     untested "failed to compile"
     return -1
@@ -45,7 +46,7 @@ proc do_test { separate_debuginfo } {
 
     # Start the process once and create varobjs referencing the loaded objfiles.
     with_test_prefix "setup" {
-	mi_load_shlibs $::shlib_path
+	mi_locate_shlib $::shlib_path
 	if { $separate_debuginfo } {
 	    mi_load_shlibs ${::shlib_path}.debug
 	}
diff --git a/gdb/testsuite/lib/mi-support.exp b/gdb/testsuite/lib/mi-support.exp
index ab251da339c..3c2dd2fab2b 100644
--- a/gdb/testsuite/lib/mi-support.exp
+++ b/gdb/testsuite/lib/mi-support.exp
@@ -2069,20 +2069,38 @@ proc check_mi_and_console_threads {name} {
   }
 }
 
+# Set solib-search-path to allow gdb to locate shlib FILE.
+proc mi_locate_shlib { file } {
+    global mi_spawn_id
+
+    if ![info exists mi_spawn_id] {
+	perror "mi_locate_shlib: GDB is not running"
+    }
+
+    # If the target is remote, we need to tell gdb where to find the
+    # libraries.
+    if { ![is_remote target] } {
+	return
+    }
+
+    # 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.
+    mi_gdb_test "set solib-search-path [file dirname $file]" "\^done" ""
+}
+
+# Copy shlib FILE to the target and set solib-search-path to allow gdb to
+# locate it.
+proc mi_load_shlib { file } {
+    set dest [gdb_download_shlib $file]
+    mi_locate_shlib $file
+    return $dest
+}
+
 # Download shared libraries to the target.
 proc mi_load_shlibs { args } {
     foreach file $args {
-	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.
-	mi_gdb_test "set solib-search-path [file dirname [lindex $args 0]]" "\^done" ""
+	mi_load_shlib $file
     }
 }
 

base-commit: 07f285934886016ddd82cac99a3873e68b499d5c
-- 
2.35.3


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-03-07  9:00 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-07  9:00 [pushed] [gdb/testsuite] Fix gdb.mi/*.exp with remote-gdbserver-on-localhost Tom de Vries

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).