From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id GeLfHud5DWrH7QkAWB0awg (envelope-from ) for ; Wed, 20 May 2026 05:07:51 -0400 Authentication-Results: simark.ca; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=YU33FAGu; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 702A01E062; Wed, 20 May 2026 05:07:51 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-3.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,RCVD_IN_VALIDITY_CERTIFIED_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED 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 C2D4C1E062 for ; Wed, 20 May 2026 05:07:49 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 34DF04BB58A2 for ; Wed, 20 May 2026 09:07:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 34DF04BB58A2 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=YU33FAGu Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.13]) by sourceware.org (Postfix) with ESMTPS id A73174BA2E10 for ; Wed, 20 May 2026 09:07:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A73174BA2E10 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=intel.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org A73174BA2E10 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=192.198.163.13 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1779268044; cv=none; b=OykgqZRAoxpgrvUBu9WyzqO8fGKa0unpJAJBOJhUnMCJBiZv4f8+Pc/GQpoFAdxTWtmSDOeBVGfdZcjo7Okweu7kv7gO/BbabRMAOGGZOsd8YZ5AGUDpySflVvvr05N0lyAHpSv8czUV+VjgfEQzGMkFApBhUL4946YN7NB47Ik= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1779268044; c=relaxed/simple; bh=by+htUZ7NXm41Zf9EVTh5SvlENVQtmyFaVZRSjbHgzo=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=dZRUoCdW6N2mRD4JcPomCf8QQ+r0p30uRlMDSGZ3OiJjsNltdgN/lPaRMJeVsmdgRrB49mTzfLN+wz6KlQeE7OMuq2u7JOraeIdFin9pCqjrGDyAfijkGtcW7xKdk4Av15lO2iiG0ZO3d7xUTC5qD33csFD259TUHl1IeymvLc0= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=YU33FAGu DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A73174BA2E10 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1779268043; x=1810804043; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=by+htUZ7NXm41Zf9EVTh5SvlENVQtmyFaVZRSjbHgzo=; b=YU33FAGu44teE8MPFqK/XsXyYpJxxYyxugUi9o2oi1cQWpferhL9y9Jl kix5Tbbd2B7qaJVsb9Rfhd/X2OIQvaAS780xpswVq0qgTxI1FQGLWzmqQ jIxSHrMpfQktKBTLx40rA6GJWZkt5sTgHRz/SHo8265sRaPx/CXXMZKFZ Nlw8+BsTsiWdjWY3PsovHBuhAT0lZpupYtlOf0JFgjRoriYgS+ZatS/Kw wjhxU+sx+8iw1ib+SNwMVX+Z1m1JeFyOH3wfXuRE8KSbFkhitFJrMf9n9 lm1nHqJGHypWrH+2Vgs2wmrcouSWrpDY2vLnO7gMDVsa0BkrTo4No1FHy w==; X-CSE-ConnectionGUID: 8kC/Hkg1R+2q2DYc9ph6Bw== X-CSE-MsgGUID: H6mGJRLkSoaeErV0+xUTGg== X-IronPort-AV: E=McAfee;i="6800,10657,11791"; a="82738253" X-IronPort-AV: E=Sophos;i="6.23,244,1770624000"; d="scan'208";a="82738253" Received: from orviesa009.jf.intel.com ([10.64.159.149]) by fmvoesa107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 May 2026 02:07:15 -0700 X-CSE-ConnectionGUID: pwxJepWTSvCAr+x0bZLkUA== X-CSE-MsgGUID: Po7tMMD1TUKKW/o+kQi+cQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,244,1770624000"; d="scan'208";a="240154971" Received: from asmit6-mobl3.ger.corp.intel.com (HELO localhost) ([10.245.114.108]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 May 2026 02:07:14 -0700 From: Abdul Basit Ijaz To: gdb-patches@sourceware.org Cc: abdul.b.ijaz@intel.com Subject: [PATCH 1/1] gdb: Handle TYPE_CODE_COMPLEX in valprint_check_validity. Date: Wed, 20 May 2026 11:07:01 +0200 Message-Id: <20260520090701.12057-1-abdul.b.ijaz@intel.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" 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 When printing complex variables with partial optimization (e.g., real part available but imaginary part optimized out), GDB incorrectly reported the entire variable as instead of showing available components. The issue occurred because valprint_check_validity () only exempted TYPE_CODE_UNION, TYPE_CODE_STRUCT, and TYPE_CODE_ARRAY from the optimized-out check, but not TYPE_CODE_COMPLEX. Complex types, like structures, can have components with different availability. A new test gdb.dwarf2/complex-partial-optimized.exp is added to verify that available components are printed. (gdb) print z1 $1 = Now after this change: (gdb) print z1 $1 = 3 + i --- .../gdb.dwarf2/complex-partial-optimized.exp | 101 ++++++++++++++++++ gdb/valprint.c | 3 +- gdb/valprint.h | 8 +- 3 files changed, 108 insertions(+), 4 deletions(-) create mode 100644 gdb/testsuite/gdb.dwarf2/complex-partial-optimized.exp diff --git a/gdb/testsuite/gdb.dwarf2/complex-partial-optimized.exp b/gdb/testsuite/gdb.dwarf2/complex-partial-optimized.exp new file mode 100644 index 00000000000..c22a729826b --- /dev/null +++ b/gdb/testsuite/gdb.dwarf2/complex-partial-optimized.exp @@ -0,0 +1,101 @@ +# 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 printing of partially optimized complex variables. + +load_lib dwarf.exp + +# This test can only be run on targets which support DWARF-2. +require dwarf2_support + +standard_testfile main.c -dw.S + +set asm_file [standard_output_file $srcfile2] + +Dwarf::assemble $asm_file { + cu {} { + compile_unit { + DW_AT_language @DW_LANG_C99 + DW_AT_name $::srcfile + DW_AT_comp_dir /tmp + } { + declare_labels float_label complex_label + + float_label: DW_TAG_base_type { + DW_AT_byte_size 4 DW_FORM_sdata + DW_AT_encoding @DW_ATE_float + DW_AT_name float + } + + complex_label: DW_TAG_base_type { + DW_AT_byte_size 8 DW_FORM_sdata + DW_AT_encoding @DW_ATE_complex_float + DW_AT_name "complex float" + } + + DW_TAG_subprogram { + MACRO_AT_func {main} + DW_AT_type :$float_label + DW_AT_external 1 DW_FORM_flag + } { + # Complex variable 'z1' with real part as constant value, imaginary + # optimized out + DW_TAG_variable { + DW_AT_name z1 + DW_AT_type :$complex_label + DW_AT_location { + DW_OP_implicit_value 0x00 0x00 0x40 0x40 + DW_OP_piece 4 + DW_OP_piece 4 + } SPECIAL_expr + } + # Complex variable 'z2' with real part optimized out, imaginary + # part as constant value + DW_TAG_variable { + DW_AT_name z2 + DW_AT_type :$complex_label + DW_AT_location { + DW_OP_piece 4 + DW_OP_implicit_value 0x00 0x00 0x40 0x40 + DW_OP_piece 4 + } SPECIAL_expr + } + } + } + } +} + +if {[prepare_for_testing "failed to prepare" ${testfile} \ + [list $srcfile $asm_file] {nodebug}]} { + return +} + +if {![runto_main]} { + return +} + +# Test that complex variable prints with real part shown and imaginary as +# . +# Expected output format: "$1 = + i". +# The regex ensures there's a real value (not ) before the +. +gdb_test "print z1" "= \[0-9\]+ \\+ i" \ + "complex with imaginary part optimized out shows real value" + +# Test that complex variable prints with real part optimized out and imaginary +# part shown. +# Expected output format: "$2 = + i". +# The regex ensures there's an imaginary value (not ) after the +. +gdb_test "print z2" "= \\+ \[0-9\]+i" \ + "complex with real part optimized out shows imaginary value" diff --git a/gdb/valprint.c b/gdb/valprint.c index 482069fbbaa..b266db550d1 100644 --- a/gdb/valprint.c +++ b/gdb/valprint.c @@ -336,7 +336,8 @@ valprint_check_validity (struct ui_file *stream, if (type->code () != TYPE_CODE_UNION && type->code () != TYPE_CODE_STRUCT - && type->code () != TYPE_CODE_ARRAY) + && type->code () != TYPE_CODE_ARRAY + && type->code () != TYPE_CODE_COMPLEX) { if (val->bits_any_optimized_out (TARGET_CHAR_BIT * field_byte_offset, TARGET_CHAR_BIT * type->length ())) diff --git a/gdb/valprint.h b/gdb/valprint.h index 146a24d174f..8e88b964722 100644 --- a/gdb/valprint.h +++ b/gdb/valprint.h @@ -197,10 +197,12 @@ extern void print_function_pointer_address (const struct value_print_options *op /* Helper function to check the validity of some bits of a value. - If TYPE represents some aggregate type (e.g., a structure), return true. + If TYPE is a structure, union, array, or complex type, return 1. These + types can have components with different availability states, so callers + should check components individually. - For non-aggregate TYPEs, if any of the bytes starting at FIELD_BYTE_OFFSET - and extending for TYPE->length () bytes are invalid, print a message to + Otherwise, if any of the bytes starting at FIELD_BYTE_OFFSET and + extending for TYPE->length () bytes are invalid, print a message to STREAM and return false. Otherwise, return true. */ extern bool valprint_check_validity (struct ui_file *stream, struct type *type, -- 2.34.1 Intel Deutschland GmbH Registered Address: Dornacher Strasse 1, 85622 Feldkirchen, Germany Tel: +49 89 991 430, www.intel.de Managing Directors: Harry Demas, Jeffrey Schneiderman, Yin Chong Sorrell Chairperson of the Supervisory Board: Nicole Lau Registered Seat: Munich Commercial Register: Amtsgericht Muenchen HRB 186928