From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16552 invoked by alias); 29 Nov 2006 15:24:39 -0000 Received: (qmail 16531 invoked by uid 22791); 29 Nov 2006 15:24:37 -0000 X-Spam-Check-By: sourceware.org Received: from mail.codesourcery.com (HELO mail.codesourcery.com) (65.74.133.4) by sourceware.org (qpsmtpd/0.31) with ESMTP; Wed, 29 Nov 2006 15:24:28 +0000 Received: (qmail 5034 invoked from network); 29 Nov 2006 15:24:26 -0000 Received: from unknown (HELO ?172.16.64.38?) (vladimir@127.0.0.2) by mail.codesourcery.com with ESMTPA; 29 Nov 2006 15:24:26 -0000 From: Vladimir Prus To: gdb-patches@sources.redhat.com Subject: MI varobj printing cleanup Date: Wed, 29 Nov 2006 15:24:00 -0000 User-Agent: KMail/1.9.1 MIME-Version: 1.0 Content-Type: Multipart/Mixed; boundary="Boundary-00=_gYabFs0ayuJMxS3" Message-Id: <200611291824.16015.vladimir@codesourcery.com> Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2006-11/txt/msg00391.txt.bz2 --Boundary-00=_gYabFs0ayuJMxS3 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-Disposition: inline Content-length: 651 There were two places where varobjs are printed, which makes it hard to add new fields, or new commands that create varobjs. This patch create new function. No regressions. It slightly changed the behaviour -- if we create a varobj with -var-create and it has no type, the old code would print type="" and the new code does not print "type" field at all. That's no a problem, however -- if there's no type for a top-level variable, you'll have lots of asserts fire before even going to printing. OK? - Volodya * mi/mi-cmd-var.c (print_varobj): New function. (mi_cmd_var_create): Use the above. (mi_cmd_var_list_children): Likewise. --Boundary-00=_gYabFs0ayuJMxS3 Content-Type: text/x-diff; charset="us-ascii"; name="varobj_printing__gdb_mainline.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="varobj_printing__gdb_mainline.diff" Content-length: 3050 === gdb/mi/mi-cmd-var.c ================================================================== --- gdb/mi/mi-cmd-var.c (/mirrors/gdb_mainline) (revision 2320) +++ gdb/mi/mi-cmd-var.c (/patches/gdb/varobj_printing/gdb_mainline) (revision 2320) @@ -39,6 +39,33 @@ static int varobj_update_one (struct varobj *var, enum print_values print_values); +static int mi_print_value_p (struct type *type, enum print_values print_values); + +/* Print variable object VAR. The PRINT_VALUES parameter controls + if the value should be printed. The PRINT_EXPRESSION parameter + controls if the expression should be printed. */ +static void +print_varobj (struct varobj *var, enum print_values print_values, + int print_expression) +{ + char *type; + + ui_out_field_string (uiout, "name", varobj_get_objname (var)); + if (print_expression) + ui_out_field_string (uiout, "exp", varobj_get_expression (var)); + ui_out_field_int (uiout, "numchild", varobj_get_num_children (var)); + + if (mi_print_value_p (varobj_get_gdb_type (var), print_values)) + ui_out_field_string (uiout, "value", varobj_get_value (var)); + + type = varobj_get_type (var); + if (type != NULL) + { + ui_out_field_string (uiout, "type", type); + xfree (type); + } +} + /* VAROBJ operations */ enum mi_cmd_result @@ -49,7 +76,6 @@ char *name; char *frame; char *expr; - char *type; struct cleanup *old_cleanups; enum varobj_type var_type; @@ -98,16 +124,7 @@ if (var == NULL) error (_("mi_cmd_var_create: unable to create variable object")); - ui_out_field_string (uiout, "name", name); - ui_out_field_int (uiout, "numchild", varobj_get_num_children (var)); - type = varobj_get_type (var); - if (type == NULL) - ui_out_field_string (uiout, "type", ""); - else - { - ui_out_field_string (uiout, "type", type); - xfree (type); - } + print_varobj (var, PRINT_NO_VALUES, 0 /* don't print expression */); do_cleanups (old_cleanups); return MI_CMD_DONE; @@ -336,17 +353,12 @@ { struct cleanup *cleanup_child; cleanup_child = make_cleanup_ui_out_tuple_begin_end (uiout, "child"); - ui_out_field_string (uiout, "name", varobj_get_objname (*cc)); - ui_out_field_string (uiout, "exp", varobj_get_expression (*cc)); - ui_out_field_int (uiout, "numchild", varobj_get_num_children (*cc)); - if (mi_print_value_p (varobj_get_gdb_type (*cc), print_values)) - ui_out_field_string (uiout, "value", varobj_get_value (*cc)); - type = varobj_get_type (*cc); - /* C++ pseudo-variables (public, private, protected) do not have a type */ - if (type) - ui_out_field_string (uiout, "type", type); + /* Not printing of the type below is wrong -- frontends can + be programmed easily if all creation of varobj always + return the same information. */ + print_varobj (*cc, print_values, 1 /* print expression */); + cc++; do_cleanups (cleanup_child); - cc++; } do_cleanups (cleanup_children); xfree (childlist); --Boundary-00=_gYabFs0ayuJMxS3--