From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3429 invoked by alias); 9 Jun 2008 12:16:58 -0000 Received: (qmail 3415 invoked by uid 22791); 9 Jun 2008 12:16:57 -0000 X-Spam-Check-By: sourceware.org Received: from viper.snap.net.nz (HELO viper.snap.net.nz) (202.37.101.25) by sourceware.org (qpsmtpd/0.31) with ESMTP; Mon, 09 Jun 2008 12:16:29 +0000 Received: from kahikatea.snap.net.nz (50.61.255.123.dynamic.snap.net.nz [123.255.61.50]) by viper.snap.net.nz (Postfix) with ESMTP id 1A1B13DA262; Tue, 10 Jun 2008 00:16:22 +1200 (NZST) Received: by kahikatea.snap.net.nz (Postfix, from userid 1000) id C7EF68FC6D; Tue, 10 Jun 2008 00:16:10 +1200 (NZST) From: Nick Roberts MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <18509.7945.19078.399646@kahikatea.snap.net.nz> Date: Mon, 09 Jun 2008 12:16:00 -0000 To: gdb-patches@sources.redhat.com Cc: ghost@cs.msu.su Subject: [patch:MI] Observer for thread-changed X-Mailer: VM 7.19 under Emacs 22.2.50.2 X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2008-06/txt/msg00155.txt.bz2 This patch is the thread-changed notification for MI using an observer. No regressions. -- Nick http://www.inet.net.nz/~nickrob 2008-06-09 Nick Roberts * mi/mi-interp.c (mi_thread_changed): New static function. (mi_interpreter_init): Register mi_thread_changed as thread_changed observer . * thread.c (thread_command): Notify thread changes using observer. * infrun.c (normal_stop): Ditto. * mi/mi-main.c (mi_cmd_thread_select): Ditto. * Makefile.in (mi-main.o) : Add dependency on observer.h. 2008-06-09 Nick Roberts * observer.texi (GDB Observers): New observer for thread_changed. Index: thread.c =================================================================== RCS file: /cvs/src/src/gdb/thread.c,v retrieving revision 1.71 diff -p -u -p -r1.71 thread.c --- thread.c 6 Jun 2008 00:32:51 -0000 1.71 +++ thread.c 9 Jun 2008 12:13:23 -0000 @@ -740,6 +740,7 @@ thread_command (char *tidstr, int from_t annotate_thread_changed (); gdb_thread_select (uiout, tidstr, NULL); + observer_notify_thread_changed (); } /* Print notices when new threads are attached and detached. */ Index: infrun.c =================================================================== RCS file: /cvs/src/src/gdb/infrun.c,v retrieving revision 1.278 diff -p -u -p -r1.278 infrun.c --- infrun.c 6 Jun 2008 00:33:52 -0000 1.278 +++ infrun.c 9 Jun 2008 12:13:25 -0000 @@ -3605,6 +3605,7 @@ normal_stop (void) target_terminal_ours_for_output (); printf_filtered (_("[Switching to %s]\n"), target_pid_to_str (inferior_ptid)); + observer_notify_thread_changed (); annotate_thread_changed (); previous_inferior_ptid = inferior_ptid; } Index: Makefile.in =================================================================== RCS file: /cvs/src/src/gdb/Makefile.in,v retrieving revision 1.1026 diff -p -u -p -r1.1026 Makefile.in --- Makefile.in 6 Jun 2008 20:58:08 -0000 1.1026 +++ Makefile.in 9 Jun 2008 12:13:28 -0000 @@ -3285,7 +3285,8 @@ mi-main.o: $(srcdir)/mi/mi-main.c $(defs $(gdb_string_h) $(exceptions_h) $(top_h) $(gdbthread_h) $(mi_cmds_h) \ $(mi_parse_h) $(mi_getopt_h) $(mi_console_h) $(ui_out_h) $(mi_out_h) \ $(interps_h) $(event_loop_h) $(event_top_h) $(gdbcore_h) $(value_h) \ - $(regcache_h) $(gdb_h) $(frame_h) $(mi_main_h) $(language_h) + $(regcache_h) $(gdb_h) $(frame_h) $(mi_main_h) $(language_h) \ + $(observer_h) $(CC) -c $(INTERNAL_CFLAGS) $(srcdir)/mi/mi-main.c mi-out.o: $(srcdir)/mi/mi-out.c $(defs_h) $(ui_out_h) $(mi_out_h) $(CC) -c $(INTERNAL_CFLAGS) $(srcdir)/mi/mi-out.c Index: mi/mi-interp.c =================================================================== RCS file: /cvs/src/src/gdb/mi/mi-interp.c,v retrieving revision 1.30 diff -p -u -p -r1.30 mi-interp.c --- mi/mi-interp.c 3 May 2008 15:10:42 -0000 1.30 +++ mi/mi-interp.c 9 Jun 2008 12:13:28 -0000 @@ -68,6 +68,7 @@ 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_thread_changed (void); static void * mi_interpreter_init (int top_level) @@ -92,6 +93,7 @@ mi_interpreter_init (int top_level) { observer_attach_new_thread (mi_new_thread); observer_attach_thread_exit (mi_thread_exit); + observer_attach_thread_changed (mi_thread_changed); } return mi; @@ -331,6 +333,27 @@ mi_thread_exit (struct thread_info *t) gdb_flush (mi->event_channel); } +static void +mi_thread_changed () +{ + struct mi_interp *mi = top_level_interpreter_data (); + struct interp *interp_to_use; + struct ui_out *old_uiout, *temp_uiout; + int version; + + fprintf_unfiltered (mi->event_channel, "thread-changed"); + interp_to_use = top_level_interpreter (); + old_uiout = uiout; + temp_uiout = interp_ui_out (interp_to_use); + version = mi_version (temp_uiout); + temp_uiout = mi_out_new (version); + uiout = temp_uiout; + ui_out_field_int (uiout, "new-thread-id", pid_to_thread_id (inferior_ptid)); + mi_out_put (uiout, mi->event_channel); + uiout = old_uiout; + gdb_flush (mi->event_channel); +} + extern initialize_file_ftype _initialize_mi_interp; /* -Wmissing-prototypes */ void Index: mi/mi-main.c =================================================================== RCS file: /cvs/src/src/gdb/mi/mi-main.c,v retrieving revision 1.115 diff -p -u -p -r1.115 mi-main.c --- mi/mi-main.c 6 May 2008 21:35:01 -0000 1.115 +++ mi/mi-main.c 9 Jun 2008 12:13:28 -0000 @@ -45,6 +45,7 @@ #include "frame.h" #include "mi-main.h" #include "language.h" +#include "observer.h" #include #include @@ -241,6 +242,7 @@ mi_cmd_thread_select (char *command, cha error ("mi_cmd_thread_select: USAGE: threadnum."); rc = gdb_thread_select (uiout, argv[0], &mi_error_message); + observer_notify_thread_changed (); if (rc == GDB_RC_FAIL) { Index: doc/observer.texi =================================================================== RCS file: /cvs/src/src/gdb/doc/observer.texi,v retrieving revision 1.15 diff -p -u -p -r1.15 observer.texi --- doc/observer.texi 3 May 2008 15:10:42 -0000 1.15 +++ doc/observer.texi 9 Jun 2008 12:13:28 -0000 @@ -137,3 +137,6 @@ The thread specified by @var{t} has been The thread specified by @var{t} has exited. @end deftypefun +@deftypefun void thread_changed () +A new thread has been selected. +@end deftypefun