From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id fpr+Jj9wf2oSWCYAWB0awg (envelope-from ) for ; Fri, 14 Aug 2026 15:45:03 -0400 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=T9rv2Ak9; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 8928D1E0A3; Fri, 14 Aug 2026 15:45:03 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-6.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id DB00A1E09B for ; Fri, 14 Aug 2026 15:45:01 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 224434BA79B3 for ; Fri, 14 Aug 2026 19:45:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 224434BA79B3 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=T9rv2Ak9 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id 13DF44BA543C for ; Fri, 14 Aug 2026 19:44:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 13DF44BA543C Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 13DF44BA543C Authentication-Results: sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1786736674; cv=none; b=Lkwu8iSaVJ5bhKignXISRI7o/GDSeEnTcV/PwMnxXTjsl444FUTOzs68HgLma7nateRE2BigVy4mCyOUluNL8CC2EHZmVlRLpOEUuur/Ov8iQAdRy0Z3fdZ/I/DAcn/OV8KVrM0emYHimH+E5pLgI8CWFJtcDp5ukooF/V3sAvQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1786736674; c=relaxed/simple; bh=nNstqmoIbrWSCvYPVhEbQfHe3hOMkbczyLbYiwDGTxU=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=w0jRUzIQ24eDy7AqtF5QegKg71JRKG+b7KhRkSc9ZIvKk8WLVDJN8mLCO1Sb8jA5sr0bie/hlM9zKW+18oynBVCz/ltyF/ZoCLkh6r4e0iMFrPGgUGbKhjuSvTElTbjuq3smlnVmLPsezps8k6SXiSUKLLuhdsAK5LZim+NYrSw= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=T9rv2Ak9 DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 13DF44BA543C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1786736673; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=J/ZVc5Bp9I6b9JWRpMqBSFQCX5kMMx+v7eIv3Cv2lTo=; b=T9rv2Ak923QyClHcybrueb0G0wxON3WjhEqOhNZhLH0HLOIc8wDAnwq0EJsYEGjpF9xxYy 4YtOm8FCtfH6APz61coPSKurdsh7qN7E7Yj2z2P4d8gu9TY0IEIsMnYc2YC9E9aP5MSILv dfdSuEIKK2rTdKyzEDT5whUEuVLngSQ= Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-150-DpZRxQivNbWj7mcESQQzzw-1; Fri, 14 Aug 2026 15:44:32 -0400 X-MC-Unique: DpZRxQivNbWj7mcESQQzzw-1 X-Mimecast-MFC-AGG-ID: DpZRxQivNbWj7mcESQQzzw_1786736671 Received: by mail-qv1-f71.google.com with SMTP id 6a1803df08f44-907c59bd73bso22915496d6.3 for ; Fri, 14 Aug 2026 12:44:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786736671; x=1787341471; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:to:subject:user-agent:mime-version:date :message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=J/ZVc5Bp9I6b9JWRpMqBSFQCX5kMMx+v7eIv3Cv2lTo=; b=UDpgyZgkpdlKbKyp2Q9vlqVEWKr1gAmFqT/S2T8nSJREkhszrq82tytgjf9uNw+vMs FLphn1/ne+jSOdNWARJxNtzzNmTLVBywUyKzysetou71PDSqliDe4xKbnTGtluPqccuZ 67Im5LornnRH0ULXY5dMAlAl8oyYOpt0HLw+PwmAK3WDLrUdKLEZfWRefC+weZuDe5Tt 1f+HdT8NuAQZAkOS0CMgUyVNLb26Ifh4ZPOcyUVOje+rntil70PwOOi6YaZHcv3X3LNh 5BZ04Eg126F1Z5RcpOZxxNtx0ZEJMOa72hTWqsIqBNtiNn+5FlH1+til5/TVYZNwZrcp nvDw== X-Forwarded-Encrypted: i=1; AHgh+Rofw+f1w40o/q+ZiXTHZA0aSTlI0HcwBofgzCq9be0EttrHG+cBC6jSetXQ/qnhKAHu5lyNvNrFm0wagA==@sourceware.org X-Gm-Message-State: AOJu0Yzr9IhD1ntXKc99Ah/6bA/tMwh9l3ZwLNTc1lTV5jFlq7AHc6WU Mj6eQ1YUkUb9IyQm5k+hnNXqcz9xkD63GJCrg347yaLFjwYpJZ1s0YzHlCsV3168/VxyFJOFfzW iZ6o8nHADudlMHcAz7oa3wGpn+pb+oKQoFELypo1z19JRORburz3OrcUjtmEyhts= X-Gm-Gg: AR+sD12D3AkAVYQc82f5ByctgLim8X9YDmichOwUmrLArDHk5vSgLo0QK32QVdxSt65 cm/meV5eUKqfceawrTUnytNIpYU0leiyX0j0mKrWsIuJsJCjbWLQvKmEXfotduK+Cw15Z5kfaOz fHAtYUjUV6ZnIGL8esUBJiYRhJtXHG7T4knCaQp91V+qTBx1wGGtEc0X4Tj1MhWJBun89MNP1kg fXotBKfTpWZsRReOk5czF1Pfug+7qXxHWfT79g9WpAf3SO3bhKsnS3IukXTGYRU1AJNbU0PHyl9 EcQ7yR9ZOyUDWLPJQ4IfYJnyqjj79SC2WzaADnFouxm+E8LxK3bN0LAqEagZsze+blkM5/3icFX 5NwN5/Q== X-Received: by 2002:a05:6214:4186:b0:8ce:ca7d:b099 with SMTP id 6a1803df08f44-90a91d7340bmr91953516d6.18.1786736671498; Fri, 14 Aug 2026 12:44:31 -0700 (PDT) X-Received: by 2002:a05:6214:4186:b0:8ce:ca7d:b099 with SMTP id 6a1803df08f44-90a91d7340bmr91953016d6.18.1786736671014; Fri, 14 Aug 2026 12:44:31 -0700 (PDT) Received: from [150.1.200.157] ([172.56.108.54]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-90a935900d1sm23963996d6.42.2026.08.14.12.44.30 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 14 Aug 2026 12:44:30 -0700 (PDT) Message-ID: <336b8728-d69e-49a1-baf2-721c5629c085@redhat.com> Date: Fri, 14 Aug 2026 12:44:28 -0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] gdb: Check DW_OP_deref_type size against type To: Jielun Wu , gdb-patches@sourceware.org References: <20260814085303.2561156-1-firmiana402@gmail.com> From: Keith Seitz In-Reply-To: <20260814085303.2561156-1-firmiana402@gmail.com> X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: Y5E382f4xIUTyWb2o7bW8FGC1omQ5fBQV1B3YN10TgE_1786736671 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.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org Hi, On 8/14/26 1:53 AM, Jielun Wu wrote: > DWARF v5 requires the explicit size operand of DW_OP_deref_type to > match the size of the referenced base type. The evaluator currently > passes both sizes to dwarf_expr_context::deref without validating the > encoding, and the generic dereference helper accepts the mismatch by > zero-extending the bytes read from memory. > > Reject a mismatch after resolving the base type. Add a DWARF assembler > test covering both DW_OP_deref_type and DW_OP_GNU_deref_type. This looks good to me and is consistent with how DW_OP_const_type handles the identical scenario. Thank you very much for the test. That is very appreciated. Reviewed-By: Keith Seitz Thank you for the patch! Keith > Tested on x86_64-linux. > > Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=34277 > Signed-off-by: Jielun Wu > --- > gdb/dwarf2/expr.c | 3 + > .../gdb.dwarf2/dw2-deref-type-size.exp | 78 +++++++++++++++++++ > 2 files changed, 81 insertions(+) > create mode 100644 gdb/testsuite/gdb.dwarf2/dw2-deref-type-size.exp > > diff --git a/gdb/dwarf2/expr.c b/gdb/dwarf2/expr.c > index 3a6b8f58199..ff23fb3e891 100644 > --- a/gdb/dwarf2/expr.c > +++ b/gdb/dwarf2/expr.c > @@ -2027,6 +2027,9 @@ dwarf_expr_context::execute_stack_op (gdb::array_view expr) > op_ptr = safe_read_uleb128 (op_ptr, op_end, &uoffset); > cu_offset type_die_cu_off = (cu_offset) uoffset; > type = get_base_type (type_die_cu_off); > + if (type->length () != addr_size) > + error (_("DW_OP_deref_type has different sizes for type and " > + "data")); > } > else > type = address_type; > diff --git a/gdb/testsuite/gdb.dwarf2/dw2-deref-type-size.exp b/gdb/testsuite/gdb.dwarf2/dw2-deref-type-size.exp > new file mode 100644 > index 00000000000..52eae9e9eae > --- /dev/null > +++ b/gdb/testsuite/gdb.dwarf2/dw2-deref-type-size.exp > @@ -0,0 +1,78 @@ > +# Copyright 2026 Free Software Foundation, Inc. > + > +# This program is free software; you can redistribute it and/or modify > +# it under the terms of the GNU General Public License as published by > +# the Free Software Foundation; either version 3 of the License, or > +# (at your option) any later version. > +# > +# This program is distributed in the hope that it will be useful, > +# but WITHOUT ANY WARRANTY; without even the implied warranty of > +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > +# GNU General Public License for more details. > +# > +# You should have received a copy of the GNU General Public License > +# along with this program. If not, see . > + > +# Test that DW_OP_deref_type rejects an explicit dereference size that > +# differs from the size of the referenced base type. > + > +load_lib dwarf.exp > + > +require dwarf2_support > + > +standard_testfile main.c -dw.S > + > +set asm_file [standard_output_file $srcfile2] > + > +Dwarf::assemble $asm_file { > + cu {version 5} { > + compile_unit {} { > + declare_labels uint64_label > + > + uint64_label: base_type { > + DW_AT_name "uint64_t" > + DW_AT_encoding @DW_ATE_unsigned > + DW_AT_byte_size 8 DW_FORM_sdata > + } > + > + foreach {var op} { > + bad_deref_type DW_OP_deref_type > + bad_gnu_deref_type DW_OP_GNU_deref_type > + } { > + DW_TAG_variable { > + DW_AT_name $var > + DW_AT_type :$uint64_label > + DW_AT_external 1 DW_FORM_flag > + DW_AT_location { > + variable _constants > + variable _cu_label > + > + DW_OP_addr main_label > + _op .byte $_constants($op) $op > + _op .byte 4 "dereference size" > + _op .uleb128 "$uint64_label - $_cu_label" \ > + "base type DIE offset" > + DW_OP_stack_value > + } SPECIAL_expr > + } > + } > + } > + } > +} > + > +if {[prepare_for_testing "failed to prepare" ${testfile} \ > + [list $srcfile $asm_file] nodebug]} { > + return > +} > + > +if {![runto_main]} { > + return > +} > + > +foreach_with_prefix var { > + bad_deref_type > + bad_gnu_deref_type > +} { > + gdb_test "print $var" \ > + "DW_OP_deref_type has different sizes for type and data" > +}