From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 31430 invoked by alias); 5 Jan 2012 20:05:12 -0000 Received: (qmail 31415 invoked by uid 22791); 5 Jan 2012 20:05:11 -0000 X-SWARE-Spam-Status: No, hits=-6.3 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_HI,SPF_HELO_PASS,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 05 Jan 2012 20:04:58 +0000 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q05K4vqM022956 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 5 Jan 2012 15:04:57 -0500 Received: from valrhona.uglyboxes.com (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q05K4sBF025230 (version=TLSv1/SSLv3 cipher=DHE-RSA-CAMELLIA256-SHA bits=256 verify=NO); Thu, 5 Jan 2012 15:04:56 -0500 Message-ID: <4F060266.4070409@redhat.com> Date: Thu, 05 Jan 2012 20:05:00 -0000 From: Keith Seitz User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:8.0) Gecko/20111115 Thunderbird/8.0 MIME-Version: 1.0 To: Tom Tromey CC: "gp >> \"gdb-patches@sourceware.org ml\"" Subject: Re: [RFA] Updated path expression computations for varobj trees References: <4EEBCC7D.4020103@redhat.com> <4EF0CA0F.20306@redhat.com> In-Reply-To: <4EF0CA0F.20306@redhat.com> Content-Type: multipart/mixed; boundary="------------020408000309030907050804" X-IsSubscribed: yes 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: 2012-01/txt/msg00205.txt.bz2 This is a multi-part message in MIME format. --------------020408000309030907050804 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-length: 720 On 12/20/2011 07:23 AM, Tom Tromey wrote: > I'm not super fond of the type regexp thing, but I suppose we can always > enhance it more later if need be. Ok, well, after fiddling with this far too much, I've (almost embarrassingly) whittled this regexp to: + if {[string index $name 0] == "*"} { + set is_compound 0 + } In other words, we assume that the construct is a compound type unless the child's name begins with "*", which means the parent must be a pointer. We may encounter difficulties with this, too, mind you, but I believe this is a cheaper and easier condition to deal with than the regexp. What do you think? Keith [Re-attaching whole patch for clarity. ChangeLog is still the same.] --------------020408000309030907050804 Content-Type: text/x-patch; name="varobj_walk_tree_update-2.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="varobj_walk_tree_update-2.patch" Content-length: 4795 diff --git a/gdb/testsuite/lib/mi-support.exp b/gdb/testsuite/lib/mi-support.exp index e1845f6..4693775 100644 --- a/gdb/testsuite/lib/mi-support.exp +++ b/gdb/testsuite/lib/mi-support.exp @@ -2012,7 +2012,7 @@ proc mi_get_features {} { # } # } # -# mi_walk_varobj_tree $tree +# mi_walk_varobj_tree c++ $tree # # If you'd prefer to walk the tree using your own callback, # simply pass the name of the callback to mi_walk_varobj_tree. @@ -2038,6 +2038,9 @@ proc mi_get_features {} { # type - the type of this variable (type="type" in the output # of -var-list-children, or the special tag "anonymous" # path_expr - the "-var-info-path-expression" for this variable +# NOTE: This member cannot be used reliably with typedefs. +# Use with caution! +# See notes inside get_path_expr for more. # parent - the variable name of the parent varobj # children - a list of children variable names (which are the # names Tcl arrays, not object names) @@ -2084,7 +2087,8 @@ namespace eval ::varobj_tree { } # The default callback used by mi_walk_varobj_tree. This callback - # simply checks all of VAR's children. + # simply checks all of VAR's children. It specifically does not test + # path expressions, since that is very problematic. # # This procedure may be used in custom callbacks. proc test_children_callback {variable_name} { @@ -2154,20 +2158,59 @@ namespace eval ::varobj_tree { # parent varobj whose variable name is given by PARENT_VARIABLE. proc get_path_expr {parent_variable name type} { upvar #0 $parent_variable parent + upvar #0 $parent_variable path_parent # If TYPE is "", this is one of the CPLUS_FAKE_CHILD varobjs, - # which has no path expression - if {[string length $type] == 0} { + # which has no path expression. Likewsise for anonymous structs + # and unions. + if {[string length $type] == 0 \ + || [string compare $type "anonymous"] == 0} { return "" } # Find the path parent variable. while {![is_path_expr_parent $parent_variable]} { - set parent_variable $parent(parent) - upvar #0 $parent_variable parent - } + set parent_variable $path_parent(parent) + upvar #0 $parent_variable path_parent + } + + # This is where things get difficult. We do not actually know + # the real type for variables defined via typedefs, so we don't actually + # know whether the parent is a structure/union or not. + # + # So we assume everything that isn't a simple type is a compound type. + set stars "" + regexp {\*+} $parent(type) stars + set is_compound 1 + if {[string index $name 0] == "*"} { + set is_compound 0 + } + + if {[string index $parent(type) end] == "\]"} { + # Parent is an array. + return "($path_parent(path_expr))\[$name\]" + } elseif {$is_compound} { + # Parent is a structure or union or a pointer to one. + if {[string length $stars]} { + set join "->" + } else { + set join "." + } + + global root - return "(($parent(path_expr)).$name)" + # To make matters even more hideous, varobj.c has slightly different + # path expressions for C and C++. + set path_expr "($path_parent(path_expr))$join$name" + if {[string compare -nocase $root(language) "c"] == 0} { + return $path_expr + } else { + return "($path_expr)" + } + } else { + # Parent is a pointer. + return "*($path_parent(path_expr))" + } } # Process the CHILDREN (a list of varobj_tree elements) of the variable @@ -2208,7 +2251,7 @@ namespace eval ::varobj_tree { # The main procedure to call the given CALLBACK on the elements of the # given varobj TREE. See detailed explanation above. - proc walk_tree {tree callback} { + proc walk_tree {language tree callback} { global root if {[llength $tree] < 3} { @@ -2216,6 +2259,7 @@ namespace eval ::varobj_tree { } # Create root node and process the tree. + array set root [list language $language] array set root [list obj_name "root"] array set root [list display_name "root"] array set root [list type "root"] @@ -2259,7 +2303,8 @@ proc mi_varobj_tree_test_children_callback {variable} { # Walk the variable object tree given by TREE, calling the specified # CALLBACK. By default this uses mi_varobj_tree_test_children_callback. -proc mi_walk_varobj_tree {tree {callback \ - mi_varobj_tree_test_children_callback}} { - ::varobj_tree::walk_tree $tree $callback +proc mi_walk_varobj_tree {language tree \ + {callback \ + mi_varobj_tree_test_children_callback}} { + ::varobj_tree::walk_tree $language $tree $callback } --------------020408000309030907050804--