From patchwork Wed Oct 14 15:28:05 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 9125 Received: (qmail 415 invoked by alias); 14 Oct 2015 15:36:06 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 403 invoked by uid 89); 14 Oct 2015 15:36:06 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL, BAYES_00, SPF_HELO_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Wed, 14 Oct 2015 15:36:05 +0000 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (Postfix) with ESMTPS id E98FC461C8 for ; Wed, 14 Oct 2015 15:28:24 +0000 (UTC) Received: from brno.lan (ovpn01.gateway.prod.ext.ams2.redhat.com [10.39.146.11]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t9EFS6Dq016846 for ; Wed, 14 Oct 2015 11:28:24 -0400 From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH 17/18] gdbserver: don't exit until GDB disconnects Date: Wed, 14 Oct 2015 16:28:05 +0100 Message-Id: <1444836486-25679-18-git-send-email-palves@redhat.com> In-Reply-To: <1444836486-25679-1-git-send-email-palves@redhat.com> References: <1444836486-25679-1-git-send-email-palves@redhat.com> When testing with "target remote" with "maint set target-non-stop on", we regressions like this: Running /home/pedro/gdb/mygit/build/../src/gdb/testsuite/gdb.threads/continue-pending-after-query.exp ... FAIL: gdb.threads/continue-pending-after-query.exp: iter 4: continue until exit FAIL: gdb.threads/continue-pending-after-query.exp: iter 6: continue until exit FAIL: gdb.threads/continue-pending-after-query.exp: iter 10: continue until exit === gdb Summary === # of expected passes 28 # of unexpected failures 3 where gdb.log shows: continue Continuing. Remote communication error. Target disconnected.: Connection reset by peer. (gdb) FAIL: gdb.threads/continue-pending-after-query.exp: iter 4: continue until exit Enabling gdb + gdbserver debug logs we see: gdbserver: <<<< exiting linux_wait_1 gdbserver: handling possible serial event gdbserver: Writing resume reply for LWP 11089.11089:0 gdbserver: handling possible serial event gdbserver: GDBserver exiting GDB: Packet received: OK GDB: infrun: prepare_to_wait GDB: Sending packet: $vStopped#55...Packet received: W0;process:2b51 GDB: Sending packet: $vStopped#55...Packet received: OK GDB: infrun: target_wait (-1.0.0, status) = GDB: infrun: -1.0.0 [Thread 0], GDB: infrun: status->kind = no-resumed GDB: Sending packet: $Hgp2b51.2b51#41...Remote connection closed (gdb) FAIL: gdb.threads/continue-pending-after-query.exp: iter 1: continue until exit Notice the "Packet received: W0;process:2b51" followed by vStopped->OK. That means the process exit notification was successfully sent to GDB and GDB fetched it. That makes gdbserver exit, in server.c:process_serial_event: if (!extended_protocol && have_ran && !target_running ()) { /* In non-stop, defer exiting until GDB had a chance to query the whole vStopped list (until it gets an OK). */ if (QUEUE_is_empty (notif_event_p, notif_stop.queue)) { /* Be transparent when GDB is connected through stdio -- no need to spam GDB's console. */ if (!remote_connection_is_stdio ()) fprintf (stderr, "GDBserver exiting\n"); remote_close (); exit (0); } } However, GDB is still busy processing an earlier "no-resumed" event, and sends a "Hg" packet, which errors out with "Remote connection closed". IOW, it's not enough to wait for GDB to query the whole vStopped list, gdbserver needs to wait until the exit event is really processed. The fix is to make gdbserver not disconnect until gdb does. Tested on x86_64 Fedora, native gdbserver, remote + extended-remote + with and without "maint set target-non-stop on". gdb/gdbserver/ChangeLog: 2015-10-14 Pedro Alves * remote-utils.c (readchar): Don't print "Got EOF" unless debugging gdbserver. * server.c (captured_main): Exit gdbserver if gdb disconnects when in "target remote" mode and there are no processes left to debug. (process_serial_event): Remove 'have_ran' static local and remove logic that exits gdbserver in "target remote" mode. --- gdb/gdbserver/remote-utils.c | 5 ++++- gdb/gdbserver/server.c | 40 ++++++++++++++-------------------------- 2 files changed, 18 insertions(+), 27 deletions(-) diff --git a/gdb/gdbserver/remote-utils.c b/gdb/gdbserver/remote-utils.c index 77280f7..05e3d63 100644 --- a/gdb/gdbserver/remote-utils.c +++ b/gdb/gdbserver/remote-utils.c @@ -882,7 +882,10 @@ readchar (void) if (readchar_bufcnt <= 0) { if (readchar_bufcnt == 0) - fprintf (stderr, "readchar: Got EOF\n"); + { + if (remote_debug) + fprintf (stderr, "readchar: Got EOF\n"); + } else perror ("readchar"); diff --git a/gdb/gdbserver/server.c b/gdb/gdbserver/server.c index d83d608..5a9b471 100644 --- a/gdb/gdbserver/server.c +++ b/gdb/gdbserver/server.c @@ -3677,11 +3677,21 @@ captured_main (int argc, char *argv[]) start_event_loop (); /* If an exit was requested (using the "monitor exit" - command), terminate now. The only other way to get - here is for getpkt to fail; close the connection - and reopen it at the top of the loop. */ + command), terminate now. */ + if (exit_requested) + throw_quit ("Quit"); + + /* The only other way to get here is for getpkt to fail: + + - If --once was specified, we're done. - if (exit_requested || run_once) + - If not in extended-remote mode, and we're no longer + debugging anything, simply exit: GDB has disconnected + after processing the last process exit. + + - Otherwise, close the connection and reopen it at the + top of the loop. */ + if (run_once || (!extended_protocol && !target_running ())) throw_quit ("Quit"); fprintf (stderr, @@ -3846,13 +3856,6 @@ process_serial_event (void) int packet_len; int new_packet_len = -1; - /* Used to decide when gdbserver should exit in - multi-mode/remote. */ - static int have_ran = 0; - - if (!have_ran) - have_ran = target_running (); - disable_async_io (); response_needed = 0; @@ -4291,21 +4294,6 @@ process_serial_event (void) response_needed = 0; - if (!extended_protocol && have_ran && !target_running ()) - { - /* In non-stop, defer exiting until GDB had a chance to query - the whole vStopped list (until it gets an OK). */ - if (QUEUE_is_empty (notif_event_p, notif_stop.queue)) - { - /* Be transparent when GDB is connected through stdio -- no - need to spam GDB's console. */ - if (!remote_connection_is_stdio ()) - fprintf (stderr, "GDBserver exiting\n"); - remote_close (); - exit (0); - } - } - if (exit_requested) return -1;