Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [RFA] Implement thread death notification.
@ 2008-04-26 17:45 Vladimir Prus
  2008-05-01 20:04 ` Daniel Jacobowitz
  0 siblings, 1 reply; 6+ messages in thread
From: Vladimir Prus @ 2008-04-26 17:45 UTC (permalink / raw)
  To: gdb-patches


We now have the 'thread-created' MI notification. This patch adds a
'thread-exited' notification to match. Are non-MI bits of this
patch OK?

- Volodya

	2008-03-29  Pedro Alves  <pedro@codesourcery.com>
	gdb/doc/
	* observer.texi (thread_exit): New.

	gdb/
	* linux-nat.c: Include observer.h.
	(exit_lwp): Call observer_notify_thread_exit.
	* Makefile.in (linux-nat.o): Update.
	* mi/mi-interp.c (mi_interpreter_init): Register mi_thread_exit as
	thread_exit observer.
	(mi_thread_exit): New.
---
 gdb/Makefile.in       |    3 ++-
 gdb/doc/observer.texi |    4 ++++
 gdb/linux-nat.c       |    6 +++++-
 gdb/mi/mi-interp.c    |   16 +++++++++++++++-
 4 files changed, 26 insertions(+), 3 deletions(-)

diff --git a/gdb/Makefile.in b/gdb/Makefile.in
index 9304bc2..9d72168 100644
--- a/gdb/Makefile.in
+++ b/gdb/Makefile.in
@@ -2375,7 +2375,8 @@ linux-nat.o: linux-nat.c $(defs_h) $(inferior_h) $(target_h) $(gdb_string_h) \
 	$(gdb_wait_h) $(gdb_assert_h) $(linux_nat_h) $(gdbthread_h) \
 	$(gdbcmd_h) $(regcache_h) $(regset_h) $(inf_ptrace_h) $(auxv_h) \
 	$(elf_bfd_h) $(gregset_h) $(gdbcore_h) $(gdbthread_h) $(gdb_stat_h) \
-	$(linux_fork_h) $(inf_loop_h) $(event_loop_h) $(event_top_h)
+	$(linux_fork_h) $(inf_loop_h) $(event_loop_h) $(event_top_h) \
+	$(observer_h)
 linux-thread-db.o: linux-thread-db.c $(defs_h) $(gdb_assert_h) \
 	$(gdb_proc_service_h) $(gdb_thread_db_h) $(bfd_h) $(exceptions_h) \
 	$(gdbthread_h) $(inferior_h) $(symfile_h) $(objfiles_h) $(target_h) \
diff --git a/gdb/doc/observer.texi b/gdb/doc/observer.texi
index 5bcc76c..af3835b 100644
--- a/gdb/doc/observer.texi
+++ b/gdb/doc/observer.texi
@@ -133,3 +133,7 @@ previously loaded symbol table data has now been invalidated.
 The thread specified by @var{t} has been created.
 @end deftypefun
 
+@deftypefun void thread_exit (struct thread_info *@var{t})
+The thread specified by @var{t} has exited.
+@end deftypefun
+
diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c
index 9511815..a97ad0f 100644
--- a/gdb/linux-nat.c
+++ b/gdb/linux-nat.c
@@ -49,6 +49,7 @@
 #include "inf-loop.h"
 #include "event-loop.h"
 #include "event-top.h"
+#include "observer.h"
 
 #ifndef O_LARGEFILE
 #define O_LARGEFILE 0
@@ -995,10 +996,13 @@ prune_lwps (void)
 static void
 exit_lwp (struct lwp_info *lp)
 {
-  if (in_thread_list (lp->ptid))
+  struct thread_info *th = find_thread_pid (lp->ptid);
+
+  if (th)
     {
       if (print_thread_events)
 	printf_unfiltered (_("[%s exited]\n"), target_pid_to_str (lp->ptid));
+      observer_notify_thread_exit (th);
 
       /* Core GDB cannot deal with us deleting the current thread.  */
       if (!ptid_equal (lp->ptid, inferior_ptid))
diff --git a/gdb/mi/mi-interp.c b/gdb/mi/mi-interp.c
index 8dfd3ee..da7a717 100644
--- a/gdb/mi/mi-interp.c
+++ b/gdb/mi/mi-interp.c
@@ -67,6 +67,7 @@ static void mi_insert_notify_hooks (void);
 static void mi_remove_notify_hooks (void);
 
 static void mi_new_thread (struct thread_info *t);
+static void mi_thread_exit (struct thread_info *t);
 
 static void *
 mi_interpreter_init (int top_level)
@@ -88,7 +89,10 @@ mi_interpreter_init (int top_level)
   mi->event_channel = mi_console_file_new (raw_stdout, "=", 0);
 
   if (top_level)
-    observer_attach_new_thread (mi_new_thread);
+    {
+      observer_attach_new_thread (mi_new_thread);
+      observer_attach_thread_exit (mi_thread_exit);
+    }
 
   return mi;
 }
@@ -317,6 +321,16 @@ mi_new_thread (struct thread_info *t)
   gdb_flush (mi->event_channel);
 }
 
+static void
+mi_thread_exit (struct thread_info *t)
+{
+  struct mi_interp *mi = top_level_interpreter_data ();
+
+  target_terminal_ours ();
+  fprintf_unfiltered (mi->event_channel, "thread-exited,id=\"%d\"", t->num);
+  gdb_flush (mi->event_channel);
+}
+
 extern initialize_file_ftype _initialize_mi_interp; /* -Wmissing-prototypes */
 
 void
-- 
1.5.3.5


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [RFA] Implement thread death notification.
  2008-04-26 17:45 [RFA] Implement thread death notification Vladimir Prus
@ 2008-05-01 20:04 ` Daniel Jacobowitz
  2008-05-01 20:13   ` Vladimir Prus
  0 siblings, 1 reply; 6+ messages in thread
From: Daniel Jacobowitz @ 2008-05-01 20:04 UTC (permalink / raw)
  To: Vladimir Prus; +Cc: gdb-patches

On Sat, Apr 26, 2008 at 08:21:50PM +0300, Vladimir Prus wrote:
> 
> We now have the 'thread-created' MI notification. This patch adds a
> 'thread-exited' notification to match. Are non-MI bits of this
> patch OK?

No, I don't think this is good enough.  It's "thread has exited but
only if the target is native GNU/Linux".  While for some targets we
will not detect thread exit until "info threads", which is
unfortunate, at least the code to call the observer should be in
generic code.  Can't we call it from delete_thread?

Also, please do not commit without documentation for the notification.

-- 
Daniel Jacobowitz
CodeSourcery


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [RFA] Implement thread death notification.
  2008-05-01 20:04 ` Daniel Jacobowitz
