summaryrefslogtreecommitdiff
path: root/gdb/inferior.h
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/inferior.h
parentd044bac8ce5e6737d13e7e5180f5a5641053e690 (diff)
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/inferior.h')
-rw-r--r--gdb/inferior.h9
1 files changed, 7 insertions, 2 deletions
diff --git a/gdb/inferior.h b/gdb/inferior.h
index 37252a695c..0705dd9d75 100644
--- a/gdb/inferior.h
+++ b/gdb/inferior.h
@@ -263,7 +263,12 @@ enum stop_kind
#define ON_STACK 1
#define AT_ENTRY_POINT 4
-struct private_inferior;
+/* Base class for target-specific inferior data. */
+
+struct private_inferior
+{
+ virtual ~private_inferior () = 0;
+};
/* Inferior process specific part of `struct infcall_control_state'.
@@ -403,7 +408,7 @@ public:
bool needs_setup = false;
/* Private data used by the target vector implementation. */
- private_inferior *priv = NULL;
+ std::unique_ptr<private_inferior> priv;
/* HAS_EXIT_CODE is true if the inferior exited with an exit code.
In this case, the EXIT_CODE field is also valid. */