Add mi/ and testsuite/gdb.mi/ subdirectories.
[deliverable/binutils-gdb.git] / gdb / infrun.c
index be1e6c78105347a8a311f60e1c726bba7138db36..2a3a1c8f99adb78d72e431acaf6385af8f95f044 100644 (file)
@@ -1,5 +1,5 @@
 /* Target-struct-independent code to start (run) and stop an inferior process.
-   Copyright 1986-1989, 1991-1999 Free Software Foundation, Inc.
+   Copyright 1986-1989, 1991-2000 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -25,7 +25,7 @@
 #include "frame.h"
 #include "inferior.h"
 #include "breakpoint.h"
-#include "wait.h"
+#include "gdb_wait.h"
 #include "gdbcore.h"
 #include "gdbcmd.h"
 #include "target.h"
@@ -861,6 +861,8 @@ resume (int step, enum target_signal sig)
 
   if (should_resume)
     {
+      int resume_pid;
+
       if (use_thread_step_needed && thread_step_needed)
        {
          /* We stopped on a BPT instruction;
@@ -872,7 +874,7 @@ resume (int step, enum target_signal sig)
            {
              /* Breakpoint deleted: ok to do regular resume
                 where all the threads either step or continue. */
-             target_resume (-1, step, sig);
+             resume_pid = -1;
            }
          else
            {
@@ -884,20 +886,19 @@ resume (int step, enum target_signal sig)
                  trap_expected = 1;
                  step = 1;
                }
-
-             target_resume (inferior_pid, step, sig);
+             resume_pid = inferior_pid;
            }
        }
       else
        {
          /* Vanilla resume. */
-
          if ((scheduler_mode == schedlock_on) ||
              (scheduler_mode == schedlock_step && step != 0))
-           target_resume (inferior_pid, step, sig);
+           resume_pid = inferior_pid;
          else
-           target_resume (-1, step, sig);
+           resume_pid = -1;
        }
+      target_resume (resume_pid, step, sig);
     }
 
   discard_cleanups (old_cleanups);
