From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 6ZudLmNf9GrZ8QEAWB0awg (envelope-from ) for ; Wed, 11 Nov 2026 07:28:19 -0500 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=lwT51b/O; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id B8343378002; Wed, 11 Nov 2026 07:28:19 -0500 (EST) 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 [IPv6:2620:52:6:3111::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 D99F41E04F for ; Wed, 11 Nov 2026 07:28:18 -0500 (EST) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 38B8B4BA79AC for ; Wed, 11 Nov 2026 12:28:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 38B8B4BA79AC 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=lwT51b/O Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.12]) by sourceware.org (Postfix) with ESMTPS id 43F3B4BA79AC for ; Wed, 11 Nov 2026 12:27:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 43F3B4BA79AC 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 43F3B4BA79AC Authentication-Results: sourceware.org; arc=none smtp.remote-ip=192.198.163.12 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1794400051; cv=none; b=OENeEf2GBBQ6Zu45cbQz2SWKsgur+OBmr9vK5PpHd9SHyLhtyAXYv4oxrC3zE0ZJGlnxYOBbidyFCRfi5C7ilDs406WPUsLc4JtFYe+iXi3jemFRvwyEkO/9f+BNMVSWYIDZAU48uH/CkBO2MiwrLep4Yz6YIPPpuS5tpiqPUh4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1794400051; c=relaxed/simple; bh=wTN8yaMARThmH9osC4Kd7NGQFpiMShzemxHVQ069pO8=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=lXlQrGILsP3KREf1KRon3+OTnVk/JqMGmWavit3EWOwwdyWMNzNnP5TGum1VsDGFeTpbwqT9AeF4tnY3hzgZ5CYu0W3wc4IiyOC9l0hSV4v8zdd3a6jOyz/loINvCz5cMpLZSO0IghLLvpK71mT5hZ/f0XN/iwynCf0qEf/IgTY= 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=lwT51b/O DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 43F3B4BA79AC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1794400051; x=1825936051; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=wTN8yaMARThmH9osC4Kd7NGQFpiMShzemxHVQ069pO8=; b=lwT51b/O5LmH33O2sQ87BcJapNVDdAO1pG4a2Maq897g8sL3EA8NE1tS Vg+E6AZTFGe5WdJeXGo/WF1NqdG/WN89bi+RKI5kMTrkHoq+ojsehmJ1r WV3hHDvsVXq29tz5K7iLT91FFcyqsXnbLC87MmzEN7TJWfQgI4IL2w6yP 58lZUs6tjnNB10B0SyDVOcgNc2tl0G38FvPWV0U8GsQZpq7jVyZm5AwCL 41EvGiU+iFPzPIEY6qVDDXiPdb/P4qDfHx2YO94U21eXTFR+jdEi0PjBP V2crOO8kRQ+szQ7Nhx+WPLV1dV/C7uY2ZUGA4PanVmE36K+dm35nepc0t Q==; X-CSE-ConnectionGUID: NajwzhcGSGGpjevSyzSgsA== X-CSE-MsgGUID: 5B607CoYTuiUabjXZr3DAg== X-IronPort-AV: E=McAfee;i="6800,10657,11962"; a="3079933" X-IronPort-AV: E=Sophos;i="6.27,207,1787036400"; d="scan'208";a="3079933" Received: from fmviesa005.fm.intel.com ([10.60.135.145]) by fmvoesa106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Nov 2026 04:27:31 -0800 X-CSE-ConnectionGUID: Sc2p3SSPRN20FyuJgI2jdQ== X-CSE-MsgGUID: NRboYxUlTNSKOxYsrcxXXg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,207,1787036400"; d="scan'208";a="8504827" Received: from dut1048pvc.igk.intel.com (HELO localhost) ([10.211.177.228]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Nov 2026 04:27:30 -0800 From: Stephan Rohr To: gdb-patches@sourceware.org Cc: tom@tromey.com Subject: [PATCH v4 1/1] gdb: resolve dynamic types of DWARF stack and implicit values Date: Wed, 11 Nov 2026 12:27:15 +0000 Message-ID: <20261111122715.612430-2-stephan.rohr@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261111122715.612430-1-stephan.rohr@intel.com> References: <20261111122715.612430-1-stephan.rohr@intel.com> 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 From: "Rohr, Stephan" GDB asserts that the data location of a value's field with a dynamic data location is resolved when fetching the field's value in "value::primitive_field". For values with a memory location, the dynamic type is properly resolved in "dwarf_expr_context::fetch_result". When evaluating a DWARF expression for a struct whose value either sits on top of the DWARF stack (DW_OP_stack_value) or is embedded in the DWARF (DW_OP_implicit_value), the dynamic type is not resolved. This triggers an assert in "value::primitive_field". Fix this by resolving the dynamic type of values on the DWARF stack and of literal values, using their contents. As for values in memory, arrays whose bounds resolve to optimized out are now marked as optimized out. --- gdb/dwarf2/expr.c | 14 +- .../locexpr-data-member-dynamic-location.exp | 147 ++++++++++++++++++ gdb/value.c | 30 ++++ gdb/value.h | 16 ++ 4 files changed, 200 insertions(+), 7 deletions(-) create mode 100644 gdb/testsuite/gdb.dwarf2/locexpr-data-member-dynamic-location.exp diff --git a/gdb/dwarf2/expr.c b/gdb/dwarf2/expr.c index f2e4deffd16..b14d51f33bf 100644 --- a/gdb/dwarf2/expr.c +++ b/gdb/dwarf2/expr.c @@ -1112,14 +1112,13 @@ dwarf_expr_context::fetch_result (struct type *type, struct type *subobj_type, if (subobj_offset + len > max) invalid_synthetic_pointer (); - retval = value::allocate (subobj_type); - /* The given offset is relative to the actual object. */ if (gdbarch_byte_order (arch) == BFD_ENDIAN_BIG) subobj_offset += n - max; - copy (val->contents_all ().slice (subobj_offset, len), - retval->contents_raw ()); + retval = value_from_implicit_contents + (subobj_type, val->contents_all ().slice (subobj_offset, len), + this->m_frame); } break; @@ -1130,9 +1129,10 @@ dwarf_expr_context::fetch_result (struct type *type, struct type *subobj_type, if (subobj_offset + n > this->m_len) invalid_synthetic_pointer (); - retval = value::allocate (subobj_type); - bfd_byte *contents = retval->contents_raw ().data (); - memcpy (contents, this->m_data + subobj_offset, n); + retval = value_from_implicit_contents + (subobj_type, + gdb::make_array_view (this->m_data + subobj_offset, n), + this->m_frame); } break; diff --git a/gdb/testsuite/gdb.dwarf2/locexpr-data-member-dynamic-location.exp b/gdb/testsuite/gdb.dwarf2/locexpr-data-member-dynamic-location.exp new file mode 100644 index 00000000000..dee5762f913 --- /dev/null +++ b/gdb/testsuite/gdb.dwarf2/locexpr-data-member-dynamic-location.exp @@ -0,0 +1,147 @@ +# Copyright 2024-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 . + +# Tests that the dynamic type of a not_lval value is properly resolved +# when evaluating the DWARF expression. Also cover the case that the upper +# bound of an array is optimized out. We expect GDB to print optimized out +# for the whole array, too. + +load_lib dwarf.exp + +require dwarf2_support + +standard_testfile implref-array.c -dw.S + +if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] } { + return +} + +set asm_file [standard_output_file $srcfile2] +Dwarf::assemble $asm_file { + cu {} { + DW_TAG_compile_unit {} { + declare_labels int_label array_label struct_label \ + opt_out_bound_label opt_out_array_label + set int_size [get_sizeof "int" 4] + + int_label: DW_TAG_base_type { + DW_AT_byte_size $int_size DW_FORM_sdata + DW_AT_encoding @DW_ATE_signed + DW_AT_name int + } + + # An array of five ints. The elements are at ARRAY plus a + # 4-byte offset read from the object by DW_OP_deref_size. The + # offset allows constant contents, as needed for + # DW_OP_implicit_value. + array_label: DW_TAG_array_type { + DW_AT_type :$int_label + DW_AT_data_location { + DW_OP_push_object_address + DW_OP_deref_size 4 + DW_OP_addr [gdb_target_symbol array] + DW_OP_plus + } SPECIAL_expr + } { + DW_TAG_subrange_type { + DW_AT_type :$int_label + DW_AT_upper_bound 4 DW_FORM_udata + } + } + + struct_label: DW_TAG_structure_type { + DW_AT_byte_size 4 DW_FORM_udata + } { + DW_TAG_member { + DW_AT_name data + DW_AT_type :$array_label + DW_AT_data_member_location 0 DW_FORM_udata + } + } + + # Define a variable for the struct type. It lives on the DWARF + # stack. The offset is 0. + DW_TAG_variable { + DW_AT_name var_a_stack_value + DW_AT_type :$struct_label + DW_AT_location { + DW_OP_lit0 + DW_OP_stack_value + } SPECIAL_expr + } + + # Same with implicit value. The offset is 0. + DW_TAG_variable { + DW_AT_name var_a_implicit_value + DW_AT_type :$struct_label + DW_AT_location { + DW_OP_implicit_value 0x00000000 + } SPECIAL_expr + } + + # Add a variable without a DWARF location for the upper bound. + # GDB resolves this to "optimized out" when reading its value. + opt_out_bound_label: DW_TAG_variable { + DW_AT_name opt_out_bound + DW_AT_type :$int_label + DW_AT_declaration 1 flag + } + + # Add a type that uses the "opt_out_bound" variable for the upper + # bound. + opt_out_array_label: DW_TAG_array_type { + DW_AT_type :$int_label + } { + DW_TAG_subrange_type { + DW_AT_type :$int_label + DW_AT_upper_bound :$opt_out_bound_label + } + } + + # Optimized out variable on the DWARF stack. + DW_TAG_variable { + DW_AT_name opt_out_stack_value + DW_AT_type :$opt_out_array_label + DW_AT_location { + DW_OP_lit1 + DW_OP_stack_value + } SPECIAL_expr + } + + # Same with implicit value. + DW_TAG_variable { + DW_AT_name opt_out_implicit_value + DW_AT_type :$opt_out_array_label + DW_AT_location { + DW_OP_implicit_value 0x01 0x00 0x00 0x00 + } SPECIAL_expr + } + } + } +} + +if { [prepare_for_testing "failed to prepare" ${testfile} \ + [list $srcfile $asm_file] {nodebug}] } { + return +} + +if {![runto_main]} { + return +} + +gdb_test "print var_a_stack_value" " = \\{data = \\{0, 1, 2, 3, 4\\}\\}" +gdb_test "print var_a_implicit_value" " = \\{data = \\{0, 1, 2, 3, 4\\}\\}" +gdb_test "print opt_out_stack_value" " = " +gdb_test "print opt_out_implicit_value" " = " diff --git a/gdb/value.c b/gdb/value.c index 87a1f804c01..1de6c8bb873 100644 --- a/gdb/value.c +++ b/gdb/value.c @@ -3695,6 +3695,36 @@ value_from_contents (struct type *type, const gdb_byte *contents) return result; } +/* See value.h. */ + +struct value * +value_from_implicit_contents (struct type *type, + gdb::array_view contents, + const frame_info_ptr &frame) +{ + /* There is no address, so pass 0. DW_OP_push_object_address then + pushes 0 and dwarf_expr_context::read_mem serves reads of the + object from CONTENTS. This returns TYPE if it is not dynamic. */ + type = resolve_dynamic_type (type, contents, 0, &frame); + + /* Resolution found that the bounds are optimized out. In this case, + mark the array itself as optimized-out. */ + struct type *real_type = check_typedef (type); + if (real_type->code () == TYPE_CODE_ARRAY + && real_type->bound_optimized_out ()) + return value::allocate_optimized_out (type); + + value *retval = value::allocate (type); + size_t len = std::min (contents.size (), (size_t) type->length ()); + copy (contents.slice (0, len), retval->contents_raw ().slice (0, len)); + + /* If only part of the data was loaded, mark the rest as unavailable. */ + if (len < type->length ()) + retval->mark_bytes_unavailable (len, type->length () - len); + + return retval; +} + /* Extract a value from the history file. Input will be of the form $digits or $$digits. See block comment above 'write_dollar_variable' for details. */ diff --git a/gdb/value.h b/gdb/value.h index 598d252abac..4c0252da7f5 100644 --- a/gdb/value.h +++ b/gdb/value.h @@ -1155,6 +1155,22 @@ extern struct value *value_from_contents_and_address const frame_info_ptr &frame = nullptr); extern struct value *value_from_contents (struct type *, const gdb_byte *); +/* Return a new not_lval value of type TYPE holding CONTENTS, for an + object that has no address in target memory, e.g. the result of + DW_OP_stack_value or DW_OP_implicit_value. FRAME is the frame used + to evaluate the dynamic properties of TYPE. + + If TYPE is dynamic, it is resolved using CONTENTS for reads relative + to the object, so that for instance a DW_AT_data_location of + "DW_OP_push_object_address; DW_OP_deref" yields the pointer stored + in CONTENTS. Resolving may change the length of the type; bytes of + the resolved type that are not covered by CONTENTS are marked + unavailable. If TYPE is an array whose bounds resolve to optimized + out, the returned value is optimized out. */ +extern struct value *value_from_implicit_contents + (struct type *type, gdb::array_view contents, + const frame_info_ptr &frame); + extern value *default_value_from_register (gdbarch *gdbarch, type *type, int regnum, const frame_info_ptr &this_frame); -- 2.43.0 ________________________________________ Intel Deutschland GmbH Registered Address: Dornacher Strasse 1, 85622 Feldkirchen, Germany Tel: +49 (89) 99143-0 www.intel.de Managing Directors: Candice Moore, Jeffrey Schneiderman, Ramachandran Sitaraman Chairperson of the Supervisory Board: Sonja Pierer Registered Seat: Munich Commercial Register B: Amtsgericht Munich HRB 186928 This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.