This is the mail archive of the gdb-patches@sources.redhat.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]

[rfc] ui_out_is_mi_like_p(); Was: [patch] Add -i=mi0 as an interpreter


> Most of it is straight forward.  The 
>> nasty bit is where I s/strcmp/strncmp/ in breakpoint.c and infrun.c. 
> 
> 
> Why can't this strncmp be done in one place and then saved in some
> variable?  If you do need to use strncmp all over the place, then I
> can't say I care to see the magical constants "mi" and 2 every time
> you do ;-)


The attached patch replaces:

> ! 	  if (interpreter_p && strncmp (interpreter_p, "mi", 2) == 0)
> 

with:

	if (ui_out_is_mi_like_p (uiout))

it addresses the immedate concern and creates a name so horrible that no 
one will want to use it :-)

	Andrew
2001-07-04  Andrew Cagney  <ac131313@redhat.com>

	* ui-out.h (struct ui_out_impl): Add field is_mi_like_p.
	(ui_out_is_mi_like_p): Declare.
	* ui-out.c (ui_out_is_mi_like_p): Define.
	(default_ui_out_impl): Initialize is_mi_like_p to zero.
	* cli-out.c (cli_ui_out_impl): Ditto.
	* breakpoint.c (print_it_typical): Use ui_out_is_mi_like_p.
	(watchpoint_check, print_one_breakpoint, mention): Ditto.
	* infrun.c (print_stop_reason, normal_stop): Ditto.

Index: mi/ChangeLog
2001-07-04  Andrew Cagney  <ac131313@redhat.com>

	* mi-out.c (mi_ui_out_impl): Initialize is_mi_like_p to one.

Index: breakpoint.c
===================================================================
RCS file: /cvs/src/src/gdb/breakpoint.c,v
retrieving revision 1.48
diff -p -r1.48 breakpoint.c
*** breakpoint.c	2001/06/28 21:34:03	1.48
--- breakpoint.c	2001/07/04 22:26:58
*************** print_it_typical (bpstat bs)
*** 1889,1895 ****
  #ifdef UI_OUT
        annotate_breakpoint (bs->breakpoint_at->number);
        ui_out_text (uiout, "\nBreakpoint ");
!       if (interpreter_p && strncmp (interpreter_p, "mi", 2) == 0)
  	ui_out_field_string (uiout, "reason", "breakpoint-hit");
        ui_out_field_int (uiout, "bkptno", bs->breakpoint_at->number);
        ui_out_text (uiout, ", ");
--- 1889,1895 ----
  #ifdef UI_OUT
        annotate_breakpoint (bs->breakpoint_at->number);
        ui_out_text (uiout, "\nBreakpoint ");
!       if (ui_out_is_mi_like_p (uiout))
  	ui_out_field_string (uiout, "reason", "breakpoint-hit");
        ui_out_field_int (uiout, "bkptno", bs->breakpoint_at->number);
        ui_out_text (uiout, ", ");
