From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jim Ingham To: GDB Patches Subject: Bug with lists in tables in ui-out.c Date: Wed, 28 Nov 2001 17:42:00 -0000 Message-id: X-SW-Source: 2001-11/msg00547.html Hi all, Turns out if you have an element of a table that is a list or tuple, then the current ui-out table code chokes. verify_field_alignment doesn't know that each of the elements of the sublist are not separate table elements, so it throws an error at the first one it sees. The following patch fixes this bug. Note that in the FSF gdb code, no one ever uses this feature, because the only client of the ui_out_table is the breakpoint printer, and it cleverly only declares the first 5 or 6 columns of the breakpoint info table in the table header, and sticks on the rest of the info as undeclared freebies (which is kind of lame, but another story...), so the commands, which are a list, don't get added to the table proper, and thus don't trip the bug. I have a patch which will fix this and make the table header accurate, but I am not submitting it here because (a) it is a separate issue and (b) it will change the output of the "info breakpoint" command (though only the header), and so may not necessarily please everyone... Jim Index: ui-out.c =================================================================== RCS file: /cvs/src/src/gdb/ui-out.c,v retrieving revision 1.18 diff -p -r1.18 ui-out.c *** ui-out.c 2001/07/06 03:53:11 1.18 --- ui-out.c 2001/11/29 01:40:59 *************** ui_out_end (struct ui_out *uiout, *** 367,372 **** --- 367,384 ---- enum ui_out_type type) { int old_level = pop_level (uiout, type); + + /* If we are building up a table, and we were making a table element + which was a list or tuple, then when we end the list, we have to + increment the header. Watch out, however, the current breakpoint + code actually emits more columns than it defines in the header + so we have to be careful not to walk off the end. */ + + if (uiout->table_flag && uiout->body_flag + && uiout->level == 1 + && uiout->headercurr != NULL) + uiout->headercurr = uiout->headercurr->next; + uo_end (uiout, type, old_level); } *************** append_header_to_list (struct ui_out *ui *** 1018,1024 **** uiout->headercurr = uiout->headerlast; } ! /* returns 0 if there is no more headers */ static int get_curr_header (struct ui_out *uiout, --- 1030,1038 ---- uiout->headercurr = uiout->headerlast; } ! /* Returns information on the current header. ALSO Increments the ! current header in UI_OUT. Returns 0 if there is no more headers, 1 ! otherwise. */ static int get_curr_header (struct ui_out *uiout, *************** specified after table_body and inside a *** 1056,1062 **** } } ! /* determines what is the alignment policy */ static void verify_field_alignment (struct ui_out *uiout, --- 1070,1079 ---- } } ! /* Determines what is the alignment policy. NB: as a side-effect of ! calling get_curr_header, this also increments the current header. So ! you have to call verify_field_alignment in any call that adds a ! complete bit of data to a table column. */ static void verify_field_alignment (struct ui_out *uiout, *************** verify_field_alignment (struct ui_out *u *** 1066,1073 **** { int colno; char *text; ! if (uiout->table_flag && get_curr_header (uiout, &colno, width, align, &text)) { if (fldno != colno) --- 1083,1097 ---- { int colno; char *text; + + /* Be careful - if you are building up a list or tuple AS AN ELEMENT + of a table, you don't want to call get_curr_header, since that will + increment the current header, which would be wrong. Currently, tables + can only be built at level 1, so I am using that as a check. If this + stuff is ever generalized, we will need to stuff the level of the + current table into the (putative) ui_table structure. */ ! if (uiout->table_flag && uiout->level == 1 && get_curr_header (uiout, &colno, width, align, &text)) { if (fldno != colno) -- +==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+== Jim Ingham jingham@apple.com Developer Tools - gdb From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26834 invoked by alias); 29 Nov 2001 01:42:27 -0000 Mailing-List: contact gdb-patches-help@sourceware.cygnus.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sources.redhat.com Received: (qmail 26809 invoked from network); 29 Nov 2001 01:42:25 -0000 Received: from unknown (HELO mail-out2.apple.com) (17.254.0.51) by hostedprojects.ges.redhat.com with SMTP; 29 Nov 2001 01:42:25 -0000 Received: from mailgate2.apple.com (A17-129-100-225.apple.com [17.129.100.225]) by mail-out2.apple.com (8.11.3/8.11.3) with ESMTP id fAT1gOX02019 for ; Wed, 28 Nov 2001 17:42:24 -0800 (PST) Received: from scv3.apple.com (scv3.apple.com) by mailgate2.apple.com (Content Technologies SMTPRS 4.2.1) with ESMTP id for ; Wed, 28 Nov 2001 17:42:23 -0800 Received: from [17.202.40.220] (inghji.apple.com [17.202.40.220]) by scv3.apple.com (8.11.3/8.11.3) with ESMTP id fAT1gND29413 for ; Wed, 28 Nov 2001 17:42:23 -0800 (PST) User-Agent: Microsoft-Entourage/10.0.0.1309 Date: Sun, 18 Nov 2001 11:04:00 -0000 Subject: Bug with lists in tables in ui-out.c From: Jim Ingham To: GDB Patches Message-ID: Mime-version: 1.0 Content-type: text/plain; charset="US-ASCII" Content-transfer-encoding: 7bit X-SW-Source: 2001-11/txt/msg00332.txt.bz2 Message-ID: <20011118110400.YvS-M9Oy86t6Y-7UGUM9gid9I_ig-xZrbCiHLTEBQls@z> Hi all, Turns out if you have an element of a table that is a list or tuple, then the current ui-out table code chokes. verify_field_alignment doesn't know that each of the elements of the sublist are not separate table elements, so it throws an error at the first one it sees. The following patch fixes this bug. Note that in the FSF gdb code, no one ever uses this feature, because the only client of the ui_out_table is the breakpoint printer, and it cleverly only declares the first 5 or 6 columns of the breakpoint info table in the table header, and sticks on the rest of the info as undeclared freebies (which is kind of lame, but another story...), so the commands, which are a list, don't get added to the table proper, and thus don't trip the bug. I have a patch which will fix this and make the table header accurate, but I am not submitting it here because (a) it is a separate issue and (b) it will change the output of the "info breakpoint" command (though only the header), and so may not necessarily please everyone... Jim Index: ui-out.c =================================================================== RCS file: /cvs/src/src/gdb/ui-out.c,v retrieving revision 1.18 diff -p -r1.18 ui-out.c *** ui-out.c 2001/07/06 03:53:11 1.18 --- ui-out.c 2001/11/29 01:40:59 *************** ui_out_end (struct ui_out *uiout, *** 367,372 **** --- 367,384 ---- enum ui_out_type type) { int old_level = pop_level (uiout, type); + + /* If we are building up a table, and we were making a table element + which was a list or tuple, then when we end the list, we have to + increment the header. Watch out, however, the current breakpoint + code actually emits more columns than it defines in the header + so we have to be careful not to walk off the end. */ + + if (uiout->table_flag && uiout->body_flag + && uiout->level == 1 + && uiout->headercurr != NULL) + uiout->headercurr = uiout->headercurr->next; + uo_end (uiout, type, old_level); } *************** append_header_to_list (struct ui_out *ui *** 1018,1024 **** uiout->headercurr = uiout->headerlast; } ! /* returns 0 if there is no more headers */ static int get_curr_header (struct ui_out *uiout, --- 1030,1038 ---- uiout->headercurr = uiout->headerlast; } ! /* Returns information on the current header. ALSO Increments the ! current header in UI_OUT. Returns 0 if there is no more headers, 1 ! otherwise. */ static int get_curr_header (struct ui_out *uiout, *************** specified after table_body and inside a *** 1056,1062 **** } } ! /* determines what is the alignment policy */ static void verify_field_alignment (struct ui_out *uiout, --- 1070,1079 ---- } } ! /* Determines what is the alignment policy. NB: as a side-effect of ! calling get_curr_header, this also increments the current header. So ! you have to call verify_field_alignment in any call that adds a ! complete bit of data to a table column. */ static void verify_field_alignment (struct ui_out *uiout, *************** verify_field_alignment (struct ui_out *u *** 1066,1073 **** { int colno; char *text; ! if (uiout->table_flag && get_curr_header (uiout, &colno, width, align, &text)) { if (fldno != colno) --- 1083,1097 ---- { int colno; char *text; + + /* Be careful - if you are building up a list or tuple AS AN ELEMENT + of a table, you don't want to call get_curr_header, since that will + increment the current header, which would be wrong. Currently, tables + can only be built at level 1, so I am using that as a check. If this + stuff is ever generalized, we will need to stuff the level of the + current table into the (putative) ui_table structure. */ ! if (uiout->table_flag && uiout->level == 1 && get_curr_header (uiout, &colno, width, align, &text)) { if (fldno != colno) -- +==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+==+== Jim Ingham jingham@apple.com Developer Tools - gdb