From patchwork Thu Oct 9 18:00:26 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 3173 Received: (qmail 20349 invoked by alias); 9 Oct 2014 18:00:35 -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 20333 invoked by uid 89); 9 Oct 2014 18:00:34 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.0 required=5.0 tests=AWL, BAYES_00, SPF_HELO_PASS, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 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; Thu, 09 Oct 2014 18:00:33 +0000 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s99I0WiZ008967 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Thu, 9 Oct 2014 14:00:32 -0400 Received: from brno.lan (ovpn01.gateway.prod.ext.ams2.redhat.com [10.39.146.11]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s99I0TSc020799 for ; Thu, 9 Oct 2014 14:00:31 -0400 From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH 1/4] Make common code handle target_terminal_* idempotency Date: Thu, 9 Oct 2014 19:00:26 +0100 Message-Id: <1412877629-12052-2-git-send-email-palves@redhat.com> In-Reply-To: <1412877629-12052-1-git-send-email-palves@redhat.com> References: <1412877629-12052-1-git-send-email-palves@redhat.com> I found a place that should be giving back the terminal to the target, but only if the target was already owning it. So I need to add a getter for who owns the terminal. The trouble is that several places/target have their own globals to track this state: - inflow.c:terminal_is_ours - remote.c:remote_async_terminal_ours_p - linux-nat.c:async_terminal_is_ours - go32-nat.c:terminal_is_ours While one might think of adding a new target_ops method to query this, conceptually, this state isn't really part of a particular target_ops. Considering multi-target, the core shouldn't have to ask all targets to know whether it's GDB that owns the terminal. There's only one GDB (or rather, only one top level interpreter). So what this comment does is add a new global that is tracked by the core instead. A subsequent pass may later remove the other globals. Tested on x86_64 Fedora 20, native and gdbserver. gdb/ 2014-10-09 Pedro Alves * target.c (enum terminal_state): New enum. (terminal_state): New global. (target_terminal_init): New function. (target_terminal_inferior): Skip if inferior already owns the terminal. (target_terminal_ours, target_terminal_ours_for_output): New functions. * target.h (target_terminal_init): Convert to function prototype. (target_terminal_ours_for_output): Convert to function prototype and tweak comment. (target_terminal_ours): Convert to function prototype and tweak comment. * windows-nat.c (do_initial_windows_stuff): Call target_terminal_init instead of child_terminal_init_with_pgrp. --- gdb/target.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ gdb/target.h | 20 +++++++------------- gdb/windows-nat.c | 2 +- 3 files changed, 64 insertions(+), 14 deletions(-) diff --git a/gdb/target.c b/gdb/target.c index 34db652..bcc736b 100644 --- a/gdb/target.c +++ b/gdb/target.c @@ -432,6 +432,35 @@ target_load (const char *arg, int from_tty) (*current_target.to_load) (¤t_target, arg, from_tty); } +/* Possible terminal states. */ + +enum terminal_state + { + /* The inferior's terminal settings are in effect. */ + terminal_is_inferior = 0, + + /* Some of our terminal settings are in effect, enough to get + proper output. */ + terminal_is_ours_for_output = 1, + + /* Our terminal settings are in effect, for output and input. */ + terminal_is_ours = 2 + }; + +static enum terminal_state terminal_state; + +/* See target.h. */ + +void +target_terminal_init (void) +{ + (*current_target.to_terminal_init) (¤t_target); + + terminal_state = terminal_is_ours; +} + +/* See target.h. */ + void target_terminal_inferior (void) { @@ -442,9 +471,36 @@ target_terminal_inferior (void) if (target_can_async_p () && !sync_execution) return; + if (terminal_state == terminal_is_inferior) + return; + /* If GDB is resuming the inferior in the foreground, install inferior's terminal modes. */ (*current_target.to_terminal_inferior) (¤t_target); + terminal_state = terminal_is_inferior; +} + +/* See target.h. */ + +void +target_terminal_ours (void) +{ + if (terminal_state == terminal_is_ours) + return; + + (*current_target.to_terminal_ours) (¤t_target); + terminal_state = terminal_is_ours; +} + +/* See target.h. */ + +void +target_terminal_ours_for_output (void) +{ + if (terminal_state != terminal_is_inferior) + return; + (*current_target.to_terminal_ours_for_output) (¤t_target); + terminal_state = terminal_is_ours_for_output; } /* See target.h. */ diff --git a/gdb/target.h b/gdb/target.h index a679228..c1ab124 100644 --- a/gdb/target.h +++ b/gdb/target.h @@ -1383,31 +1383,25 @@ extern int target_remove_breakpoint (struct gdbarch *gdbarch, /* Initialize the terminal settings we record for the inferior, before we actually run the inferior. */ -#define target_terminal_init() \ - (*current_target.to_terminal_init) (¤t_target) +extern void target_terminal_init (void); /* Put the inferior's terminal settings into effect. This is preparation for starting or resuming the inferior. */ extern void target_terminal_inferior (void); -/* Put some of our terminal settings into effect, - enough to get proper results from our output, - but do not change into or out of RAW mode - so that no input is discarded. +/* Put some of our terminal settings into effect, enough to get proper + results from our output, but do not change into or out of RAW mode + so that no input is discarded. This is a no-op if terminal_ours + was most recently called. */ - After doing this, either terminal_ours or terminal_inferior - should be called to get back to a normal state of affairs. */ - -#define target_terminal_ours_for_output() \ - (*current_target.to_terminal_ours_for_output) (¤t_target) +extern void target_terminal_ours_for_output (void); /* Put our terminal settings into effect. First record the inferior's terminal settings so they can be restored properly later. */ -#define target_terminal_ours() \ - (*current_target.to_terminal_ours) (¤t_target) +extern void target_terminal_ours (void); /* Return true if the target stack has a non-default "to_terminal_ours" method. */ diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c index 754a2d1..0f98793 100644 --- a/gdb/windows-nat.c +++ b/gdb/windows-nat.c @@ -1741,7 +1741,7 @@ do_initial_windows_stuff (struct target_ops *ops, DWORD pid, int attaching) current thread until we report an event out of windows_wait. */ inferior_ptid = pid_to_ptid (pid); - child_terminal_init_with_pgrp (pid); + target_terminal_init (); target_terminal_inferior (); windows_initialization_done = 0;