From patchwork Mon Apr 15 15:56:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 88501 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1E15D3858CDA for ; Mon, 15 Apr 2024 15:56:56 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2a07:de40:b251:101:10:150:64:2]) by sourceware.org (Postfix) with ESMTPS id D76673849AF5 for ; Mon, 15 Apr 2024 15:56:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D76673849AF5 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org D76673849AF5 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a07:de40:b251:101:10:150:64:2 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713196578; cv=none; b=ixuTEFH2Qbbimcw3H7YWgoxPpznqinZMNmVHS3l45HC84ttshWqR+RScRoAo/dm3ff2Rc08zODn2+t6f6f32PTRuX4UJ/+5LpkzzNHS7AKnVyLEhfqTnI+wIaITccVTTp0mE7+/zjX7cbNyctf7TtnRBoeaH/tqy2onqBzJUmLI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713196578; c=relaxed/simple; bh=CgivRwauee3IW0afWdASLxxRL8uwwi+gyOliGdc1Lew=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:From: To:Subject:Date:Message-Id:MIME-Version; b=QKLg4wEHTwLXflgobbex20OI02nWnH0m5Du1pndItS9D7SeAuyzsZ60hYlYrI6y8BBzuQCA8Z6EvACD62x9wv3oLYg4xIUWOVBKqc3izQwBfmZZLaAs8f6ePj+W7pJP71hOD+jWuA4zngyIljJA5yQ5hqe2VhxtkrKHUB/80wD8= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 5DEAF5D2C4 for ; Mon, 15 Apr 2024 15:56:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1713196574; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=OTjTtc5WVIP76/JtfeifPONDTuhKaM+FUyS+y3+uNVU=; b=utkYooskc7hEYLZMZV936raF3AVAGbE4JreXwIBm7amFWLc+PozT8OuXvcaeu1+FuWAtVQ CM0T1LA+j05XohZAYtDBm7eXB6lWERjm2GyhygTdORQ98UeGrCDhYBnVA9CH7WbxBsZFkE VVJI4a6tgtEUJJk3+XQW4v0Db6n2JXw= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1713196574; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=OTjTtc5WVIP76/JtfeifPONDTuhKaM+FUyS+y3+uNVU=; b=eDl0Qj4/rXowBp4GNLSPbqDnb1Pmne9JLoF3uUJreZ5r8PHH5L74zBcp3aXrdAIKZ3p591 U24t+yDYLeTrL2AA== Authentication-Results: smtp-out2.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=utkYoosk; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b="eDl0Qj4/" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1713196574; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=OTjTtc5WVIP76/JtfeifPONDTuhKaM+FUyS+y3+uNVU=; b=utkYooskc7hEYLZMZV936raF3AVAGbE4JreXwIBm7amFWLc+PozT8OuXvcaeu1+FuWAtVQ CM0T1LA+j05XohZAYtDBm7eXB6lWERjm2GyhygTdORQ98UeGrCDhYBnVA9CH7WbxBsZFkE VVJI4a6tgtEUJJk3+XQW4v0Db6n2JXw= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1713196574; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=OTjTtc5WVIP76/JtfeifPONDTuhKaM+FUyS+y3+uNVU=; b=eDl0Qj4/rXowBp4GNLSPbqDnb1Pmne9JLoF3uUJreZ5r8PHH5L74zBcp3aXrdAIKZ3p591 U24t+yDYLeTrL2AA== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 47A311386E for ; Mon, 15 Apr 2024 15:56:14 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id uV8qEB5OHWaVRgAAD6G6ig (envelope-from ) for ; Mon, 15 Apr 2024 15:56:14 +0000 From: Tom de Vries 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 Message-Id: <20240415155627.22108-1-tdevries@suse.de> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 X-Spam-Score: -4.01 X-Rspamd-Action: no action X-Rspamd-Queue-Id: 5DEAF5D2C4 X-Spam-Level: X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Spamd-Result: default: False [-4.01 / 50.00]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; DWL_DNSWL_LOW(-1.00)[suse.de:dkim]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; TO_MATCH_ENVRCPT_ALL(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; FUZZY_BLOCKED(0.00)[rspamd.com]; MIME_TRACE(0.00)[0:+]; ARC_NA(0.00)[]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:104:10:150:64:97:from]; RCVD_TLS_ALL(0.00)[]; DKIM_TRACE(0.00)[suse.de:+]; RCVD_COUNT_TWO(0.00)[2]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from]; TO_DN_NONE(0.00)[]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:106:10:150:64:167:received]; PREVIOUSLY_DELIVERED(0.00)[gdb-patches@sourceware.org]; RCVD_VIA_SMTP_AUTH(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:dkim, imap1.dmz-prg2.suse.org:helo, imap1.dmz-prg2.suse.org:rdns] X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org 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(-) base-commit: 9dd918142787246ea7ed53494d9cbc6b51486133 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 } }