*************** print_it_typical (bpstat bs)
*** 2034,2040 ****
  	{
  	  annotate_watchpoint (bs->breakpoint_at->number);
  #ifdef UI_OUT
! 	  if (interpreter_p && strncmp (interpreter_p, "mi", 2) == 0)
  	    ui_out_field_string (uiout, "reason", "watchpoint-trigger");
  	  mention (bs->breakpoint_at);
  	  ui_out_tuple_begin (uiout, "value");
--- 2034,2040 ----
  	{
  	  annotate_watchpoint (bs->breakpoint_at->number);
  #ifdef UI_OUT
! 	  if (ui_out_is_mi_like_p (uiout))
  	    ui_out_field_string (uiout, "reason", "watchpoint-trigger");
  	  mention (bs->breakpoint_at);
  	  ui_out_tuple_begin (uiout, "value");
*************** print_it_typical (bpstat bs)
*** 2064,2070 ****
  
      case bp_read_watchpoint:
  #ifdef UI_OUT
!       if (interpreter_p && strncmp (interpreter_p, "mi", 2) == 0)
  	ui_out_field_string (uiout, "reason", "read-watchpoint-trigger");
        mention (bs->breakpoint_at);
        ui_out_tuple_begin (uiout, "value");
--- 2064,2070 ----
  
      case bp_read_watchpoint:
  #ifdef UI_OUT
!       if (ui_out_is_mi_like_p (uiout))
  	ui_out_field_string (uiout, "reason", "read-watchpoint-trigger");
        mention (bs->breakpoint_at);
        ui_out_tuple_begin (uiout, "value");
*************** print_it_typical (bpstat bs)
*** 2088,2094 ****
        if (bs->old_val != NULL)     
  	{
  	  annotate_watchpoint (bs->breakpoint_at->number);
! 	  if (interpreter_p && strncmp (interpreter_p, "mi", 2) == 0)
  	    ui_out_field_string (uiout, "reason", "access-watchpoint-trigger");
  	  mention (bs->breakpoint_at);
  	  ui_out_tuple_begin (uiout, "value");
--- 2088,2094 ----
        if (bs->old_val != NULL)     
  	{
  	  annotate_watchpoint (bs->breakpoint_at->number);
! 	  if (ui_out_is_mi_like_p (uiout))
  	    ui_out_field_string (uiout, "reason", "access-watchpoint-trigger");
  	  mention (bs->breakpoint_at);
  	  ui_out_tuple_begin (uiout, "value");
*************** print_it_typical (bpstat bs)
*** 2102,2108 ****
        else 
  	{
  	  mention (bs->breakpoint_at);
! 	  if (interpreter_p && strncmp (interpreter_p, "mi", 2) == 0)
  	    ui_out_field_string (uiout, "reason", "access-watchpoint-trigger");
  	  ui_out_tuple_begin (uiout, "value");
  	  ui_out_text (uiout, "\nValue = ");
--- 2102,2108 ----
        else 
  	{
  	  mention (bs->breakpoint_at);
! 	  if (ui_out_is_mi_like_p (uiout))
  	    ui_out_field_string (uiout, "reason", "access-watchpoint-trigger");
  	  ui_out_tuple_begin (uiout, "value");
  	  ui_out_text (uiout, "\nValue = ");
*************** print_it_typical (bpstat bs)
*** 2139,2145 ****
  
      case bp_finish:
  #ifdef UI_OUT
!       if (interpreter_p && strncmp (interpreter_p, "mi", 2) == 0)
  	ui_out_field_string (uiout, "reason", "function-finished");
  #endif
        return PRINT_UNKNOWN;
--- 2139,2145 ----
  
      case bp_finish:
  #ifdef UI_OUT
!       if (ui_out_is_mi_like_p (uiout))
  	ui_out_field_string (uiout, "reason", "function-finished");
  #endif
        return PRINT_UNKNOWN;
*************** print_it_typical (bpstat bs)
*** 2147,2153 ****
  
      case bp_until:
  #ifdef UI_OUT
!       if (interpreter_p && strncmp (interpreter_p, "mi", 2) == 0)
  	ui_out_field_string (uiout, "reason", "location-reached");
  #endif
        return PRINT_UNKNOWN;
--- 2147,2153 ----
  
      case bp_until:
  #ifdef UI_OUT
!       if (ui_out_is_mi_like_p (uiout))
  	ui_out_field_string (uiout, "reason", "location-reached");
  #endif
        return PRINT_UNKNOWN;
*************** watchpoint_check (PTR p)
*** 2354,2360 ****
  	 will be deleted already. So we have no choice but print the
  	 information here. */
  #ifdef UI_OUT
!       if (interpreter_p && strncmp (interpreter_p, "mi", 2) == 0)
  	ui_out_field_string (uiout, "reason", "watchpoint-scope");
        ui_out_text (uiout, "\nWatchpoint ");
        ui_out_field_int (uiout, "wpnum", bs->breakpoint_at->number);
--- 2354,2360 ----
  	 will be deleted already. So we have no choice but print the
  	 information here. */
  #ifdef UI_OUT
!       if (ui_out_is_mi_like_p (uiout))
  	ui_out_field_string (uiout, "reason", "watchpoint-scope");
        ui_out_text (uiout, "\nWatchpoint ");
        ui_out_field_int (uiout, "wpnum", bs->breakpoint_at->number);
*************** print_one_breakpoint (struct breakpoint 
*** 3481,3487 ****
  #ifdef UI_OUT
    /* Output the count also if it is zero, but only if this is
       mi. FIXME: Should have a better test for this. */
!   if (interpreter_p && strncmp (interpreter_p, "mi", 2) == 0)
      if (show_breakpoint_hit_counts && b->hit_count == 0)
        ui_out_field_int (uiout, "times", b->hit_count);
  #endif
--- 3481,3487 ----
  #ifdef UI_OUT
    /* Output the count also if it is zero, but only if this is
       mi. FIXME: Should have a better test for this. */
!   if (ui_out_is_mi_like_p (uiout))
      if (show_breakpoint_hit_counts && b->hit_count == 0)
        ui_out_field_int (uiout, "times", b->hit_count);
  #endif
*************** mention (struct breakpoint *b)
*** 4509,4515 ****
  #endif
      case bp_breakpoint:
  #ifdef UI_OUT
!       if (interpreter_p && strncmp (interpreter_p, "mi", 2) == 0)
  	{
  	  say_where = 0;
  	  break;
--- 4509,4515 ----
  #endif
      case bp_breakpoint:
  #ifdef UI_OUT
!       if (ui_out_is_mi_like_p (uiout))
  	{
  	  say_where = 0;
  	  break;
*************** mention (struct breakpoint *b)
*** 4520,4526 ****
        break;
      case bp_hardware_breakpoint:
  #ifdef UI_OUT
!       if (interpreter_p && strncmp (interpreter_p, "mi", 2) == 0)
  	{
  	  say_where = 0;
  	  break;
--- 4520,4526 ----
        break;
      case bp_hardware_breakpoint:
  #ifdef UI_OUT
!       if (ui_out_is_mi_like_p (uiout))
  	{
  	  say_where = 0;
  	  break;
*************** mention (struct breakpoint *b)
*** 4583,4589 ****
    do_cleanups (old_chain);
  #endif
  #ifdef UI_OUT
!   if (interpreter_p && strncmp (interpreter_p, "mi", 2) == 0)
      return;
  #endif
    printf_filtered ("\n");
--- 4583,4589 ----
    do_cleanups (old_chain);
  #endif
  #ifdef UI_OUT
!   if (ui_out_is_mi_like_p (uiout))
      return;
  #endif
    printf_filtered ("\n");
Index: cli-out.c
===================================================================
RCS file: /cvs/src/src/gdb/cli-out.c,v
retrieving revision 1.12
diff -p -r1.12 cli-out.c
*** cli-out.c	2001/06/21 22:54:06	1.12
--- cli-out.c	2001/07/04 22:26:58
*************** static struct ui_out_impl cli_ui_out_imp
*** 89,95 ****
    cli_text,
    cli_message,
    cli_wrap_hint,
!   cli_flush
  };
  
  /* Prototypes for local functions */
--- 89,96 ----
    cli_text,
    cli_message,
    cli_wrap_hint,
!   cli_flush,
!   0, /* Does not need MI hacks (i.e. needs CLI hacks).  */
  };
  
  /* Prototypes for local functions */
Index: infrun.c
===================================================================
RCS file: /cvs/src/src/gdb/infrun.c,v
retrieving revision 1.41
diff -p -r1.41 infrun.c
*** infrun.c	2001/06/28 21:48:41	1.41
--- infrun.c	2001/07/04 22:27:13
*************** print_stop_reason (enum inferior_stop_re
*** 3308,3314 ****
        /* 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 && strncmp (interpreter_p, "mi", 2) == 0)
  	  ui_out_field_string (uiout, "reason", "end-stepping-range");
  #endif
        break;
--- 3308,3314 ----
        /* Print a message only if not in the middle of doing a "step n"
  	 operation for n > 1 */
        if (!step_multi || !stop_step)
! 	if (ui_out_is_mi_like_p (uiout))
  	  ui_out_field_string (uiout, "reason", "end-stepping-range");
  #endif
        break;
*************** print_stop_reason (enum inferior_stop_re
*** 3320,3326 ****
        /* The inferior was terminated by a signal. */
  #ifdef UI_OUT
        annotate_signalled ();
!       if (interpreter_p && strncmp (interpreter_p, "mi", 2) == 0)
  	ui_out_field_string (uiout, "reason", "exited-signalled");
        ui_out_text (uiout, "\nProgram terminated with signal ");
        annotate_signal_name ();
--- 3320,3326 ----
        /* The inferior was terminated by a signal. */
  #ifdef UI_OUT
        annotate_signalled ();
!       if (ui_out_is_mi_like_p (uiout))
  	ui_out_field_string (uiout, "reason", "exited-signalled");
        ui_out_text (uiout, "\nProgram terminated with signal ");
        annotate_signal_name ();
*************** print_stop_reason (enum inferior_stop_re
*** 3354,3360 ****
        annotate_exited (stop_info);
        if (stop_info)
  	{
! 	  if (interpreter_p && strncmp (interpreter_p, "mi", 2) == 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);
--- 3354,3360 ----
        annotate_exited (stop_info);
        if (stop_info)
  	{
! 	  if (ui_out_is_mi_like_p (uiout))
  	    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);
*************** print_stop_reason (enum inferior_stop_re
*** 3362,3368 ****
  	}
        else
  	{
! 	  if (interpreter_p && strncmp (interpreter_p, "mi", 2) == 0)
  	    ui_out_field_string (uiout, "reason", "exited-normally");
  	  ui_out_text (uiout, "\nProgram exited normally.\n");
  	}
--- 3362,3368 ----
  	}
        else
  	{
! 	  if (ui_out_is_mi_like_p (uiout))
  	    ui_out_field_string (uiout, "reason", "exited-normally");
  	  ui_out_text (uiout, "\nProgram exited normally.\n");
  	}
*************** and/or watchpoints.\n");
*** 3548,3559 ****
  #ifdef UI_OUT
  	  /* For mi, have the same behavior every time we stop:
               print everything but the source line. */
! 	  if (interpreter_p && strncmp (interpreter_p, "mi", 2) == 0)
  	    source_flag = LOC_AND_ADDRESS;
  #endif
  
  #ifdef UI_OUT
! 	  if (interpreter_p && strncmp (interpreter_p, "mi", 2) == 0)
  	    ui_out_field_int (uiout, "thread-id",
  	                      pid_to_thread_id (inferior_ptid));
  #endif
--- 3548,3559 ----
  #ifdef UI_OUT
  	  /* For mi, have the same behavior every time we stop:
               print everything but the source line. */
! 	  if (ui_out_is_mi_like_p (uiout))
  	    source_flag = LOC_AND_ADDRESS;
  #endif
  
  #ifdef UI_OUT
! 	  if (ui_out_is_mi_like_p (uiout))
  	    ui_out_field_int (uiout, "thread-id",
  	                      pid_to_thread_id (inferior_ptid));
  #endif
Index: ui-out.c
===================================================================
RCS file: /cvs/src/src/gdb/ui-out.c,v
retrieving revision 1.17
diff -p -r1.17 ui-out.c
*** ui-out.c	2001/06/21 15:39:52	1.17
--- ui-out.c	2001/07/04 22:27:14
*************** struct ui_out_impl default_ui_out_impl =
*** 190,196 ****
    default_text,
    default_message,
    default_wrap_hint,
!   default_flush
  };
  
  /* The default ui_out */
--- 190,197 ----
    default_text,
    default_message,
    default_wrap_hint,
!   default_flush,
!   0, /* Does not need MI hacks.  */
  };
  
  /* The default ui_out */
*************** gdb_query (struct ui_out *uiout, int qfl
*** 711,716 ****
--- 712,723 ----
  {
  }
  #endif
+ 
+ int
+ ui_out_is_mi_like_p (struct ui_out *uiout)
+ {
+   return uiout->impl->is_mi_like_p;
+ }
  
  /* default gdb-out hook functions */
  
Index: ui-out.h
===================================================================
RCS file: /cvs/src/src/gdb/ui-out.h,v
retrieving revision 1.14
diff -p -r1.14 ui-out.h
*** ui-out.h	2001/06/21 15:39:52	1.14
--- ui-out.h	2001/07/04 22:27:15
*************** extern void gdb_error (struct ui_out *ui
*** 184,189 ****
--- 184,197 ----
  extern void gdb_query (struct ui_out *uiout, int qflags, char *qprompt);
  #endif
  
+ /* HACK: Some code in core GDB is currently looks at the output
+    builder to determine what output should be generated.  This
+    function is a hack to encapsulate that test.  Once GDB manages to
+    separate the CLI/MI from the core of GDB the problem should just go
+    away....  */
+ 
+ extern int ui_out_is_mi_like_p (struct ui_out *uiout);
+ 
  /* From here on we have things that are only needed by implementation
     routines and main.c.   We should pehaps have a separate file for that,
     like a  ui-out-impl.h  file */
*************** struct ui_out_impl
*** 253,258 ****
--- 261,267 ----
      message_ftype *message;
      wrap_hint_ftype *wrap_hint;
      flush_ftype *flush;
+     int is_mi_like_p;
    };
  
  extern struct ui_out_data *ui_out_data (struct ui_out *uiout);
Index: mi/mi-out.c
===================================================================
RCS file: /cvs/src/src/gdb/mi/mi-out.c,v
retrieving revision 1.19
diff -p -r1.19 mi-out.c
*** mi-out.c	2001/06/27 17:27:06	1.19
--- mi-out.c	2001/07/04 22:28:11
*************** struct ui_out_impl mi_ui_out_impl =
*** 88,94 ****
    mi_text,
    mi_message,
    mi_wrap_hint,
!   mi_flush
  };
  
  /* Prototypes for local functions */
--- 88,95 ----
    mi_text,
    mi_message,
    mi_wrap_hint,
!   mi_flush,
!   1, /* Needs MI hacks.  */
  };
  
  /* Prototypes for local functions */

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