From patchwork Fri May 28 18:33:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Botcazou X-Patchwork-Id: 1485307 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=adacore-com.20150623.gappssmtp.com header.i=@adacore-com.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=ZH8br7AG; dkim-atps=neutral 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 (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FsCxx3NQtz9sRN for ; Sat, 29 May 2021 04:33:56 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 15471388CC1A; Fri, 28 May 2021 18:33:54 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by sourceware.org (Postfix) with ESMTPS id F2061385703F for ; Fri, 28 May 2021 18:33:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org F2061385703F Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=botcazou@adacore.com Received: by mail-wm1-x32a.google.com with SMTP id f75-20020a1c1f4e0000b0290171001e7329so2912586wmf.1 for ; Fri, 28 May 2021 11:33:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=ZxYtPK0e78997R3IcbgReu37x+PsdVHCO3Se3ms6d0s=; b=ZH8br7AGdcYXFBX6pcea/b2HusALD7L4/dVhyabLzqtA2aqBsTw9Qh1ZFJMMaK9b6C cgNVmyuw3EX6l9Pn+vqSN5SU3QrIPm01+Y7xUZarKnuu/lnB32PpVNk8HKTCqmkJhPjp VEmBDQ3vDYyp1Wk/CcMsj1BfQrWEbBKgnfXlN5knrB1k1geFOt/w6+EtRby0JgY5QY0V 4qgpKR2UWO5r9obYTxZxQcZF2BeXrd85yZ2g4LPaCWsNUD7T5LyYbNIspsf9iL4LLAK+ AvBWCxG7lTVdJkOh87eZLontRLPFW2DjTPYZWEshpJz6PqVQ4RjxUFCvcLMoa1nsvplG Rqxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=ZxYtPK0e78997R3IcbgReu37x+PsdVHCO3Se3ms6d0s=; b=ScUbmPAkf+z1EHz27Hy0KrUGIraC5VBPGvvCUskPrNjrmyBoip442RxttkK4V7UB/B EONXHVONIpzM3+/QQ+ELXSWBnjVH8UjEsTBjQ7LyqaRo1ECQXrupH8cGyWy9U2HLOFZw BBE2P8SpKBA7aFrs4HI1bFrRUjtXfAyTHfqnqHOxeFUnt8dgq6pr8B212XNA5izGKkWH L+5opBydtGJ2bQJWNpg2alUtpL3pHFA+qElpyH5S4cQdNDbYkGskyd8a6dpmkHsdjoug 0ObXcxxZ1mvebJEc3p3zlmp2VgQKhd1/bca+K+pK098op/aCztAXP16DAApvst9vtXxS 4r/g== X-Gm-Message-State: AOAM531mBYJl2clN4eGsH+W3rfLqqvhB+IcF1tn/RwVKkPSljkGXK0j9 D44uAevvJ00wsz2dAO5nW/6QE+Zmml9uaI5V X-Google-Smtp-Source: ABdhPJzxcsoRxAH5E2IarVCqHLBCgOklRVWqKFC59STeEJBIo5duyu6rMQw8P2TzIFgaYkXH1LnNpg== X-Received: by 2002:a1c:e243:: with SMTP id z64mr9684744wmg.25.1622226829962; Fri, 28 May 2021 11:33:49 -0700 (PDT) Received: from fomalhaut.localnet ([2a01:e0a:41b:84f0:cf71:f5e0:b050:bede]) by smtp.gmail.com with ESMTPSA id y189sm6608935wmy.25.2021.05.28.11.33.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 May 2021 11:33:49 -0700 (PDT) From: Eric Botcazou X-Google-Original-From: Eric Botcazou To: gcc-patches@gcc.gnu.org Subject: [DWARF] Also generate DW_OP_GNU_variable_value at file scope Date: Fri, 28 May 2021 20:33:48 +0200 Message-ID: <7246028.EvYhyI6sBW@fomalhaut> MIME-Version: 1.0 X-Spam-Status: No, score=-11.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" But only for the reference variant (dw_val_class_die_ref). This is needed for variable-sized types declared at library level in Ada. Tested on x86-64/Linux, both GCC and GDB, OK for the mainline? 2021-05-28 Eric Botcazou * dwarf2out.c (loc_list_from_tree_1) : Also generate DW_OP_GNU_variable_value referencing an existing DIE at file scope. (type_byte_size): Inline into... (add_byte_size_attribute): ...this and call add_scalar_info. diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c index 523735e1521..ebb01ac0cef 100644 --- a/gcc/dwarf2out.c +++ b/gcc/dwarf2out.c @@ -18829,25 +18829,25 @@ loc_list_from_tree_1 (tree loc, int want_address, { if (TREE_CODE (loc) != FUNCTION_DECL && early_dwarf - && current_function_decl && want_address != 1 && ! DECL_IGNORED_P (loc) && (INTEGRAL_TYPE_P (TREE_TYPE (loc)) || POINTER_TYPE_P (TREE_TYPE (loc))) - && DECL_CONTEXT (loc) == current_function_decl && (GET_MODE_SIZE (SCALAR_INT_TYPE_MODE (TREE_TYPE (loc))) <= DWARF2_ADDR_SIZE)) { dw_die_ref ref = lookup_decl_die (loc); - ret = new_loc_descr (DW_OP_GNU_variable_value, 0, 0); if (ref) { + ret = new_loc_descr (DW_OP_GNU_variable_value, 0, 0); ret->dw_loc_oprnd1.val_class = dw_val_class_die_ref; ret->dw_loc_oprnd1.v.val_die_ref.die = ref; ret->dw_loc_oprnd1.v.val_die_ref.external = 0; } - else + else if (current_function_decl + && DECL_CONTEXT (loc) == current_function_decl) { + ret = new_loc_descr (DW_OP_GNU_variable_value, 0, 0); ret->dw_loc_oprnd1.val_class = dw_val_class_decl_ref; ret->dw_loc_oprnd1.v.val_decl_ref = loc; } @@ -19588,32 +19588,6 @@ round_up_to_align (const offset_int &t, unsigned int align) return wi::udiv_trunc (t + align - 1, align) * align; } -/* Compute the size of TYPE in bytes. If possible, return NULL and store the - size as an integer constant in CST_SIZE. Otherwise, if possible, return a - DWARF expression that computes the size. Return NULL and set CST_SIZE to -1 - if we fail to return the size in one of these two forms. */ - -static dw_loc_descr_ref -type_byte_size (const_tree type, HOST_WIDE_INT *cst_size) -{ - /* Return a constant integer in priority, if possible. */ - *cst_size = int_size_in_bytes (type); - if (*cst_size != -1) - return NULL; - - struct loc_descr_context ctx = { - const_cast (type), /* context_type */ - NULL_TREE, /* base_decl */ - NULL, /* dpi */ - false, /* placeholder_arg */ - false, /* placeholder_seen */ - false /* strict_signedness */ - }; - - tree tree_size = TYPE_SIZE_UNIT (TYPE_MAIN_VARIANT (type)); - return tree_size ? loc_descriptor_from_tree (tree_size, 0, &ctx) : NULL; -} - /* Helper structure for RECORD_TYPE processing. */ struct vlr_context { @@ -21555,7 +21529,6 @@ add_byte_size_attribute (dw_die_ref die, tree tree_node) { dw_die_ref decl_die; HOST_WIDE_INT size; - dw_loc_descr_ref size_expr = NULL; switch (TREE_CODE (tree_node)) { @@ -21572,7 +21545,7 @@ add_byte_size_attribute (dw_die_ref die, tree tree_node) add_AT_die_ref (die, DW_AT_byte_size, decl_die); return; } - size_expr = type_byte_size (tree_node, &size); + size = int_size_in_bytes (tree_node); break; case FIELD_DECL: /* For a data member of a struct or union, the DW_AT_byte_size is @@ -21585,19 +21558,31 @@ add_byte_size_attribute (dw_die_ref die, tree tree_node) gcc_unreachable (); } - /* Support for dynamically-sized objects was introduced by DWARFv3. - At the moment, GDB does not handle variable byte sizes very well, - though. */ - if ((dwarf_version >= 3 || !dwarf_strict) - && gnat_encodings == DWARF_GNAT_ENCODINGS_MINIMAL - && size_expr != NULL) - add_AT_loc (die, DW_AT_byte_size, size_expr); - /* Note that `size' might be -1 when we get to this point. If it is, that - indicates that the byte size of the entity in question is variable and - that we could not generate a DWARF expression that computes it. */ + indicates that the byte size of the entity in question is variable. */ if (size >= 0) add_AT_unsigned (die, DW_AT_byte_size, size); + + /* Support for dynamically-sized objects was introduced by DWARFv3. */ + else if (TYPE_P (tree_node) + && (dwarf_version >= 3 || !dwarf_strict) + && gnat_encodings == DWARF_GNAT_ENCODINGS_MINIMAL) + { + struct loc_descr_context ctx = { + const_cast (tree_node), /* context_type */ + NULL_TREE, /* base_decl */ + NULL, /* dpi */ + false, /* placeholder_arg */ + false, /* placeholder_seen */ + false /* strict_signedness */ + }; + + tree tree_size = TYPE_SIZE_UNIT (TYPE_MAIN_VARIANT (tree_node)); + add_scalar_info (die, DW_AT_byte_size, tree_size, + dw_scalar_form_exprloc + | dw_scalar_form_reference, + &ctx); + } } /* Add a DW_AT_alignment attribute to DIE with TREE_NODE's non-default