From patchwork Sun Feb 24 16:51:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 31574 Received: (qmail 113566 invoked by alias); 24 Feb 2019 16:52:00 -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 113485 invoked by uid 89); 24 Feb 2019 16:51:59 -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=escaped, Must, Loop, noinline X-HELO: gateway22.websitewelcome.com Received: from gateway22.websitewelcome.com (HELO gateway22.websitewelcome.com) (192.185.47.48) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 24 Feb 2019 16:51:57 +0000 Received: from cm14.websitewelcome.com (cm14.websitewelcome.com [100.42.49.7]) by gateway22.websitewelcome.com (Postfix) with ESMTP id C20635F36 for ; Sun, 24 Feb 2019 10:51:55 -0600 (CST) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id xx0NgpfRk2qH7xx0NgLVpq; Sun, 24 Feb 2019 10:51:55 -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=WaBzreDKUBR+y+zkpiQui4NCi8dWXSYlubO5w2APDAY=; b=XI6l/pWU2k12S1Gai7NIk6RcHu Ngs8wLHK15WfM+F4/KH2aJ9TWEICA/3pSImq7YpHr0s9BkTIluIDk2PGLVn4oJSGE3exrXzS6bpBG CZCgcnp/cRXSSxeHcYiMhhkrb; 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 1gxx0N-001AKk-I2; Sun, 24 Feb 2019 10:51:55 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFC 02/17] Move gdb-specific code out of start_event_loop Date: Sun, 24 Feb 2019 09:51:38 -0700 Message-Id: <20190224165153.5062-3-tom@tromey.com> In-Reply-To: <20190224165153.5062-1-tom@tromey.com> References: <20190224165153.5062-1-tom@tromey.com> This moves some gdb-specific code out of start_event_loop, into a new function that must be supplied by the event-loop client. gdb/ChangeLog 2019-02-24 Tom Tromey * main.c (handle_event_loop_exception): New function. * event-loop.c: Don't include event-top.h or observable.h. (start_event_loop): Remove gdb-specific code. Call handle_event_loop_exception. * event-loop.h (handle_event_loop_exception): Declare. --- gdb/ChangeLog | 8 ++++++++ gdb/event-loop.c | 26 ++------------------------ gdb/event-loop.h | 6 +++++- gdb/main.c | 28 ++++++++++++++++++++++++++++ 4 files changed, 43 insertions(+), 25 deletions(-) diff --git a/gdb/event-loop.c b/gdb/event-loop.c index 4d05eb9a243..f41094e9add 100644 --- a/gdb/event-loop.c +++ b/gdb/event-loop.c @@ -19,7 +19,6 @@ #include "defs.h" #include "event-loop.h" -#include "event-top.h" #include "ser-event.h" #ifdef HAVE_POLL @@ -33,7 +32,6 @@ #include #include "common/gdb_sys_time.h" #include "gdb_select.h" -#include "observable.h" #include "top.h" /* Tell create_file_handler what events we are interested in. @@ -355,7 +353,7 @@ gdb_do_one_event (void) from the command loop. */ void -start_event_loop (void) +start_event_loop () { /* Loop until there is nothing to do. This is the entry point to the event loop engine. gdb_do_one_event will process one event @@ -371,27 +369,7 @@ start_event_loop (void) } CATCH (ex, RETURN_MASK_ALL) { - exception_print (gdb_stderr, ex); - - /* If any exception escaped to here, we better enable - stdin. Otherwise, any command that calls async_disable_stdin, - and then throws, will leave stdin inoperable. */ - async_enable_stdin (); - /* If we long-jumped out of do_one_event, we probably didn't - get around to resetting the prompt, which leaves readline - in a messed-up state. Reset it here. */ - current_ui->prompt_state = PROMPT_NEEDED; - gdb::observers::command_error.notify (); - /* This call looks bizarre, but it is required. If the user - entered a command that caused an error, - after_char_processing_hook won't be called from - rl_callback_read_char_wrapper. Using a cleanup there - won't work, since we want this function to be called - after a new prompt is printed. */ - if (after_char_processing_hook) - (*after_char_processing_hook) (); - /* Maybe better to set a flag to be checked somewhere as to - whether display the prompt or not. */ + handle_event_loop_exception (ex); } END_CATCH diff --git a/gdb/event-loop.h b/gdb/event-loop.h index 99b776618bd..f11b008848d 100644 --- a/gdb/event-loop.h +++ b/gdb/event-loop.h @@ -80,7 +80,7 @@ typedef void (timer_handler_func) (gdb_client_data); /* Exported functions from event-loop.c */ -extern void start_event_loop (void); +extern void start_event_loop (); extern int gdb_do_one_event (void); extern void delete_file_handler (int fd); extern void add_file_handler (int fd, handler_func *proc, @@ -131,4 +131,8 @@ extern void clear_async_event_handler (struct async_event_handler *handler); extern void initialize_async_signal_handlers (void); +/* Must be defined by client. */ + +extern void handle_event_loop_exception (const gdb_exception &); + #endif /* EVENT_LOOP_H */ diff --git a/gdb/main.c b/gdb/main.c index e14dd06fa8c..f60f0d0a092 100644 --- a/gdb/main.c +++ b/gdb/main.c @@ -48,6 +48,7 @@ #include #include "common/pathstuff.h" #include "cli/cli-style.h" +#include "observable.h" /* The selected interpreter. This will be used as a set command variable, so it should always be malloc'ed - since @@ -314,6 +315,33 @@ setup_alternate_signal_stack (void) here. */ static void captured_command_loop () __attribute__((noinline)); +/* Called to handle an exception when processing an event. */ +void +handle_event_loop_exception (const gdb_exception &ex) +{ + exception_print (gdb_stderr, ex); + + /* If any exception escaped to here, we better enable + stdin. Otherwise, any command that calls async_disable_stdin, + and then throws, will leave stdin inoperable. */ + async_enable_stdin (); + /* If we long-jumped out of do_one_event, we probably didn't + get around to resetting the prompt, which leaves readline + in a messed-up state. Reset it here. */ + current_ui->prompt_state = PROMPT_NEEDED; + gdb::observers::command_error.notify (); + /* This call looks bizarre, but it is required. If the user + entered a command that caused an error, + after_char_processing_hook won't be called from + rl_callback_read_char_wrapper. Using a cleanup there + won't work, since we want this function to be called + after a new prompt is printed. */ + if (after_char_processing_hook) + (*after_char_processing_hook) (); + /* Maybe better to set a flag to be checked somewhere as to + whether display the prompt or not. */ +} + static void captured_command_loop () {