aboutsummaryrefslogtreecommitdiff
path: root/gdb/remote.c
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@ericsson.com>2017-11-24 10:39:30 -0500
committerSimon Marchi <simon.marchi@ericsson.com>2017-11-24 10:39:31 -0500
commit089354bb0613ca1559813f0a79fbe73655113785 (patch)
treec80fccf71444a91fb1103b8d750d04fcb2e71d33 /gdb/remote.c
parentd044bac8ce5e6737d13e7e5180f5a5641053e690 (diff)
downloadgdb-089354bb0613ca1559813f0a79fbe73655113785.zip
gdb-089354bb0613ca1559813f0a79fbe73655113785.tar.gz
gdb-089354bb0613ca1559813f0a79fbe73655113785.tar.bz2
Create private_inferior class hierarchy
There are currently multiple definitions of private_inferior, defined in remote.c and darwin-nat.h. The patch that poisons XNEW and friends for non-POD types trips on that, because private_inferior is freed in ~inferior(), where it is an opaque type. Since the compiler can't tell whether the type is POD, it gives an error. Also, we can't start using C++ features in these structures (make them non-POD) as long as there are multiple definitions with the same name. For these reasons, this patch makes a class hierarchy, with private_inferior being the abstract base class, and darwin_inferior & remote_inferior inheriting from it. Destruction is done through the virtual destructor. I stumbled on some suspicious code in the darwin implementation though. darwin_check_new_threads does an XCNEW(darwin_thread_t) when it finds a new thread, allocating a new structure for it (darwin_thread_t is a typedef for private_thread_info). It then VEC_safe_pushes it in a vector defined as DEF_VEC_O (a vector of objects). This means that the structure content gets copied in the vector. The thread_info object is created with the XCNEW'ed structure as the private thread info, while the rest of the code works with the instance in the vector. We have therefore two distinct instances of darwin_thread_t/private_thread_info for each thread. This is not really a problem in practice, because thread_info::priv is not used in the darwin code. I still find it weird and far from ideal, so I tried to fix it by changing the vector to be a vector of pointers. There should now be a single instance of the structure for each thread. The deallocation of the darwin_thread_t/private_thread_info structure is done by the thread_info destructor. I am able to build on macOS, but not really test, since the port seems a bit broken. I am not able to debug reliably on the machine I have access to, which runs macOS 10.12.6. gdb/ChangeLog: * inferior.h (private_inferior): Define structure type, add virtual pure destructor. (inferior) <priv>: Change type to unique_ptr. * inferior.c (private_inferior::~private_inferior): Provide default implementation. (inferior::~inferior): Don't free priv field. (exit_inferior_1): Likewise. * darwin-nat.h (struct darwin_exception_info): Initialize fields. (darwin_exception_info): Remove typedef. (DEF_VEC_O (darwin_thread_t)); Remove. (private_inferior): Rename to ... (darwin_private_inferior): ... this, extend private_inferior. (get_darwin_inferior): New. <threads>: Change type to std::vector of darwin_thread_t pointers. * darwin-nat.c (darwin_check_new_threads): Adjust. (find_inferior_task_it): Adjust. (darwin_find_thread); Adjust. (darwin_suspend_inferior): Adjust. (darwin_resume_inferior): Adjust. (darwin_find_new_inferior): Adjust. (darwin_decode_notify_message): Adjust. (darwin_send_reply): Adjust. (darwin_resume_inferior_threads): Adjust. (darwin_suspend_inferior_threads): Adjust. (darwin_decode_message): Adjust. (darwin_wait): Adjust. (darwin_interrupt): Adjust. (darwin_deallocate_threads): Adjust. (darwin_mourn_inferior): Adjust, don't free private data. (darwin_reply_to_all_pending_messages): Adjust. (darwin_stop_inferior): Adjust. (darwin_setup_exceptions): Adjust. (darwin_kill_inferior): Adjust. (darwin_setup_request_notification): Adjust. (darwin_attach_pid): Adjust. (darwin_init_thread_list): Adjust. (darwin_setup_fake_stop_event): Adjust. (darwin_attach): Adjust. (darwin_detach): Adjust. (darwin_xfer_partial): Adjust. (set_enable_mach_exceptions): Adjust. (darwin_pid_to_exec_file): Adjust. (darwin_get_ada_task_ptid): Adjust. * darwin-nat-info.c (get_task_from_args): Adjust. (info_mach_ports_command): Adjust. (info_mach_region_command): Adjust. (info_mach_exceptions_command): Adjust. * remote.c (private_inferior): Rename to ... (remote_private_inferior): ... this, initialize fields. (get_remote_inferior); New. (remote_commit_resume): Use get_remote_inferior. (check_pending_event_prevents_wildcard_vcont_callback): Likewise.
Diffstat (limited to 'gdb/remote.c')
-rw-r--r--gdb/remote.c31
1 files changed, 21 insertions, 10 deletions
diff --git a/gdb/remote.c b/gdb/remote.c
index 62ac055..5445bb2 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -5826,12 +5826,23 @@ static int is_pending_fork_parent_thread (struct thread_info *thread);
/* Private per-inferior info for target remote processes. */
-struct private_inferior
+struct remote_inferior : public private_inferior
{
/* Whether we can send a wildcard vCont for this process. */
- int may_wildcard_vcont;
+ bool may_wildcard_vcont = true;
};
+/* Get the remote private inferior data associated to INF. */
+
+static remote_inferior *
+get_remote_inferior (inferior *inf)
+{
+ if (inf->priv == NULL)
+ inf->priv.reset (new remote_inferior);
+
+ return static_cast<remote_inferior *> (inf->priv.get ());
+}
+
/* Structure used to track the construction of a vCont packet in the
outgoing packet buffer. This is used to send multiple vCont
packets if we have more actions than would fit a single packet. */
@@ -5993,9 +6004,9 @@ remote_commit_resume (struct target_ops *ops)
/* And assume every process is individually wildcard-able too. */
ALL_NON_EXITED_INFERIORS (inf)
{
- if (inf->priv == NULL)
- inf->priv = XNEW (struct private_inferior);
- inf->priv->may_wildcard_vcont = 1;
+ remote_inferior *priv = get_remote_inferior (inf);
+
+ priv->may_wildcard_vcont = true;
}
/* Check for any pending events (not reported or processed yet) and
@@ -6008,7 +6019,7 @@ remote_commit_resume (struct target_ops *ops)
can't wildcard that process. */
if (!tp->executing)
{
- tp->inf->priv->may_wildcard_vcont = 0;
+ get_remote_inferior (tp->inf)->may_wildcard_vcont = false;
/* And if we can't wildcard a process, we can't wildcard
everything either. */
@@ -6042,7 +6053,7 @@ remote_commit_resume (struct target_ops *ops)
if (!remote_thr->last_resume_step
&& remote_thr->last_resume_sig == GDB_SIGNAL_0
- && tp->inf->priv->may_wildcard_vcont)
+ && get_remote_inferior (tp->inf)->may_wildcard_vcont)
{
/* We'll send a wildcard resume instead. */
remote_thr->vcont_resumed = 1;
@@ -6062,7 +6073,7 @@ remote_commit_resume (struct target_ops *ops)
ALL_NON_EXITED_INFERIORS (inf)
{
- if (inf->priv->may_wildcard_vcont)
+ if (get_remote_inferior (inf)->may_wildcard_vcont)
{
any_process_wildcard = 1;
break;
@@ -6083,7 +6094,7 @@ remote_commit_resume (struct target_ops *ops)
{
ALL_NON_EXITED_INFERIORS (inf)
{
- if (inf->priv->may_wildcard_vcont)
+ if (get_remote_inferior (inf)->may_wildcard_vcont)
{
vcont_builder_push_action (&vcont_builder,
pid_to_ptid (inf->pid),
@@ -6579,7 +6590,7 @@ check_pending_event_prevents_wildcard_vcont_callback
we'd resume this process too. */
*may_global_wildcard_vcont = 0;
if (inf != NULL)
- inf->priv->may_wildcard_vcont = 0;
+ get_remote_inferior (inf)->may_wildcard_vcont = false;
return 1;
}