@@ -1441,7 +1442,13 @@ handle_inferior_event (struct execution_control_state *ecs)
       {
        add_thread (ecs->pid);
 
+#ifdef UI_OUT
+       ui_out_text (uiout, "[New ");
+       ui_out_text (uiout, target_pid_or_tid_to_str (ecs->pid));
+       ui_out_text (uiout, "]\n");
+#else
        printf_filtered ("[New %s]\n", target_pid_or_tid_to_str (ecs->pid));
+#endif
 
 #if 0
        /* NOTE: This block is ONLY meant to be invoked in case of a
@@ -3216,6 +3223,13 @@ print_stop_reason (enum inferior_stop_reason stop_reason, int stop_info)
     case END_STEPPING_RANGE:
       /* We are done with a step/next/si/ni command. */
       /* For now print nothing. */
+#ifdef UI_OUT
+      /* Print a message only if not in the middle of doing a "step n"
+        operation for n > 1 */
+      if (!step_multi || !stop_step)
+       if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
+         ui_out_field_string (uiout, "reason", "end-stepping-range");
+#endif
       break;
     case BREAKPOINT_HIT:
       /* We found a breakpoint. */
@@ -3223,6 +3237,21 @@ print_stop_reason (enum inferior_stop_reason stop_reason, int stop_info)
       break;
     case SIGNAL_EXITED:
       /* The inferior was terminated by a signal. */
+#ifdef UI_OUT
+      annotate_signalled ();
+      if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
+       ui_out_field_string (uiout, "reason", "exited-signalled");
+      ui_out_text (uiout, "\nProgram terminated with signal ");
+      annotate_signal_name ();
+      ui_out_field_string (uiout, "signal-name", target_signal_to_name (stop_info));
+      annotate_signal_name_end ();
+      ui_out_text (uiout, ", ");
+      annotate_signal_string ();
+      ui_out_field_string (uiout, "signal-meaning", target_signal_to_string (stop_info));
+      annotate_signal_string_end ();
+      ui_out_text (uiout, ".\n");
+      ui_out_text (uiout, "The program no longer exists.\n");
+#else
       annotate_signalled ();
       printf_filtered ("\nProgram terminated with signal ");
       annotate_signal_name ();
@@ -3236,19 +3265,50 @@ print_stop_reason (enum inferior_stop_reason stop_reason, int stop_info)
 
       printf_filtered ("The program no longer exists.\n");
       gdb_flush (gdb_stdout);
+#endif
       break;
     case EXITED:
       /* The inferior program is finished. */
+#ifdef UI_OUT
+      annotate_exited (stop_info);
+      if (stop_info)
+       {
+         if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
+           ui_out_field_string (uiout, "reason", "exited");
+         ui_out_text (uiout, "\nProgram exited with code ");
+         ui_out_field_fmt (uiout, "exit-code", "0%o", (unsigned int) stop_info);
+         ui_out_text (uiout, ".\n");
+       }
+      else
+       {
+         if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
+           ui_out_field_string (uiout, "reason", "exited-normally");
+         ui_out_text (uiout, "\nProgram exited normally.\n");
+       }
+#else
       annotate_exited (stop_info);
       if (stop_info)
        printf_filtered ("\nProgram exited with code 0%o.\n",
                         (unsigned int) stop_info);
       else
        printf_filtered ("\nProgram exited normally.\n");
+#endif
       break;
     case SIGNAL_RECEIVED:
       /* Signal received. The signal table tells us to print about
          it. */
+#ifdef UI_OUT
+      annotate_signal ();
+      ui_out_text (uiout, "\nProgram received signal ");
+      annotate_signal_name ();
+      ui_out_field_string (uiout, "signal-name", target_signal_to_name (stop_info));
+      annotate_signal_name_end ();
+      ui_out_text (uiout, ", ");
+      annotate_signal_string ();
+      ui_out_field_string (uiout, "signal-meaning", target_signal_to_string (stop_info));
+      annotate_signal_string_end ();
+      ui_out_text (uiout, ".\n");
+#else
       annotate_signal ();
       printf_filtered ("\nProgram received signal ");
       annotate_signal_name ();
@@ -3260,6 +3320,7 @@ print_stop_reason (enum inferior_stop_reason stop_reason, int stop_info)
       annotate_signal_string_end ();
       printf_filtered (".\n");
       gdb_flush (gdb_stdout);      
+#endif
       break;
     default:
       internal_error ("print_stop_reason: unrecognized enum value");
@@ -3381,15 +3442,15 @@ The same program may be running in another process.\n");
              if (stop_step
                  && step_frame_address == FRAME_FP (get_current_frame ())
                  && step_start_function == find_pc_function (stop_pc))
-               source_flag = -1;   /* finished step, just print source line */
+               source_flag = SRC_LINE;   /* finished step, just print source line */
              else
-               source_flag = 1;    /* print location and source line */
+               source_flag = SRC_AND_LOC;    /* print location and source line */
              break;
            case PRINT_SRC_AND_LOC:
-             source_flag = 1;      /* print location and source line */
+             source_flag = SRC_AND_LOC;    /* print location and source line */
              break;
            case PRINT_SRC_ONLY:
-             source_flag = -1;
+             source_flag = SRC_LINE;
              break;
            case PRINT_NOTHING:
              do_frame_printing = 0;
@@ -3397,12 +3458,22 @@ The same program may be running in another process.\n");
            default:
              internal_error ("Unknown value.");
            }
+#ifdef UI_OUT
+         /* For mi, have the same behavior every time we stop:
+             print everything but the source line. */
+         if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
+           source_flag = LOC_AND_ADDRESS;
+#endif
 
+#ifdef UI_OUT
+         if (interpreter_p && strcmp (interpreter_p, "mi") == 0)
+           ui_out_field_int (uiout, "thread-id", pid_to_thread_id (inferior_pid));
+#endif
          /* The behavior of this routine with respect to the source
             flag is:
-            -1: Print only source line
-            0: Print only location
-            1: Print location and source line */
+            SRC_LINE: Print only source line
+            LOCATION: Print only location
+            SRC_AND_LOC: Print location and source line */
          if (do_frame_printing)
            show_and_print_stack_frame (selected_frame, -1, source_flag);
 
This page took 0.026592 seconds and 4 git commands to generate.