From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 115104 invoked by alias); 24 Feb 2019 16:52:08 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 114781 invoked by uid 89); 24 Feb 2019 16:52:06 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=Functions, Really, tracing, rid X-HELO: gateway23.websitewelcome.com Received: from gateway23.websitewelcome.com (HELO gateway23.websitewelcome.com) (192.185.50.108) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 24 Feb 2019 16:52:01 +0000 Received: from cm14.websitewelcome.com (cm14.websitewelcome.com [100.42.49.7]) by gateway23.websitewelcome.com (Postfix) with ESMTP id 6EC3A1247F for ; Sun, 24 Feb 2019 10:52:00 -0600 (CST) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id xx0SgpfTT2qH7xx0SgLVrY; Sun, 24 Feb 2019 10:52:00 -0600 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=pGcipDCOWJ+3FQ0wPzJ98cBxXMOnlYiRUCkuUsgs7Eo=; b=bf9CfjFQZvNoQ01vWvoASKbi6U I5Qp9EMOynzzECXyQWEW7EIqIUBtQx2jKQwcGdbustcVARMQRSq3nW6Knh76NvpXF9U8PLD+fuwPo KPieBwcRBb3DV1rQl6qxacJNZ; Received: from 75-166-72-210.hlrn.qwest.net ([75.166.72.210]:44502 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.91) (envelope-from ) id 1gxx0S-001AKk-5J; Sun, 24 Feb 2019 10:52:00 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFC 17/17] Simplify gdbserver's serial event handling Date: Sun, 24 Feb 2019 16:52:00 -0000 Message-Id: <20190224165153.5062-18-tom@tromey.com> In-Reply-To: <20190224165153.5062-1-tom@tromey.com> References: <20190224165153.5062-1-tom@tromey.com> X-SW-Source: 2019-02/txt/msg00399.txt.bz2 Currently, when gdbserver handles a serial event, it also calls 'reschedule' to install a timer that is then used to process any data that remains after the previous packet was processed. It seemed better to me to simply have the file descriptor callback loop, processing packets until complete. 2019-02-24 Tom Tromey * server.h (handle_serial_event): Update. * server.c (handle_serial_event): Return int. Remove parameters. * remote-utils.c (readchar_callback): Remove. (handle_accept_event, remote_open): Use handle_all_serial_events. (readchar): Don't call reschedule. (reset_readchar): Update. (process_remaining, reschedule): Remove. (handle_all_serial_events): New function. --- gdb/gdbserver/ChangeLog | 11 ++++++++ gdb/gdbserver/remote-utils.c | 53 +++++++++++++----------------------- gdb/gdbserver/server.c | 10 +++---- gdb/gdbserver/server.h | 2 +- 4 files changed, 35 insertions(+), 41 deletions(-) diff --git a/gdb/gdbserver/remote-utils.c b/gdb/gdbserver/remote-utils.c index b1e4e869b69..7b41090efcc 100644 --- a/gdb/gdbserver/remote-utils.c +++ b/gdb/gdbserver/remote-utils.c @@ -83,13 +83,9 @@ enum { NOT_SCHEDULED = -1 }; -/* Status of the readchar callback. - Either NOT_SCHEDULED or the callback id. */ -static int readchar_callback = NOT_SCHEDULED; - static int readchar (void); static void reset_readchar (void); -static void reschedule (void); +static void handle_all_serial_events (int err, gdb_client_data client_data); /* A cache entry for a successfully looked-up symbol. */ struct sym_cache @@ -204,7 +200,7 @@ handle_accept_event (int err, gdb_client_data client_data) enable_async_notification (remote_desc); /* Register the event loop handler. */ - add_file_handler (remote_desc, handle_serial_event, NULL); + add_file_handler (remote_desc, handle_all_serial_events, NULL); /* We have a new GDB connection now. If we were disconnected tracing, there's a window where the target could report a stop @@ -341,7 +337,7 @@ remote_open (const char *name) enable_async_notification (remote_desc); /* Register the event loop handler. */ - add_file_handler (remote_desc, handle_serial_event, NULL); + add_file_handler (remote_desc, handle_all_serial_events, NULL); } #ifndef USE_WIN32API else if (port_str == NULL) @@ -382,7 +378,7 @@ remote_open (const char *name) enable_async_notification (remote_desc); /* Register the event loop handler. */ - add_file_handler (remote_desc, handle_serial_event, NULL); + add_file_handler (remote_desc, handle_all_serial_events, NULL); } #endif /* USE_WIN32API */ else @@ -879,9 +875,9 @@ initialize_async_io (void) #endif } -/* Internal buffer used by readchar. - These are global to readchar because reschedule_remote needs to be - able to tell whether the buffer is empty. */ +/* Internal buffer used by readchar. These are global to readchar + because handle_all_serial_events needs to be able to tell whether + the buffer is empty. */ static unsigned char readchar_buf[BUFSIZ]; static int readchar_bufcnt = 0; @@ -916,7 +912,6 @@ readchar (void) readchar_bufcnt--; ch = *readchar_bufp++; - reschedule (); return ch; } @@ -926,33 +921,23 @@ static void reset_readchar (void) { readchar_bufcnt = 0; - if (readchar_callback != NOT_SCHEDULED) - { - delete_timer (readchar_callback); - readchar_callback = NOT_SCHEDULED; - } } -/* Process remaining data in readchar_buf. */ +/* Loop, calling handle_serial_event, until there is no more data + available. */ static void -process_remaining (void *context) +handle_all_serial_events (int err, gdb_client_data client_data) { - /* This is a one-shot event. */ - readchar_callback = NOT_SCHEDULED; - - if (readchar_bufcnt > 0) - handle_serial_event (0, NULL); -} - -/* If there is still data in the buffer, queue another event to process it, - we can't sleep in select yet. */ - -static void -reschedule (void) -{ - if (readchar_bufcnt > 0 && readchar_callback == NOT_SCHEDULED) - readchar_callback = create_timer (0, process_remaining, NULL); + do + { + if (handle_serial_event () < 0) + { + stop_event_loop (); + break; + } + } + while (readchar_bufcnt > 0); } /* Read a packet from the remote machine, with error checking, diff --git a/gdb/gdbserver/server.c b/gdb/gdbserver/server.c index 42147c1d836..3732d53cfbc 100644 --- a/gdb/gdbserver/server.c +++ b/gdb/gdbserver/server.c @@ -4389,22 +4389,20 @@ process_serial_event (void) /* Event-loop callback for serial events. */ -void -handle_serial_event (int err, gdb_client_data client_data) +int +handle_serial_event () { if (debug_threads) debug_printf ("handling possible serial event\n"); /* Really handle it. */ if (process_serial_event () < 0) - { - stop_event_loop (); - return; - } + return -1; /* Be sure to not change the selected thread behind GDB's back. Important in the non-stop mode asynchronous protocol. */ set_desired_thread (); + return 0; } /* Push a stop notification on the notification queue. */ diff --git a/gdb/gdbserver/server.h b/gdb/gdbserver/server.h index e6a8dcc9bf1..9ffc9e0c958 100644 --- a/gdb/gdbserver/server.h +++ b/gdb/gdbserver/server.h @@ -83,7 +83,7 @@ extern int non_stop; /* Functions from server.c. */ extern void handle_v_requests (char *own_buf, int packet_len, int *new_packet_len); -extern void handle_serial_event (int err, gdb_client_data client_data); +extern int handle_serial_event (); extern void handle_target_event (int err, gdb_client_data client_data); /* Get rid of the currently pending stop replies that match PTID. */ -- 2.17.2