public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Pedro Alves <palves@redhat.com>
To: gdb-patches@sourceware.org
Subject: [PATCH v2 16/25] Simplify starting the command event loop
Date: Mon, 21 Mar 2016 15:29:00 -0000	[thread overview]
Message-ID: <1458573675-15478-17-git-send-email-palves@redhat.com> (raw)
In-Reply-To: <1458573675-15478-1-git-send-email-palves@redhat.com>

All interpreter types (CLI/TUI/MI) print the prompt, and then call
start_event_loop.

Because we'll need an interpreter hook to display the
interpreter-specific prompt before going back to the event loop,
without actually starting an event loop, this patch moves the
start_event_loop call to common code, and replaces the command_loop
hook with a pre_command_look hook, that now just prints the prompt.

Turns out to be a cleanup on its own right anyway.
---
 gdb/cli/cli-interp.c | 10 +++++++++-
 gdb/cli/cli-interp.h |  2 ++
 gdb/event-top.c      | 13 -------------
 gdb/interps.c        | 16 ++++++----------
 gdb/interps.h        | 12 ++++++++----
 gdb/main.c           |  7 ++++++-
 gdb/mi/mi-interp.c   |  7 ++-----
 gdb/tui/tui-interp.c |  2 +-
 8 files changed, 34 insertions(+), 35 deletions(-)

diff --git a/gdb/cli/cli-interp.c b/gdb/cli/cli-interp.c
index 6e86e4d..11fad19 100644
--- a/gdb/cli/cli-interp.c
+++ b/gdb/cli/cli-interp.c
@@ -187,6 +187,14 @@ cli_on_command_error (void)
   display_gdb_prompt (NULL);
 }
 
+/* pre_command_loop implementation.  */
+
+void
+cli_interpreter_pre_command_loop (struct interp *self)
+{
+  display_gdb_prompt (0);
+}
+
 /* These implement the cli out interpreter: */
 
 static void *
@@ -307,7 +315,7 @@ static const struct interp_procs cli_interp_procs = {
   cli_interpreter_exec,		/* exec_proc */
   cli_ui_out,			/* ui_out_proc */
   NULL,                       	/* set_logging_proc */
-  cli_command_loop,		/* command_loop_proc */
+  cli_interpreter_pre_command_loop, /* pre_command_loop_proc */
   cli_interpreter_supports_command_editing, /* supports_command_editing_proc */
 };
 
diff --git a/gdb/cli/cli-interp.h b/gdb/cli/cli-interp.h
index 07b7505..85be118 100644
--- a/gdb/cli/cli-interp.h
+++ b/gdb/cli/cli-interp.h
@@ -22,4 +22,6 @@ struct interp;
 
 extern int cli_interpreter_supports_command_editing (struct interp *interp);
 
+extern void cli_interpreter_pre_command_loop (struct interp *self);
+
 #endif
diff --git a/gdb/event-top.c b/gdb/event-top.c
index 63f15c5..db4cb5e 100644
--- a/gdb/event-top.c
+++ b/gdb/event-top.c
@@ -131,19 +131,6 @@ rl_callback_read_char_wrapper (gdb_client_data client_data)
     (*after_char_processing_hook) ();
 }
 
-/* Initialize all the necessary variables, start the event loop,
-   register readline, and stdin, start the loop.  The DATA is the
-   interpreter data cookie, ignored for now.  */
-
-void
-cli_command_loop (void *data)
-{
-  display_gdb_prompt (0);
-
-  /* Now it's time to start the event loop.  */
-  start_event_loop ();
-}
-
 /* Change the function to be invoked every time there is a character
    ready on stdin.  This is used when the user sets the editing off,
    therefore bypassing readline, and letting gdb handle the input
diff --git a/gdb/interps.c b/gdb/interps.c
index e9c96fd..90d0de8 100644
--- a/gdb/interps.c
+++ b/gdb/interps.c
@@ -107,9 +107,6 @@ interp_new (const char *name, const struct interp_procs *procs, void *data)
   new_interp->procs = procs;
   new_interp->inited = 0;
 
-  /* Check for required procs.  */
-  gdb_assert (procs->command_loop_proc != NULL);
-
   return new_interp;
 }
 
@@ -383,16 +380,15 @@ command_interp (void)
     return ui_interp->current_interpreter;
 }
 
-/* Run the current command interpreter's main loop.  */
+/* See interps.h.  */
+
 void
-current_interp_command_loop (void)
+interp_pre_command_loop (struct interp *interp)
 {
-  struct ui_interp_info *ui_interp = get_current_interp_info ();
-  struct interp *interp = ui_interp->current_interpreter;
-
-  gdb_assert (ui_interp->current_interpreter != NULL);
+  gdb_assert (interp != NULL);
 
-  interp->procs->command_loop_proc (interp->data);
+  if (interp->procs->pre_command_loop_proc != NULL)
+    interp->procs->pre_command_loop_proc (interp);
 }
 
 /* See interp.h  */
