From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 21anJMXsempayRwAWB0awg (envelope-from ) for ; Tue, 11 Aug 2026 05:35:01 -0400 Authentication-Results: simark.ca; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=RKXHxxOY; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 69E881E033; Tue, 11 Aug 2026 05:35:01 -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,FREEMAIL_FROM,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 7C5751E033 for ; Tue, 11 Aug 2026 05:34:57 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3E11B4BA79AC for ; Tue, 11 Aug 2026 09:34:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3E11B4BA79AC Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=RKXHxxOY Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) by sourceware.org (Postfix) with ESMTPS id 98A2C4BA798C for ; Tue, 11 Aug 2026 09:34:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 98A2C4BA798C Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 98A2C4BA798C Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::634 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1786440865; cv=none; b=ngCF/eCM3DHa0t3jm2Gyyed4WYJy2SKx12EE0t0AnEBtj36BHHoSwb1Ub7AHC2MR39NLdjOTloakkOfWASiWJ7kO8lXfE8pPDd4EaS1Wql3LErZauxG3P4Av0yd5PFnNyvW2EtH/K6YN7BemPafhuUD7/Px1RURYVefVOys1KeU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1786440865; c=relaxed/simple; bh=QHZdXR05abV6BPJTYGxpF6OuG0tCfDxP9DEI3WiyysI=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=VLDsSbKYjWOkpDN5OJACeYsL3MPQzNTLcgeX992sPwVqUwNnfrDeyhLgM+xe0kU3+keYYXJrTibO7PxiDc5jAAGtyIsj6Js+jgi+pJLfupEQwPswrBJ77eLkhaQ6lm4TUu8ICM6w2JrILVDOwgROTnowzou/hmxPVh01xNA9sN0= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=RKXHxxOY DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 98A2C4BA798C Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-2d01548ac96so3906505ad.3 for ; Tue, 11 Aug 2026 02:34:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1786440864; x=1787045664; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=3xh6BN7wT4RkVstAqrpjVpHoZzU6B4M6PXlsyFeaBZE=; b=RKXHxxOYw7bm6yeaHtY/IgpREkdxsAvIUYFqSyokteIHg36Sht/U1rurbwXaFv7jCi SS4yUCbf/oovKJq3YoLX9IyJZmMfXJM2+nRlNszDErnIOabXJVanYKI8/AJdHApWPSXf wnHXvCDdIuN+r+Oo3K62rGHiyktMudLgF6mrbH4Ckm7p9MI0t4x0c51QocL1ovAf0qCk FvmdbdgXbjRqZryOn4Mq3VrL5fP0gAOp2qMHwLNZEcAe9BnTmv9zut+FNfnCsl2tx0ap 2EVVZlKLbYb25lIsrc0WAwiJi5ezWFiCC2ZN7xJqm+hEUrxmo+tdwkEAxiorzKDfQVwc n8Cg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786440865; x=1787045665; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to:content-type; bh=3xh6BN7wT4RkVstAqrpjVpHoZzU6B4M6PXlsyFeaBZE=; b=NEeOts0VyoUa5pOUH0hd18uGJOvKYUm2V8Ff7sQ1OQdqvuUSemQIatfmAu6NRrsflc mkbdXXAoyQiP4b4EUus9Xk03Oj7GOkhvWMa3pquOZEEbwxdreQyu3t8HL35qKigVUmnQ l/5kZnfjjlZiqtAQdl+J/lduFaD1PieeRxCHQCkCxTGxEm22WGwo8HtckTdXlwW8UITK OZQxBdzNjLT3TDJHlKi66/d9MRhhGhgdREOdVUGgjRwMRBLCrrftHX0z4NXJ9Z+Eu5ip P0+RFRbcUa8DuoGsgQeL8dJzBisZmV0Y4x//73UI7ZGlHHwnrGVYZhFFU0fuic993M7N C66A== X-Gm-Message-State: AOJu0YxyQweaRePlwQnECQTDu2Bi5KQzlJl5X4ZnlgR+IxLOZKtols/I reTW0Lo5892c/arG20m43twunVkx0LUwmLgZN7pd+tps7zse80FJNmdzPy9tWuEN X-Gm-Gg: AR+sD11Oq5iLnNHc8huxb4b46fUwYGIFBKXKSiCNbN/mBdpWK7cxkMCbrtEZd3cjAJC 2w9Y+Lvgj5hzKktIotYx0Xk8T3Y6oQVA9lPrIXRklg9tpmMWuvyTdZvNwbixnTKDusBi5CkSSCU 5ry329IWD8jYSShc+x43hO3KahdXho3ZI6Pt6xIk4vWT+52fikEvooVPm3olUpfGjTRz2hcJduO WY/s9eNwhwnj5cwr6RjeyKnA3g6YIebxrA0H3fdUhm6PJtHgrNPfXuTzW/2cG5Fd/2PRa6rLA3v G1aievmGfeLKug+gSDSiVXpTufhYUAZCJz54poQLEZ9Z4sCIU0xUrzhKzvyPktjRDDIc9Q3ZKm8 Hcokxwsk9qSEQmKiPBAOGc0OQTVfa1Fw1gMQsC5Ah5AAxyuM8tFdW2ygXp9hGsHVDgZoMBJcswX niNv36rJKAD2K/lfFgyq8qZl0y7GTkoKwtpZNUW0AAlFEXt96b06kxZyI2slftw87vO5Jmuc7y1 hudG8G0RVYflNZfPXhzrSrjET3eIj32h6Bph2xk0C0= X-Received: by 2002:a17:903:b0e:b0:2d0:2741:f31b with SMTP id d9443c01a7336-2d31794d71dmr15484935ad.4.1786440864509; Tue, 11 Aug 2026 02:34:24 -0700 (PDT) Received: from poweredge.r760.114.212.189.32.r760.114.212.189.32 ([155.254.126.227]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-31c619d00edsm3303382eec.3.2026.08.11.02.34.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Aug 2026 02:34:24 -0700 (PDT) From: Jielun Wu To: gdb-patches@sourceware.org Subject: [PATCH] gdb: Preserve the operand type in DW_OP_plus_uconst Date: Tue, 11 Aug 2026 17:34:20 +0800 Message-Id: <20260811093420.3948263-1-firmiana402@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 DWARF v5 requires DW_OP_plus_uconst to interpret its unsigned LEB128 constant as the type of the popped stack entry and push a result of that same type. GDB instead reconstructs the result using address_type, discarding an explicit base type. Construct the result using the popped value's type. Add a DWARF assembler test that uses a typed value after DW_OP_plus_uconst in another typed arithmetic operation. Without the fix, the expression fails with incompatible DWARF stack types. Tested on x86_64-linux. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=34315 Signed-off-by: Jielun Wu --- gdb/dwarf2/expr.c | 2 +- .../gdb.dwarf2/dw2-plus-uconst-type.exp | 75 +++++++++++++++++++ 2 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 gdb/testsuite/gdb.dwarf2/dw2-plus-uconst-type.exp diff --git a/gdb/dwarf2/expr.c b/gdb/dwarf2/expr.c index 3a6b8f58199..2d9408a3a27 100644 --- a/gdb/dwarf2/expr.c +++ b/gdb/dwarf2/expr.c @@ -2063,7 +2063,7 @@ dwarf_expr_context::execute_stack_op (gdb::array_view expr) result = value_as_long (result_val); op_ptr = safe_read_uleb128 (op_ptr, op_end, ®); result += reg; - result_val = value_from_ulongest (address_type, result); + result_val = value_from_ulongest (result_val->type (), result); break; } } diff --git a/gdb/testsuite/gdb.dwarf2/dw2-plus-uconst-type.exp b/gdb/testsuite/gdb.dwarf2/dw2-plus-uconst-type.exp new file mode 100644 index 00000000000..224324798c6 --- /dev/null +++ b/gdb/testsuite/gdb.dwarf2/dw2-plus-uconst-type.exp @@ -0,0 +1,75 @@ +# 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_plus_uconst preserves the type of the popped stack value. +# A following DW_OP_plus checks this: it reports an error if the intermediate +# result and the second explicitly typed value have incompatible types. + +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 uint32_label + + uint32_label: base_type { + DW_AT_name "uint32_t" + DW_AT_encoding @DW_ATE_unsigned + DW_AT_byte_size 4 DW_FORM_sdata + } + + DW_TAG_variable { + DW_AT_name "plus_uconst_preserves_type" + DW_AT_type :$uint32_label + DW_AT_external 1 DW_FORM_flag + DW_AT_location { + variable _constants + variable _cu_label + + _op .byte $_constants(DW_OP_const_type) + _op .uleb128 "$uint32_label - $_cu_label" \ + "base type DIE offset" + _op .byte 4 "constant size" + _op .4byte 40 "constant data" + DW_OP_plus_uconst 1 + _op .byte $_constants(DW_OP_const_type) + _op .uleb128 "$uint32_label - $_cu_label" \ + "base type DIE offset" + _op .byte 4 "constant size" + _op .4byte 1 "constant data" + DW_OP_plus + DW_OP_stack_value + } SPECIAL_expr + } + } + } +} + +if {[prepare_for_testing "failed to prepare" ${testfile} \ + [list $srcfile $asm_file] nodebug]} { + return +} + +if {![runto_main]} { + return +} + +gdb_test "print plus_uconst_preserves_type" " = 42" -- 2.34.1