aboutsummaryrefslogtreecommitdiff
path: root/gdb/inferior.c
diff options
context:
space:
mode:
authorPedro Alves <palves@redhat.com>2017-04-13 16:15:35 +0100
committerPedro Alves <palves@redhat.com>2017-04-13 16:18:16 +0100
commit0550c9559522c84341edcb334af30bc9bf2df9fb (patch)
treef8b901ca49c06e2f92bd1d0c1e1c362c11f96312 /gdb/inferior.c
parente3d60dfc000a29959c78bd69b85100aab33f7ab5 (diff)
Make inferior a class with cdtors, and use new/delete
struct inferior became a non-POD when enum_flags was made a non-POD, so we should be allocating/destroying inferiors with new/delete, etc. That's what this commit does. Note: this commit makes all boolean fields of inferior be "bool", except the "detaching" field. That'll require more work, so I split it to a separate patch. gdb/ChangeLog: 2017-04-13 Pedro Alves <palves@redhat.com> * inferior.c (free_inferior): Convert to ... (inferior::~inferior): ... this dtor. (inferior::inferior): New ctor, factored out from ... (add_inferior_silent): ... here. Allocate the inferior with a new expression. (delete_inferior): Call delete instead of free_inferior. * inferior.h (gdb_environ, continuation): Forward declare. (inferior): Now a class. Add in-class initialization to all members. Make boolean fields bool, except 'detaching'. (inferior::inferior): New explicit ctor. (inferior::~inferior): New.
Diffstat (limited to 'gdb/inferior.c')
-rw-r--r--gdb/inferior.c35
1 files changed, 16 insertions, 19 deletions
diff --git a/gdb/inferior.c b/gdb/inferior.c
index 54e9967667..327590adaa 100644
--- a/gdb/inferior.c
+++ b/gdb/inferior.c
@@ -92,9 +92,10 @@ save_current_inferior (void)
return old_chain;
}
-static void
-free_inferior (struct inferior *inf)
+inferior::~inferior ()
{
+ inferior *inf = this;
+
discard_all_inferior_continuations (inf);
inferior_free_data (inf);
xfree (inf->args);
@@ -102,38 +103,34 @@ free_inferior (struct inferior *inf)
free_environ (inf->environment);
target_desc_info_free (inf->tdesc_info);
xfree (inf->priv);
- xfree (inf);
+}
+
+inferior::inferior (int pid_)
+ : num (++highest_inferior_num),
+ pid (pid_),
+ environment (make_environ ()),
+ registry_data ()
+{
+ init_environ (this->environment);
+ inferior_alloc_data (this);
}
struct inferior *
add_inferior_silent (int pid)
{
- struct inferior *inf;
-
- inf = XNEW (struct inferior);
- memset (inf, 0, sizeof (*inf));
- inf->pid = pid;
-
- inf->control.stop_soon = NO_STOP_QUIETLY;
-
- inf->num = ++highest_inferior_num;
+ inferior *inf = new inferior (pid);
if (inferior_list == NULL)
inferior_list = inf;
else
{
- struct inferior *last;
+ inferior *last;
for (last = inferior_list; last->next != NULL; last = last->next)
;
last->next = inf;
}
- inf->environment = make_environ ();
- init_environ (inf->environment);
-
- inferior_alloc_data (inf);
-
observer_notify_inferior_added (inf);
if (pid != 0)
@@ -207,7 +204,7 @@ delete_inferior (struct inferior *todel)
if (program_space_empty_p (inf->pspace))
delete_program_space (inf->pspace);
- free_inferior (inf);
+ delete inf;
}
/* If SILENT then be quiet -- don't announce a inferior exit, or the