From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10568 invoked by alias); 14 Mar 2017 01:26:53 -0000 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 Received: (qmail 10558 invoked by uid 89); 14 Mar 2017 01:26:53 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.9 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,KAM_LAZY_DOMAIN_SECURITY,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 spammy=INT, supposedly, GDB-specific, GDBspecific X-HELO: mail-wm0-f47.google.com Received: from mail-wm0-f47.google.com (HELO mail-wm0-f47.google.com) (74.125.82.47) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 14 Mar 2017 01:26:51 +0000 Received: by mail-wm0-f47.google.com with SMTP id v186so53098864wmd.0 for ; Mon, 13 Mar 2017 18:26:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:cc:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=A+S3jVPwci0iF9ziHD2FeF6VBrOlrElKVpWR0VF6En0=; b=BeKS9EQr/hkyI8RmF/uMg/tu3vLONvpndA6+IBOIzBVoGZmmt6ADxwpg6LV6Gzbhlb QyS+dD6kYfcVh6+d8gLeF8iDgT5tw0Bhx9okuzHcVXS3nSLw1ZUvTbaNPjfXkedSqgau xeu0rGaahyUEdgSEuJ5z+7Yb3JaWcHKduW3+4C5iAd2IPSKPyHHrCTxq7WrCF43QP8hz y5Ag2rcSlr/HRHq2vepaBGZWgRPvlqwPbPO9+ZP94DIeJ3MjM7DZjp9NFTVyCnuJIheo uvHD7Mg4igBKzNDuGyPqnnykDEjMgcCT9gqBXZIh0Sq4ZaDNxH4F3KwsbOJAij9zmi/C bI/g== X-Gm-Message-State: AFeK/H34xcRRMiPtBZc+R7Os0UUTOj/rwoBt7WVHBQWHyYt5eX8tDWXG264mPFEHjSdFTwhH X-Received: by 10.28.151.142 with SMTP id z136mr13837108wmd.20.1489454809963; Mon, 13 Mar 2017 18:26:49 -0700 (PDT) Received: from [192.168.0.101] ([37.189.166.198]) by smtp.gmail.com with ESMTPSA id r8sm11101907wrb.33.2017.03.13.18.26.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 13 Mar 2017 18:26:49 -0700 (PDT) Subject: Re: [PATCH] libiberty: Initialize d_printing in all cplus_demangle_* functions. To: Mark Wielaard References: <1489356354-27648-1-git-send-email-mark@klomp.org> <20170313181150.GA287@x4> <20170313182959.GC2167@stream> <1489437334.21350.72.camel@klomp.org> Cc: Markus Trippelsdorf , gdb-patches@sourceware.org, Nathan Sidwell , Ian Lance Taylor , Nick Clifton From: Pedro Alves Message-ID: Date: Tue, 14 Mar 2017 01:26:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: <1489437334.21350.72.camel@klomp.org> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-SW-Source: 2017-03/txt/msg00214.txt.bz2 On 03/13/2017 08:35 PM, Mark Wielaard wrote: > Switching mailinglist from gcc to gdb. > > On Mon, 2017-03-13 at 18:54 +0000, Pedro Alves wrote: >> On 03/13/2017 06:29 PM, Mark Wielaard wrote: >> >> Should gdb be memsetting instead to avoid having to know about >> libiberty's "internals"? > > Maybe. But I went with the version I tested. Thanks, this restores master to a working state quickly. > Basically none of this would be needed if gdb only used the > cplus_demangle_fill_* functions to initialize the data structures > (although that is where there was a bug, but that is now fixed). > > cp-name-parser.y however sometimes uses the cplus_demangle_fill > functions, but other times fills in the data structures by hand (using > its own partial fill function make_empty). I know too little of this > code to know why. Maybe the set of cplus_demangle_fill functions isn't > complete enough or maybe the way the parser works not all information > needed is there yet to call cplus_demangle_fill or maybe doing it by > hand just felt more efficient? I don't know either. I have never had to look much deeply into this file. Git blame points at the commit that added the parser in the first place (git fb4c6eba): https://sourceware.org/ml/gdb-patches/2005-03/msg00182.html But that doesn't include any comment about this either. Seems like all uses of GDB's make_empty are followed by referring to the "s_binary" union member via these two macros: #define d_left(dc) (dc)->u.s_binary.left #define d_right(dc) (dc)->u.s_binary.right "s_binary" is documented as being "for other types": struct demangle_component { ... /* For other types. */ struct { /* Left (or only) subtree. */ struct demangle_component *left; /* Right subtree. */ struct demangle_component *right; } s_binary; And there's a cplus_demangle_fill_component function to fill these in. It's already used by cp-name-parser.y in other cases, via the fill_comp wrapper function. Using that seems to work, testing the patch below on x86_64 Fedora 23 shows no regressions. >From e55453c67bbe772ce001ea15b152f8dc44b8945e Mon Sep 17 00:00:00 2001 From: Pedro Alves Date: Mon, 13 Mar 2017 22:54:09 +0000 Subject: [PATCH] gdb/cp-name-parser.y: Eliminate make_empty, use cplus_demangle_fill_component The demangler exports the cplus_demangle_fill_component function that clients should use to initialize demangle_component components that use the "s_binary" union member. cp-name-parser.y uses it in some places, via the fill_comp wrapper, but not all. Several places instead use a GDB-specific "make_empty" function. Because this function does not call any of the demangler "fill" functions, we had to patch it recently to clear the allocated demangle_component's "d_printing" field, which is supposedly a "private" demangler field. To avoid such problems in the future, this commit switches those places to use "fill_comp" instead, and eliminates the "make_empty" function. gdb/ChangeLog: 2017-03-13 Pedro Alves * cp-name-parser.y (make_empty): Delete. (demangler_special, nested_name, ptr_operator, array_indicator) (direct_declarator, declarator_1): Use fill_comp instead of make_empty. --- gdb/cp-name-parser.y | 57 ++++++++++++---------------------------------------- 1 file changed, 13 insertions(+), 44 deletions(-) diff --git a/gdb/cp-name-parser.y b/gdb/cp-name-parser.y index 70790fc..5a9e51c 100644 --- a/gdb/cp-name-parser.y +++ b/gdb/cp-name-parser.y @@ -197,15 +197,6 @@ fill_comp (enum demangle_component_type d_type, struct demangle_component *lhs, } static struct demangle_component * -make_empty (enum demangle_component_type d_type) -{ - struct demangle_component *ret = d_grab (); - ret->type = d_type; - ret->d_printing = 0; - return ret; -} - -static struct demangle_component * make_operator (const char *name, int args) { struct demangle_component *ret = d_grab (); @@ -433,9 +424,7 @@ function demangler_special : DEMANGLER_SPECIAL start - { $$ = make_empty ((enum demangle_component_type) $1); - d_left ($$) = $2; - d_right ($$) = NULL; } + { $$ = fill_comp ((enum demangle_component_type) $1, $2, NULL); } | CONSTRUCTION_VTABLE start CONSTRUCTION_IN start { $$ = fill_comp (DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE, $2, $4); } ; @@ -600,30 +589,22 @@ ext_only_name : nested_name unqualified_name ; nested_name : NAME COLONCOLON - { $$.comp = make_empty (DEMANGLE_COMPONENT_QUAL_NAME); - d_left ($$.comp) = $1; - d_right ($$.comp) = NULL; + { $$.comp = fill_comp (DEMANGLE_COMPONENT_QUAL_NAME, $1, NULL); $$.last = $$.comp; } | nested_name NAME COLONCOLON { $$.comp = $1.comp; - d_right ($1.last) = make_empty (DEMANGLE_COMPONENT_QUAL_NAME); + d_right ($1.last) = fill_comp (DEMANGLE_COMPONENT_QUAL_NAME, $2, NULL); $$.last = d_right ($1.last); - d_left ($$.last) = $2; - d_right ($$.last) = NULL; } | templ COLONCOLON - { $$.comp = make_empty (DEMANGLE_COMPONENT_QUAL_NAME); - d_left ($$.comp) = $1; - d_right ($$.comp) = NULL; + { $$.comp = fill_comp (DEMANGLE_COMPONENT_QUAL_NAME, $1, NULL); $$.last = $$.comp; } | nested_name templ COLONCOLON { $$.comp = $1.comp; - d_right ($1.last) = make_empty (DEMANGLE_COMPONENT_QUAL_NAME); + d_right ($1.last) = fill_comp (DEMANGLE_COMPONENT_QUAL_NAME, $2, NULL); $$.last = d_right ($1.last); - d_left ($$.last) = $2; - d_right ($$.last) = NULL; } ; @@ -761,41 +742,31 @@ builtin_type : int_seq ; ptr_operator : '*' qualifiers_opt - { $$.comp = make_empty (DEMANGLE_COMPONENT_POINTER); - $$.comp->u.s_binary.left = $$.comp->u.s_binary.right = NULL; + { $$.comp = fill_comp (DEMANGLE_COMPONENT_POINTER, NULL, NULL); $$.last = &d_left ($$.comp); $$.comp = d_qualify ($$.comp, $2, 0); } /* g++ seems to allow qualifiers after the reference? */ | '&' - { $$.comp = make_empty (DEMANGLE_COMPONENT_REFERENCE); - $$.comp->u.s_binary.left = $$.comp->u.s_binary.right = NULL; + { $$.comp = fill_comp (DEMANGLE_COMPONENT_REFERENCE, NULL, NULL); $$.last = &d_left ($$.comp); } | nested_name '*' qualifiers_opt - { $$.comp = make_empty (DEMANGLE_COMPONENT_PTRMEM_TYPE); - $$.comp->u.s_binary.left = $1.comp; + { $$.comp = fill_comp (DEMANGLE_COMPONENT_PTRMEM_TYPE, $1.comp, NULL); /* Convert the innermost DEMANGLE_COMPONENT_QUAL_NAME to a DEMANGLE_COMPONENT_NAME. */ *$1.last = *d_left ($1.last); - $$.comp->u.s_binary.right = NULL; $$.last = &d_right ($$.comp); $$.comp = d_qualify ($$.comp, $3, 0); } | COLONCOLON nested_name '*' qualifiers_opt - { $$.comp = make_empty (DEMANGLE_COMPONENT_PTRMEM_TYPE); - $$.comp->u.s_binary.left = $2.comp; + { $$.comp = fill_comp (DEMANGLE_COMPONENT_PTRMEM_TYPE, $2.comp, NULL); /* Convert the innermost DEMANGLE_COMPONENT_QUAL_NAME to a DEMANGLE_COMPONENT_NAME. */ *$2.last = *d_left ($2.last); - $$.comp->u.s_binary.right = NULL; $$.last = &d_right ($$.comp); $$.comp = d_qualify ($$.comp, $4, 0); } ; array_indicator : '[' ']' - { $$ = make_empty (DEMANGLE_COMPONENT_ARRAY_TYPE); - d_left ($$) = NULL; - } + { $$ = fill_comp (DEMANGLE_COMPONENT_ARRAY_TYPE, NULL, NULL); } | '[' INT ']' - { $$ = make_empty (DEMANGLE_COMPONENT_ARRAY_TYPE); - d_left ($$) = $2; - } + { $$ = fill_comp (DEMANGLE_COMPONENT_ARRAY_TYPE, $2, NULL); } ; /* Details of this approach inspired by the G++ < 3.4 parser. */ @@ -948,8 +919,7 @@ direct_declarator $$.last = &d_right ($2); } | colon_ext_name - { $$.comp = make_empty (DEMANGLE_COMPONENT_TYPED_NAME); - d_left ($$.comp) = $1; + { $$.comp = fill_comp (DEMANGLE_COMPONENT_TYPED_NAME, $1, NULL); $$.last = &d_right ($$.comp); } ; @@ -965,8 +935,7 @@ declarator_1 : ptr_operator declarator_1 $$.last = $1.last; *$2.last = $1.comp; } | colon_ext_name - { $$.comp = make_empty (DEMANGLE_COMPONENT_TYPED_NAME); - d_left ($$.comp) = $1; + { $$.comp = fill_comp (DEMANGLE_COMPONENT_TYPED_NAME, $1, NULL); $$.last = &d_right ($$.comp); } | direct_declarator_1 -- 2.5.5