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.h | |
parent | d044bac8ce5e6737d13e7e5180f5a5641053e690 (diff) | |
download | gdb-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/darwin-nat.h')
-rw-r--r-- | gdb/darwin-nat.h | 38 |
1 files changed, 20 insertions, 18 deletions
diff --git a/gdb/darwin-nat.h b/gdb/darwin-nat.h index 77feb0e..db72698 100644 --- a/gdb/darwin-nat.h +++ b/gdb/darwin-nat.h @@ -26,21 +26,20 @@ struct darwin_exception_info { /* Exceptions handled by the port. */ - exception_mask_t masks[EXC_TYPES_COUNT]; + exception_mask_t masks[EXC_TYPES_COUNT] {}; /* Ports receiving exception messages. */ - mach_port_t ports[EXC_TYPES_COUNT]; + mach_port_t ports[EXC_TYPES_COUNT] {}; /* Type of messages sent. */ - exception_behavior_t behaviors[EXC_TYPES_COUNT]; + exception_behavior_t behaviors[EXC_TYPES_COUNT] {}; /* Type of state to be sent. */ - thread_state_flavor_t flavors[EXC_TYPES_COUNT]; + thread_state_flavor_t flavors[EXC_TYPES_COUNT] {}; /* Number of elements set. */ - mach_msg_type_number_t count; + mach_msg_type_number_t count = 0; }; -typedef struct darwin_exception_info darwin_exception_info; struct darwin_exception_msg { @@ -95,36 +94,39 @@ struct private_thread_info }; typedef struct private_thread_info darwin_thread_t; -/* Define the threads vector type. */ -DEF_VEC_O (darwin_thread_t); - - /* Describe an inferior. */ -struct private_inferior +struct darwin_inferior : public private_inferior { /* Corresponding task port. */ - task_t task; + task_t task = 0; /* Port which will receive the dead-name notification for the task port. This is used to detect the death of the task. */ - mach_port_t notify_port; + mach_port_t notify_port = 0; /* Initial exception handling. */ darwin_exception_info exception_info; /* Number of messages that have been received but not yet replied. */ - unsigned int pending_messages; + unsigned int pending_messages = 0; /* Set if inferior is not controlled by ptrace(2) but through Mach. */ - unsigned char no_ptrace; + bool no_ptrace = false; /* True if this task is suspended. */ - unsigned char suspended; + bool suspended = false; /* Sorted vector of known threads. */ - VEC(darwin_thread_t) *threads; + std::vector<darwin_thread_t *> threads; }; -typedef struct private_inferior darwin_inferior; + +/* Return the darwin_inferior attached to INF. */ + +static inline darwin_inferior * +get_darwin_inferior (inferior *inf) +{ + return static_cast<darwin_inferior *> (inf->priv.get ()); +} /* Exception port. */ extern mach_port_t darwin_ex_port; |