From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id 1AF66384402A for ; Thu, 9 Jul 2020 16:00:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 1AF66384402A Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=simark.ca Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=simark@simark.ca Received: from [10.0.0.11] (173-246-6-90.qc.cable.ebox.net [173.246.6.90]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id ACBE71E5F9; Thu, 9 Jul 2020 12:00:10 -0400 (EDT) Subject: Re: [PATCH] gdb: Don't let SIGWINCH interrupt waiting for remote target To: Andrew Burgess , gdb-patches@sourceware.org References: <20200709150228.79385-1-andrew.burgess@embecosm.com> From: Simon Marchi Message-ID: Date: Thu, 9 Jul 2020 12:00:09 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <20200709150228.79385-1-andrew.burgess@embecosm.com> Content-Type: text/plain; charset=utf-8 Content-Language: fr Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3.9 required=5.0 tests=BAYES_00, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 09 Jul 2020 16:00:12 -0000 Wow thanks, I didn't expect a patch when I filed the bug report, and especially not that fast :). > gdb/testsuite/ChangeLog: > > PR remote/26221 > * gdb.server/connect-resize-quit.exp: New file. Does the new test really belong in `gdb.server`? I would imagine that this directory contains tests specific to GDBserver. This is more a test for GDB's remote target. > + # Open a connection to a remote target, but use a port number that is > + # unlikely to actually be in use. We want this connection to block > + # waiting for a remote so we can test GDB's behaviour in this blocked > + # state. > + gdb_test_no_output "set tcp connect-timeout 2" > + > + set timeout_count 0 > + while { $timeout_count < 5} { > + # Try connecting. This should block waiting for a remote to appear. > + send_gdb "target remote :0\n" What happens when trying to connect to port 0? At first I thought it would try to connect to a random port, but that wouldn't make sense (it wouldn't be very useful). I confused that with trying to _bind_ to port 0. According to this: https://unix.stackexchange.com/questions/180492/is-it-possible-to-connect-to-tcp-port-0 It will actually try to connect to port 0, but since there's no way of binding to port 0, it will never connect. Smart! So it should be fine on Linux, I don't know about other platforms. I could imagine other OSes returning EINVAL or something like that. We'll see. > + > + # Now send a signal to GDB and follow up by sending some other command. > + set gdb_pid [exp_pid -i [board_info host fileid]] GDB's spawn id is available as $gdb_spawn_id. I don't know which is better between that and `[board_info host fileid]`, but I usually get it from $gdb_spawn_id. > + remote_exec host "kill -${sig} $gdb_pid" > + send_gdb "echo xxyyzz\\n\n" > + > + # Now try to figure out what GDB did. > + set got_timeout false > + gdb_test_multiple "" "$testname" { > + -re "^target remote :0\r\n:0: Connection timed out\\..*$gdb_prompt $" { > + # It's possible that we didn't send the signal quickly enough. > + # Maybe the testing machine is heavily loaded? > + set got_timeout true > + } > + -re "^target remote :0\r\n:0: Interrupted system call\\.\r\n$gdb_prompt.*xxyyzz.*$gdb_prompt $" { > + fail "$gdb_test_name (interrupted by $sig)" > + return > + } > + -re "^target remote :0\r\necho xxyyzz\\\\n\r.:0: Connection timed out.\r\n$gdb_prompt.*xxyyzz.*$gdb_prompt $" { > + if { $sig == "WINCH" } { > + pass $gdb_test_name > + } else { > + fail "$gdb_test_name (unexpected timeout)" > + } > + return > + } > + -re "^target remote :0\r\nQuit\r\n$gdb_prompt.*xxyyzz.*$gdb_prompt $" { > + if { $sig == "INT" } { > + pass $gdb_test_name > + } else { > + fail "$gdb_test_name (unexpected QUIT)" > + } > + return > + } > + } I don't remember, what happens if none of the -re match, will that generate a FAIL? I just want to be sure that if GDB outputs something else, we'll see a failure. Simon