aboutsummaryrefslogtreecommitdiff
path: root/gdb/nat
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@ericsson.com>2017-10-12 16:48:22 -0400
committerSimon Marchi <simon.marchi@ericsson.com>2017-10-12 16:48:22 -0400
commit466eeceef409597388dd2b4e8b907cf080bedcf1 (patch)
tree68e05edddda6b537193b5b5ca6221e8eae7e7c6d /gdb/nat
parent6bf0052db8bbeed41e512d1d3ce14ba2a446723d (diff)
downloadgdb-466eeceef409597388dd2b4e8b907cf080bedcf1.zip
gdb-466eeceef409597388dd2b4e8b907cf080bedcf1.tar.gz
gdb-466eeceef409597388dd2b4e8b907cf080bedcf1.tar.bz2
lwp_info: Make the arch code free arch_lwp_info
I have the goal of "poisoning" the XNEW/xfree-family of functions, so that we catch their usages with non-POD types. A few things need to be fixed in the mean time, this is one. The common lwp code in linux-nat.c and gdbserver/linux-low.c xfrees the private lwp data of type arch_lwp_info. However, that type is opaque from its point of view, as its defined differently in each arch-specific implementation. This trips on the std::is_pod<T> check, since the compiler can't tell whether the type is POD or not if it doesn't know about it. My initial patch [1] made a class hierarchy with a virtual destructor. However, as Pedro pointed out, we only have one native architecture at the time built in gdb and gdbserver, so that's overkill. Instead, we can move the responsibility of free'ing arch_lwp_info to the arch code (which is also the one that allocated it in the first place). This is what this patch does. Also, I had the concern that if we wanted to use C++ features in these structures, we would have a problem with the one-definition rule. However, since a build will only have one version of arch_lwp_info, that's not a problem. There are changes in arch-specific files, I was only able to built-test this patch with the following cross-compilers: aarch64-linux-gnu alpha-linux-gnu arm-linux-gnueabihf hppa-linux-gnu m68k-linux-gnu mips64el-linux-gnuabi64 powerpc64-linux-gnu s390x-linux-gnu sh4-linux-gnu sparc64-linux-gnu x86_64-linux-gnu x86_64-w64-mingw32 A buildbot run didn't find any regression. [1] https://sourceware.org/ml/gdb-patches/2017-08/msg00255.html gdb/ChangeLog: * linux-nat.h (linux_nat_set_delete_thread): New declaration. * linux-nat.c (linux_nat_delete_thread): New variable. (lwp_free): Invoke linux_nat_delete_thread if set. (linux_nat_set_delete_thread): New function. * aarch64-linux-nat.c (_initialize_aarch64_linux_nat): Assign thread delete callback. * arm-linux-nat.c (arm_linux_delete_thread): New function. (_initialize_arm_linux_nat): Assign thread delete callback. * s390-linux-nat.c (s390_delete_thread): New function. (_initialize_s390_nat): Assign thread delete callback. * x86-linux-nat.c (x86_linux_add_target): Likewise. * nat/aarch64-linux.c (aarch64_linux_delete_thread): New function. * nat/aarch64-linux.h (aarch64_linux_delete_thread): New declaration. * nat/x86-linux.c (x86_linux_delete_thread): New function. * nat/x86-linux.h (x86_linux_delete_thread): New declaration. gdb/gdbserver/ChangeLog: * linux-aarch64-low.c (the_low_target): Add thread delete callback. * linux-arm-low.c (arm_delete_thread): New function. (the_low_target): Add thread delete callback. * linux-bfin-low.c (the_low_target): Likewise. * linux-crisv32-low.c (the_low_target): Likewise. * linux-low.c (delete_lwp): Invoke delete_thread callback if set. * linux-low.h (struct linux_target_ops) <delete_thread>: New field. * linux-m32r-low.c (the_low_target): Add thread delete callback. * linux-mips-low.c (mips_linux_delete_thread): New function. (the_low_target): Add thread delete callback. * linux-ppc-low.c (the_low_target): Likewise. * linux-s390-low.c (the_low_target): Likewise. * linux-sh-low.c (the_low_target): Likewise. * linux-tic6x-low.c (the_low_target): Likewise. * linux-tile-low.c (the_low_target): Likewise. * linux-x86-low.c (the_low_target): Likewise. * linux-xtensa-low.c (the_low_target): Likewise.
Diffstat (limited to 'gdb/nat')
-rw-r--r--gdb/nat/aarch64-linux.c8
-rw-r--r--gdb/nat/aarch64-linux.h3
-rw-r--r--gdb/nat/x86-linux.c8
-rw-r--r--gdb/nat/x86-linux.h4
4 files changed, 23 insertions, 0 deletions
diff --git a/gdb/nat/aarch64-linux.c b/gdb/nat/aarch64-linux.c
index 388eee8..d7abee8 100644
--- a/gdb/nat/aarch64-linux.c
+++ b/gdb/nat/aarch64-linux.c
@@ -84,6 +84,14 @@ aarch64_linux_new_thread (struct lwp_info *lwp)
lwp_set_arch_private_info (lwp, info);
}
+/* See nat/aarch64-linux.h. */
+
+void
+aarch64_linux_delete_thread (struct arch_lwp_info *arch_lwp)
+{
+ xfree (arch_lwp);
+}
+
/* Convert native siginfo FROM to the siginfo in the layout of the
inferior's architecture TO. */
diff --git a/gdb/nat/aarch64-linux.h b/gdb/nat/aarch64-linux.h
index 191e1c6..db98df4 100644
--- a/gdb/nat/aarch64-linux.h
+++ b/gdb/nat/aarch64-linux.h
@@ -122,6 +122,9 @@ void aarch64_linux_prepare_to_resume (struct lwp_info *lwp);
void aarch64_linux_new_thread (struct lwp_info *lwp);
+/* Function to call when a thread is being deleted. */
+void aarch64_linux_delete_thread (struct arch_lwp_info *arch_lwp);
+
ps_err_e aarch64_ps_get_thread_area (struct ps_prochandle *ph,
lwpid_t lwpid, int idx, void **base,
int is_64bit_p);
diff --git a/gdb/nat/x86-linux.c b/gdb/nat/x86-linux.c
index b499e74..fc68106 100644
--- a/gdb/nat/x86-linux.c
+++ b/gdb/nat/x86-linux.c
@@ -68,6 +68,14 @@ x86_linux_new_thread (struct lwp_info *lwp)
/* See nat/x86-linux.h. */
void
+x86_linux_delete_thread (struct arch_lwp_info *arch_lwp)
+{
+ xfree (arch_lwp);
+}
+
+/* See nat/x86-linux.h. */
+
+void
x86_linux_prepare_to_resume (struct lwp_info *lwp)
{
x86_linux_update_debug_registers (lwp);
diff --git a/gdb/nat/x86-linux.h b/gdb/nat/x86-linux.h
index 1b7fee4..493c722 100644
--- a/gdb/nat/x86-linux.h
+++ b/gdb/nat/x86-linux.h
@@ -39,6 +39,10 @@ extern int lwp_debug_registers_changed (struct lwp_info *lwp);
extern void x86_linux_new_thread (struct lwp_info *lwp);
+/* Function to call when a thread is being deleted. */
+
+extern void x86_linux_delete_thread (struct arch_lwp_info *arch_lwp);
+
/* Function to call prior to resuming a thread. */
extern void x86_linux_prepare_to_resume (struct lwp_info *lwp);