@ 2008-05-01 20:13   ` Vladimir Prus
  2008-05-01 20:21     ` Daniel Jacobowitz
  0 siblings, 1 reply; 6+ messages in thread
From: Vladimir Prus @ 2008-05-01 20:13 UTC (permalink / raw)
  To: Daniel Jacobowitz; +Cc: gdb-patches

On Friday 02 May 2008 00:03:53 Daniel Jacobowitz wrote:
> On Sat, Apr 26, 2008 at 08:21:50PM +0300, Vladimir Prus wrote:
> > 
> > We now have the 'thread-created' MI notification. This patch adds a
> > 'thread-exited' notification to match. Are non-MI bits of this
> > patch OK?
> 
> No, I don't think this is good enough.  It's "thread has exited but
> only if the target is native GNU/Linux".  While for some targets we
> will not detect thread exit until "info threads", which is
> unfortunate, at least the code to call the observer should be in
> generic code.  Can't we call it from delete_thread?

Yes, I think so. OK with that change?

> 
> Also, please do not commit without documentation for the notification.

Ehm! The documentation patch is approved last week.

- Volodya


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [RFA] Implement thread death notification.
  2008-05-01 20:13   ` Vladimir Prus
@ 2008-05-01 20:21     ` Daniel Jacobowitz
  0 siblings, 0 replies; 6+ messages in thread
