From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 110982 invoked by alias); 20 Jan 2016 09:47:08 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 109796 invoked by uid 89); 20 Jan 2016 09:47:07 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.9 required=5.0 tests=BAYES_00,KAM_LAZY_DOMAIN_SECURITY,RCVD_IN_DNSWL_NONE autolearn=no version=3.3.2 spammy=gnu99, derodatadacorecom, derodat@adacore.com, *create X-HELO: smtp.eu.adacore.com Received: from mel.act-europe.fr (HELO smtp.eu.adacore.com) (194.98.77.210) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Wed, 20 Jan 2016 09:47:06 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id D086E28FB989; Wed, 20 Jan 2016 10:47:02 +0100 (CET) Received: from smtp.eu.adacore.com ([127.0.0.1]) by localhost (smtp.eu.adacore.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id FAea0CBmtSkW; Wed, 20 Jan 2016 10:47:02 +0100 (CET) Received: from [10.10.1.112] (cacatoes.act-europe.fr [10.10.1.112]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.eu.adacore.com (Postfix) with ESMTPSA id 42EB328F94FD; Wed, 20 Jan 2016 10:47:02 +0100 (CET) Subject: Re: [PATCH] DWARF: add abstract origin links on lexical blocks DIEs To: Eric Botcazou , Richard Biener References: <5695323E.3030700@adacore.com> <2525095.H2qxPUPuhJ@polaris> <2625220.VCcl1m8Hoi@polaris> <569CB499.9080601@adacore.com> Cc: gcc-patches@gcc.gnu.org From: Pierre-Marie de Rodat Message-ID: <569F5796.3080309@adacore.com> Date: Wed, 20 Jan 2016 09:47:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.5.0 MIME-Version: 1.0 In-Reply-To: <569CB499.9080601@adacore.com> Content-Type: multipart/mixed; boundary="------------080407020703000503020905" X-IsSubscribed: yes X-SW-Source: 2016-01/txt/msg01495.txt.bz2 This is a multi-part message in MIME format. --------------080407020703000503020905 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-length: 315 On 01/18/2016 10:47 AM, Pierre-Marie de Rodat wrote: > Thank you for your inputs! I’m going to try that, then. I hope this test > will not be too fragile… Here it is! Re-bootstrapped and regtested successfuly on x86_64-linux. I’ve checked that the testcase fails on the mainline. -- Pierre-Marie de Rodat --------------080407020703000503020905 Content-Type: text/x-diff; name="0001-DWARF-add-abstract-origin-links-on-lexical-blocks-DI.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0001-DWARF-add-abstract-origin-links-on-lexical-blocks-DI.pa"; filename*1="tch" Content-length: 4933 >From 451d62ff871734727b0f0f570f89b6cfbed922f2 Mon Sep 17 00:00:00 2001 From: Pierre-Marie de Rodat Date: Tue, 12 Jan 2016 14:50:33 +0100 Subject: [PATCH] DWARF: add abstract origin links on lexical blocks DIEs Track from which abstract lexical block concrete ones come from in DWARF so that debuggers can inherit the former from the latter. This enables debuggers to properly handle the following case: * function Child2 is nested in a lexical block, itself nested in function Child1; * function Child1 is inlined into some call site; * function Child2 is never inlined. Here, Child2 is described in DWARF only in the abstract instance of Child1. So when debuggers decode Child1's concrete instances, they need to fetch the definition for Child2 in the corresponding abstract instance: the DW_AT_abstract_origin link on the lexical block that embeds Child1 enables them to do that. Bootstrapped and regtested on x86_64-linux. gcc/ChangeLog: * dwarf2out.c (add_abstract_origin_attribute): Adjust documentation comment. For BLOCK nodes, add a DW_AT_abstract_origin attribute that points to the DIE generated for the origin BLOCK. (gen_lexical_block_die): Call add_abstract_origin_attribute for blocks from inlined functions. gcc/testsuite/Changelog: * gcc.dg/debug/dwarf2/nested_fun.c: New testcase. --- gcc/dwarf2out.c | 13 ++++-- gcc/testsuite/gcc.dg/debug/dwarf2/nested_fun.c | 65 ++++++++++++++++++++++++++ 2 files changed, 75 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/debug/dwarf2/nested_fun.c diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c index f742900..d1503ec 100644 --- a/gcc/dwarf2out.c +++ b/gcc/dwarf2out.c @@ -18470,15 +18470,16 @@ add_prototyped_attribute (dw_die_ref die, tree func_type) } /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found - by looking in either the type declaration or object declaration - equate table. */ + by looking in the type declaration, the object declaration equate table or + the block mapping. */ static inline dw_die_ref add_abstract_origin_attribute (dw_die_ref die, tree origin) { dw_die_ref origin_die = NULL; - if (TREE_CODE (origin) != FUNCTION_DECL) + if (TREE_CODE (origin) != FUNCTION_DECL + && TREE_CODE (origin) != BLOCK) { /* We may have gotten separated from the block for the inlined function, if we're in an exception handler or some such; make @@ -18500,6 +18501,8 @@ add_abstract_origin_attribute (dw_die_ref die, tree origin) origin_die = lookup_decl_die (origin); else if (TYPE_P (origin)) origin_die = lookup_type_die (origin); + else if (TREE_CODE (origin) == BLOCK) + origin_die = BLOCK_DIE (origin); /* XXX: Functions that are never lowered don't always have correct block trees (in the case of java, they simply have no block tree, in some other @@ -21307,6 +21310,10 @@ gen_lexical_block_die (tree stmt, dw_die_ref context_die) BLOCK_DIE (stmt) = stmt_die; old_die = NULL; } + + tree origin = block_ultimate_origin (stmt); + if (origin != NULL_TREE && origin != stmt) + add_abstract_origin_attribute (stmt_die, origin); } if (old_die) diff --git a/gcc/testsuite/gcc.dg/debug/dwarf2/nested_fun.c b/gcc/testsuite/gcc.dg/debug/dwarf2/nested_fun.c new file mode 100644 index 0000000..c783ac0 --- /dev/null +++ b/gcc/testsuite/gcc.dg/debug/dwarf2/nested_fun.c @@ -0,0 +1,65 @@ +/* As part of inlining, a BLOCK (described as DW_TAG_lexical_block DIE's) may + be present both as an abstract instance and a concrete one in the DWARF + output. This testcase attempts to make sure that the concrete ones refer to + the abstract ones thanks to the DW_AT_abstract_origin attribute. + + Such a back-link enables debuggers to make entities present in the abstract + instance only available in concrete ones. */ + +/* { dg-options "-O2 -g -std=gnu99 -gdwarf -dA" } */ +/* { dg-final { scan-assembler-times "\\(DIE \\(0x.*\\) DW_TAG_lexical_block\\)\[^)\]*DW_AT_abstract_origin" 1 } } */ + +extern void *create (const char *); +extern void destroy (void *); +extern void do_nothing (char); + +struct string +{ + const char *data; + int lb; + int ub; +}; + +int +main (void) +{ + void *o1 = create ("foo"); + + void + parent (void) + { + { + void *o2 = create ("bar"); + + int + child (struct string s) + { + int i = s.lb; + + if (s.lb <= s.ub) + while (1) + { + char c = s.data[i - s.lb]; + do_nothing (c); + if (c == 'o') + return 1; + if (i == s.ub) + break; + ++i; + } + return 0; + } + + int r; + + r = child ((struct string) {"baz", 1, 3}); + r = child ((struct string) {"qux", 2, 4}); + r = child ((struct string) {"foobar", 1, 6}); + } + + do_nothing (0); + } + + parent (); + return 0; +} -- 2.3.3.199.g52cae64 --------------080407020703000503020905--