diff options
author | Tom Tromey <tom@tromey.com> | 2019-04-21 09:20:20 -0600 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2019-05-08 16:01:46 -0600 |
commit | 6509b8ebfb19769d726c16eb3a8967ac6784f621 (patch) | |
tree | 6cd0e48fcc4e659250289cb2cb5d71ac8879d3f6 /gdb | |
parent | 35632941c90f406f69512c9559ae7ba561f7eee8 (diff) | |
download | gdb-6509b8ebfb19769d726c16eb3a8967ac6784f621.zip gdb-6509b8ebfb19769d726c16eb3a8967ac6784f621.tar.gz gdb-6509b8ebfb19769d726c16eb3a8967ac6784f621.tar.bz2 |
Convert inflow to type-safe registry API
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'.
gdb/ChangeLog
2019-05-08 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.
Diffstat (limited to 'gdb')
-rw-r--r-- | gdb/ChangeLog | 9 | ||||
-rw-r--r-- | gdb/inflow.c | 55 |
2 files changed, 27 insertions, 37 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 5c8680b..e461a06 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,14 @@ 2019-05-08 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. + +2019-05-08 Tom Tromey <tom@tromey.com> + * target-dcache.c (target_dcache_cleanup): Remove. (target_dcache_aspace_key): Change type. (target_dcache_init_p, target_dcache_invalidate) diff --git a/gdb/inflow.c b/gdb/inflow.c index b715113..339b55c 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); } |