From patchwork Fri May 3 23:12:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 32513 Received: (qmail 130303 invoked by alias); 3 May 2019 23:12:39 -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 130186 invoked by uid 89); 3 May 2019 23:12:38 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-18.2 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS autolearn=ham version=3.3.1 spammy=Our X-HELO: gateway31.websitewelcome.com Received: from gateway31.websitewelcome.com (HELO gateway31.websitewelcome.com) (192.185.143.38) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 03 May 2019 23:12:36 +0000 Received: from cm17.websitewelcome.com (cm17.websitewelcome.com [100.42.49.20]) by gateway31.websitewelcome.com (Postfix) with ESMTP id 55AC8C3A8 for ; Fri, 3 May 2019 18:12:34 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id MhM2hJkVf90onMhM2hRemx; Fri, 03 May 2019 18:12:34 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=tGjZgJkEdtaIJMz/ZnDuDmadGL0WHIiKDoDvz5sFdYw=; b=Bj3/omE5ns39y5YC1XkpHvk6Lh doAhEttfmWnv/ZIHMWGQDNyEXj/CnWsm5mTE0XE9P7EhPaUkixwEdBqQHdDLiEmqmREFrTMQxcim0 AE08riQbbKhIu4phC+dAH8+Zo; Received: from 97-122-168-123.hlrn.qwest.net ([97.122.168.123]:37502 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.91) (envelope-from ) id 1hMhM2-003AAO-FS; Fri, 03 May 2019 18:12:34 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH v2 05/31] Convert inflow to type-safe registry API Date: Fri, 3 May 2019 17:12:05 -0600 Message-Id: <20190503231231.8954-6-tom@tromey.com> In-Reply-To: <20190503231231.8954-1-tom@tromey.com> References: <20190503231231.8954-1-tom@tromey.com> This changes inflow.c to use the type-safe registry API. This fixes a latent bug in swap_terminal_info, which previously said: terminal_info *info_a = (terminal_info *) inferior_data (a, inflow_inferior_data); terminal_info *info_b = (terminal_info *) inferior_data (a, inflow_inferior_data); ... both of which examine 'a'. 2019-04-22 Tom Tromey * inflow.c (struct terminal_info): Add destructor and initializers. (inflow_inferior_data): Change type. (~terminal_info): Rename from inflow_inferior_data_cleanup. (get_inflow_inferior_data, inflow_inferior_exit) (swap_terminal_info, _initialize_inflow): Update. --- gdb/ChangeLog | 9 +++++++++ gdb/inflow.c | 55 +++++++++++++++++---------------------------------- 2 files changed, 27 insertions(+), 37 deletions(-) diff --git a/gdb/inflow.c b/gdb/inflow.c index b71511308b3..339b55c0bc6 100644 --- a/gdb/inflow.c +++ b/gdb/inflow.c @@ -58,13 +58,16 @@ static struct serial *stdin_serial; the inferior is resumed in the foreground. */ struct terminal_info { + terminal_info () = default; + ~terminal_info (); + /* The name of the tty (from the `tty' command) that we gave to the inferior when it was started. */ - char *run_terminal; + char *run_terminal = nullptr; /* TTY state. We save it whenever the inferior stops, and restore it when it resumes in the foreground. */ - serial_ttystate ttystate; + serial_ttystate ttystate {}; #ifdef HAVE_TERMIOS_H /* The terminal's foreground process group. Saved whenever the @@ -80,11 +83,11 @@ struct terminal_info inf2's pgrp in the foreground instead of inf1's (which would be problematic since it would be left stopped: Ctrl-C wouldn't work, for example). */ - pid_t process_group; + pid_t process_group = 0; #endif /* fcntl flags. Saved and restored just like ttystate. */ - int tflags; + int tflags = 0; }; /* Our own tty state, which we restore every time we need to deal with @@ -623,16 +626,12 @@ child_pass_ctrlc (struct target_ops *self) } /* Per-inferior data key. */ -static const struct inferior_data *inflow_inferior_data; +static const struct inferior_key inflow_inferior_data; -static void -inflow_inferior_data_cleanup (struct inferior *inf, void *arg) +terminal_info::~terminal_info () { - struct terminal_info *info = (struct terminal_info *) arg; - - xfree (info->run_terminal); - xfree (info->ttystate); - xfree (info); + xfree (run_terminal); + xfree (ttystate); } /* Get the current svr4 data. If none is found yet, add it now. This @@ -643,12 +642,9 @@ get_inflow_inferior_data (struct inferior *inf) { struct terminal_info *info; - info = (struct terminal_info *) inferior_data (inf, inflow_inferior_data); + info = inflow_inferior_data.get (inf); if (info == NULL) - { - info = XCNEW (struct terminal_info); - set_inferior_data (inf, inflow_inferior_data, info); - } + info = inflow_inferior_data.emplace (inf); return info; } @@ -662,18 +658,8 @@ get_inflow_inferior_data (struct inferior *inf) static void inflow_inferior_exit (struct inferior *inf) { - struct terminal_info *info; - inf->terminal_state = target_terminal_state::is_ours; - - info = (struct terminal_info *) inferior_data (inf, inflow_inferior_data); - if (info != NULL) - { - xfree (info->run_terminal); - xfree (info->ttystate); - xfree (info); - set_inferior_data (inf, inflow_inferior_data, NULL); - } + inflow_inferior_data.clear (inf); } void @@ -705,13 +691,11 @@ copy_terminal_info (struct inferior *to, struct inferior *from) void swap_terminal_info (inferior *a, inferior *b) { - terminal_info *info_a - = (terminal_info *) inferior_data (a, inflow_inferior_data); - terminal_info *info_b - = (terminal_info *) inferior_data (a, inflow_inferior_data); + terminal_info *info_a = inflow_inferior_data.get (a); + terminal_info *info_b = inflow_inferior_data.get (b); - set_inferior_data (a, inflow_inferior_data, info_b); - set_inferior_data (b, inflow_inferior_data, info_a); + inflow_inferior_data.set (a, info_b); + inflow_inferior_data.set (b, info_a); std::swap (a->terminal_state, b->terminal_state); } @@ -1006,7 +990,4 @@ _initialize_inflow (void) have_job_control (); gdb::observers::inferior_exit.attach (inflow_inferior_exit); - - inflow_inferior_data - = register_inferior_data_with_cleanup (NULL, inflow_inferior_data_cleanup); }