This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[3/3] broken -thread-info output in non-stop mode, fix it


This fixes the broken -thread-info output mentioned in this thread:

 http://sourceware.org/ml/gdb-patches/2009-03/msg00236.html

... as suggested by Vladimir, the patch makes us output ^running
only if the target was proceeded.  I've added a new observer
(about_to_proceed), and implemented Vladimir's suggestion on top of
it.  There's this `breakpoint_proceeded' global that is used
by the breakpoint.c module for something very similar, so I've
moved that global into breakpoint.c, and made it static, and then
used the same observer to set it.  Since breakpoint_proceeded is
not global anymore, we can't save/restore it when doing infcalls
from infrun.c.  What I've done instead, was to make the
about_to_proceed observer in breakpoint.c not set breakpoint_proceeded if
we're about to do an inferior function call.  And we know we're doing
an infcall due to this new thread_info->in_infcall flag added by the
previous patch.

Vladimir, does this look like what you were picturing?

Tested on x86_64-linux, sync/async, and made sure the -thread-info
output is fixed in remote non-stop case, when we find new threads,
like so:

-thread-info
=thread-created,id="3",group-id="32"
~"[New Thread 32.32801]\n"
*running,thread-id="3"
^done,threads=[{id="3",target-id="Thread 32.32801",details="...",state="running"},{id="2",target-id="...",details="...",frame={level="0",...},state="stopped"},{id="1",target-id="...",details="...",frame={level="0",...},state="stopped"}]
(gdb)

-- 
Pedro Alves

2009-03-17  Pedro Alves  <pedro@codesourcery.com>

	* mi/mi-interp.c (mi_interpreter_init): Attach mi_about_to_proceed
	to the about_to_proceed observer notification.
	(mi_about_to_proceed): New.
	(mi_on_resume): Only output ^running and the prompt here if the
	target was proceeded.
	* breakpoint.c (breakpoint_proceeded): New static.
	(breakpoint_about_to_proceed): New.
	(_initialize_breakpoints): Attach breakpoint_about_to_proceed to
	the about_to_proceed observer notification.
	* doc/observer.texi (about_to_proceed): New.
	* inferior.h (breakpoint_proceeded): Delete declaration.
	* infrun.c (clear_proceed_status): Don't set breakpoint_proceeded.
	Notify the about_to_proceed observers.
	(struct inferior_status): Delete breakpoint_proceeded member.
	(save_inferior_status): Don't save it.
	(restore_inferior_status): Don't restore it.
	* mi-main.h (mi_proceeded): Declare.
	* mi/mi-main.c (mi_cmd_execute): Clear mi_proceeded before running
	a command.

---
 gdb/breakpoint.c      |   26 ++++++++++++++++++++++++++
 gdb/doc/observer.texi |    4 ++++
 gdb/inferior.h        |    5 -----
 gdb/infrun.c          |    6 ++----
 gdb/mi/mi-interp.c    |   21 +++++++++++++++++++--
 gdb/mi/mi-main.c      |    5 +++++
 gdb/mi/mi-main.h      |    1 +
 7 files changed, 57 insertions(+), 11 deletions(-)

Index: src/gdb/mi/mi-interp.c
===================================================================
--- src.orig/gdb/mi/mi-interp.c	2009-03-17 05:51:35.000000000 +0000
+++ src/gdb/mi/mi-interp.c	2009-03-17 05:56:02.000000000 +0000
@@ -61,6 +61,7 @@ static void mi_inferior_exit (int pid);
 static void mi_on_resume (ptid_t ptid);
 static void mi_solib_loaded (struct so_list *solib);
 static void mi_solib_unloaded (struct so_list *solib);
+static void mi_about_to_proceed (void);
 
 static void *
 mi_interpreter_init (int top_level)
