public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [PATCH v2 05/31] Convert inflow to type-safe registry API
Date: Fri, 03 May 2019 23:12:00 -0000	[thread overview]
Message-ID: <20190503231231.8954-6-tom@tromey.com> (raw)
In-Reply-To: <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  <tom@tromey.com>

	* 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<terminal_info> 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);
 }
-- 
2.17.2

  parent reply	other threads:[~2019-05-03 23:12 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-03 23:12 [PATCH v2 00/31] Add a type-safe API to registries Tom Tromey
2019-05-03 23:12 ` [PATCH v2 13/31] Convert breakpoint.c to type-safe registry API Tom Tromey
2019-05-03 23:12 ` [PATCH v2 08/31] Convert auto-load.c " Tom Tromey
2019-05-03 23:12 ` [PATCH v2 12/31] Convert linux-tdep.c " Tom Tromey
2019-05-03 23:12 ` [PATCH v2 19/31] Convert fbsd-tdep.c " Tom Tromey
2019-05-06 20:56   ` John Baldwin
2019-05-08 17:58     ` Tom Tromey
2019-05-08 22:06       ` Tom Tromey
2019-05-03 23:12 ` [PATCH v2 10/31] Convert symfile-debug.c " Tom Tromey
2019-05-03 23:12 ` [PATCH v2 07/31] Convert objfiles.c " Tom Tromey
2019-05-03 23:12 ` [PATCH v2 04/31] Convert target dcache " Tom Tromey
2019-05-03 23:12 ` [PATCH v2 20/31] Convert coffread.c " Tom Tromey
2019-05-03 23:12 ` [PATCH v2 18/31] Convert ada-tasks.c " Tom Tromey
2019-05-03 23:12 ` [PATCH v2 01/31] Add a type-safe C++ interface to a registry Tom Tromey
2019-05-03 23:12 ` [PATCH v2 24/31] Convert mdebugread.c to type-safe registry API Tom Tromey
2019-05-03 23:12 ` Tom Tromey [this message]
2019-05-03 23:12 ` [PATCH v2 23/31] Add a noop deleter Tom Tromey
2019-05-03 23:12 ` [PATCH v2 15/31] Convert solib-svr4.c to type-safe registry API Tom Tromey
2019-05-03 23:12 ` [PATCH v2 25/31] Convert elfread.c " Tom Tromey
2019-05-03 23:12 ` [PATCH v2 16/31] Convert xcoffread.c " Tom Tromey
2019-05-03 23:12 ` [PATCH v2 03/31] Convert symbol_cache " Tom Tromey
2019-05-03 23:12 ` [PATCH v2 17/31] Convert probes " Tom Tromey
2019-05-03 23:12 ` [PATCH v2 06/31] Convert break-catch-syscall.c " Tom Tromey
2019-05-03 23:12 ` [PATCH v2 21/31] Convert ada-lang.c " Tom Tromey
2019-05-03 23:13 ` [PATCH v2 09/31] Convert dwarf2_per_objfile " Tom Tromey
2019-05-03 23:13 ` [PATCH v2 14/31] Convert remote.c " Tom Tromey
2019-05-03 23:13 ` [PATCH v2 22/31] Convert nto-tdep.c " Tom Tromey
2019-05-03 23:13 ` [PATCH v2 29/31] Convert objc-lang.c " Tom Tromey
2019-05-03 23:13 ` [PATCH v2 26/31] Convert hppa-tdep.c " Tom Tromey
2019-05-03 23:13 ` [PATCH v2 28/31] Convert stabsread.c " Tom Tromey
2019-05-03 23:13 ` [PATCH v2 27/31] Remove mips_pdr_data Tom Tromey
2019-05-03 23:13 ` [PATCH v2 02/31] Convert main_info to type-safe registry API Tom Tromey
2019-05-03 23:13 ` [PATCH v2 11/31] Convert auxv.c " Tom Tromey
2019-05-03 23:31 ` [PATCH v2 31/31] Convert gdbtypes.c " Tom Tromey
2019-05-03 23:31 ` [PATCH v2 30/31] Convert dwarf2-frame.c " Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190503231231.8954-6-tom@tromey.com \
    --to=tom@tromey.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).