This is the mail archive of the gdb@sourceware.cygnus.com 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]

Some handle_inferior_event() cleanups



This cleanup moves all the code that prints the reason for stopping
out of handle_inferior_event(), into a print_stop_reason() routine.
Right now only the exited, exited with signal and signalled cases are
handled. However this mechanism will facilitate handling other cases
like when the end of the stepping range is reached, or when a shlib
event occurs. The motivation for this being that future gdblib clients
may need to do more than just printing a message to the interface.
print_stop_reason() (or a corresponding interface specific function)
would be the place where the extra information can be passed to the
user interface. Possibly whenever handle_inferior_event() calls
stop_stepping(), print_stop_reason() could also be called, if
necessary.

Elena 

Index: infrun.c
===================================================================
RCS file: /cvs/cvsfiles/devo/gdb/infrun.c,v
retrieving revision 1.259
diff -c -r1.259 infrun.c
*** infrun.c	1999/10/18 16:03:44	1.259
--- infrun.c	1999/11/02 17:57:02
***************
*** 1160,1165 ****
--- 1160,1183 ----
    infwait_nonstep_watch_state
  };
  
+ /* Why did the inferior stop? Used to print the appropriate messages
+    to the interface from within handle_inferior_event(). */
+ enum inferior_stop_reason
+ {
+   /* We don't know why. */
+   STOP_UNKNOWN,
+   /* Step, next, nexti, stepi finished. */
+   END_STEPPING_RANGE,
+   /* Found breakpoint. */
+   BREAKPOINT_HIT,
+   /* Inferior terminated by signal. */
+   SIGNAL_EXITED,
+   /* Inferior exited. */
+   EXITED,
+   /* Inferior received signal, and user asked to be notified. */
+   SIGNAL_RECEIVED
+ };
+ 
  /* This structure contains what used to be local variables in
     wait_for_inferior.  Probably many of them can return to being
     locals in handle_inferior_event.  */
***************
*** 1202,1207 ****
--- 1220,1226 ----
  static void stop_stepping (struct execution_control_state *ecs);
  static void prepare_to_wait (struct execution_control_state *ecs);
  static void keep_going (struct execution_control_state *ecs);
+ static void print_stop_reason (enum inferior_stop_reason stop_reason, int stop_info);
  
  /* Wait for control to return from inferior to debugger.
     If inferior gets a signal, we may decide to start it up again
***************
*** 1499,1510 ****
  
        case TARGET_WAITKIND_EXITED:
  	target_terminal_ours ();	/* Must do this before mourn anyway */
! 	annotate_exited (ecs->ws.value.integer);
! 	if (ecs->ws.value.integer)
! 	  printf_filtered ("\nProgram exited with code 0%o.\n",
! 			   (unsigned int) ecs->ws.value.integer);
! 	else
! 	  printf_filtered ("\nProgram exited normally.\n");
  
  	/* Record the exit code in the convenience variable $_exitcode, so
  	   that the user can inspect this again later.  */
--- 1518,1524 ----
  
        case TARGET_WAITKIND_EXITED:
  	target_terminal_ours ();	/* Must do this before mourn anyway */
! 	print_stop_reason (EXITED, ecs->ws.value.integer);
  
  	/* Record the exit code in the convenience variable $_exitcode, so
  	   that the user can inspect this again later.  */
***************
*** 1522,1528 ****
  	stop_print_frame = 0;
  	stop_signal = ecs->ws.value.sig;
  	target_terminal_ours ();	/* Must do this before mourn anyway */
- 	annotate_signalled ();
  
  	/* This looks pretty bogus to me.  Doesn't TARGET_WAITKIND_SIGNALLED
  	   mean it is already dead?  This has been here since GDB 2.8, so
--- 1536,1541 ----
***************
*** 1530,1548 ****
  	   For the moment I'm just kludging around this in remote.c
  	   rather than trying to change it here --kingdon, 5 Dec 1994.  */
  	target_kill ();		/* kill mourns as well */
- 
- 	printf_filtered ("\nProgram terminated with signal ");
- 	annotate_signal_name ();
- 	printf_filtered ("%s", target_signal_to_name (stop_signal));
- 	annotate_signal_name_end ();
- 	printf_filtered (", ");
- 	annotate_signal_string ();
- 	printf_filtered ("%s", target_signal_to_string (stop_signal));
- 	annotate_signal_string_end ();
- 	printf_filtered (".\n");
  
