From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id aG7ZJ/6MH2EhNgAAWB0awg (envelope-from ) for ; Fri, 20 Aug 2021 07:07:42 -0400 Received: by simark.ca (Postfix, from userid 112) id A02261EDFB; Fri, 20 Aug 2021 07:07:42 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 6F47F1EA7E for ; Fri, 20 Aug 2021 07:07:41 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2007F3847835 for ; Fri, 20 Aug 2021 11:07:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2007F3847835 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1629457661; bh=q/LKT4+WXlWdytRVHyhVCdRm39KDXSGSAgltXBrntio=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=L3vh5BvLzLZVeOHsjD5QQiOdAC6GT1tjx1JIdCAp6CmPi812WEabkWOtfx1EqWwaz KMeH3SUuAC273m64bT2/yKNJ+843bkH7dRUSDtfrAfRAZ4hGtzJMJPo+7dM4N52pcS BZXsGcuiasr+Kq2AzqorNqZ/tYT7bSPdoVEfHsQg= Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by sourceware.org (Postfix) with ESMTPS id 745343857C5E for ; Fri, 20 Aug 2021 11:06:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 745343857C5E X-IronPort-AV: E=McAfee;i="6200,9189,10081"; a="216754155" X-IronPort-AV: E=Sophos;i="5.84,337,1620716400"; d="scan'208";a="216754155" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Aug 2021 04:06:53 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.84,337,1620716400"; d="scan'208";a="523537126" Received: from irvmail001.ir.intel.com ([10.43.11.63]) by FMSMGA003.fm.intel.com with ESMTP; 20 Aug 2021 04:06:52 -0700 Received: from labpc2030.iul.intel.com (labpc2030.iul.intel.com [172.28.48.46]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with SMTP id 17KB6o6n012274; Fri, 20 Aug 2021 12:06:50 +0100 Received: by labpc2030.iul.intel.com (sSMTP sendmail emulation); Fri, 20 Aug 2021 13:06:50 +0200 To: gdb-patches@sourceware.org Subject: [PATCH 1/1] gdb: Fix arrays of variable length strings for FORTRAN Date: Fri, 20 Aug 2021 13:06:38 +0200 Message-Id: <20210820110638.26648-2-abdul.b.ijaz@intel.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210820110638.26648-1-abdul.b.ijaz@intel.com> References: <20210820110638.26648-1-abdul.b.ijaz@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: "abdul.b.ijaz via Gdb-patches" Reply-To: "abdul.b.ijaz" Cc: abdul.b.ijaz@intel.com Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" GDB is not able to print arrays of FORTRAN variable length strings when dwarf info contains DW_AT_string_length only regarding the string length information. So handing of dynamic array is updated to handle such cases. Suppose we have subroutine vla_array (arr1, arr2) character (len=*):: arr1 (:) character (len=5):: arr2 (:) print *, arr1 ! break-here print *, arr2 end subroutine vla_array The "print arr1" and "print arr2" command at the "break-here" line gives the following output: (gdb) print arr1 $1 = ( (gdb) print arr2 $2 = ('abcde', 'abcde', 'abcde') (gdb) ptype arr1 type = character*(*) (5) (gdb) ptype arr2 type = character*5 (3) So GDB is able to print the array of string with static length but for variable length it fail to do so. For this case now improve handling of the TYPE_CODE_STRING code in dynamic array length resolving function to set the static length of strings as well when only DW_AT_string_length is given in the dwarf info. Dwarf info using IntelĀ® Fortran Compiler for such case contains following: <1>: Abbrev Number: 12 (DW_TAG_string_type) DW_AT_name : (indirect string, offset: 0xd2): .str.ARR1 <102> DW_AT_string_length: 3 byte block: 97 23 8 (DW_OP_push_object_address; DW_OP_plus_uconst: 8) After fixing it and compiling using IntelĀ® Fortran Compiler now gdb shows following: (gdb) p arr1 $1 = ('abddefghij', 'abddefghij', 'abddefghij', 'abddefghij', 'abddefghij') (gdb) p arr2 $2 = ('abcde', 'abcde', 'abcde') (gdb) ptype arr1 type = character*10 (5) (gdb) ptype arr2 type = character*5 (3) gdb/ChangeLog: 2021-08-20 Abdul Basit Ijaz * gdbtypes.c (resolve_dynamic_array_or_string): Improve handling of TYPE_CODE_STRING code to use return value of create_string_type outcome for this case. * c-valprint.c (c_value_print_inner): Handle String type code in the same way as the Array type code. gdb/testsuite/ChangeLog: 2021-08-20 Abdul Basit Ijaz * gdb.fortran/vla-array.f90: New fie. * gdb.fortran/vla-array.exp: New fie. 2021-08-20 Abdul Basit Ijaz --- gdb/c-valprint.c | 1 + gdb/gdbtypes.c | 12 ++++-- gdb/testsuite/gdb.fortran/vla-array.exp | 57 +++++++++++++++++++++++++ gdb/testsuite/gdb.fortran/vla-array.f90 | 44 +++++++++++++++++++ 4 files changed, 110 insertions(+), 4 deletions(-) create mode 100644 gdb/testsuite/gdb.fortran/vla-array.exp create mode 100644 gdb/testsuite/gdb.fortran/vla-array.f90 diff --git a/gdb/c-valprint.c b/gdb/c-valprint.c index 9c82869525f..e5a8e122676 100644 --- a/gdb/c-valprint.c +++ b/gdb/c-valprint.c @@ -426,6 +426,7 @@ c_value_print_inner (struct value *val, struct ui_file *stream, int recurse, switch (type->code ()) { case TYPE_CODE_ARRAY: + case TYPE_CODE_STRING: c_value_print_array (val, stream, recurse, options); break; diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c index 74ad5d6f7fe..1444c5feb6c 100644 --- a/gdb/gdbtypes.c +++ b/gdb/gdbtypes.c @@ -2312,8 +2312,9 @@ resolve_dynamic_array_or_string (struct type *type, range_type = resolve_dynamic_range (range_type, addr_stack, resolve_p); ary_dim = check_typedef (TYPE_TARGET_TYPE (type)); - if (ary_dim != NULL && ary_dim->code () == TYPE_CODE_ARRAY) - elt_type = resolve_dynamic_array_or_string (ary_dim, addr_stack, resolve_p); + if (ary_dim != NULL && (ary_dim->code () == TYPE_CODE_ARRAY + || ary_dim->code () == TYPE_CODE_STRING)) + elt_type = resolve_dynamic_array_or_string (ary_dim, addr_stack); else elt_type = TYPE_TARGET_TYPE (type); @@ -2337,8 +2338,11 @@ resolve_dynamic_array_or_string (struct type *type, else bit_stride = TYPE_FIELD_BITSIZE (type, 0); - return create_array_type_with_stride (type, elt_type, range_type, NULL, - bit_stride); + if (type->code () == TYPE_CODE_STRING) + return create_string_type (type, elt_type, range_type); + else + return create_array_type_with_stride (type, elt_type, range_type, NULL, + bit_stride); } /* Resolve dynamic bounds of members of the union TYPE to static diff --git a/gdb/testsuite/gdb.fortran/vla-array.exp b/gdb/testsuite/gdb.fortran/vla-array.exp new file mode 100644 index 00000000000..a9223576bbd --- /dev/null +++ b/gdb/testsuite/gdb.fortran/vla-array.exp @@ -0,0 +1,57 @@ +# Copyright 2021 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 . + +standard_testfile ".f90" +load_lib "fortran.exp" + +if {[skip_fortran_tests]} { return -1 } + +if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} \ + {debug f90 quiet}] } { + return -1 +} + +if ![fortran_runto_main] { + untested "could not run to main" + return -1 +} + +# Try to access vla string / vla string array / string array values +gdb_breakpoint [gdb_get_line_number "arr_vla1-print"] +gdb_continue_to_breakpoint "arr_vla1-print" + +# GFortran does not emit DW_TAG_string_type for array of variable length +# string. +if [test_compiler_info "gcc*"] { setup_xfail *-*-* gcc/101826 } +gdb_test "print arr_vla1" \ + " = \\\('vlaaryvlaary', 'vlaaryvlaary', 'vlaaryvlaary', 'vlaaryvlaary', 'vlaaryvlaary'\\\)" \ + "print vla string array" + +if [test_compiler_info "gcc*"] { setup_xfail *-*-* gcc/101826 } +gdb_test "ptype arr_vla1" \ + "type = character\\*12 \\(5\\)" \ + "print variable length string array type" +gdb_test "print arr_vla2" \ + " = 'vlaary'" \ + "print variable length string" +gdb_test "ptype arr_vla2" \ + "type = character\\*6" \ + "print variable length string type" +gdb_test "print arr2" \ + " = \\\('vlaaryvla', 'vlaaryvla', 'vlaaryvla'\\\)" \ + "print string array" +gdb_test "ptype arr2" \ + "type = character\\*9 \\(3\\)" \ + "print string array type" diff --git a/gdb/testsuite/gdb.fortran/vla-array.f90 b/gdb/testsuite/gdb.fortran/vla-array.f90 new file mode 100644 index 00000000000..612e84fe213 --- /dev/null +++ b/gdb/testsuite/gdb.fortran/vla-array.f90 @@ -0,0 +1,44 @@ +! Copyright 2021 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 . + +subroutine vla_array_func (arr_vla1, arr_vla2, arr2) + character (len=*):: arr_vla1 (:) + character (len=*):: arr_vla2 + character (len=9):: arr2 (:) + + print *, arr_vla1 ! arr_vla1-print + print *, arr_vla2 + print *, arr2 +end subroutine vla_array_func + +program vla_array_main +interface + subroutine vla_array_func (arr_vla1, arr_vla2, arr2) + character (len=*):: arr_vla1 (:) + character (len=*):: arr_vla2 + character (len=9):: arr2 (:) + end subroutine vla_array_func +end interface + character (len=9) :: arr1 (3) + character (len=6) :: arr2 + character (len=12) :: arr3 (5) + + arr1 = 'vlaaryvla' + arr2 = 'vlaary' + arr3 = 'vlaaryvlaary' + + call vla_array_func (arr3, arr2, arr1) + +end program vla_array_main -- 2.31.1