From: Daniel Jacobowitz @ 2008-05-01 20:21 UTC (permalink / raw)
  To: Vladimir Prus; +Cc: gdb-patches

On Fri, May 02, 2008 at 12:13:33AM +0400, Vladimir Prus wrote:
> Yes, I think so. OK with that change?

Yep.

> Ehm! The documentation patch is approved last week.

Oh good :-)

-- 
Daniel Jacobowitz
CodeSourcery


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [RFA] Implement thread death notification.
  2008-04-27 15:03 Nick Roberts
@ 2008-04-29 20:07 ` Vladimir Prus
  0 siblings, 0 replies; 6+ messages in thread
From: Vladimir Prus @ 2008-04-29 20:07 UTC (permalink / raw)
  To: Nick Roberts; +Cc: gdb-patches@sources

On Sunday 27 April 2008 13:02:38 Nick Roberts wrote:
> 
> > We now have the 'thread-created' MI notification. This patch adds a
> > 'thread-exited' notification to match. Are non-MI bits of this
> > patch OK?
> 
> When I suggested this previously, we said:
> 
> > > I'm not sure what you mean.  If I run Gdb normally with a multi-threaded
> > > application, I get:
> > > 
> > > [New Thread -1210639472 (LWP 7235)]
> > > 
> > > when a thread is created and:
> > > 
> > > [Thread -1210639472 (LWP 7235) exited]
> > > 
> > > when it is terminated.
> >
> > At which point, and where in code is that message printed? It is
> > printed by linux-thread-db.c:detach_thread, so it's not good for
> > generic code. And generic code will hold on to thread until 
> > "info thread". It's not very good if you need to issue "info thread"
> > to get notifications about exited thread.
> > 
> > So, thread.c and its interaction with linux-thread-db.c have to
> > be fixed.
> 
> Does it mean that this has now been fixed?

No. However, it seems useful to provide this notification initially for Linux.

- Volodya


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [RFA] Implement thread death notification.
@ 2008-04-27 15:03 Nick Roberts
  2008-04-29 20:07 ` Vladimir Prus
  0 siblings, 1 reply; 6+ messages in thread
From: Nick Roberts @ 2008-04-27 15:03 UTC (permalink / raw)
  To: Vladimir Prus; +Cc: gdb-patches@sources


> We now have the 'thread-created' MI notification. This patch adds a
> 'thread-exited' notification to match. Are non-MI bits of this
> patch OK?

When I suggested this previously, we said:

> > I'm not sure what you mean.  If I run Gdb normally with a multi-threaded
> > application, I get:
> > 
> > [New Thread -1210639472 (LWP 7235)]
> > 
> > when a thread is created and:
> > 
> > [Thread -1210639472 (LWP 7235) exited]
> > 
> > when it is terminated.
>
> At which point, and where in code is that message printed? It is
> printed by linux-thread-db.c:detach_thread, so it's not good for
> generic code. And generic code will hold on to thread until 
> "info thread". It's not very good if you need to issue "info thread"
> to get notifications about exited thread.
> 
> So, thread.c and its interaction with linux-thread-db.c have to
> be fixed.

Does it mean that this has now been fixed?

-- 
Nick                                           http://www.inet.net.nz/~nickrob


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2008-05-01 20:21 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-04-26 17:45 [RFA] Implement thread death notification Vladimir Prus
2008-05-01 20:04 ` Daniel Jacobowitz
2008-05-01 20:13   ` Vladimir Prus
2008-05-01 20:21     ` Daniel Jacobowitz
2008-04-27 15:03 Nick Roberts
2008-04-29 20:07 ` Vladimir Prus

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox