Simplify starting the command event loop
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/ChangeLog: 2016-06-21 Pedro Alves <palves@redhat.com> * cli/cli-interp.c (cli_interpreter_pre_command_loop): New function. (cli_interp_procs): Install it instead of cli_command_loop. * cli/cli-interp.h (cli_interpreter_pre_command_loop): Declare. * event-top.c (cli_command_loop): Delete. * interps.c (interp_new): Remove reference to command_loop_proc. (current_interp_command_loop): Delete. (interp_pre_command_loop): New function. (interp_command_loop_ftype): Delete. * interps.h (interp_pre_command_loop_ftype): New typedef. (struct interp_procs) <command_loop_proc>: Delele field. <pre_command_loop_proc>: New field. (current_interp_command_loop): Delete declaration. (interp_pre_command_loop): New declaration. * main.c (captured_command_loop): Call interp_pre_command_loop instead of current_interp_command_loop and start an event loop. * mi/mi-interp.c (mi_command_loop): Delete. (mi_interpreter_pre_command_loop): New. (mi_interp_procs): Update. * tui/tui-interp.c (tui_interp_procs): Install cli_interpreter_pre_command_loop instead of cli_command_loop.
This commit is contained in:
parent
9204d6922c
commit
b2d86570b3
9 changed files with 59 additions and 36 deletions
|
@ -1,3 +1,27 @@
|
||||||
|
2016-06-21 Pedro Alves <palves@redhat.com>
|
||||||
|
|
||||||
|
* cli/cli-interp.c (cli_interpreter_pre_command_loop): New
|
||||||
|
function.
|
||||||
|
(cli_interp_procs): Install it instead of cli_command_loop.
|
||||||
|
* cli/cli-interp.h (cli_interpreter_pre_command_loop): Declare.
|
||||||
|
* event-top.c (cli_command_loop): Delete.
|
||||||
|
* interps.c (interp_new): Remove reference to command_loop_proc.
|
||||||
|
(current_interp_command_loop): Delete.
|
||||||
|
(interp_pre_command_loop): New function.
|
||||||
|
(interp_command_loop_ftype): Delete.
|
||||||
|
* interps.h (interp_pre_command_loop_ftype): New typedef.
|
||||||
|
(struct interp_procs) <command_loop_proc>: Delele field.
|
||||||
|
<pre_command_loop_proc>: New field.
|
||||||
|
(current_interp_command_loop): Delete declaration.
|
||||||
|
(interp_pre_command_loop): New declaration.
|
||||||
|
* main.c (captured_command_loop): Call interp_pre_command_loop
|
||||||
|
instead of current_interp_command_loop and start an event loop.
|
||||||
|
* mi/mi-interp.c (mi_command_loop): Delete.
|
||||||
|
(mi_interpreter_pre_command_loop): New.
|
||||||
|
(mi_interp_procs): Update.
|
||||||
|
* tui/tui-interp.c (tui_interp_procs): Install
|
||||||
|
cli_interpreter_pre_command_loop instead of cli_command_loop.
|
||||||
|
|
||||||
2016-06-21 Pedro Alves <palves@redhat.com>
|
2016-06-21 Pedro Alves <palves@redhat.com>
|
||||||
|
|
||||||
* interps.c (current_interpreter): New function.
|
* interps.c (current_interpreter): New function.
|
||||||
|
|
|
@ -190,6 +190,14 @@ cli_on_command_error (void)
|
||||||
display_gdb_prompt (NULL);
|
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: */
|
/* These implement the cli out interpreter: */
|
||||||
|
|
||||||
static void *
|
static void *
|
||||||
|
@ -312,7 +320,7 @@ static const struct interp_procs cli_interp_procs = {
|
||||||
cli_interpreter_exec, /* exec_proc */
|
cli_interpreter_exec, /* exec_proc */
|
||||||
cli_ui_out, /* ui_out_proc */
|
cli_ui_out, /* ui_out_proc */
|
||||||
NULL, /* set_logging_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 */
|
cli_interpreter_supports_command_editing, /* supports_command_editing_proc */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -22,4 +22,6 @@ struct interp;
|
||||||
|
|
||||||
extern int cli_interpreter_supports_command_editing (struct interp *interp);
|
extern int cli_interpreter_supports_command_editing (struct interp *interp);
|
||||||
|
|
||||||
|
extern void cli_interpreter_pre_command_loop (struct interp *self);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -216,19 +216,6 @@ gdb_rl_callback_handler (char *rl)
|
||||||
throw_exception_sjlj (gdb_rl_expt);
|
throw_exception_sjlj (gdb_rl_expt);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 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
|
/* 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,
|
ready on stdin. This is used when the user sets the editing off,
|
||||||
therefore bypassing readline, and letting gdb handle the input
|
therefore bypassing readline, and letting gdb handle the input
|
||||||
|
|
|
@ -117,9 +117,6 @@ interp_new (const char *name, const struct interp_procs *procs, void *data)
|
||||||
new_interp->procs = procs;
|
new_interp->procs = procs;
|
||||||
new_interp->inited = 0;
|
new_interp->inited = 0;
|
||||||
|
|
||||||
/* Check for required procs. */
|
|
||||||
gdb_assert (procs->command_loop_proc != NULL);
|
|
||||||
|
|
||||||
return new_interp;
|
return new_interp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -411,16 +408,15 @@ command_interp (void)
|
||||||
return ui_interp->current_interpreter;
|
return ui_interp->current_interpreter;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Run the current command interpreter's main loop. */
|
/* See interps.h. */
|
||||||
|
|
||||||
void
|
void
|
||||||
current_interp_command_loop (void)
|
interp_pre_command_loop (struct interp *interp)
|
||||||
{
|
{
|
||||||
struct ui_interp_info *ui_interp = get_current_interp_info ();
|
gdb_assert (interp != NULL);
|
||||||
struct interp *interp = ui_interp->current_interpreter;
|
|
||||||
|
|
||||||
gdb_assert (ui_interp->current_interpreter != NULL);
|
if (interp->procs->pre_command_loop_proc != NULL)
|
||||||
|
interp->procs->pre_command_loop_proc (interp);
|
||||||
interp->procs->command_loop_proc (interp->data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* See interp.h */
|
/* See interp.h */
|
||||||
|
|
|
@ -46,7 +46,7 @@ typedef int (interp_resume_ftype) (void *data);
|
||||||
typedef int (interp_suspend_ftype) (void *data);
|
typedef int (interp_suspend_ftype) (void *data);
|
||||||
typedef struct gdb_exception (interp_exec_ftype) (void *data,
|
typedef struct gdb_exception (interp_exec_ftype) (void *data,
|
||||||
const char *command);
|
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 struct ui_out *(interp_ui_out_ftype) (struct interp *self);
|
||||||
|
|
||||||
typedef int (interp_set_logging_ftype) (struct interp *self, int start_log,
|
typedef int (interp_set_logging_ftype) (struct interp *self, int start_log,
|
||||||
|
@ -73,7 +73,9 @@ struct interp_procs
|
||||||
disabled. */
|
disabled. */
|
||||||
interp_set_logging_ftype *set_logging_proc;
|
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
|
/* Returns true if this interpreter supports using the readline
|
||||||
library; false if it uses GDB's own simplified readline
|
library; false if it uses GDB's own simplified readline
|
||||||
|
@ -100,8 +102,6 @@ extern struct interp *interp_set_temp (const char *name);
|
||||||
|
|
||||||
extern int current_interp_named_p (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
|
/* Call this function to give the current interpreter an opportunity
|
||||||
to do any special handling of streams when logging is enabled or
|
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,
|
disabled. START_LOG is 1 when logging is starting, 0 when it ends,
|
||||||
|
@ -127,6 +127,10 @@ extern void clear_interpreter_hooks (void);
|
||||||
if it uses GDB's own simplified form of readline. */
|
if it uses GDB's own simplified form of readline. */
|
||||||
extern int interp_supports_command_editing (struct interp *interp);
|
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 */
|
/* well-known interpreters */
|
||||||
#define INTERP_CONSOLE "console"
|
#define INTERP_CONSOLE "console"
|
||||||
#define INTERP_MI1 "mi1"
|
#define INTERP_MI1 "mi1"
|
||||||
|
|
|
@ -315,7 +315,12 @@ captured_command_loop (void *data)
|
||||||
here on. */
|
here on. */
|
||||||
current_ui->async = 1;
|
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
|
/* FIXME: cagney/1999-11-05: A correct command_loop() implementaton
|
||||||
would clean things up (restoring the cleanup chain) to the state
|
would clean things up (restoring the cleanup chain) to the state
|
||||||
they were just prior to the call. Technically, this means that
|
they were just prior to the call. Technically, this means that
|
||||||
|
|
|
@ -44,7 +44,6 @@
|
||||||
|
|
||||||
static void mi_execute_command_wrapper (const char *cmd);
|
static void mi_execute_command_wrapper (const char *cmd);
|
||||||
static void mi_execute_command_input_handler (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
|
/* These are hooks that we put in place while doing interpreter_exec
|
||||||
so we can report interesting things that happened "behind the MI's
|
so we can report interesting things that happened "behind the MI's
|
||||||
|
@ -329,9 +328,9 @@ mi_execute_command_input_handler (char *cmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
mi_command_loop (void *data)
|
mi_interpreter_pre_command_loop (struct interp *self)
|
||||||
{
|
{
|
||||||
struct mi_interp *mi = (struct mi_interp *) data;
|
struct mi_interp *mi = (struct mi_interp *) interp_data (self);
|
||||||
|
|
||||||
/* Turn off 8 bit strings in quoted output. Any character with the
|
/* Turn off 8 bit strings in quoted output. Any character with the
|
||||||
high bit set is printed using C's octal format. */
|
high bit set is printed using C's octal format. */
|
||||||
|
@ -339,8 +338,6 @@ mi_command_loop (void *data)
|
||||||
|
|
||||||
/* Tell the world that we're alive. */
|
/* Tell the world that we're alive. */
|
||||||
display_mi_prompt (mi);
|
display_mi_prompt (mi);
|
||||||
|
|
||||||
start_event_loop ();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -1442,7 +1439,7 @@ static const struct interp_procs mi_interp_procs =
|
||||||
mi_interpreter_exec, /* exec_proc */
|
mi_interpreter_exec, /* exec_proc */
|
||||||
mi_ui_out, /* ui_out_proc */
|
mi_ui_out, /* ui_out_proc */
|
||||||
mi_set_logging, /* set_logging_proc */
|
mi_set_logging, /* set_logging_proc */
|
||||||
mi_command_loop /* command_loop_proc */
|
mi_interpreter_pre_command_loop /* pre_command_loop_proc */
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Factory for MI interpreters. */
|
/* Factory for MI interpreters. */
|
||||||
|
|
|
@ -278,7 +278,7 @@ static const struct interp_procs tui_interp_procs = {
|
||||||
tui_exec,
|
tui_exec,
|
||||||
tui_ui_out,
|
tui_ui_out,
|
||||||
NULL,
|
NULL,
|
||||||
cli_command_loop,
|
cli_interpreter_pre_command_loop,
|
||||||
cli_interpreter_supports_command_editing,
|
cli_interpreter_supports_command_editing,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue