From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id /WyoOYqp82K2UyQAWB0awg (envelope-from ) for ; Wed, 10 Aug 2022 08:50:18 -0400 Received: by simark.ca (Postfix, from userid 112) id DEF751E5EA; Wed, 10 Aug 2022 08:50:18 -0400 (EDT) Authentication-Results: simark.ca; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=b7+naeNa; dkim-atps=neutral X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-3.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,NICE_REPLY_A,RDNS_DYNAMIC, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 6ED581E21F for ; Wed, 10 Aug 2022 08:50:18 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B77A73857BAF for ; Wed, 10 Aug 2022 12:50:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B77A73857BAF DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1660135816; bh=yMAV7OjmmF9sIhakKK0CYrmQHP+7SM3DIx6BNR8Cn3o=; h=Date:Subject:To:References:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=b7+naeNa77cau2rltSDZCO1ZfzAgn4flnxVJjw92Gbs3BsD248N6gm1jYa1N/ETF4 LVveFsrfedmhNnUMN4a2k2FJ/B0Gyfdak7NUc3NsM8H1vnbIFLzVbRBsjJ7saljflq haOUV/8wmjsKw1C6RPJ8gKBI3YWD0YGgHgu+exx0= Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id ACC423858401 for ; Wed, 10 Aug 2022 12:49:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org ACC423858401 Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-350-4vS273hMPHiYG_kEopkuIA-1; Wed, 10 Aug 2022 08:49:55 -0400 X-MC-Unique: 4vS273hMPHiYG_kEopkuIA-1 Received: by mail-ed1-f72.google.com with SMTP id z20-20020a05640235d400b0043e1e74a495so9219894edc.11 for ; Wed, 10 Aug 2022 05:49:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc; bh=yMAV7OjmmF9sIhakKK0CYrmQHP+7SM3DIx6BNR8Cn3o=; b=YiMDji5/sQBomQo7qB7NvCuwuPp5gpIt+yLcqiQBMFZ1ZmRsCKHNbxRu/vVule9raG TGT2ZTQEX1zWs8KsWyRzfdiOnruntNqWKVA7yQoWJpTUWlToLU1EowXYChxd6Rzf0cxm eDRALRo6Al+HdL+C9Te0r214gmwyWi8YvbWDsdOsZ5fFuDSpPSmfstmNK9lQ1IBKOq5Z DeaH0iYMyTmqdfaij5vWBxL98uc2w5c9TyFo33UrbQqx1E3Pmb4LZhD4JZ1kmeaj5urS 4HRFeM9QymGX5etX0Mintpp5xhPbMPNJ6DJ5VhfipKCUZq5p6tka6rKZtOMNZu6r0fXs l4og== X-Gm-Message-State: ACgBeo1G6R7l137u0r6TujVL1nhPcPSB1q2vujB3LsF2lMmicF6H6O/1 6f+VHrucvjr4OaWezMVM5BPR03sRhzdypxgoPYTkwHVs0m0SHIo0s3gX53DU7SHjtdcig5Mv45j fb34r1ZsMnmgtpeF3VXS2KA== X-Received: by 2002:a17:906:845c:b0:730:bbf1:196a with SMTP id e28-20020a170906845c00b00730bbf1196amr20311160ejy.13.1660135793799; Wed, 10 Aug 2022 05:49:53 -0700 (PDT) X-Google-Smtp-Source: AA6agR5fMYyk1lSjBXMBGfnp0OjUGQovvZhKZYv/PflQPLIRrbE8xqP4y//NsFDo9Qoh9owAGzSsCA== X-Received: by 2002:a17:906:845c:b0:730:bbf1:196a with SMTP id e28-20020a170906845c00b00730bbf1196amr20311152ejy.13.1660135793534; Wed, 10 Aug 2022 05:49:53 -0700 (PDT) Received: from [10.43.2.144] (nat-pool-brq-t.redhat.com. [213.175.37.10]) by smtp.gmail.com with ESMTPSA id c1-20020a170906528100b007246492658asm2268241ejm.117.2022.08.10.05.49.52 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 10 Aug 2022 05:49:52 -0700 (PDT) Message-ID: <41945aae-a1f9-f76c-c2b5-e899ab07990f@redhat.com> Date: Wed, 10 Aug 2022 14:49:51 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.12.0 Subject: Re: [PATCH v2 2/2] gdb, dwarf: create symbols for template tags without names To: Nils-Christian Kempke , gdb-patches@sourceware.org References: <20220804130351.3898972-2-nils-christian.kempke@intel.com> <20220804130351.3898972-3-nils-christian.kempke@intel.com> In-Reply-To: <20220804130351.3898972-3-nils-christian.kempke@intel.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Bruno Larsen via Gdb-patches Reply-To: Bruno Larsen Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" On 04/08/2022 15:03, Nils-Christian Kempke wrote: > The following GDB behavior was also reported as a GDB bug in > > https://sourceware.org/bugzilla/show_bug.cgi?id=28396 > > I will reiterate the problem a bit and give some more information here. > This patch closes the above mentioned bug. > > The DWARF 5 standard 2.23 'Template Parameters' reads: > > A template type parameter is represented by a debugging information > entry with the tag DW_TAG_template_type_parameter. A template value > parameter is represented by a debugging information entry with the tag > DW_TAG_template_value_parameter. The actual template parameter entries > appear in the same order as the corresponding template formal > parameter declarations in the source progam. > > A type or value parameter entry may have a DW_AT_name attribute, whose > value is a null-terminated string containing the name of the > corresponding formal parameter. > > So the DW_AT_name attribute for DW_TAG_template_type_parameter and > DW_TAG_template_value_parameter is optional. > > Within GDB, creating a new symbol from some read DIE usually requires the > presence of a DW_AT_name for the DIE (an exception here is the case of > unnamed namespaces or the existence of a linkage name). > > This patch makes the presence of the DW_AT_name for template value/type > tags optional, similar to the unnamed namespaces. > > For unnamed namespaces dwarf2_name simply returns the constant string > CP_ANONYMOUS_NAMESPACE_STR '(anonymous namespace)'. For template tags a > case was added to the switch statement calling the > unnamed_template_tag_name helper. Within the scope of parent which > the template parameter is a child of, the helper counts the position > of the template tag within the unnamed template tags and returns > '' where NUMBER is its position. This way we end up with > unique names within the respective scope of the function/class/struct > (these are the only currenltly supported template kinds within GDB and > usually the compilers) where we discovered the template tags in. > > While I do not know of a way to bring GCC to emit template tags without > names there is one for clang/icpx. Consider the following example > > template > class Foo {}; > > template > class Foo; > > int main () { > Foo f; > return 0; > } > > The forward declaration for 'Foo' with the missing template type names > 'A' and 'C' makes clang emit a bunch of template tags without names: > > ... > <2><43>: Abbrev Number: 3 (DW_TAG_variable) > <44> DW_AT_location : 2 byte block: 91 78 (DW_OP_fbreg: -8) > <47> DW_AT_name : (indirect string, offset: 0x63): f > <4b> DW_AT_decl_file : 1 > <4c> DW_AT_decl_line : 8 > <4d> DW_AT_type : <0x59> > ... > <1><59>: Abbrev Number: 5 (DW_TAG_class_type) > <5a> DW_AT_calling_convention: 5 (pass by value) > <5b> DW_AT_name : (indirect string, offset: 0x74): Foo > <5f> DW_AT_byte_size : 1 > <60> DW_AT_decl_file : 1 > <61> DW_AT_decl_line : 2 > <2><62>: Abbrev Number: 6 (DW_TAG_template_type_param) > <63> DW_AT_type : <0x76> > <2><67>: Abbrev Number: 7 (DW_TAG_template_type_param) > <68> DW_AT_type : <0x52> > <6c> DW_AT_name : (indirect string, offset: 0x6c): B > <2><70>: Abbrev Number: 6 (DW_TAG_template_type_param) > <71> DW_AT_type : <0x7d> > ... > > Befor this patch, GDB would not create any symbols for the read template > tag DIEs and thus lose knowledge about them. Breaking at the return > statement and printing f's type would read > > (gdb) ptype f > type = class Foo [with B = int] { > > } > > After this patch GDB does generate symbols from the DWARF (with their > artificial names: > > (gdb) ptype f > type = class Foo [with = double, B = int, > = float] { > > } > > The same principle theoretically applies to template functions. Also > here, GDB would not record unnamed template TAGs but I know of no visual > way to trigger and test this changed behavior. Template functions do > not emit a '[with...]' list and their name generation also does not > suffer from template tags without names. GDB does not check whether or > not a template tag has a name in 'dwarf2_compute_name' and thus, the > names of the template functions are created independently of whether or > not the template TAGs have a DW_TAT_name attribute. A testcase has > been added in the gdb.dwarf2 for template classes and structs. > > Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=28396 Hi Nils, Thanks for working on this. This version looks OK to me, and is no longer failing. I can't approve patches, but it gets a +1 from me -- Cheers, Bruno