From: Pedro Alves <palves@redhat.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 6/8] Make inferior a class with cdtors, and use new/delete
Date: Tue, 11 Apr 2017 23:51:00 -0000 [thread overview]
Message-ID: <1491954673-29172-7-git-send-email-palves@redhat.com> (raw)
In-Reply-To: <1491954673-29172-1-git-send-email-palves@redhat.com>
A following patch in this series will add a private field to struct
inferior, making it a non-POD, which requires allocating/destroying
inferiors with new/delete, etc.
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:
yyyy-mm-dd 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.
---
gdb/inferior.c | 35 ++++++++++++++----------------
gdb/inferior.h | 67 +++++++++++++++++++++++++++++++---------------------------
2 files changed, 52 insertions(+), 50 deletions(-)
diff --git a/gdb/inferior.c b/gdb/inferior.c
index 54e9967..327590a 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 29ec7be..2638ac7 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;
--
2.5.5
next prev parent reply other threads:[~2017-04-11 23:51 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-04-11 23:51 [PATCH 0/8] Fix removing inferiors from within "thread apply" commands Pedro Alves
2017-04-11 23:51 ` [PATCH 2/8] Fix follow-fork latent bug Pedro Alves
2017-04-13 9:58 ` Yao Qi
2017-04-13 12:09 ` Pedro Alves
2017-04-13 15:33 ` Yao Qi
2017-04-11 23:51 ` [PATCH 1/8] watch_command_1: Fix dangling frame access Pedro Alves
2017-04-13 9:34 ` Yao Qi
2017-04-13 15:26 ` Pedro Alves
2017-04-11 23:51 ` [PATCH 8/8] Fix removing inferiors from within "thread apply" commands Pedro Alves
2017-04-13 11:33 ` Yao Qi
2017-04-13 12:22 ` Pedro Alves
2017-04-13 14:49 ` Pedro Alves
2017-04-19 8:23 ` Yao Qi
2017-04-19 12:15 ` Pedro Alves
2017-04-19 12:20 ` Pedro Alves
2017-04-13 15:31 ` Yao Qi
2017-04-11 23:51 ` Pedro Alves [this message]
2017-04-13 10:24 ` [PATCH 6/8] Make inferior a class with cdtors, and use new/delete Yao Qi
2017-04-11 23:51 ` [PATCH 7/8] Make inferior::detaching a bool, and introduce scoped_restore::release() Pedro Alves
2017-04-11 23:51 ` [PATCH 3/8] C++fy thread_apply_all_command Pedro Alves
2017-04-13 10:06 ` Yao Qi
2017-04-11 23:56 ` [PATCH 5/8] GC inferior.c:init_inferior_list Pedro Alves
2017-04-13 10:10 ` Yao Qi
2017-04-11 23:56 ` [PATCH 4/8] Improve coverage of the PR threads/13217 regression test Pedro Alves
2017-04-13 10:09 ` Yao Qi
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=1491954673-29172-7-git-send-email-palves@redhat.com \
--to=palves@redhat.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