@@ -91,6 +92,7 @@ mi_interpreter_init (int top_level)
       observer_attach_target_resumed (mi_on_resume);
       observer_attach_solib_loaded (mi_solib_loaded);
       observer_attach_solib_unloaded (mi_solib_unloaded);
+      observer_attach_about_to_proceed (mi_about_to_proceed);
     }
 
   return mi;
@@ -368,6 +370,21 @@ mi_on_normal_stop (struct bpstats *bs, i
 }
 
 static void
+mi_about_to_proceed (void)
+{
+  /* Suppress output while calling an inferior function.  */
+
+  if (!ptid_equal (inferior_ptid, null_ptid))
+    {
+      struct thread_info *tp = inferior_thread ();
+      if (tp->in_infcall)
+	return;
+    }
+
+  mi_proceeded = 1;
+}
+
+static void
 mi_on_resume (ptid_t ptid)
 {
   struct thread_info *tp = NULL;
@@ -389,7 +406,7 @@ mi_on_resume (ptid_t ptid)
      will make it impossible for frontend to know what's going on.
 
      In future (MI3), we'll be outputting "^done" here.  */
-  if (!running_result_record_printed)
+  if (!running_result_record_printed && mi_proceeded)
     {
       if (current_token)
 	fputs_unfiltered (current_token, raw_stdout);
@@ -411,7 +428,7 @@ mi_on_resume (ptid_t ptid)
       fprintf_unfiltered (raw_stdout, "*running,thread-id=\"%d\"\n", ti->num);
     }
 
-  if (!running_result_record_printed)
+  if (!running_result_record_printed && mi_proceeded)
     {
       running_result_record_printed = 1;
       /* This is what gdb used to do historically -- printing prompt even if
Index: src/gdb/breakpoint.c
===================================================================
--- src.orig/gdb/breakpoint.c	2009-03-17 05:27:43.000000000 +0000
+++ src/gdb/breakpoint.c	2009-03-17 05:56:02.000000000 +0000
@@ -191,6 +191,11 @@ static int is_hardware_watchpoint (struc
 
 static void insert_breakpoint_locations (void);
 
+/* Flag indicating that a command has proceeded the inferior past the
+   current breakpoint.  */
+
+static int breakpoint_proceeded;
+
 static const char *
 bpdisp_text (enum bpdisp disp)
 {
@@ -2083,6 +2088,25 @@ bpstat_clear_actions (bpstat bs)
     }
 }
 
+/* Called when a command is about to proceed the inferior.  */
+
+static void
+breakpoint_about_to_proceed (void)
+{
+  if (!ptid_equal (inferior_ptid, null_ptid))
+    {
+      struct thread_info *tp = inferior_thread ();
+
+      /* Allow inferior function calls in breakpoint commands.  When
+	 the call finishes successfully, the inferior will be standing
+	 at the same breakpoint as if nothing happened.  */
+      if (tp->in_infcall)
+	return;
+    }
+
+  breakpoint_proceeded = 1;
+}
+
 /* Stub for cleaning up our state if we error-out of a breakpoint command */
 static void
 cleanup_executing_breakpoints (void *ignore)
@@ -8498,4 +8522,6 @@ inferior in all-stop mode, gdb behaves a
 			   &breakpoint_show_cmdlist);
   
   automatic_hardware_breakpoints = 1;
+
+  observer_attach_about_to_proceed (breakpoint_about_to_proceed);
 }
Index: src/gdb/doc/observer.texi
===================================================================
--- src.orig/gdb/doc/observer.texi	2009-03-17 05:27:43.000000000 +0000
+++ src/gdb/doc/observer.texi	2009-03-17 05:56:02.000000000 +0000
@@ -151,6 +151,10 @@ The target was resumed.  The @var{ptid} 
 thread was resume, and may be RESUME_ALL if all threads are resumed.
 @end deftypefun
 
