aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPedro Alves <palves@redhat.com>2016-06-21 01:11:52 +0100
committerPedro Alves <palves@redhat.com>2016-06-21 01:11:52 +0100
commit26cde2cc30c25ba4d5666ea502db51ee6cb5b069 (patch)
tree53fbaa24468a33fab9765222e0ce7cb7ddf3b8d9
parenta8836c9358a11055a08d11ecacc5d7c8f6d5e7a8 (diff)
downloadgdb-26cde2cc30c25ba4d5666ea502db51ee6cb5b069.zip
gdb-26cde2cc30c25ba4d5666ea502db51ee6cb5b069.tar.gz
gdb-26cde2cc30c25ba4d5666ea502db51ee6cb5b069.tar.bz2
New function should_print_stop_to_console
There's code in the MI interpreter that decides whether a stop should be sent to MI's console stream. Move this check to the CLI interpreter code, so that we can reuse it in both the CLI and TUI interpreters. gdb/ChangeLog: 2016-06-21 Pedro Alves <palves@redhat.com> * cli/cli-interp.c: Include gdbthread.h and thread-fsm.h. (should_print_stop_to_console): New function, factored out from mi_on_normal_stop_1. * cli/cli-interp.h (should_print_stop_to_console): Declare. * mi/mi-interp.c (mi_on_normal_stop_1): Use should_print_stop_to_console. Pass it the current UI's console interpreter. * mi/mi-main.c (captured_mi_execute_command): Use the INTERP_CONSOLE symbol rather than explicit "console".
-rw-r--r--gdb/ChangeLog12
-rw-r--r--gdb/cli/cli-interp.c34
-rw-r--r--gdb/cli/cli-interp.h5
-rw-r--r--gdb/mi/mi-interp.c27
-rw-r--r--gdb/mi/mi-main.c2
5 files changed, 56 insertions, 24 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index bc681d9..49ea003 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,17 @@
2016-06-21 Pedro Alves <palves@redhat.com>
+ * cli/cli-interp.c: Include gdbthread.h and thread-fsm.h.
+ (should_print_stop_to_console): New function, factored out from
+ mi_on_normal_stop_1.
+ * cli/cli-interp.h (should_print_stop_to_console): Declare.
+ * mi/mi-interp.c (mi_on_normal_stop_1): Use
+ should_print_stop_to_console. Pass it the current UI's console
+ interpreter.
+ * mi/mi-main.c (captured_mi_execute_command): Use the
+ INTERP_CONSOLE symbol rather than explicit "console".
+
+2016-06-21 Pedro Alves <palves@redhat.com>
+
* infcmd.c (prepare_execution_command): Use
all_uis_on_sync_execution_starting.
* infrun.c (all_uis_on_sync_execution_starting): New function.
diff --git a/gdb/cli/cli-interp.c b/gdb/cli/cli-interp.c
index 40cbe35..b0eef29 100644
--- a/gdb/cli/cli-interp.c
+++ b/gdb/cli/cli-interp.c
@@ -27,6 +27,8 @@
#include "event-top.h"
#include "infrun.h"
#include "observer.h"
+#include "gdbthread.h"
+#include "thread-fsm.h"
/* The console interpreter. */
struct cli_interp
@@ -51,6 +53,38 @@ static struct gdb_exception safe_execute_command (struct ui_out *uiout,
char *command,
int from_tty);
+/* See cli-interp.h.
+
+ Breakpoint hits should always be mirrored to a console. Deciding
+ what to mirror to a console wrt to breakpoints and random stops
+ gets messy real fast. E.g., say "s" trips on a breakpoint. We'd
+ clearly want to mirror the event to the console in this case. But
+ what about more complicated cases like "s&; thread n; s&", and one
+ of those steps spawning a new thread, and that thread hitting a
+ breakpoint? It's impossible in general to track whether the thread
+ had any relation to the commands that had been executed. So we
+ just simplify and always mirror breakpoints and random events to
+ all consoles.
+
+ OTOH, we should print the source line to the console when stepping
+ or other similar commands, iff the step was started by that console
+ (or in MI's case, by a console command), but not if it was started
+ with MI's -exec-step or similar. */
+
+int
+should_print_stop_to_console (struct interp *console_interp,
+ struct thread_info *tp)
+{
+ if ((bpstat_what (tp->control.stop_bpstat).main_action
+ == BPSTAT_WHAT_STOP_NOISY)
+ || !(tp->thread_fsm != NULL
+ && thread_fsm_finished_p (tp->thread_fsm))
+ || (tp->control.command_interp != NULL
+ && tp->control.command_interp == console_interp))
+ return 1;
+ return 0;
+}
+
/* Observers for several run control events. If the interpreter is
quiet (i.e., another interpreter is being run with
interpreter-exec), print nothing. */
diff --git a/gdb/cli/cli-interp.h b/gdb/cli/cli-interp.h
index 85be118..004b967 100644
--- a/gdb/cli/cli-interp.h
+++ b/gdb/cli/cli-interp.h
@@ -24,4 +24,9 @@ extern int cli_interpreter_supports_command_editing (struct interp *interp);
extern void cli_interpreter_pre_command_loop (struct interp *self);
+/* Returns true if the current stop should be printed to
+ CONSOLE_INTERP. */
+extern int should_print_stop_to_console (struct interp *interp,
+ struct thread_info *tp);
+
#endif
diff --git a/gdb/mi/mi-interp.c b/gdb/mi/mi-interp.c
index 5db61e1..76238ec 100644
--- a/gdb/mi/mi-interp.c
+++ b/gdb/mi/mi-interp.c
@@ -38,6 +38,7 @@
#include "tracepoint.h"
#include "cli-out.h"
#include "thread-fsm.h"
+#include "cli/cli-interp.h"
/* These are the interpreter setup, etc. functions for the MI
interpreter. */
@@ -686,6 +687,7 @@ mi_on_normal_stop_1 (struct bpstats *bs, int print_frame)
{
struct thread_info *tp;
int core;
+ struct interp *console_interp;
tp = inferior_thread ();
@@ -700,31 +702,10 @@ mi_on_normal_stop_1 (struct bpstats *bs, int print_frame)
}
print_stop_event (mi_uiout);
- /* Breakpoint hits should always be mirrored to the console.
- Deciding what to mirror to the console wrt to breakpoints and
- random stops gets messy real fast. E.g., say "s" trips on a
- breakpoint. We'd clearly want to mirror the event to the
- console in this case. But what about more complicated cases
- like "s&; thread n; s&", and one of those steps spawning a
- new thread, and that thread hitting a breakpoint? It's
- impossible in general to track whether the thread had any
- relation to the commands that had been executed. So we just
- simplify and always mirror breakpoints and random events to
- the console.
-
- OTOH, we should print the source line to the console when
- stepping or other similar commands, iff the step was started
- by a console command, but not if it was started with
- -exec-step or similar. */
- if ((bpstat_what (tp->control.stop_bpstat).main_action
- == BPSTAT_WHAT_STOP_NOISY)
- || !(tp->thread_fsm != NULL
- && thread_fsm_finished_p (tp->thread_fsm))
- || (tp->control.command_interp != NULL
- && tp->control.command_interp != top_level_interpreter ()))
+ console_interp = interp_lookup (current_ui, INTERP_CONSOLE);
+ if (should_print_stop_to_console (console_interp, tp))
print_stop_event (mi->cli_uiout);
- tp = inferior_thread ();
ui_out_field_int (mi_uiout, "thread-id", tp->global_num);
if (non_stop)
{
diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
index 8e51edc..188547b 100644
--- a/gdb/mi/mi-main.c
+++ b/gdb/mi/mi-main.c
@@ -2042,7 +2042,7 @@ captured_mi_execute_command (struct ui_out *uiout, struct mi_parse *context)
/* Echo the command on the console. */
fprintf_unfiltered (gdb_stdlog, "%s\n", context->command);
/* Call the "console" interpreter. */
- argv[0] = "console";
+ argv[0] = INTERP_CONSOLE;
argv[1] = context->command;
mi_cmd_interpreter_exec ("-interpreter-exec", argv, 2);