diff --git a/gdb/interps.h b/gdb/interps.h
index 7bcc0b9..6d8930f 100644
--- a/gdb/interps.h
+++ b/gdb/interps.h
@@ -43,7 +43,7 @@ typedef int (interp_resume_ftype) (void *data);
 typedef int (interp_suspend_ftype) (void *data);
 typedef struct gdb_exception (interp_exec_ftype) (void *data,
 						  const char *command);
-typedef void (interp_command_loop_ftype) (void *data);
+typedef void (interp_pre_command_loop_ftype) (struct interp *self);
 typedef struct ui_out *(interp_ui_out_ftype) (struct interp *self);
 
 typedef int (interp_set_logging_ftype) (struct interp *self, int start_log,
@@ -70,7 +70,9 @@ struct interp_procs
      disabled.  */
   interp_set_logging_ftype *set_logging_proc;
 
-  interp_command_loop_ftype *command_loop_proc;
+  /* Called before starting an event loop, to give the interpreter a
+     chance to e.g., print a prompt.  */
+  interp_pre_command_loop_ftype *pre_command_loop_proc;
 
   /* Returns true if this interpreter supports using the readline
      library; false if it uses GDB's own simplified readline
@@ -91,8 +93,6 @@ extern struct interp *interp_set_temp (const char *name);
 
 extern int current_interp_named_p (const char *name);
 
-extern void current_interp_command_loop (void);
-
 /* Call this function to give the current interpreter an opportunity
    to do any special handling of streams when logging is enabled or
    disabled.  START_LOG is 1 when logging is starting, 0 when it ends,
@@ -115,6 +115,10 @@ extern void clear_interpreter_hooks (void);
    if it uses GDB's own simplified form of readline.  */
 extern int interp_supports_command_editing (struct interp *interp);
 
+/* Called before starting an event loop, to give the interpreter a
+   chance to e.g., print a prompt.  */
+extern void interp_pre_command_loop (struct interp *interp);
+
 /* well-known interpreters */
 #define INTERP_CONSOLE		"console"
 #define INTERP_MI1             "mi1"
diff --git a/gdb/main.c b/gdb/main.c
index d070b4d..1139487 100644
--- a/gdb/main.c
+++ b/gdb/main.c
@@ -313,7 +313,12 @@ captured_command_loop (void *data)
      here on.  */
   current_ui->async = 1;
 
-  current_interp_command_loop ();
+  /* Give the interpreter a chance to print a prompt.  */
+  interp_pre_command_loop (top_level_interpreter ());
+
+  /* Now it's time to start the event loop.  */
+  start_event_loop ();
+
   /* FIXME: cagney/1999-11-05: A correct command_loop() implementaton
      would clean things up (restoring the cleanup chain) to the state
      they were just prior to the call.  Technically, this means that
diff --git a/gdb/mi/mi-interp.c b/gdb/mi/mi-interp.c
index e1d186d..6d4936b 100644
--- a/gdb/mi/mi-interp.c
+++ b/gdb/mi/mi-interp.c
@@ -44,7 +44,6 @@
 
 static void mi_execute_command_wrapper (const char *cmd);
 static void mi_execute_command_input_handler (char *cmd);
-static void mi_command_loop (void *data);
 
 /* These are hooks that we put in place while doing interpreter_exec
    so we can report interesting things that happened "behind the MI's
@@ -323,7 +322,7 @@ mi_execute_command_input_handler (char *cmd)
 }
 
 static void
-mi_command_loop (void *data)
+mi_interpreter_pre_command_loop (struct interp *self)
 {
   /* Turn off 8 bit strings in quoted output.  Any character with the
      high bit set is printed using C's octal format.  */
@@ -331,8 +330,6 @@ mi_command_loop (void *data)
 
   /* Tell the world that we're alive.  */
   display_mi_prompt ();
-
-  start_event_loop ();
 }
 
 static void
@@ -1330,7 +1327,7 @@ static const struct interp_procs mi_interp_procs =
   mi_interpreter_exec,		/* exec_proc */
   mi_ui_out, 			/* ui_out_proc */
   mi_set_logging,		/* set_logging_proc */
-  mi_command_loop		/* command_loop_proc */
+  mi_interpreter_pre_command_loop /* pre_command_loop_proc */
 };
 
 static struct interp *
diff --git a/gdb/tui/tui-interp.c b/gdb/tui/tui-interp.c
index 2481a26..ef46837 100644
--- a/gdb/tui/tui-interp.c
+++ b/gdb/tui/tui-interp.c
@@ -273,7 +273,7 @@ static const struct interp_procs tui_interp_procs = {
   tui_exec,
   tui_ui_out,
   NULL,
-  cli_command_loop,
+  cli_interpreter_pre_command_loop,
   cli_interpreter_supports_command_editing,
 };
 
-- 
2.5.0

  parent reply	other threads:[~2016-03-21 15:29 UTC|newest]

