From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 392E03858D37 for ; Fri, 17 Nov 2023 11:18:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 392E03858D37 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 392E03858D37 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700219928; cv=none; b=qWZIQx5uxB4+Y4ZlEOwOUiuYcErZUr9KZKQ8PerJZmMb56VPMQe8ntcb+BtewrDt0cImGRpirITMz3Tx6KySAUiN1Ca+r5F+KYUOK8i4trTlriuRv3Em7AVVJ3Gu3FjCGls04is3F9XwmV4H8qlV83qbmzlQO2nGCyCly62Iz4M= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700219928; c=relaxed/simple; bh=RcTHOJCgBOUwTTfL6zkbIE70k2Arbkm3Y+CJz5WETw0=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=wZxFjfoANcey+ePAG4ru+RtQ9AX8fm3ZgYgdVRCz6Tkmt3mf6+CMLkU9IHXBxTR8FggJy7HRFipX+k0u+9Mu66X9g+/aQESdUgR0bXpqAWq20t4Fj/vcTXNRkpTTH/Br/OTzktFWR9vmspSyBJfJR4wdcBvioNbbmg7vwN9mkPo= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700219926; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rSaHTZPBHJuOkDb0G6wsHLD8YsJmXMl8KvMC1ULM7mE=; b=RfPRYWDHsj4AdsdTtWd7c1Xv7cBKzCp9PV6cU4nrMzO1n4b/9UsQyljkOlxNbFE+IQTH6O us/0uu1ysEXdwylkieYtdTA5PQeZlc2qG7lbBikSlP0X+pFn2tZLfmXtpqsdEg1I1bLWr6 F/BizLi4BD1kt4uvsNfVv4IjpU0G+iE= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-608-E3m_ChBwPvyAR-LU0vXmuQ-1; Fri, 17 Nov 2023 06:18:45 -0500 X-MC-Unique: E3m_ChBwPvyAR-LU0vXmuQ-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8122538116E0 for ; Fri, 17 Nov 2023 11:18:45 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.45.242.6]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6B7DC2026D4C; Fri, 17 Nov 2023 11:18:44 +0000 (UTC) From: =?UTF-8?q?Alexandra=20H=C3=A1jkov=C3=A1?= To: gdb-patches@sourceware.org Cc: ahajkova@redhat.com Subject: [PATCH 1/6] gdb.server/non-existing-program.exp: Use gdbserver_start. Date: Fri, 17 Nov 2023 12:18:35 +0100 Message-ID: <20231117111840.2040709-2-ahajkova@redhat.com> In-Reply-To: <20231117111840.2040709-1-ahajkova@redhat.com> References: <20231117111840.2040709-1-ahajkova@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-10.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Also modify GDBserver_start to match more messages from the server and return them to the caller. This test tests if GDBserver exits cleanly when GDBserver is called using stdio with some program that does not exist. My series modifies the GDBserver in such a way, it defers starting the inferior till certain packets arrive when stdio is used. The result was, when GDBserver was called using stdio with some nonexistent file, it was waiting for those packets to come but since GDB was never attached, they would never do so and the test timed out. Running GDBserver using stdio without planning to attach there with GDB is not a realistic situation and what the user would normally do. The test was modifyied to start GDBserver with a port number instead of stdio by calling GDBserver_start proc which was modifyied to return a message from GDBserver. --- .../gdb.server/non-existing-program.exp | 54 +++++----------- gdb/testsuite/lib/gdbserver-support.exp | 62 +++++++++++++------ 2 files changed, 58 insertions(+), 58 deletions(-) diff --git a/gdb/testsuite/gdb.server/non-existing-program.exp b/gdb/testsuite/gdb.server/non-existing-program.exp index eea1eb1d911..99b98e1222c 100644 --- a/gdb/testsuite/gdb.server/non-existing-program.exp +++ b/gdb/testsuite/gdb.server/non-existing-program.exp @@ -30,44 +30,20 @@ if { $gdbserver == "" } { return } -# Fire off gdbserver. The port doesn't really matter, gdbserver tries -# to spawn the program before opening the connection. -set spawn_id [remote_spawn target "$gdbserver stdio non-existing-program"] - -set msg "gdbserver exits cleanly" -set saw_exiting 0 -expect { - # This is what we get on ptrace-based targets with - # startup-with-shell disabled (e.g., when the SHELL variable is - # unset). - -re "stdin/stdout redirected.*gdbserver: Cannot exec non-existing-program\r\ngdbserver: Error: No such file or directory\r\n\r\nDuring startup program exited with code 127\.\r\nExiting\r\n" { - set saw_exiting 1 - exp_continue - } - # Likewise, but with startup-with-shell enabled, which is the - # default behaviour. - -re "stdin/stdout redirected.*exec: non-existing-program: not found\r\nDuring startup program exited with code 127\.\r\nExiting\r\n" { - set saw_exiting 1 - exp_continue - } - # This is what we get on Windows. - -re "Error creating process\r\n\r\nExiting\r\n" { - set saw_exiting 1 - exp_continue - } - -re "A problem internal to GDBserver has been detected" { - fail "$msg (GDBserver internal error)" - wait - } - eof { - gdb_assert $saw_exiting $msg - wait +foreach_with_prefix start_with_shell { on off } { + if { $start_with_shell } { + set arg "--startup-with-shell" + } else { + set arg "--no-startup-with-shell" } - timeout { - fail "$msg (timeout)" - } -} -# expect defaults to spawn_id in many places. Avoid confusing any -# following code. -unset spawn_id + set msg "GDBserver exits cleanly" + set res [gdbserver_start $arg non-existent-file] + set status [lindex $res 2] + + # We expect GDBserver to fail with the message indicating executable + # does not exist. + gdb_assert { $status == "During startup program exited with code 127\.\r\nExiting\r\n" + || $status == "Error creating process\r\n\r\nExiting\r\n"} $msg + +} diff --git a/gdb/testsuite/lib/gdbserver-support.exp b/gdb/testsuite/lib/gdbserver-support.exp index 30d94fd7eb6..aa22315ef92 100644 --- a/gdb/testsuite/lib/gdbserver-support.exp +++ b/gdb/testsuite/lib/gdbserver-support.exp @@ -244,7 +244,8 @@ proc gdbserver_default_get_comm_port { port } { # Start a gdbserver process with initial OPTIONS and trailing ARGUMENTS. # The port will be filled in between them automatically. # -# Returns the target protocol and socket to connect to. +# Returns the target protocol, socket to connect to and the status +# message from the gdbserver. proc gdbserver_start { options arguments } { global portnum @@ -363,33 +364,56 @@ proc gdbserver_start { options arguments } { # talk to the program using GDBserver's tty instead. global inferior_spawn_id set inferior_spawn_id $server_spawn_id + set msg 0 # Wait for the server to open its TCP socket, so that GDB can connect. expect { - -i $server_spawn_id - -timeout 120 - -notransfer - -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] { - # Bump the port number to avoid the conflict. - wait -i $expect_out(spawn_id) - incr portnum - continue - } - } - -re ".*: cannot resolve name: .*\r\n" { - error "gdbserver cannot resolve name." - } - timeout { + -i $server_spawn_id + -timeout 120 + -notransfer + -re "Listening on" { + set msg $expect_out(0,string) + } + -re "Can't (bind address|listen on socket): Address already in use\\.\r\n" { + verbose -log "Port $portnum is already in use." + set msg "Port is already in use" + if ![target_info exists gdb,socketport] { + # Bump the port number to avoid the conflict. + wait -i $expect_out(spawn_id) + incr portnum + continue + } + } + -re ".*: cannot resolve name: .*\r\n" { + error "gdbserver cannot resolve name." + } + # Likewise, but with startup-with-shell enabled, which is the + # default behaviour. + -re "During startup program exited with code 127\.\r\nExiting\r\n" { + set msg $expect_out(0,string) + exp_continue + } + -re "Can't bind address: Address already in use\.\r\nExiting\r\n" { + set msg $expect_out(0,string) + exp_continue + } + # This is what we get on Windows. + -re "Error creating process\r\n\r\nExiting\r\n" { + set msg $expect_out(0,string) + exp_continue + } + -re "A problem internal to GDBserver has been detected" { + set msg $expect_out(0,string) + wait + } + timeout { error "Timeout waiting for gdbserver response." } } break } - return [list $protocol [$get_remote_address $debughost $portnum]] + return [list $protocol [$get_remote_address $debughost $portnum] $msg] } # Start a gdbserver process running SERVER_EXEC, and connect GDB -- 2.41.0