From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [RFC 02/17] Move gdb-specific code out of start_event_loop
Date: Sun, 24 Feb 2019 16:52:00 -0000 [thread overview]
Message-ID: <20190224165153.5062-3-tom@tromey.com> (raw)
In-Reply-To: <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 <tom@tromey.com>
* 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 <sys/types.h>
#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 <vector>
#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 ()
{
--
2.17.2
next prev parent reply other threads:[~2019-02-24 16:52 UTC|newest]
Thread overview: 52+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-24 16:51 [RFC 00/17] Merge event loop implementations Tom Tromey
2019-02-24 16:52 ` [RFC 01/17] Remove include from event-loop.c Tom Tromey
2019-02-24 16:52 ` [RFC 16/17] Remove gdb_fildes_t Tom Tromey
2019-02-24 16:52 ` [RFC 11/17] Implement event-loop glue for gdbserver Tom Tromey
2019-02-24 16:52 ` [RFC 12/17] Add the ability to stop the event loop Tom Tromey
2019-02-24 16:52 ` Tom Tromey [this message]
2019-09-26 14:02 ` [RFC 02/17] Move gdb-specific code out of start_event_loop Pedro Alves
2019-02-24 16:52 ` [RFC 08/17] Introduce and use flush_streams Tom Tromey
2019-02-24 16:52 ` [RFC 15/17] Move gdb_notifier comment Tom Tromey
2019-09-26 14:06 ` Pedro Alves
2019-02-24 16:52 ` [RFC 03/17] Move event-loop configury to common.m4 Tom Tromey
2019-02-24 16:52 ` [RFC 07/17] Use warning in event-loop Tom Tromey
2019-09-26 14:02 ` Pedro Alves
2019-02-24 16:52 ` [RFC 13/17] Switch gdbserver to common event loop Tom Tromey
2019-02-24 16:52 ` [RFC 17/17] Simplify gdbserver's serial event handling Tom Tromey
2019-09-26 17:36 ` Pedro Alves
2019-10-04 22:08 ` Tom Tromey
2019-02-24 16:52 ` [RFC 10/17] Move event-loop.[ch] to common/ Tom Tromey
2019-09-26 14:06 ` Pedro Alves
2019-10-04 22:06 ` Tom Tromey
2019-02-24 16:52 ` [RFC 14/17] Remove some dead code from event-loop.c Tom Tromey
2019-02-24 16:52 ` [RFC 06/17] Include <chrono> in event-loop.c Tom Tromey
2019-09-26 14:02 ` Pedro Alves
2019-02-24 16:52 ` [RFC 09/17] Introduce async-event.[ch] Tom Tromey
2019-09-26 14:06 ` Pedro Alves
2019-10-04 22:17 ` Tom Tromey
2019-02-24 16:52 ` [RFC 04/17] Move gdb_select.h to common/ Tom Tromey
2019-02-24 16:52 ` [RFC 05/17] Remove gdb_usleep.c Tom Tromey
2019-09-26 14:02 ` Pedro Alves
2019-09-26 14:43 ` Tom Tromey
2019-02-24 17:14 ` [RFC 00/17] Merge event loop implementations Eli Zaretskii
2019-02-24 17:26 ` Tom Tromey
2019-02-24 17:45 ` Eli Zaretskii
2019-02-25 19:57 ` Tom Tromey
2019-02-25 20:30 ` Eli Zaretskii
2019-02-25 20:55 ` Tom Tromey
2019-02-26 16:04 ` Eli Zaretskii
2019-02-26 16:23 ` Tom Tromey
2019-02-26 16:46 ` Eli Zaretskii
2019-09-26 17:47 ` Pedro Alves
2019-09-26 23:09 ` Tom Tromey
2019-09-27 13:53 ` Pedro Alves
2019-09-27 14:05 ` Pedro Alves
2019-09-27 14:21 ` Eli Zaretskii
2019-09-27 14:53 ` Pedro Alves
2019-09-27 15:32 ` Eli Zaretskii
2019-09-27 19:10 ` Tom Tromey
2020-02-14 2:22 ` Tom Tromey
2020-02-14 17:58 ` Pedro Alves
2020-02-14 18:36 ` Tom Tromey
2019-10-04 22:25 ` Tom Tromey
2020-02-14 18:20 ` Pedro Alves
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190224165153.5062-3-tom@tromey.com \
--to=tom@tromey.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox