From patchwork Tue Mar 5 11:36:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rohr, Stephan" X-Patchwork-Id: 86793 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B2F91385828F for ; Tue, 5 Mar 2024 11:37:35 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.12]) by sourceware.org (Postfix) with ESMTPS id 308163858C54 for ; Tue, 5 Mar 2024 11:37:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 308163858C54 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 308163858C54 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=192.198.163.12 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709638628; cv=none; b=VUMMQyxKugeToUTtd4PK3yYs+Aw60RkRYj16MhXTn5tPeKIfzaCN5ncGvco2vsKGCfHknFUNcWCd1x7WvOvoTOM0yB54WAs9YZNyDx96+AAfnS+ceV6hypLurjLNTOb7WFc8pTds7ewNUewC0pRpsQrIa1SFjx/oUX70F9Crr3A= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709638628; c=relaxed/simple; bh=hR4s42TcJlp3z8Wm9ppU7c9sgjdX6ThteaOlAOrvsKU=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=ngSlpyDb9uMpDCEblyu46HI+jSbXIUrxwbZok+Z3FGRtgSN355iBzt4iSX8VfbxKBAT0dlGPHk8TiLQ6TaK3APHhgPHZiWGFbq7WQ9U8FcpdvmlgWSwZ5XhM6t4xogDGbPfUUFIUm7ykqJTqGcNsi2+q9L0ZEdQK9w6oh7wgkiM= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1709638626; x=1741174626; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=hR4s42TcJlp3z8Wm9ppU7c9sgjdX6ThteaOlAOrvsKU=; b=Bbmfns1UFrpdNSnhmpk12y5uICDMRYx/Wml3JTCFhH0MFWmCDVdnLB/D mwexkxuV3JW3UVbN4Imh+h/24AYSVLIk2T/r5HJgY5GZXikInEGJK0h9g pH3ZXMVFvzJ05RSXqC0LbjfLL2QaZJJDd4sfspKN0Ij7XigWjAm5hRPcF Fp+kBkW8zmThkNHQ4Brs2D+exW8Rp3S0fJELxvdKKFv69U8snxps7w0Nz wVWRr3f+6CXjj0cAhxkBRiZ6U+jf10hqV3sSCqz31VPT//m7Wk+vgrlvP geLt6c2zoodglEx7PjE1ODQztL6x5e7qvs+Wz2v3RjXvYQny2SuV5cYsV g==; X-IronPort-AV: E=McAfee;i="6600,9927,11003"; a="7951197" X-IronPort-AV: E=Sophos;i="6.06,205,1705392000"; d="scan'208";a="7951197" Received: from orviesa007.jf.intel.com ([10.64.159.147]) by fmvoesa106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Mar 2024 03:37:05 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,205,1705392000"; d="scan'208";a="9763933" Received: from 984fee0031af.jf.intel.com (HELO localhost) ([10.165.54.65]) by orviesa007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Mar 2024 03:37:05 -0800 From: Stephan Rohr To: gdb-patches@sourceware.org Cc: tom@tromey.com Subject: [PATCH v2 1/1] gdb: Fix assertion in 'value_primitive_field' Date: Tue, 5 Mar 2024 03:36:53 -0800 Message-Id: <20240305113653.2546426-2-stephan.rohr@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240305113653.2546426-1-stephan.rohr@intel.com> References: <20240305113653.2546426-1-stephan.rohr@intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.3 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org 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+patchwork=sourceware.org@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'. This assertion was hit because of bogus DWARF generated by the Intel Fortran compiler. While that compiler should fix the DWARF, we prefer GDB to error out here instead, e.g. to allow the user to continue debugging other parts of the program. --- .../locexpr-data-member-dynamic-location.c | 31 ++++ .../locexpr-data-member-dynamic-location.exp | 136 ++++++++++++++++++ gdb/value.c | 4 +- 3 files changed, 170 insertions(+), 1 deletion(-) create mode 100644 gdb/testsuite/gdb.dwarf2/locexpr-data-member-dynamic-location.c create mode 100644 gdb/testsuite/gdb.dwarf2/locexpr-data-member-dynamic-location.exp diff --git a/gdb/testsuite/gdb.dwarf2/locexpr-data-member-dynamic-location.c b/gdb/testsuite/gdb.dwarf2/locexpr-data-member-dynamic-location.c new file mode 100644 index 00000000000..3c3f6910298 --- /dev/null +++ b/gdb/testsuite/gdb.dwarf2/locexpr-data-member-dynamic-location.c @@ -0,0 +1,31 @@ +/* Copyright 2024 Free Software Foundation, Inc. + + This file is part of GDB. + + 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 . */ + +struct container +{ + int *data; + int size; +}; + +int var_a_data[] = {5, 8, 13, 21, 34}; +struct container var_a = {var_a_data, 5}; + +int +main (void) +{ + return 0; +} 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..8d13ac04651 --- /dev/null +++ b/gdb/testsuite/gdb.dwarf2/locexpr-data-member-dynamic-location.exp @@ -0,0 +1,136 @@ +# Copyright 2024 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 GDB prints an error when fetching a value's (dynamic) field +# with unresolved data location. For a reproducer, we setup the following +# struct type: +# +# struct container +# { +# int *data; +# int size; +# }; +# +# We use 'DW_AT_upper_bound' to create a non-static field 'data'. The error +# reproduces with invalid DWARF, i.e. when pushing the memory location of an +# instance 'var_a' of struct 'container' on the DWARF stack: +# +# DW_AT_location { +# DW_OP_addr [gdb_target_symbol var_a] +# DW_OP_deref +# DW_OP_stack_value +# } SPECIAL_expr} + +load_lib dwarf.exp + +# This test can only be run on targets which support DWARF-2 and use gas. +if {![dwarf2_support]} { + return 0 +} + +standard_testfile .c -dw.S + +if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] } { + return -1 +} + +# Make some DWARF for the test. +set asm_file [standard_output_file $srcfile2] +Dwarf::assemble $asm_file { + cu {} { + DW_TAG_compile_unit {} { + declare_labels integer_label array_label struct_label var_a_label + set int_size [get_sizeof "int" 4] + set addr_size [get_sizeof "void *" 8] + + integer_label: DW_TAG_base_type { + {DW_AT_byte_size $int_size DW_FORM_sdata} + {DW_AT_encoding @DW_ATE_signed} + } + + array_label: DW_TAG_array_type { + {DW_AT_type :$integer_label} + {DW_AT_data_location { + DW_OP_push_object_address + DW_OP_deref + } SPECIAL_expr} + } { + DW_TAG_subrange_type { + {DW_AT_type :$integer_label} + {DW_AT_upper_bound { + DW_OP_push_object_address + DW_OP_plus_uconst $addr_size + DW_OP_deref_size $int_size + DW_OP_lit1 + DW_OP_minus + } SPECIAL_expr} + } + } + + struct_label: DW_TAG_structure_type { + {DW_AT_byte_size 12 DW_FORM_udata} + } { + DW_TAG_member { + {DW_AT_name "data"} + {DW_AT_type :${array_label}} + {DW_AT_data_member_location 0 DW_FORM_udata} + } + + DW_TAG_member { + {DW_AT_name "size"} + {DW_AT_type :${integer_label}} + {DW_AT_data_member_location $addr_size DW_FORM_udata} + } + } + + DW_TAG_variable { + {DW_AT_name var_a_valid_location} + {DW_AT_type :$struct_label} + {DW_AT_location { + DW_OP_addr [gdb_target_symbol var_a] + } SPECIAL_expr} + } + + DW_TAG_variable { + {DW_AT_name var_a_invalid_location} + {DW_AT_type :$struct_label} + {DW_AT_location { + DW_OP_addr [gdb_target_symbol var_a] + DW_OP_deref + DW_OP_stack_value + } SPECIAL_expr} + } + } + } +} + +# Now that we've generated the DWARF debugging info, rebuild our +# program using our debug info instead of the info generated by +# the compiler. + +if { [prepare_for_testing "failed to prepare" ${testfile} \ + [list $srcfile $asm_file] {nodebug}] } { + return -1 +} + +if ![runto_main] { + return -1 +} + +gdb_test "print var_a_valid_location" \ + " = \\{data = \\{5, 8, 13, 21, 34\\}, size = 5\\}" + +gdb_test "print var_a_invalid_location" \ + " = \\{data = is_constant ()); + if (!TYPE_DATA_LOCATION (type)->is_constant ()) + error (_("cannot read %s, expected an already resolved data " + "location."), arg_type->field (fieldno).name ()); /* For dynamic data types defer memory allocation until we actual access the value. */ v = value::allocate_lazy (type);