Emit inferior, thread and frame selection events to all UIs
[deliverable/binutils-gdb.git] / gdb / cli / cli-interp.c
index b0eef293971f4c391c8281d608b1a25f1e79dd63..cc556a457cace7524d84504d5caaf95e0bacfb48 100644 (file)
@@ -37,6 +37,12 @@ struct cli_interp
   struct ui_out *cli_uiout;
 };
 
+/* Suppress notification struct.  */
+struct cli_suppress_notification cli_suppress_notification =
+  {
+    0   /* user_selected_context_changed */
+  };
+
 /* Returns the INTERP's data cast as cli_interp if INTERP is a CLI,
    and returns NULL otherwise.  */
 
@@ -77,10 +83,9 @@ should_print_stop_to_console (struct interp *console_interp,
 {
   if ((bpstat_what (tp->control.stop_bpstat).main_action
        == BPSTAT_WHAT_STOP_NOISY)
-      || !(tp->thread_fsm != NULL
-          && thread_fsm_finished_p (tp->thread_fsm))
-      || (tp->control.command_interp != NULL
-         && tp->control.command_interp == console_interp))
+      || tp->thread_fsm == NULL
+      || tp->thread_fsm->command_interp == console_interp
+      || !thread_fsm_finished_p (tp->thread_fsm))
     return 1;
   return 0;
 }
@@ -96,14 +101,20 @@ cli_on_normal_stop (struct bpstats *bs, int print_frame)
 {
   struct switch_thru_all_uis state;
 
+  if (!print_frame)
+    return;
+
   SWITCH_THRU_ALL_UIS (state)
     {
-      struct cli_interp *cli = as_cli_interp (top_level_interpreter ());
+      struct interp *interp = top_level_interpreter ();
+      struct cli_interp *cli = as_cli_interp (interp);
+      struct thread_info *thread;
 
       if (cli == NULL)
        continue;
 
-      if (print_frame)
+      thread = inferior_thread ();
+      if (should_print_stop_to_console (interp, thread))
        print_stop_event (cli->cli_uiout);
     }
 }
@@ -224,6 +235,36 @@ cli_on_command_error (void)
   display_gdb_prompt (NULL);
 }
 
+/* Observer for the user_selected_context_changed notification.  */
+
+static void
+cli_on_user_selected_context_changed (user_selected_what selection)
+{
+  struct switch_thru_all_uis state;
+  struct thread_info *tp;
+
+  /* This event is suppressed.  */
+  if (cli_suppress_notification.user_selected_context)
+    return;
+
+  tp = find_thread_ptid (inferior_ptid);
+
+  SWITCH_THRU_ALL_UIS (state)
+    {
+      struct cli_interp *cli = as_cli_interp (top_level_interpreter ());
+
+      if (cli == NULL)
+       continue;
+
+      if (selection & USER_SELECTED_INFERIOR)
+       print_selected_inferior (cli->cli_uiout);
+
+      if (tp != NULL
+         && ((selection & (USER_SELECTED_THREAD | USER_SELECTED_FRAME))))
+       print_selected_thread_frame (cli->cli_uiout, selection);
+    }
+}
+
 /* pre_command_loop implementation.  */
 
 void
@@ -388,4 +429,6 @@ _initialize_cli_interp (void)
   observer_attach_no_history (cli_on_no_history);
   observer_attach_sync_execution_done (cli_on_sync_execution_done);
   observer_attach_command_error (cli_on_command_error);
+  observer_attach_user_selected_context_changed
+    (cli_on_user_selected_context_changed);
 }
This page took 0.025012 seconds and 4 git commands to generate.