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]
Other format: [Raw text]

[patch/rfc] Revamp ui-out table verification


Hello,

Hopefully (?) the attached addresses the problem JimI found with the 
ui-out table code.  It keeps track of the table.entry_level and uses 
that to decide what to do.

That should restrict it to updating header fields for table row entries 
and not all fields.

It doesn't cause any regressions.  I need to think of a way of testing 
it.  Perhaphs I'll just hack my local breakpoint.c a bit.

	Andrew
2001-12-08  Andrew Cagney  <ac131313@redhat.com>

	* ui-out.c (struct ui_out_table): Add field entry_level.
	(verify_field): New function.
	(verify_field_proper_position): Delete function.
	(verify_field_alignment): Delete function.
	(ui_out_field_int): Update to use verify_field.
	(ui_out_field_skip): Ditto.
	(ui_out_field_string): Ditto.
	(ui_out_field_fmt): Ditto.
	(ui_out_table_begin): Initialize table.entry_level.
	(ui_out_table_end): Clear table.entry_level.
	(ui_out_begin): Call verify_field before pushing the new tuple or
	list onto the stack.  Use table.entry_level.

Index: ui-out.c
===================================================================
RCS file: /cvs/src/src/gdb/ui-out.c,v
retrieving revision 1.19
diff -p -r1.19 ui-out.c
*** ui-out.c	2001/12/07 17:51:13	1.19
--- ui-out.c	2001/12/09 18:18:46
*************** struct ui_out_table
*** 71,76 ****
--- 71,81 ----
       header is being generated.  */
    int body_flag;
  
+   /* The level at which each entry of the table is to be found.  A row
+      (a tuple) is made up of entries.  Consequently ENTRY_LEVEL is one
+      above that of the table.  */
+   int entry_level;
+ 
    /* Number of table columns (as specified in the table_begin call).  */
    int columns;
  
*************** static void append_header_to_list (struc
*** 262,269 ****
  static int get_next_header (struct ui_out *uiout, int *colno, int *width,
  			    int *alignment, char **colhdr);
  static void clear_header_list (struct ui_out *uiout);
! static void verify_field_proper_position (struct ui_out *uiout);
! static void verify_field_alignment (struct ui_out *uiout, int fldno, int *width, int *alignment);
  
  static void init_ui_out_state (struct ui_out *uiout);
  
--- 267,274 ----
  static int get_next_header (struct ui_out *uiout, int *colno, int *width,
  			    int *alignment, char **colhdr);
  static void clear_header_list (struct ui_out *uiout);
! static void verify_field (struct ui_out *uiout, int *fldno, int *width,
! 			  int *align);
  
  static void init_ui_out_state (struct ui_out *uiout);
  
*************** previous table_end.");
*** 283,288 ****
--- 288,294 ----
  
    uiout->table.flag = 1;
    uiout->table.body_flag = 0;
+   uiout->table.entry_level = uiout->level + 1;
    uiout->table.columns = nbrofcols;
    if (tblid != NULL)
      uiout->table.id = xstrdup (tblid);
*************** ui_out_table_end (struct ui_out *uiout)
*** 322,327 ****
--- 328,334 ----
      internal_error (__FILE__, __LINE__,
  		    "misplaced table_end or missing table_begin.");
  
+   uiout->table.entry_level = 0;
    uiout->table.body_flag = 0;
    uiout->table.flag = 0;
  
*************** ui_out_begin (struct ui_out *uiout,
*** 357,365 ****
      internal_error (__FILE__, __LINE__,
  		    "table header or table_body expected; lists must be \
  specified after table_body.");
    new_level = push_level (uiout, type, id);
!   if (uiout->table.flag && (new_level == 1))
      uiout->table.header_next = uiout->table.header_first;
    uo_begin (uiout, type, new_level, id);
  }
  
--- 364,392 ----
      internal_error (__FILE__, __LINE__,
  		    "table header or table_body expected; lists must be \
  specified after table_body.");
+ 
+   /* Be careful to verify the ``field'' before the new tuple/list is
+      pushed onto the stack.  That way the containing list/table/row is
+      verified and not the newly created tuple/list.  This verification
+      is needed (at least) for the case where a table row entry
+      contains either a tuple/list.  For that case bookkeeping such as
+      updating the column count or advancing to the next heading still
+      needs to be performed.  */
+   {
+     int fldno;
+     int width;
+     int align;
+     verify_field (uiout, &fldno, &width, &align);
+   }
+ 
    new_level = push_level (uiout, type, id);
! 
!   /* If the push puts us at the same level as a table row entry, we've
!      got a new table row.  Put the header pointer back to the start.  */
!   if (uiout->table.body_flag
!       && uiout->table.entry_level == new_level)
      uiout->table.header_next = uiout->table.header_first;
+ 
    uo_begin (uiout, type, new_level, id);
  }
  
*************** ui_out_field_int (struct ui_out *uiout,
*** 455,467 ****
    int width;
    int align;
    struct ui_out_level *current = current_level (uiout);
- 
-   verify_field_proper_position (uiout);
- 
-   current->field_count += 1;
-   fldno = current->field_count;
  
!   verify_field_alignment (uiout, fldno, &width, &align);
  
    uo_field_int (uiout, fldno, width, align, fldname, value);
  }