Thread overview: 58+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-21 15:21 [PATCH v2 00/25] Towards great frontend GDB consoles Pedro Alves
2016-03-21 15:21 ` [PATCH v2 01/25] Introduce "struct ui" Pedro Alves
2016-03-21 15:21 ` [PATCH v2 03/25] Make the interpreters be per UI Pedro Alves
2016-03-21 15:21 ` [PATCH v2 12/25] Make command line editing (use of readline) " Pedro Alves
2016-03-21 15:21 ` [PATCH v2 22/25] Make main_ui be heap allocated Pedro Alves
2016-03-22 10:14   ` Yao Qi
2016-05-06 11:50     ` Pedro Alves
2016-03-21 15:21 ` [PATCH v2 02/25] Make gdb_stdout&co be per UI Pedro Alves
2016-03-21 15:22 ` [PATCH v2 24/25] Add new command to create extra console/mi UI channels Pedro Alves
2016-03-21 16:31   ` Eli Zaretskii
2016-03-21 16:51     ` Pedro Alves
2016-03-21 17:12       ` Eli Zaretskii
2016-03-21 17:57         ` Pedro Alves
2016-05-26 11:43           ` Pedro Alves
2016-05-26 15:46             ` Eli Zaretskii
2016-05-26 16:03               ` Pedro Alves
2016-05-26 16:36                 ` Eli Zaretskii
2016-05-26 16:41                   ` Pedro Alves
2016-03-21 15:22 ` [PATCH v2 18/25] Replace the sync_execution global with a new enum prompt_state tristate Pedro Alves
2016-03-21 15:22 ` [PATCH v2 13/25] Always process target events in the main UI Pedro Alves
2016-03-22 10:26   ` Yao Qi
2016-05-06 11:53     ` Pedro Alves
2016-03-21 15:26 ` [PATCH v2 10/25] Delete def_uiout Pedro Alves
2016-03-21 15:26 ` [PATCH v2 08/25] Make input_fd be per UI Pedro Alves
2016-03-22  9:46   ` Yao Qi
2016-05-06 11:53     ` Pedro Alves
2016-03-21 15:27 ` [PATCH v2 23/25] Handle UI terminal closed Pedro Alves
2016-03-21 15:27 ` [PATCH v2 09/25] Make outstream be per UI Pedro Alves
2016-03-21 15:27 ` [PATCH v2 21/25] Only send sync execution command output to the UI that ran the command Pedro Alves
2016-03-21 15:27 ` [PATCH v2 15/25] Introduce display_mi_prompt Pedro Alves
2016-03-21 15:29 ` Pedro Alves [this message]
2016-03-21 15:29 ` [PATCH v2 05/25] Make the intepreters output to all UIs Pedro Alves
2016-03-22  9:33   ` Yao Qi
2016-05-06 12:19     ` Pedro Alves
2016-03-21 15:29 ` [PATCH v2 17/25] Make gdb_in_secondary_prompt_p() be per UI Pedro Alves
2016-03-21 15:29 ` [PATCH v2 11/25] Make current_ui_out " Pedro Alves
2016-03-21 15:29 ` [PATCH v2 04/25] Introduce interpreter factories Pedro Alves
2016-03-22  8:55   ` Yao Qi
2016-05-06 11:49     ` Pedro Alves
2016-03-21 15:30 ` [PATCH v2 20/25] Push thread->control.command_interp to the struct thread_fsm Pedro Alves
2016-03-21 15:30 ` [PATCH v2 25/25] Add command to list UIs Pedro Alves
2016-03-22 10:36   ` Yao Qi
2016-05-06 11:49     ` Pedro Alves
2016-03-21 15:30 ` [PATCH v2 06/25] Always run async signal handlers in the main UI Pedro Alves
2016-03-21 15:30 ` [PATCH v2 07/25] Make instream and serial_stdin be per UI Pedro Alves
2016-03-21 15:30 ` [PATCH v2 19/25] New function should_print_stop_to_console Pedro Alves
2016-03-21 15:39 ` [PATCH v2 14/25] Make target_terminal_inferior/ours almost nops on non-main UIs Pedro Alves
2016-03-21 16:34 ` [PATCH v2 00/25] Towards great frontend GDB consoles Eli Zaretskii
2016-03-21 17:02   ` Pedro Alves
2016-03-21 17:17     ` Eli Zaretskii
2016-03-21 17:43     ` Marc Khouzam
2016-03-21 18:35 ` Marc Khouzam
2016-03-21 18:51   ` Pedro Alves
2016-03-21 19:06     ` Marc Khouzam
2016-03-21 19:12       ` Pedro Alves
2016-05-06 12:58     ` Pedro Alves
2016-03-22 10:41 ` Yao Qi
2016-05-06 11:58   ` 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=1458573675-15478-17-git-send-email-palves@redhat.com \
    --to=palves@redhat.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).