From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 6wq7NAA4g2qfPy0AWB0awg (envelope-from ) for ; Mon, 17 Aug 2026 12:34:08 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=simark.ca; s=mail; t=1786984448; bh=LeG8iWt0dyi5t/w9rgc0w1XUNTNjKfucSafdRL6QtG0=; h=Date:Subject:To:References:From:In-Reply-To:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=lLR8e0pm5Yusox8dEijhKcpE7336JAK/ejACAooGZdlI3HuwkXhSx7AoUb44bVt8L zokqQvZcILu9AoN3SHPpWSMF/XwZdyCkdpzembggnshpHjzTqmCB400BuFnAS7Ykef M4mmKZH8wEgcHDivOWAntUyBhFm6GXI8wAleqvzs= Received: by simark.ca (Postfix, from userid 112) id B2F671E033; Mon, 17 Aug 2026 12:34:08 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-5.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=4.0.1 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=simark.ca header.i=@simark.ca header.a=rsa-sha256 header.s=mail header.b=e6D/WnHH; dkim-atps=neutral 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 15AB21E033 for ; Mon, 17 Aug 2026 12:34:07 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3FE6A4B9DB57 for ; Mon, 17 Aug 2026 16:34:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3FE6A4B9DB57 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=simark.ca header.i=@simark.ca header.a=rsa-sha256 header.s=mail header.b=e6D/WnHH Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id 437A64BA9009 for ; Mon, 17 Aug 2026 16:33:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 437A64BA9009 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=simark.ca Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=simark.ca ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 437A64BA9009 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=158.69.221.121 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1786984422; cv=none; b=pYzAiqalpKmblJCq3KQ6aXcV4+5Ivk5lMAvQHplqIXocwSKi85uHnIeoZZddewCaM8YneVS6Mj1xwAzotSVtr/IMpUXJ9XfFT9KxgQ1dizZ+W3a374GdtR7YtgbcG2M5xlBVwagwgxOPWO9AradFUkYkBxIKMXubjtkH5K87NAs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1786984422; c=relaxed/simple; bh=LeG8iWt0dyi5t/w9rgc0w1XUNTNjKfucSafdRL6QtG0=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=UH7xPcCB0Su8XmboR9ZH12T4e/h4BFNHGsdwgY5duAn9pRW5LzawxoW3zC2N30PYQDoGmW0Idq35itSeYdP8VhgSanTGSgQ6lzejIJMsfgOuinDkne4S46Efa5aEWoGwDMQzNHXYiXcLiSgaSRbhp6/Hut1a9IzADEuExLPoLYQ= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=simark.ca header.i=@simark.ca header.a=rsa-sha256 header.s=mail header.b=e6D/WnHH DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 437A64BA9009 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=simark.ca; s=mail; t=1786984421; bh=LeG8iWt0dyi5t/w9rgc0w1XUNTNjKfucSafdRL6QtG0=; h=Date:Subject:To:References:From:In-Reply-To:From; b=e6D/WnHH9bGb4lOxoKURr0p9CGhIrP92pnl2OX3ioLyhVdCgRxLJdowXqaFG7A2Ue Weng1re0DDj72euHcwSOEMu3ejot37zAQk9YlvxuotfSzx9GmGo9aXCWyGJhdw06HW RlF97Ikh3sUkagWCQZlsyV73PAcTb/WFvkjuWbU8= Received: by simark.ca (Postfix) id EEB781E033; Mon, 17 Aug 2026 12:33:40 -0400 (EDT) Message-ID: Date: Mon, 17 Aug 2026 12:33:40 -0400 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> Content-Language: fr From: Simon Marchi In-Reply-To: <20260814085303.2561156-1-firmiana402@gmail.com> Content-Type: text/plain; charset=UTF-8 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 On 8/14/26 4: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. > > 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")); I think the error message could be clearer, "type" and "data" are very vague. Ideally, we would print the actual op used (DW_OP_deref_type vs DW_OP_GNU_deref_type), since they don't have the same encoding. We could also at least print the sizes involved, that could help someone figure out what is wrong. Suggestion: if (type->length () != addr_size) error (_("%s has dereference size %d, but its " "type has size %s"), get_DW_OP_name (op), addr_size, pulongest (type->length ())); Orthogonal to your change: the addr_size variable seems misnamed, nothing says that the value we are accessing is an address. > +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" Instead of emitting the bytes in-line here, could you please add the necessary "_handle_DW_OP_*" procs to lib/dwarf.exp? > + 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" > +} Could you add some tests where the access works? It doesn't seem like we have coverage for that in the testsuite (at least for DWARF assembler-based tests). Simon