From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 75CCC396E07D for ; Thu, 17 Nov 2022 10:27:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 75CCC396E07D Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1668680877; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=yvud3+C10HivoNBQxhqU1pgVwfvPW9VfjnBMCIn1ag4=; b=gURk/+oQ/V11q09nSGh54E7FFJ0pGn4qlH9cTLx07QgDbT5J+JTVqtQg0VgZrE/If7MbD1 R//ZsIc117bNUDkIPoBnQJpz4tx83WhYxcqekQjKxucn9s2f0Wv+CaPdUrjZ1uWv8S95pA hU21RwG9x5gYG4ukJDVcpy3nDYm5Z84= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-474-_sF5FjPCP8qk62T2jxyJ6g-1; Thu, 17 Nov 2022 05:27:56 -0500 X-MC-Unique: _sF5FjPCP8qk62T2jxyJ6g-1 Received: by mail-wr1-f72.google.com with SMTP id w11-20020adfbacb000000b002418a90da01so515780wrg.16 for ; Thu, 17 Nov 2022 02:27:55 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=mime-version:message-id:date:references:in-reply-to:subject:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=yvud3+C10HivoNBQxhqU1pgVwfvPW9VfjnBMCIn1ag4=; b=IPqrGjspgcIXh87sXbdvOwB5GCUCnDT193NN6lF+hoWc2wxV2ypK5NCycHRe2k26dt gyTbtYdNxHJTWRDe6px/bGPLOn1K2l8eHCvLqzq5KlC0ZwO+xAobVkNu7LCisNSqZUjd +KhtuNE6oIjpXMBdVMRFVoLHeZ8jSbNRKRpAceOTeXVmLHVNjAijuKTGB7mNoi+bZMsu EbGtIXfRO2yT6ShNLxkJMteMbIyjbqQuIv6DnjCZk/i8aL12weuqNIc9bEVrbhaxuixn zJmnp5a11cZg5gMpBMA4oJyduiwRicpev5YtOwV/JuUZ1CZpcJZe3B5dNHy03LAXqKZS gZ9A== X-Gm-Message-State: ANoB5pk+O7elADqMmQ2YdsoIFuT3X/kwLp2fyO+Q92H44JGNTTtTwTcE LkwcSFM6KocUE9+wh0rHXtV268PEFjFOcDIUXxY+wQhqSCccsH6z/zGdg/1fEyVi7jfR2Bne6jx vByyj8BclDcbB2bHHZKVMyQ== X-Received: by 2002:a05:600c:4211:b0:3c6:b656:5b52 with SMTP id x17-20020a05600c421100b003c6b6565b52mr4870257wmh.1.1668680874565; Thu, 17 Nov 2022 02:27:54 -0800 (PST) X-Google-Smtp-Source: AA0mqf6g6/3GWWsKD88ChBLiUMGwjYvHAl1Lb3Kxz6SeqCNCzcRW7M8C4izb1Vl5uZTjPq/NhqE6Pw== X-Received: by 2002:a05:600c:4211:b0:3c6:b656:5b52 with SMTP id x17-20020a05600c421100b003c6b6565b52mr4870250wmh.1.1668680874314; Thu, 17 Nov 2022 02:27:54 -0800 (PST) Received: from localhost ([31.111.84.238]) by smtp.gmail.com with ESMTPSA id y13-20020adff6cd000000b00236e9755c02sm503521wrp.111.2022.11.17.02.27.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Nov 2022 02:27:53 -0800 (PST) From: Andrew Burgess To: Tom Tromey , Andrew Burgess via Gdb-patches Subject: Re: [PATCH] gdb/fortran/testsuite: print values and types of string variables In-Reply-To: <87o7t6uacf.fsf@tromey.com> References: <87o7t6uacf.fsf@tromey.com> Date: Thu, 17 Nov 2022 10:27:52 +0000 Message-ID: <87wn7t98pj.fsf@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Tom Tromey writes: >>>>>> "Andrew" == Andrew Burgess via Gdb-patches writes: > > Andrew> While looking through the Fortran tests, I couldn't find a test of GDB > Andrew> printing the value and type of a Fortran string defined using the > Andrew> 'character*SIZE' notation. > > Andrew> This works fine in GDB right now, but I thought it wouldn't hurt to > Andrew> have a test for this, so this commit adds such a test. > > Seems good to me, though I don't actually know Fortran :) > > Are there any tests of Fortran-style quoting of weird (control or > whatever) characters? If not, that might be a worthwhile addition. Good idea. I updated the test to include some basic escape characters, and pushed the patch below. Thanks, Andrew --- commit 1c01b23603766fbca4ed4dd12fdd710860e6038e Author: Andrew Burgess Date: Fri Nov 4 14:51:11 2022 +0000 gdb/fortran/testsuite: print values and types of string variables While looking through the Fortran tests, I couldn't find a test of GDB printing the value and type of a Fortran string defined using the 'character*SIZE' notation. This works fine in GDB right now, but I thought it wouldn't hurt to have a test for this, so this commit adds such a test. The test also includes printing a string that includes some embedded special characters: \n \r \t \000 - that's right, as Fortran strings are stored as an address and length, it is fine to include an embedded null, so this test includes an example of that. Standard Fortran doesn't support backslash escape sequences within strings, the special characters must be generated using the `achar` function. However, when GDB prints the strings we currently print using the standard C like backslash sequences. I'm not currently proposing to change that behaviour, the backslash sequences are more compact than the standard Fortran way of doing things, and are so widely used that I suspect most Fortran programmers will understand them. diff --git a/gdb/testsuite/gdb.fortran/string-types.exp b/gdb/testsuite/gdb.fortran/string-types.exp new file mode 100644 index 00000000000..7031c070169 --- /dev/null +++ b/gdb/testsuite/gdb.fortran/string-types.exp @@ -0,0 +1,70 @@ +# Copyright 2022 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 print the value, and type, of Fortran string variables declared in +# different ways in the test program. + +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] } { + perror "Couldn't run to main" + return +} + +gdb_breakpoint [gdb_get_line_number "First breakpoint"] +gdb_breakpoint [gdb_get_line_number "Second breakpoint"] +gdb_breakpoint [gdb_get_line_number "Third breakpoint"] + +with_test_prefix "first breakpoint" { + # Continue to the first breakpoint. + gdb_continue_to_breakpoint "continue" + gdb_test "print s" " = 'foo'" + gdb_test "ptype s" "type = character\\*3" +} + +with_test_prefix "second breakpoint" { + # Continue to the second breakpoint. + gdb_continue_to_breakpoint "continue" + gdb_test "print s" " = 'foo'" + gdb_test "ptype s" "type = character\\*3" +} + +with_test_prefix "third breakpoint, first time" { + # Continue to the third breakpoint. + gdb_continue_to_breakpoint "continue" + gdb_test "print s" " = 'foo'" + gdb_test "ptype s" "type = character \\(3\\)" +} + +with_test_prefix "third breakpoint, second time" { + # Continue to the third breakpoint again. The string we print + # this time includes some embedded special characters (newline, + # tab, carriage-return, and an embedded null byte). Currently GDB + # prints these as C style backslash sequences, which isn't valid + # Fortran code, but is more compact than the Fortran way of doing + # it (see the test source for details), and is likely understood + # by most users, so seems good enough. + gdb_continue_to_breakpoint "continue" + gdb_test "print s" " = 'foo\\\\n\\\\t\\\\r\\\\000bar'" + gdb_test "ptype s" "type = character \\(10\\)" +} diff --git a/gdb/testsuite/gdb.fortran/string-types.f90 b/gdb/testsuite/gdb.fortran/string-types.f90 new file mode 100644 index 00000000000..2317d234b1a --- /dev/null +++ b/gdb/testsuite/gdb.fortran/string-types.f90 @@ -0,0 +1,37 @@ +! Copyright 2022 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 fixed_size_string_v1(s) + character*3 s + print *, "" ! First breakpoint. +end subroutine fixed_size_string_v1 + +subroutine fixed_size_string_v2(s) + character(3) s + print *, "" ! Second breakpoint. +end subroutine fixed_size_string_v2 + +subroutine variable_size_string(s) + character*(*) s + print *, "" ! Third breakpoint. +end subroutine variable_size_string + +program test + call fixed_size_string_v1('foo') + call fixed_size_string_v2('foo') + call variable_size_string('foo') + call variable_size_string('foo' // achar(10) // achar(9) // achar(13) // & + achar(0) // 'bar') +end program test