[binutils-gdb] gdb: Remove cleanup from linux_nat_target::follow_fork
Andrew Burgess
aburgess@sourceware.org
Thu Jan 3 21:26:00 GMT 2019
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=169bb27bce3dc43b2bb5f6abf7fc21c19de5454a
commit 169bb27bce3dc43b2bb5f6abf7fc21c19de5454a
Author: Andrew Burgess <andrew.burgess@embecosm.com>
Date: Mon Dec 31 22:20:56 2018 +0000
gdb: Remove cleanup from linux_nat_target::follow_fork
Remove cleanup from linux_nat_target::follow_fork, instead add a new
unique_ptr specialisation for holding lwp_info pointers and use this
to ensure the pointer is cleaned up when needed.
gdb/ChangeLog:
* linux-nat.c (delete_lwp_cleanup): Delete.
(struct lwp_deleter): New struct.
(lwp_info_up): New typedef.
(linux_nat_target::follow_fork): Delete cleanup, and make use of
lwp_info_up.
Diff:
---
gdb/ChangeLog | 8 ++++++++
gdb/linux-nat.c | 27 ++++++++++++++++-----------
2 files changed, 24 insertions(+), 11 deletions(-)
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index e1bd349..da92e3f 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,13 @@
2019-01-03 Andrew Burgess <andrew.burgess@embecosm.com>
+ * linux-nat.c (delete_lwp_cleanup): Delete.
+ (struct lwp_deleter): New struct.
+ (lwp_info_up): New typedef.
+ (linux_nat_target::follow_fork): Delete cleanup, and make use of
+ lwp_info_up.
+
+2019-01-03 Andrew Burgess <andrew.burgess@embecosm.com>
+
* linux-fork.c (class scoped_switch_fork_info): New class.
(inferior_call_waitpid): Update to use scoped_switch_fork_info.
diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c
index 7286207..73d4fd1 100644
--- a/gdb/linux-nat.c
+++ b/gdb/linux-nat.c
@@ -425,15 +425,19 @@ num_lwps (int pid)
return count;
}
-/* Call delete_lwp with prototype compatible for make_cleanup. */
+/* Deleter for lwp_info unique_ptr specialisation. */
-static void
-delete_lwp_cleanup (void *lp_voidp)
+struct lwp_deleter
{
- struct lwp_info *lp = (struct lwp_info *) lp_voidp;
+ void operator() (struct lwp_info *lwp) const
+ {
+ delete_lwp (lwp->ptid);
+ }
+};
- delete_lwp (lp->ptid);
-}
+/* A unique_ptr specialisation for lwp_info. */
+
+typedef std::unique_ptr<struct lwp_info, lwp_deleter> lwp_info_up;
/* Target hook for follow_fork. On entry inferior_ptid must be the
ptid of the followed inferior. At return, inferior_ptid will be
@@ -466,10 +470,13 @@ linux_nat_target::follow_fork (int follow_child, int detach_fork)
{
int child_stop_signal = 0;
bool detach_child = true;
- struct cleanup *old_chain = make_cleanup (delete_lwp_cleanup,
- child_lp);
- linux_target->low_prepare_to_resume (child_lp);
+ /* Move CHILD_LP into a unique_ptr and clear the source pointer
+ to prevent us doing anything stupid with it. */
+ lwp_info_up child_lp_ptr (child_lp);
+ child_lp = nullptr;
+
+ linux_target->low_prepare_to_resume (child_lp_ptr.get ());
/* When debugging an inferior in an architecture that supports
hardware single stepping on a kernel without commit
@@ -508,8 +515,6 @@ linux_nat_target::follow_fork (int follow_child, int detach_fork)
signo = 0;
ptrace (PTRACE_DETACH, child_pid, 0, signo);
}
-
- do_cleanups (old_chain);
}
else
{
More information about the Gdb-cvs
mailing list