From: Tom de Vries <tdevries@suse.de>
To: gdb-patches@sourceware.org
Subject: [PATCH 1/7] [gdb/testsuite] Factor out proc get_portnum
Date: Mon, 15 Apr 2024 17:56:21 +0200 [thread overview]
Message-ID: <20240415155627.22108-1-tdevries@suse.de> (raw)
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.
---
gdb/testsuite/lib/gdbserver-support.exp | 40 ++++++++++++++++++-------
1 file changed, 29 insertions(+), 11 deletions(-)
diff --git a/gdb/testsuite/lib/gdbserver-support.exp b/gdb/testsuite/lib/gdbserver-support.exp
index 727a66e2ab1..bf000119db6 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
}
}
base-commit: 9dd918142787246ea7ed53494d9cbc6b51486133
--
2.35.3
next reply other threads:[~2024-04-15 15:56 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-15 15:56 Tom de Vries [this message]
2024-04-15 15:56 ` [PATCH 2/7] [gdb/testsuite] Make portnum a persistent global Tom de Vries
2024-05-03 20:20 ` Tom Tromey
2024-04-15 15:56 ` [PATCH 3/7] [gdb/testsuite] Factor out proc with_lock Tom de Vries
2024-05-03 20:22 ` Tom Tromey
2024-04-15 15:56 ` [PATCH 4/7] [gdb/testsuite] Factor out proc lock_dir Tom de Vries
2024-05-03 20:23 ` Tom Tromey
2024-04-15 15:56 ` [PATCH 5/7] [gdb/testsuite] Move gpu-parallel.lock to cache dir Tom de Vries
2024-05-03 20:25 ` Tom Tromey
2024-04-15 15:56 ` [PATCH 6/7] [gdb/testsuite] Use unique portnum in parallel testing Tom de Vries
2024-05-03 20:27 ` Tom Tromey
2024-04-15 15:56 ` [PATCH 7/7] [gdb/testsuite] Use unique portnum in parallel testing (check//% case) Tom de Vries
2024-05-03 20:30 ` Tom Tromey
2024-05-04 7:48 ` Tom de Vries
2024-05-03 20:19 ` [PATCH 1/7] [gdb/testsuite] Factor out proc get_portnum Tom Tromey
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240415155627.22108-1-tdevries@suse.de \
--to=tdevries@suse.de \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).