From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23300 invoked by alias); 16 Jan 2007 18:39:09 -0000 Received: (qmail 23291 invoked by uid 22791); 16 Jan 2007 18:39:09 -0000 X-Spam-Check-By: sourceware.org Received: from zigzag.lvk.cs.msu.su (HELO zigzag.lvk.cs.msu.su) (158.250.17.23) by sourceware.org (qpsmtpd/0.31) with ESMTP; Tue, 16 Jan 2007 18:39:05 +0000 Received: from Debian-exim by zigzag.lvk.cs.msu.su with spam-scanned (Exim 4.50) id 1H6tCy-0001Dv-8y for gdb-patches@sources.redhat.com; Tue, 16 Jan 2007 21:39:02 +0300 Received: from localhost ([127.0.0.1] helo=ip6-localhost) by zigzag.lvk.cs.msu.su with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA:32) (Exim 4.50) id 1H6tCx-0001Di-1K for gdb-patches@sources.redhat.com; Tue, 16 Jan 2007 21:38:56 +0300 From: Vladimir Prus To: gdb-patches@sources.redhat.com Subject: [mi] fix 'editable' attribute for references Date: Tue, 16 Jan 2007 18:39:00 -0000 User-Agent: KMail/1.9.1 MIME-Version: 1.0 Content-Type: Multipart/Mixed; boundary="Boundary-00=_vuRrFPrtqGU9n/B" Message-Id: <200701162138.39578.ghost@cs.msu.su> 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: 2007-01/txt/msg00360.txt.bz2 --Boundary-00=_vuRrFPrtqGU9n/B Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-Disposition: inline Content-length: 1091 I've noticed that the -var-show-references returns 'attr=noneditable' for structures, but 'attr=editable' for references to structures, which makes no sense. This patch fixes this. Some clarification is is order. Each varobj has three types associated with it. One type is the declared type in the source program. Second type is the type of the value we're actually storing. Third type is the type of value we're operating with when getting children. To be more concrete, first type is the type in program, no changes at all. Second type is type in program with top-level reference stripped. Third type also has top-level pointer dereferenced. This patch introduces, explicitly, a function to get the second type and makes c_variable_ediatable use it. OK? - Volodya Fix the 'editable' attribute computation for references. testsuite/ * gdb.mi/mi-var-cp.exp: Run the reference_to_struct testcase. * gdb.mi/mi-var-cp.cc (reference_to_struct): New function. (main): Call the above. gdb/ * varobj.c (get_value_type): New function. (c_variable_editable): Use get_value_type. --Boundary-00=_vuRrFPrtqGU9n/B Content-Type: text/x-diff; charset="us-ascii"; name="path_3_5_references__gdb_mainline.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="path_3_5_references__gdb_mainline.diff" Content-length: 3012 --- gdb/testsuite/gdb.mi/mi-var-cp.exp (/mirrors/gdb_mainline) (revision 3171) +++ gdb/testsuite/gdb.mi/mi-var-cp.exp (/patches/gdb/path_3_5_references/gdb_mainline) (revision 3171) @@ -44,6 +44,7 @@ mi_prepare_inline_tests $srcfile mi_run_inline_test reference_update mi_run_inline_test base_in_reference mi_run_inline_test reference_to_pointer +mi_run_inline_test reference_to_struct mi_gdb_exit return 0 --- gdb/testsuite/gdb.mi/mi-var-cp.cc (/mirrors/gdb_mainline) (revision 3171) +++ gdb/testsuite/gdb.mi/mi-var-cp.cc (/patches/gdb/path_3_5_references/gdb_mainline) (revision 3171) @@ -96,10 +96,30 @@ int reference_to_pointer () /*: END: reference_to_pointer :*/ } +int reference_to_struct () +{ + /*: BEGIN: reference_to_struct :*/ + S s; + S& r = s; + /*: + mi_create_varobj S s "create varobj for s" + mi_create_varobj R r "create varobj for s" + mi_gdb_test "-var-show-attributes S" \ + "\\^done,attr=\"noneditable\"" \ + "check attributes of S" + mi_gdb_test "-var-show-attributes R" \ + "\\^done,attr=\"noneditable\"" \ + "check attributes of R" + :*/ + return 99; + /*: END: reference_to_struct :*/ +} + int main () { reference_update_tests (); base_in_reference_test_main (); reference_to_pointer (); + reference_to_struct (); return 0; } --- gdb/varobj.c (/mirrors/gdb_mainline) (revision 3171) +++ gdb/varobj.c (/patches/gdb/path_3_5_references/gdb_mainline) (revision 3171) @@ -176,6 +176,8 @@ static struct cleanup *make_cleanup_free static struct type *get_type (struct varobj *var); +static struct type *get_value_type (struct varobj *var); + static struct type *get_type_deref (struct varobj *var); static struct type *get_target_type (struct type *); @@ -1459,6 +1461,35 @@ get_type (struct varobj *var) return type; } +/* Return the type of the value that's stored in VAR, + or that would have being stored there if the + value were accessible. + + This differs from VAR->type in that VAR->type is always + the true type of the expession in the source language. + The return value of this function is the type we're + actually storing in varobj, and using for displaying + the values and for comparing previous and new values. + + For example, top-level references are always stripped. */ +static struct type * +get_value_type (struct varobj *var) +{ + struct type *type; + + if (var->value) + type = value_type (var->value); + else + type = var->type; + + if (TYPE_CODE (type) == TYPE_CODE_REF) + type = get_target_type (type); + + type = check_typedef (type); + + return type; +} + /* This returns the type of the variable, dereferencing references, pointers and references to pointers, too. */ static struct type * @@ -2020,7 +2051,7 @@ c_type_of_child (struct varobj *parent, static int c_variable_editable (struct varobj *var) { - switch (TYPE_CODE (get_type (var))) + switch (TYPE_CODE (get_value_type (var))) { case TYPE_CODE_STRUCT: case TYPE_CODE_UNION: --Boundary-00=_vuRrFPrtqGU9n/B--