[2/7,gdb/testsuite] Make portnum a persistent global

Message ID 20240415155627.22108-2-tdevries@suse.de
State New
Headers
Series [1/7,gdb/testsuite] Factor out proc get_portnum |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Testing passed
linaro-tcwg-bot/tcwg_gdb_check--master-arm success Testing passed
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 success Testing passed

Commit Message

Tom de Vries April 15, 2024, 3:56 p.m. UTC
  When instrumenting get_portnum using:
...
    puts "PORTNUM: $res"
...
and running:
...
$ cd build/gdb
$ make check TESTS=gdb.server/*.exp
...
we get:
...
Running gdb.server/target-exec-file.exp ...
PORTNUM: 2345
Running gdb.server/stop-reply-no-thread-multi.exp ...
PORTNUM: 2345
PORTNUM: 2346
PORTNUM: 2347
PORTNUM: 2348
PORTNUM: 2349
PORTNUM: 2350
...

So, while get_portnum does return increasing numbers in a single test-case, it
restarts at each test-case.

This is a regression since the introduction of persistent globals.

Fix this by using "gdb_persistent_global portnum", such that we get:
...
Running gdb.server/target-exec-file.exp ...
PORTNUM: 2345
Running gdb.server/stop-reply-no-thread-multi.exp ...
PORTNUM: 2346
PORTNUM: 2347
PORTNUM: 2348
PORTNUM: 2349
PORTNUM: 2350
PORTNUM: 2351
...

Tested on aarch64-linux.
---
 gdb/testsuite/lib/gdbserver-support.exp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Patch

diff --git a/gdb/testsuite/lib/gdbserver-support.exp b/gdb/testsuite/lib/gdbserver-support.exp
index bf000119db6..0f97ce9c0fd 100644
--- a/gdb/testsuite/lib/gdbserver-support.exp
+++ b/gdb/testsuite/lib/gdbserver-support.exp
@@ -142,7 +142,7 @@  proc get_portnum {} {
     set initial_portnum 2345
 
     # Currently available port number.
-    global portnum
+    gdb_persistent_global portnum
 
     # Initialize, if necessary.
     if { ![info exists portnum] } {