From patchwork Thu Mar 20 19:26:57 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 108651 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5F16C3857B84 for ; Thu, 20 Mar 2025 19:33:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5F16C3857B84 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, secure) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256 header.s=google header.b=d+VmRVUa X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-io1-xd30.google.com (mail-io1-xd30.google.com [IPv6:2607:f8b0:4864:20::d30]) by sourceware.org (Postfix) with ESMTPS id 282373858427 for ; Thu, 20 Mar 2025 19:27:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 282373858427 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 282373858427 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::d30 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1742498822; cv=none; b=kVfUB8zWGcZFW1jhxKnKaEr4m8AkCoEoNkp+z246jzMTSsFehw0m434QcHgNdJmSqGaSZ0lw3O510lESEvh9I97PlWOfBFY+WX86bx8pVCwA5aJPfpjwyXaUQUJ20S5kcUgaIsNCm+/M4zrIg2ZmVjxOrioz+hbS39iFfLM67So= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1742498822; c=relaxed/simple; bh=hS0SB/kA5dP2LfZ4N1CVesO3wK/dKxq4hmpLv9iAt3k=; h=DKIM-Signature:From:Date:Subject:MIME-Version:Message-Id:To; b=Ic8Apg3AZ1qshKRzn0TyMYW/I5r+d2uaVCqQtgn+eLoye9NjtXf3s3OmLd7mPRHdKxAzmNnA4Z7zlZJpXHWzNGt/h6CFOUCuk8T7N+habnUZl5I2nfSSkd5nISm+JxF3u0u1siTDzmbCoQBDm9p46fqIXEw+xesBNMUdtdhgDTs= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 282373858427 Received: by mail-io1-xd30.google.com with SMTP id ca18e2360f4ac-85b44094782so35818939f.3 for ; Thu, 20 Mar 2025 12:27:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1742498821; x=1743103621; darn=sourceware.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=sf+GjQ7tNHy15d8yjCsSIUPIx0dVjdDYMMJiJIIWzd8=; b=d+VmRVUadgTk/V2M9o4NDP6q7XiM3lbiO/79IQTkSkeF93FGfUHGdrngW68LRU0ki9 5oHh3oQyCwd56y3tWwvjCbOVmgGHUskGz2uuARTGU9DWgJxsFCCH+33IJ9i6RZ5lxXAL Ap6LanibhkZ4+RquRpf30HYWFx5hKEOadXx2PlHTDporpC63mjIjyxHcC0a402MKWOl0 NshEZ0aakDGNflHb78N9OnZgdoLQu2TAmZBK8aINvwGVJNd9BX+dqt12j3to/w5idXly 4VQh3U+KqthvMOGJ3j5uFPAjo3tIlZ2Co+vmqzZc77p1pjUcJmLT8aYcUiVMJiwx8Soe JBjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742498821; x=1743103621; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=sf+GjQ7tNHy15d8yjCsSIUPIx0dVjdDYMMJiJIIWzd8=; b=JwqIorJ7grEZhqJPLIIrQZAnEURi9nW0Rx3J72KXI65c/0Lidk31GkEMU7mlFU6Su/ yL6X6uFAGC3yrPvs+p0QRu78X42cqduInjaVnJr5+IBOi83DLIcuCZApPPqtBdlrjNv7 ELmouO3N2c3YhkyP+cFqbEHJhiC56C9AbzGO9co7MmA0lvegjhlnnujoEnKMbJgfLgb2 DzdrEjqlbag3HTXm3zWtBgnMKwGrFnzGUYnD1jMDxyeP+R2+p9419mRjZXM0z1OqGNTI 6AIOfvoz0qIYKo+7DPHi0pOjg3uuVoVvb/sS5gUNc1RrJ5P8Nk4yoleHx3j3ilpf2o/1 h5Dg== X-Gm-Message-State: AOJu0YyZob1FRzKNLy+ksfAVsmXsvIg24LkOGJABfBSf8u7Q1GH1r2t+ clkaY1gLyoSc0ZEWAPq4OFfKqU9XqPUYHzc4nEddhZY+RXwOPaS/31s1ys9jvA== X-Gm-Gg: ASbGnct502XEFBKiFztK5oKdAPVaEV2+v/WIfilSMKBI1VTIpDlQZDZgd3XrhCG+/BR tntse08QaXewvGom4fksl3isf4nvaYTjGYGcrekkVAwI5hu38VLkgXo7ouDeQugPWda+WKF5Lu/ 62Cb0M/uioCWZ1TqWjFaMKX1Wcw+LRzP2dU3tPFx9/oifHQL5d+lSvn24kuWr7OmnfF7pelT2pk WBHvxSOieVys5KEzxto4NTeJ2tkVdY6PC9QZOEf8u/R01/6n1LNj4noXCValOBUM+Oe1lxfmFZa vzZwyJAzoVeiimDJ1De3kD1x3fmIjO9ZedmU/ohz+Mc2f9r83Y1jsg5dI1jPN3hkheAKyrqGz9T r/UYUT34ADkSRGIvu/94= X-Google-Smtp-Source: AGHT+IHl8WmsgY3GSY2t1gWyK8Jt4huHyY840lBYlBFXA1XP/DyDgSpDRTnbKczoBkcjnCVUEWnUTg== X-Received: by 2002:a05:6602:388c:b0:85c:c7f9:9a23 with SMTP id ca18e2360f4ac-85e2cc60437mr57308439f.14.1742498821334; Thu, 20 Mar 2025 12:27:01 -0700 (PDT) Received: from localhost.localdomain (97-122-123-18.hlrn.qwest.net. [97.122.123.18]) by smtp.gmail.com with ESMTPSA id ca18e2360f4ac-85e2bc6ab31sm8285939f.22.2025.03.20.12.27.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Mar 2025 12:27:00 -0700 (PDT) From: Tom Tromey Date: Thu, 20 Mar 2025 13:26:57 -0600 Subject: [PATCH 01/13] Use attribute::unsigned_constant for sizes MIME-Version: 1.0 Message-Id: <20250320-attribute-madness-v1-1-79d42789f881@adacore.com> References: <20250320-attribute-madness-v1-0-79d42789f881@adacore.com> In-Reply-To: <20250320-attribute-madness-v1-0-79d42789f881@adacore.com> To: gdb-patches@sourceware.org Cc: Tom Tromey X-Mailer: b4 0.14.2 X-Spam-Status: No, score=-11.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~patchwork=sourceware.org@sourceware.org This changes the DWARF reader to use attribute::unsigned_constant for DW_AT_bit_size, DW_AT_byte_size, DW_AT_data_byte_size, and DW_AT_string_length. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32680 --- gdb/dwarf2/read.c | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index b9040a57cf962e9b04921aad4ed27dc767cc8e00..25d5566926de8cf836ecb83d656caa7a057b07c2 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -10168,7 +10168,7 @@ dwarf2_add_field (struct field_info *fip, struct die_info *die, /* Get bit size of field (zero if none). */ attr = dwarf2_attr (die, DW_AT_bit_size, cu); if (attr != nullptr) - fp->set_bitsize (attr->constant_value (0)); + fp->set_bitsize (attr->unsigned_constant ().value_or (0)); else fp->set_bitsize (0); @@ -10203,7 +10203,7 @@ dwarf2_add_field (struct field_info *fip, struct die_info *die, /* The size of the anonymous object containing the bit field is explicit, so use the indicated size (in bytes). */ - anonymous_size = attr->constant_value (0); + anonymous_size = attr->unsigned_constant ().value_or (0); } else { @@ -11176,7 +11176,7 @@ read_structure_type (struct die_info *die, struct dwarf2_cu *cu) if (attr != nullptr) { if (attr->form_is_constant ()) - type->set_length (attr->constant_value (0)); + type->set_length (attr->unsigned_constant ().value_or (0)); else { struct dynamic_prop prop; @@ -11772,7 +11772,7 @@ read_enumeration_type (struct die_info *die, struct dwarf2_cu *cu) attr = dwarf2_attr (die, DW_AT_byte_size, cu); if (attr != nullptr) - type->set_length (attr->constant_value (0)); + type->set_length (attr->unsigned_constant ().value_or (0)); else type->set_length (0); @@ -12731,7 +12731,8 @@ read_tag_pointer_type (struct die_info *die, struct dwarf2_cu *cu) attr_byte_size = dwarf2_attr (die, DW_AT_byte_size, cu); if (attr_byte_size) - byte_size = attr_byte_size->constant_value (cu_header->addr_size); + byte_size = (attr_byte_size->unsigned_constant () + .value_or (cu_header->addr_size)); else byte_size = cu_header->addr_size; @@ -12843,7 +12844,8 @@ read_tag_reference_type (struct die_info *die, struct dwarf2_cu *cu, type = lookup_reference_type (target_type, refcode); attr = dwarf2_attr (die, DW_AT_byte_size, cu); if (attr != nullptr) - type->set_length (attr->constant_value (cu_header->addr_size)); + type->set_length (attr->unsigned_constant () + .value_or (cu_header->addr_size)); else type->set_length (cu_header->addr_size); @@ -13007,9 +13009,7 @@ read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu) len = dwarf2_attr (die, DW_AT_byte_size, cu); if (len != nullptr && len->form_is_constant ()) { - /* Pass 0 as the default as we know this attribute is constant - and the default value will not be returned. */ - LONGEST sz = len->constant_value (0); + LONGEST sz = len->unsigned_constant ().value_or (0); prop_type = objfile_int_type (objfile, sz, true); } else @@ -13028,15 +13028,14 @@ read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu) else if (attr != nullptr) { /* This DW_AT_string_length just contains the length with no - indirection. There's no need to create a dynamic property in this - case. Pass 0 for the default value as we know it will not be - returned in this case. */ - length = attr->constant_value (0); + indirection. There's no need to create a dynamic property in + this case. */ + length = attr->unsigned_constant ().value_or (0); } else if ((attr = dwarf2_attr (die, DW_AT_byte_size, cu)) != nullptr) { /* We don't currently support non-constant byte sizes for strings. */ - length = attr->constant_value (1); + length = attr->unsigned_constant ().value_or (1); } else { @@ -13752,7 +13751,7 @@ read_base_type (struct die_info *die, struct dwarf2_cu *cu) } attr = dwarf2_attr (die, DW_AT_byte_size, cu); if (attr != nullptr) - bits = attr->constant_value (0) * TARGET_CHAR_BIT; + bits = attr->unsigned_constant ().value_or (0) * TARGET_CHAR_BIT; name = dwarf2_full_name (nullptr, die, cu); if (!name) complaint (_("DW_AT_name missing from DW_TAG_base_type")); @@ -13903,7 +13902,7 @@ read_base_type (struct die_info *die, struct dwarf2_cu *cu) attr = dwarf2_attr (die, DW_AT_bit_size, cu); if (attr != nullptr && attr->form_is_constant ()) { - unsigned real_bit_size = attr->constant_value (0); + unsigned real_bit_size = attr->unsigned_constant ().value_or (0); if (real_bit_size >= 0 && real_bit_size <= 8 * type->length ()) { attr = dwarf2_attr (die, DW_AT_data_bit_offset, cu); @@ -14319,7 +14318,7 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu) attr = dwarf2_attr (die, DW_AT_byte_size, cu); if (attr != nullptr) - range_type->set_length (attr->constant_value (0)); + range_type->set_length (attr->unsigned_constant ().value_or (0)); maybe_set_alignment (cu, die, range_type);