diff options
author | Simon Marchi <simon.marchi@ericsson.com> | 2017-11-24 10:39:30 -0500 |
---|---|---|
committer | Simon Marchi <simon.marchi@ericsson.com> | 2017-11-24 10:39:31 -0500 |
commit | 089354bb0613ca1559813f0a79fbe73655113785 (patch) | |
tree | c80fccf71444a91fb1103b8d750d04fcb2e71d33 /gdb/darwin-nat-info.c | |
parent | d044bac8ce5e6737d13e7e5180f5a5641053e690 (diff) | |
download | fsf-binutils-gdb-089354bb0613ca1559813f0a79fbe73655113785.zip fsf-binutils-gdb-089354bb0613ca1559813f0a79fbe73655113785.tar.gz fsf-binutils-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/darwin-nat-info.c')
-rw-r--r-- | gdb/darwin-nat-info.c | 48 |
1 files changed, 26 insertions, 22 deletions
diff --git a/gdb/darwin-nat-info.c b/gdb/darwin-nat-info.c index 44782bf..97847b9 100644 --- a/gdb/darwin-nat-info.c +++ b/gdb/darwin-nat-info.c @@ -118,7 +118,10 @@ get_task_from_args (const char *args) { if (ptid_equal (inferior_ptid, null_ptid)) printf_unfiltered (_("No inferior running\n")); - return current_inferior ()->priv->task; + + darwin_inferior *priv = get_darwin_inferior (current_inferior ()); + + return priv->task; } if (strcmp (args, "gdb") == 0) return mach_task_self (); @@ -257,36 +260,31 @@ info_mach_ports_command (const char *args, int from_tty) else if (!ptid_equal (inferior_ptid, null_ptid)) { struct inferior *inf = current_inferior (); + darwin_inferior *priv = get_darwin_inferior (inf); - if (port == inf->priv->task) + if (port == priv->task) printf_unfiltered (_(" inferior-task")); - else if (port == inf->priv->notify_port) + else if (port == priv->notify_port) printf_unfiltered (_(" inferior-notify")); else { - int k; - darwin_thread_t *t; - - for (k = 0; k < inf->priv->exception_info.count; k++) - if (port == inf->priv->exception_info.ports[k]) + for (int k = 0; k < priv->exception_info.count; k++) + if (port == priv->exception_info.ports[k]) { printf_unfiltered (_(" inferior-excp-port")); break; } - if (inf->priv->threads) + for (darwin_thread_t *t : priv->threads) { - for (k = 0; - VEC_iterate(darwin_thread_t, - inf->priv->threads, k, t); - k++) - if (port == t->gdb_port) - { - printf_unfiltered (_(" inferior-thread for 0x%x"), - inf->priv->task); - break; - } + if (port == t->gdb_port) + { + printf_unfiltered (_(" inferior-thread for 0x%x"), + priv->task); + break; + } } + } } } @@ -738,7 +736,8 @@ info_mach_region_command (const char *exp, int from_tty) error (_("Inferior not available")); inf = current_inferior (); - darwin_debug_region (inf->priv->task, address); + darwin_inferior *priv = get_darwin_inferior (inf); + darwin_debug_region (priv->task, address); } static void @@ -807,7 +806,10 @@ info_mach_exceptions_command (const char *args, int from_tty) { if (ptid_equal (inferior_ptid, null_ptid)) printf_unfiltered (_("No inferior running\n")); - disp_exception (¤t_inferior ()->priv->exception_info); + + darwin_inferior *priv = get_darwin_inferior (current_inferior ()); + + disp_exception (&priv->exception_info); return; } else if (strcmp (args, "host") == 0) @@ -830,8 +832,10 @@ info_mach_exceptions_command (const char *args, int from_tty) printf_unfiltered (_("No inferior running\n")); inf = current_inferior (); + darwin_inferior *priv = get_darwin_inferior (inf); + kret = task_get_exception_ports - (inf->priv->task, EXC_MASK_ALL, info.masks, + (priv->task, EXC_MASK_ALL, info.masks, &info.count, info.ports, info.behaviors, info.flavors); MACH_CHECK_ERROR (kret); disp_exception (&info); |