aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom de Vries <tdevries@suse.de>2024-05-04 10:41:09 +0200
committerTom de Vries <tdevries@suse.de>2024-05-04 10:41:09 +0200
commitb6dfea2438b61116f7883926b3a3819277788752 (patch)
treebc879eb8203f27360fe867355ae57c679a511ebc
parentf4b228ee68fc411a6db0f0b86ae6071c98f5e8a3 (diff)
downloadbinutils-b6dfea2438b61116f7883926b3a3819277788752.zip
binutils-b6dfea2438b61116f7883926b3a3819277788752.tar.gz
binutils-b6dfea2438b61116f7883926b3a3819277788752.tar.bz2
[gdb/testsuite] Factor out proc get_portnum
In gdbserver_start, we have some code that determines what port number to use: ... # Port id -- either specified in baseboard file, or managed here. if [target_info exists gdb,socketport] { set portnum [target_info gdb,socketport] } else { # Bump the port number to avoid conflicts with hung ports. incr portnum } ... Factor this out into a new proc get_portnum. Tested on aarch64-linux. Approved-By: Tom Tromey <tom@tromey.com>
-rw-r--r--gdb/testsuite/lib/gdbserver-support.exp40
1 files changed, 29 insertions, 11 deletions
diff --git a/gdb/testsuite/lib/gdbserver-support.exp b/gdb/testsuite/lib/gdbserver-support.exp
index 727a66e2..bf00011 100644
--- a/gdb/testsuite/lib/gdbserver-support.exp
+++ b/gdb/testsuite/lib/gdbserver-support.exp
@@ -129,8 +129,31 @@ proc gdb_target_cmd { args } {
return [expr $res == 0 ? 0 : 1]
}
-global portnum
-set portnum "2345"
+# Return a usable port number.
+
+proc get_portnum {} {
+ if { [target_info exists gdb,socketport] } {
+ # Hard-coded in target board.
+ return [target_info gdb,socketport]
+ }
+
+ # Not hard-coded in target board. Return increasing port numbers,
+ # starting at $initial_portnum, to avoid conflicts with hung ports.
+ set initial_portnum 2345
+
+ # Currently available port number.
+ global portnum
+
+ # Initialize, if necessary.
+ if { ![info exists portnum] } {
+ set portnum $initial_portnum
+ }
+
+ # Return currently available port number, and update it.
+ set res $portnum
+ incr portnum
+ return $res
+}
# Locate the gdbserver binary. Returns "" if gdbserver could not be found.
@@ -247,16 +270,10 @@ proc gdbserver_default_get_comm_port { port } {
# Returns the target protocol and socket to connect to.
proc gdbserver_start { options arguments } {
- global portnum
global GDB_TEST_SOCKETHOST
# Port id -- either specified in baseboard file, or managed here.
- if [target_info exists gdb,socketport] {
- set portnum [target_info gdb,socketport]
- } else {
- # Bump the port number to avoid conflicts with hung ports.
- incr portnum
- }
+ set portnum [get_portnum]
# Extract the local and remote host ids from the target board struct.
if { [info exists GDB_TEST_SOCKETHOST] } {
@@ -372,10 +389,11 @@ proc gdbserver_start { options arguments } {
-re "Listening on" { }
-re "Can't (bind address|listen on socket): Address already in use\\.\r\n" {
verbose -log "Port $portnum is already in use."
- if ![target_info exists gdb,socketport] {
+ set other_portnum [get_portnum]
+ if { $other_portnum != $portnum } {
# Bump the port number to avoid the conflict.
wait -i $expect_out(spawn_id)
- incr portnum
+ set portnum $other_portnum
continue
}
}