aboutsummaryrefslogtreecommitdiff
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
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.
-rw-r--r--gdb/ChangeLog14
-rw-r--r--gdb/inferior.c35
-rw-r--r--gdb/inferior.h67
3 files changed, 66 insertions, 50 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 0f701f03c7..b739d8d0e4 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,19 @@
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.
+
+2017-04-13 Pedro Alves <palves@redhat.com>
+
* inferior.c (init_inferior_list): Delete.
* inferior.h (init_inferior_list): Delete.
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
diff --git a/gdb/inferior.h b/gdb/inferior.h
index 58fe974f3c..b5eb3d11fc 100644
--- a/gdb/inferior.h
+++ b/gdb/inferior.h
@@ -30,6 +30,8 @@ struct regcache;
struct ui_out;
struct terminal_info;
struct target_desc_info;
+struct gdb_environ;
+struct continuation;
/* For bpstat. */
#include "breakpoint.h"
@@ -305,111 +307,114 @@ struct inferior_control_state
target process ids. Each inferior may in turn have multiple
threads running in it. */
-struct inferior
+class inferior
{
+public:
+ explicit inferior (int pid);
+ ~inferior ();
+
/* Pointer to next inferior in singly-linked list of inferiors. */
- struct inferior *next;
+ struct inferior *next = NULL;
/* Convenient handle (GDB inferior id). Unique across all
inferiors. */
- int num;
+ int num = 0;
/* Actual target inferior id, usually, a process id. This matches
the ptid_t.pid member of threads of this inferior. */
- int pid;
+ int pid = 0;
/* True if the PID was actually faked by GDB. */
- int fake_pid_p;
+ bool fake_pid_p = false;
/* The highest thread number this inferior ever had. */
- int highest_thread_num;
+ int highest_thread_num = 0;
/* State of GDB control of inferior process execution.
See `struct inferior_control_state'. */
- struct inferior_control_state control;
+ inferior_control_state control {NO_STOP_QUIETLY};
/* True if this was an auto-created inferior, e.g. created from
following a fork; false, if this inferior was manually added by
the user, and we should not attempt to prune it
automatically. */
- int removable;
+ bool removable = false;
/* The address space bound to this inferior. */
- struct address_space *aspace;
+ struct address_space *aspace = NULL;
/* The program space bound to this inferior. */
- struct program_space *pspace;
+ struct program_space *pspace = NULL;
/* The arguments string to use when running. */
- char *args;
+ char *args = NULL;
/* The size of elements in argv. */
- int argc;
+ int argc = 0;
/* The vector version of arguments. If ARGC is nonzero,
then we must compute ARGS from this (via the target).
This is always coming from main's argv and therefore
should never be freed. */
- char **argv;
+ char **argv = NULL;
/* The name of terminal device to use for I/O. */
- char *terminal;
+ char *terminal = NULL;
/* Environment to use for running inferior,
in format described in environ.h. */
- struct gdb_environ *environment;
+ gdb_environ *environment = NULL;
- /* Nonzero if this child process was attached rather than
- forked. */
- int attach_flag;
+ /* True if this child process was attached rather than forked. */
+ bool attach_flag = false;
/* If this inferior is a vfork child, then this is the pointer to
its vfork parent, if GDB is still attached to it. */
- struct inferior *vfork_parent;
+ inferior *vfork_parent = NULL;
/* If this process is a vfork parent, this is the pointer to the
child. Since a vfork parent is left frozen by the kernel until
the child execs or exits, a process can only have one vfork child
at a given time. */
- struct inferior *vfork_child;
+ inferior *vfork_child = NULL;
/* True if this inferior should be detached when it's vfork sibling
exits or execs. */
- int pending_detach;
+ bool pending_detach = false;
/* True if this inferior is a vfork parent waiting for a vfork child
not under our control to be done with the shared memory region,
either by exiting or execing. */
- int waiting_for_vfork_done;
+ bool waiting_for_vfork_done = false;
/* True if we're in the process of detaching from this inferior. */
- int detaching;
+ int detaching = 0;
/* What is left to do for an execution command after any thread of
this inferior stops. For continuations associated with a
specific thread, see `struct thread_info'. */
- struct continuation *continuations;
+ continuation *continuations = NULL;
/* True if setup_inferior wasn't called for this inferior yet.
Until that is done, we must not access inferior memory or
registers, as we haven't determined the target
architecture/description. */
- int needs_setup;
+ bool needs_setup = false;
/* Private data used by the target vector implementation. */
- struct private_inferior *priv;
+ private_inferior *priv = NULL;
/* HAS_EXIT_CODE is true if the inferior exited with an exit code.
In this case, the EXIT_CODE field is also valid. */
- int has_exit_code;
- LONGEST exit_code;
+ bool has_exit_code = false;
+ LONGEST exit_code = 0;
/* Default flags to pass to the symbol reading functions. These are
used whenever a new objfile is created. */
- symfile_add_flags symfile_flags;
+ symfile_add_flags symfile_flags = 0;
/* Info about an inferior's target description (if it's fetched; the
user supplied description's filename, if any; etc.). */
- struct target_desc_info *tdesc_info;
+ target_desc_info *tdesc_info = NULL;
/* The architecture associated with the inferior through the
connection to the target.
@@ -422,7 +427,7 @@ struct inferior
per-thread/per-frame/per-objfile properties, accesses to
per-inferior/target properties should be made through
this gdbarch. */
- struct gdbarch *gdbarch;
+ struct gdbarch *gdbarch = NULL;
/* Per inferior data-pointers required by other GDB modules. */
REGISTRY_FIELDS;