! 	printf_filtered ("The program no longer exists.\n");
! 	gdb_flush (gdb_stdout);
  	singlestep_breakpoints_inserted_p = 0;	/*SOFTWARE_SINGLE_STEP_P */
  	stop_stepping (ecs);
  	return;
--- 1543,1550 ----
  	   For the moment I'm just kludging around this in remote.c
  	   rather than trying to change it here --kingdon, 5 Dec 1994.  */
  	target_kill ();		/* kill mourns as well */
  
! 	print_stop_reason (SIGNAL_EXITED, stop_signal);
  	singlestep_breakpoints_inserted_p = 0;	/*SOFTWARE_SINGLE_STEP_P */
  	stop_stepping (ecs);
  	return;
***************
*** 2182,2198 ****
  	  {
  	    printed = 1;
  	    target_terminal_ours_for_output ();
! 	    annotate_signal ();
! 	    printf_filtered ("\nProgram received signal ");
! 	    annotate_signal_name ();
! 	    printf_filtered ("%s", target_signal_to_name (stop_signal));
! 	    annotate_signal_name_end ();
! 	    printf_filtered (", ");
! 	    annotate_signal_string ();
! 	    printf_filtered ("%s", target_signal_to_string (stop_signal));
! 	    annotate_signal_string_end ();
! 	    printf_filtered (".\n");
! 	    gdb_flush (gdb_stdout);
  	  }
  	if (signal_stop[stop_signal])
  	  {
--- 2184,2190 ----
  	  {
  	    printed = 1;
  	    target_terminal_ours_for_output ();
! 	    print_stop_reason (SIGNAL_RECEIVED, stop_signal);
  	  }
  	if (signal_stop[stop_signal])
  	  {
***************
*** 3191,3196 ****
--- 3183,3256 ----
       want to wait for the inferior some more and get called again
       soon.  */
    ecs->wait_some_more = 1;
+ }
+ 
+ /* Print why the inferior has stopped. We always print something when
+    the inferior exits, or receives a signal. The rest of the cases are
+    dealt with later on in normal_stop() and print_it_typical().  Ideally
+    there should be a call to this function from handle_inferior_event()
+    each time stop_stepping() is called.*/
+ static void
+ print_stop_reason (enum inferior_stop_reason stop_reason, int stop_info)
+ {
+   switch (stop_reason)
+     {
+     case STOP_UNKNOWN:
+       /* We don't deal with these cases from handle_inferior_event()
+          yet. */
+       break;
+     case END_STEPPING_RANGE:
+       /* We are done with a step/next/si/ni command. */
+       /* For now print nothing. */
+       break;
+     case BREAKPOINT_HIT:
+       /* We found a breakpoint. */
+       /* For now print nothing. */
+       break;
+     case SIGNAL_EXITED:
+       /* The inferior was terminated by a signal. */
+       annotate_signalled ();
+       printf_filtered ("\nProgram terminated with signal ");
+       annotate_signal_name ();
+       printf_filtered ("%s", target_signal_to_name (stop_info));
+       annotate_signal_name_end ();
+       printf_filtered (", ");
+       annotate_signal_string ();
+       printf_filtered ("%s", target_signal_to_string (stop_info));
+       annotate_signal_string_end ();
+       printf_filtered (".\n");
+ 
+       printf_filtered ("The program no longer exists.\n");
+       gdb_flush (gdb_stdout);
+       break;
+     case EXITED:
+       /* The inferior program is finished. */
+       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");
+       break;
+     case SIGNAL_RECEIVED:
+       /* Signal received. The signal table tells us to print about
+          it. */
+       annotate_signal ();
+       printf_filtered ("\nProgram received signal ");
+       annotate_signal_name ();
+       printf_filtered ("%s", target_signal_to_name (stop_info));
+       annotate_signal_name_end ();
+       printf_filtered (", ");
+       annotate_signal_string ();
+       printf_filtered ("%s", target_signal_to_string (stop_info));
+       annotate_signal_string_end ();
+       printf_filtered (".\n");
+       gdb_flush (gdb_stdout);      
+       break;
+     default:
+       internal_error ("print_stop_reason: unrecognized enum value");
+       break;
+     }
  }
  
  

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