+@deftypefun void about_to_proceed (void)
+The target is about to be proceeded.
+@end deftypefun
+
 @deftypefun void breakpoint_created (int @var{bpnum})
 A new breakpoint has been created.  The argument @var{bpnum} is the
 number of the newly-created breakpoint.
Index: src/gdb/inferior.h
===================================================================
--- src.orig/gdb/inferior.h	2009-03-17 05:51:35.000000000 +0000
+++ src/gdb/inferior.h	2009-03-17 05:56:02.000000000 +0000
@@ -287,11 +287,6 @@ extern void notice_new_inferior (ptid_t,
 
 extern CORE_ADDR stop_pc;
 
-/* Flag indicating that a command has proceeded the inferior past the
-   current breakpoint.  */
-
-extern int breakpoint_proceeded;
-
 /* Nonzero if stopped due to completion of a stack dummy routine.  */
 
 extern int stop_stack_dummy;
Index: src/gdb/infrun.c
===================================================================
--- src.orig/gdb/infrun.c	2009-03-17 05:52:06.000000000 +0000
+++ src/gdb/infrun.c	2009-03-17 05:56:02.000000000 +0000
@@ -1230,7 +1230,8 @@ clear_proceed_status (void)
     }
 
   stop_after_trap = 0;
-  breakpoint_proceeded = 1;	/* We're about to proceed... */
+
+  observer_notify_about_to_proceed ();
 
   if (stop_registers)
     {
@@ -4998,7 +4999,6 @@ struct inferior_status
   /* ID if the selected frame when the inferior function call was made.  */
   struct frame_id selected_frame_id;
 
-  int breakpoint_proceeded;
   int proceed_to_finish;
   int in_infcall;
 };
@@ -5029,7 +5029,6 @@ save_inferior_status (void)
      called.  */
   inf_status->stop_bpstat = tp->stop_bpstat;
   tp->stop_bpstat = bpstat_copy (tp->stop_bpstat);
-  inf_status->breakpoint_proceeded = breakpoint_proceeded;
   inf_status->proceed_to_finish = tp->proceed_to_finish;
   inf_status->in_infcall = tp->in_infcall;
 
@@ -5080,7 +5079,6 @@ restore_inferior_status (struct inferior
   bpstat_clear (&tp->stop_bpstat);
   tp->stop_bpstat = inf_status->stop_bpstat;
   inf_status->stop_bpstat = NULL;
-  breakpoint_proceeded = inf_status->breakpoint_proceeded;
   tp->proceed_to_finish = inf_status->proceed_to_finish;
   tp->in_infcall = inf_status->in_infcall;
 
Index: src/gdb/mi/mi-main.h
===================================================================
--- src.orig/gdb/mi/mi-main.h	2009-03-17 05:27:43.000000000 +0000
+++ src/gdb/mi/mi-main.h	2009-03-17 05:56:02.000000000 +0000
@@ -31,6 +31,7 @@ extern void mi_print_timing_maybe (void)
 extern char *current_token;
 
 extern int running_result_record_printed;
+extern int mi_proceeded;
 
 #endif
 
Index: src/gdb/mi/mi-main.c
===================================================================
--- src.orig/gdb/mi/mi-main.c	2009-03-17 05:27:43.000000000 +0000
+++ src/gdb/mi/mi-main.c	2009-03-17 05:56:02.000000000 +0000
@@ -78,6 +78,10 @@ static int do_timings = 0;
 char *current_token;
 int running_result_record_printed = 1;
 
+/* Flag indicating that the target has proceeded since the last
+   command was issued.  */
+int mi_proceeded;
+
 extern void _initialize_mi_main (void);
 static void mi_cmd_execute (struct mi_parse *parse);
 
@@ -1147,6 +1151,7 @@ captured_mi_execute_command (struct ui_o
   cleanup = make_cleanup (free_current_contents, &current_token);
 
   running_result_record_printed = 0;
+  mi_proceeded = 0;
   switch (context->op)
     {
     case MI_COMMAND:


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]