--- 482,489 ----
    int width;
    int align;
    struct ui_out_level *current = current_level (uiout);
  
!   verify_field (uiout, &fldno, &width, &align);
  
    uo_field_int (uiout, fldno, width, align, fldname, value);
  }
*************** ui_out_field_skip (struct ui_out *uiout,
*** 505,518 ****
    int fldno;
    int width;
    int align;
-   struct ui_out_level *current = current_level (uiout);
- 
-   verify_field_proper_position (uiout);
- 
-   current->field_count += 1;
-   fldno = current->field_count;
  
!   verify_field_alignment (uiout, fldno, &width, &align);
  
    uo_field_skip (uiout, fldno, width, align, fldname);
  }
--- 527,534 ----
    int fldno;
    int width;
    int align;
  
!   verify_field (uiout, &fldno, &width, &align);
  
    uo_field_skip (uiout, fldno, width, align, fldname);
  }
*************** ui_out_field_string (struct ui_out *uiou
*** 525,538 ****
    int fldno;
    int width;
    int align;
-   struct ui_out_level *current = current_level (uiout);
- 
-   verify_field_proper_position (uiout);
- 
-   current->field_count += 1;
-   fldno = current->field_count;
  
!   verify_field_alignment (uiout, fldno, &width, &align);
  
    uo_field_string (uiout, fldno, width, align, fldname, string);
  }
--- 541,548 ----
    int fldno;
    int width;
    int align;
  
!   verify_field (uiout, &fldno, &width, &align);
  
    uo_field_string (uiout, fldno, width, align, fldname, string);
  }
*************** ui_out_field_fmt (struct ui_out *uiout,
*** 547,561 ****
    int fldno;
    int width;
    int align;
-   struct ui_out_level *current = current_level (uiout);
- 
-   verify_field_proper_position (uiout);
  
-   current->field_count += 1;
-   fldno = current->field_count;
- 
    /* will not align, but has to call anyway */
!   verify_field_alignment (uiout, fldno, &width, &align);
  
    va_start (args, format);
  
--- 557,565 ----
    int fldno;
    int width;
    int align;
  
    /* will not align, but has to call anyway */
!   verify_field (uiout, &fldno, &width, &align);
  
    va_start (args, format);
  
*************** get_next_header (struct ui_out *uiout,
*** 1054,1093 ****
    uiout->table.header_next = uiout->table.header_next->next;
    return 1;
  }
  
! /* makes sure the field_* calls were properly placed */
  
  static void
! verify_field_proper_position (struct ui_out *uiout)
  {
    if (uiout->table.flag)
      {
        if (!uiout->table.body_flag)
  	internal_error (__FILE__, __LINE__,
  			"table_body missing; table fields must be \
  specified after table_body and inside a list.");
!       if (uiout->level == 0)
! 	internal_error (__FILE__, __LINE__,
! 			"list_begin missing; table fields must be \
! specified after table_body and inside a list.");
      }
- }
  
! /* determines what is the alignment policy */
! 
! static void
! verify_field_alignment (struct ui_out *uiout,
! 			int fldno,
! 			int *width,
! 			int *align)
! {
!   int colno;
!   char *text;
  
!   if (uiout->table.flag
!       && get_next_header (uiout, &colno, width, align, &text))
      {
!       if (fldno != colno)
  	internal_error (__FILE__, __LINE__,
  			"ui-out internal error in handling headers.");
      }
--- 1058,1095 ----
    uiout->table.header_next = uiout->table.header_next->next;
    return 1;
  }
+ 
  
! /* Verify that the field/tuple/list is correctly positioned.  Return
!    the field number and corresponding alignment (if
!    available/applicable).  */
  
  static void
! verify_field (struct ui_out *uiout, int *fldno, int *width, int *align)
  {
+   struct ui_out_level *current = current_level (uiout);
+   char *text;
+ 
    if (uiout->table.flag)
      {
        if (!uiout->table.body_flag)
  	internal_error (__FILE__, __LINE__,
  			"table_body missing; table fields must be \
  specified after table_body and inside a list.");
!       /* NOTE: cagney/2001-12-08: There was a check here to ensure
! 	 that this code was only executed when uiout->level was
! 	 greater than zero.  That no longer applies - this code is run
! 	 before each table row tuple is started and at that point the
! 	 level is zero.  */
      }
  
!   current->field_count += 1;
  
!   if (uiout->table.body_flag
!       && uiout->table.entry_level == uiout->level
!       && get_next_header (uiout, fldno, width, align, &text))
      {
!       if (*fldno != current->field_count)
  	internal_error (__FILE__, __LINE__,
  			"ui-out internal error in handling headers.");
      }
*************** verify_field_alignment (struct ui_out *u
*** 1095,1102 ****
--- 1097,1106 ----
      {
        *width = 0;
        *align = ui_noalign;
+       *fldno = current->field_count;
      }
  }
+ 
  
  /* access to ui_out format private members */
  

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