[pushed] Make default_mi_gdb_start/dbx_gdb_start use gdb_spawn

Pedro Alves pedro@palves.net
Sun Sep 13 19:50:06 GMT 2020


If a board file wants to customize how gdb is launched, the obvious
way is to have the board override gdb_spawn.  However, that doesn't
work for either gdb.mi/ testcases or gdb.base/dbx.exp, because
default_mi_gdb_start and dbx_gdb_start don't use gdb_spawn currently.

That is fixed by this patch.

gdb/testsuite/

	* gdb.base/dbx.exp (dbx_gdb_start): Adjust to use gdb_spawn
	instead of spawning GDB with remote_spawn.
	* lib/mi-support.exp (default_mi_gdb_start): Adjust to use
	gdb_spawn instead of spawning GDB with remote_spawn.
---
 gdb/testsuite/gdb.base/dbx.exp   | 18 ++++++++++--------
 gdb/testsuite/lib/mi-support.exp | 27 +++++++++++++--------------
 2 files changed, 23 insertions(+), 22 deletions(-)

diff --git a/gdb/testsuite/gdb.base/dbx.exp b/gdb/testsuite/gdb.base/dbx.exp
index 2a53f99a28d..5228f2e6c22 100644
--- a/gdb/testsuite/gdb.base/dbx.exp
+++ b/gdb/testsuite/gdb.base/dbx.exp
@@ -26,31 +26,33 @@ if {[build_executable $testfile.exp $testfile \
 # start gdb -- start gdb running, default procedure
 #
 proc dbx_gdb_start { } {
-    global GDB
-    global INTERNAL_GDBFLAGS GDBFLAGS
     global prompt
-    global spawn_id
     global timeout
-    verbose "Spawning $GDB -dbx $INTERNAL_GDBFLAGS $GDBFLAGS"
+    global gdb_spawn_id
 
-    if { [which $GDB] == 0 } then {
-        perror "$GDB does not exist."
-        exit 1
+    save_vars { GDBFLAGS } {
+	append GDBFLAGS " -dbx"
+
+	set res [gdb_spawn]
+	if { $res != 0} {
+	    return $res
+	}
     }
 
     set oldtimeout $timeout
     set timeout [expr "$timeout + 60"]
-    eval "spawn $GDB -dbx $INTERNAL_GDBFLAGS $GDBFLAGS"
     gdb_expect {
         -re ".*\r\n$gdb_prompt $" {
             verbose "GDB initialized."
         }
         -re "$prompt $" {
             perror "GDB never initialized."
+	    unset gdb_spawn_id
             return -1
         }
         timeout         {
             perror "(timeout) GDB never initialized."
+	    unset gdb_spawn_id
             return -1
         }
     }
diff --git a/gdb/testsuite/lib/mi-support.exp b/gdb/testsuite/lib/mi-support.exp
index 7c1dcd6f3fb..5c1fcca4d23 100644
--- a/gdb/testsuite/lib/mi-support.exp
+++ b/gdb/testsuite/lib/mi-support.exp
@@ -226,24 +226,19 @@ proc default_mi_gdb_start { args } {
 	sid_start
     }
 
-    verbose "Spawning $GDB $INTERNAL_GDBFLAGS $GDBFLAGS $MIFLAGS"
-
     if [info exists gdb_spawn_id] {
 	return 0
     }
 
-    if ![is_remote host] {
-	if { [which $GDB] == 0 } then {
-	    perror "$GDB does not exist."
-	    exit 1
+    save_vars { GDBFLAGS } {
+	append GDBFLAGS " $MIFLAGS"
+
+	set res [gdb_spawn]
+	if { $res != 0} {
+	    return $res
 	}
     }
 
-    set res [remote_spawn host "$GDB $INTERNAL_GDBFLAGS $GDBFLAGS $MIFLAGS [host_info gdb_opts]"]
-    if { $res < 0 || $res == "" } {
-	perror "Spawning $GDB failed."
-	return 1
-    }
     gdb_expect {
 	-re "~\"GNU.*\r\n~\".*$mi_gdb_prompt$" {
 	    # We have a new format mi startup prompt.  If we are
@@ -252,6 +247,7 @@ proc default_mi_gdb_start { args } {
 	    if { $MIFLAGS == "-i=mi1" } {
 		perror "(mi startup) Got unexpected new mi prompt."
 		remote_close host
+		unset gdb_spawn_id
 		return -1
 	    }
 	    verbose "GDB initialized."
@@ -263,6 +259,7 @@ proc default_mi_gdb_start { args } {
 	    if { $MIFLAGS != "-i=mi1" } {
 		perror "(mi startup) Got unexpected old mi prompt."
 		remote_close host
+		unset gdb_spawn_id
 		return -1
 	    }
 	    verbose "GDB initialized."
@@ -270,22 +267,24 @@ proc default_mi_gdb_start { args } {
 	-re ".*unrecognized option.*for a complete list of options." {
 	    untested "skip mi tests (not compiled with mi support)."
 	    remote_close host
+	    unset gdb_spawn_id
 	    return -1
 	}
 	-re ".*Interpreter `mi' unrecognized." {
 	    untested "skip mi tests (not compiled with mi support)."
 	    remote_close host
+	    unset gdb_spawn_id
 	    return -1
 	}
 	timeout {
 	    perror "(timeout) GDB never initialized after 10 seconds."
 	    remote_close host
+	    unset gdb_spawn_id
 	    return -1
 	}
     }
-    set gdb_spawn_id $res
-    set gdb_main_spawn_id $res
-    set mi_spawn_id $res
+    set gdb_main_spawn_id $gdb_spawn_id
+    set mi_spawn_id $gdb_spawn_id
 
     # FIXME: mi output does not go through pagers, so these can be removed.
     # force the height to "unlimited", so no pagers get used

base-commit: c49da0e466e1bcb6e1f363ea4a806cfd2c322cb0
-- 
2.14.5



More information about the Gdb-patches mailing list