From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18606 invoked by alias); 10 Sep 2002 23:41:20 -0000 Mailing-List: contact gdb-patches-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sources.redhat.com Received: (qmail 18596 invoked from network); 10 Sep 2002 23:41:20 -0000 Received: from unknown (HELO valrhona.uglyboxes.com) (64.1.192.220) by sources.redhat.com with SMTP; 10 Sep 2002 23:41:20 -0000 Received: from localhost.localdomain (IDENT:HmY5rNZNuxuUpsl9//gSxRLjW3hRCzgQ@localhost.localdomain [127.0.0.1]) by valrhona.uglyboxes.com (8.11.6/8.11.6) with ESMTP id g8ANi3J22781 for ; Tue, 10 Sep 2002 16:44:03 -0700 Date: Tue, 10 Sep 2002 16:41:00 -0000 From: Keith Seitz X-X-Sender: keiths@valrhona.uglyboxes.com To: gdb-patches@sources.redhat.com Subject: [RFC/A] gdb/680: ui_out_reset? Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-SW-Source: 2002-09/txt/msg00169.txt.bz2 Hi, Following up to gdb/680 where the MI register commands cause assertion failures with errors... There are several ways to approach this. One is to make sure that everytime ui_out_{list,tuple}_begin is called, there is a ui_out_{list,tuple}_end. This leads to code like (from mi_data_list_register_values): ui_out_list_begin (uiout, "register-values"); if (argc == 1) /* No args, beside the format: do all the regs */ { for (regnum = 0; regnum < numregs; regnum++) { if (REGISTER_NAME (regnum) == NULL || *(REGISTER_NAME (regnum)) == '\0') continue; ui_out_tuple_begin (uiout, NULL); ui_out_field_int (uiout, "number", regnum); result = get_register (regnum, format); if (result == -1) { ui_out_tuple_end (uiout); ui_out_list_end (uiout); return MI_CMD_ERROR; } ui_out_tuple_end (uiout); } } /* snip */ I'd rather just propose a new ui-out function, ui_out_reset, which can be called to "cleanup" the uiout in case of errors. In this case, mi_out_rewind could call ui_out_reset and reset the "levels" field. Of course, I think that Kevin also proposed something in the longjmp case which is needed in these functions, afaict, but that's another bug/patch. What do people think? Explicitly call ui_out_{list,tuple}_end before returning an error code or add ui_out_reset? Perhaps another solution I've overlooked? Keith ChangeLog 2002-09-05 Keith Seitz * ui-out.c (ui_out_reset): New function. (ui_out_new): Use ui_out_reset. * ui-out.h (ui_out_reset): Add declaration. mi/ChangeLog 2002-09-05 Keith Seitz * mi-out.c (mi_out_rewind): Call ui_out_reset to reset the uiout in case of errors. Patch Index: ui-out.c =================================================================== RCS file: /cvs/src/src/gdb/ui-out.c,v retrieving revision 1.23 diff -p -r1.23 ui-out.c *** ui-out.c 27 Jul 2002 01:54:15 -0000 1.23 --- ui-out.c 5 Sep 2002 15:02:46 -0000 *************** ui_out_data (struct ui_out *uiout) *** 1119,1124 **** --- 1119,1136 ---- return uiout->data; } + void + ui_out_reset (struct ui_out *uiout) + { + uiout->table.flag = 0; + uiout->table.body_flag = 0; + uiout->level = 0; + memset (uiout->levels, 0, sizeof (uiout->levels)); + uiout->table.header_first = NULL; + uiout->table.header_last = NULL; + uiout->table.header_next = NULL; + } + /* initalize private members at startup */ struct ui_out * *************** ui_out_new (struct ui_out_impl *impl, *** 1130,1142 **** uiout->data = data; uiout->impl = impl; uiout->flags = flags; ! uiout->table.flag = 0; ! uiout->table.body_flag = 0; ! uiout->level = 0; ! memset (uiout->levels, 0, sizeof (uiout->levels)); ! uiout->table.header_first = NULL; ! uiout->table.header_last = NULL; ! uiout->table.header_next = NULL; return uiout; } --- 1142,1148 ---- uiout->data = data; uiout->impl = impl; uiout->flags = flags; ! ui_out_reset (uiout); return uiout; } Index: ui-out.h =================================================================== RCS file: /cvs/src/src/gdb/ui-out.h,v retrieving revision 1.15 diff -p -r1.15 ui-out.h *** ui-out.h 6 Jul 2001 03:53:11 -0000 1.15 --- ui-out.h 5 Sep 2002 15:02:46 -0000 *************** extern struct ui_out *ui_out_new (struct *** 272,275 **** --- 272,278 ---- struct ui_out_data *data, int flags); + /* Reset the ui_out object. This is useful when dealing with errors. */ + extern void ui_out_reset (struct ui_out *uiout); + #endif /* UI_OUT_H */ Index: mi/mi-out.c =================================================================== RCS file: /cvs/src/src/gdb/mi/mi-out.c,v retrieving revision 1.23 diff -p -r1.23 mi-out.c *** mi/mi-out.c 19 Mar 2002 02:51:08 -0000 1.23 --- mi/mi-out.c 5 Sep 2002 15:02:46 -0000 *************** mi_out_rewind (struct ui_out *uiout) *** 409,414 **** --- 409,417 ---- { struct ui_out_data *data = ui_out_data (uiout); ui_file_rewind (data->buffer); + + /* Reset the uiout in case there was an error. */ + ui_out_reset (uiout); } /* dump the buffer onto the specified stream */