From patchwork Wed Feb 3 16:43:55 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 10727 Received: (qmail 75884 invoked by alias); 3 Feb 2016 16:53:01 -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 75835 invoked by uid 89); 3 Feb 2016 16:53:00 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.3 required=5.0 tests=BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=trips, 27, 6, Deciding X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Wed, 03 Feb 2016 16:52:52 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (Postfix) with ESMTPS id C2D9E2C9D46 for ; Wed, 3 Feb 2016 16:44:15 +0000 (UTC) Received: from brno.lan (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u13GhwPc022971 for ; Wed, 3 Feb 2016 11:44:15 -0500 From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH 20/23] New function should_print_stop_to_console Date: Wed, 3 Feb 2016 16:43:55 +0000 Message-Id: <1454517838-7784-21-git-send-email-palves@redhat.com> In-Reply-To: <1454517838-7784-1-git-send-email-palves@redhat.com> References: <1454517838-7784-1-git-send-email-palves@redhat.com> Move this check to the cli interpreter code, so that we can reuse it in the future with both the cli and tui interpreters. --- gdb/cli/cli-interp.c | 34 ++++++++++++++++++++++++++++++++++ gdb/cli/cli-interp.h | 5 +++++ gdb/mi/mi-interp.c | 37 +++++++------------------------------ gdb/mi/mi-main.c | 2 +- 4 files changed, 47 insertions(+), 31 deletions(-) diff --git a/gdb/cli/cli-interp.c b/gdb/cli/cli-interp.c index f5fde57..07c56c0 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 @@ -48,6 +50,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 d8cfcf7..d784111 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. */ @@ -617,12 +618,14 @@ mi_on_normal_stop_1 (struct bpstats *bs, int print_frame) /* Since this can be called when CLI command is executing, using cli interpreter, be sure to use MI uiout for output, not the current one. */ - struct ui_out *mi_uiout = interp_ui_out (top_level_interpreter ()); + struct mi_interp *mi = as_mi_interp (top_level_interpreter ()); + struct ui_out *mi_uiout = mi->mi_uiout; if (print_frame) { struct thread_info *tp; int core; + struct interp *console_interp; tp = inferior_thread (); @@ -637,36 +640,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 ())) - { - struct mi_interp *mi - = (struct mi_interp *) top_level_interpreter_data (); + console_interp = interp_lookup (INTERP_CONSOLE); + if (should_print_stop_to_console (console_interp, tp)) + print_stop_event (mi->cli_uiout); - 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 e25eedf..2c39316 100644 --- a/gdb/mi/mi-main.c +++ b/gdb/mi/mi-main.c @@ -2037,7 +2037,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);