From patchwork Mon Mar 18 12:52:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 31885 Received: (qmail 22854 invoked by alias); 18 Mar 2019 12:52:41 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 22768 invoked by uid 89); 18 Mar 2019 12:52:40 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-18.5 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=january, FLOOR, January X-HELO: mail-wm1-f65.google.com Received: from mail-wm1-f65.google.com (HELO mail-wm1-f65.google.com) (209.85.128.65) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 18 Mar 2019 12:52:37 +0000 Received: by mail-wm1-f65.google.com with SMTP id z6so2096911wmi.0 for ; Mon, 18 Mar 2019 05:52:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=YfKX6SC1iQXg8NYXfVOc7DRg2ImAeMOQIkZb/8Nmv4k=; b=LuzE1sjV6tEj7LoQHKLObzlmB0RJXIqxWp7Rm0NAz4rPuKDQPgv6nDzc603lLdD2f7 yFPDjk7PLPUrdIkbwNNgUZU4IVrRDFQJjF1stXrIPzNZLnluvtB81KujFGw8O40KZfiE oi5OP8JBa0f0rdeu1TemI/o4u6cp7WIUge6ZpVaOZPLm6LXtiLwoEVrzEtc4FiDLHovH 6mutna+nIFwgQjGPW/e/Ma510MnYzcwTTYswsZ72k447VVUqO2/yvM54I4XLLv8Ei2dG PpFfC9Ja7e96ymLmAFcR2BFWsMZSVMGknwb3yFcw+X6fYbF0PuIIf7mo+BOd73J7TCpk 9QBQ== Return-Path: Received: from localhost (host86-142-70-198.range86-142.btcentralplus.com. [86.142.70.198]) by smtp.gmail.com with ESMTPSA id h126sm17199361wmf.2.2019.03.18.05.52.33 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 18 Mar 2019 05:52:34 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Richard Bunt , Andrew Burgess Subject: [PATCH 4/8] gdb/fortran: better types for components of complex numbers Date: Mon, 18 Mar 2019 12:52:19 +0000 Message-Id: In-Reply-To: References: In-Reply-To: References: X-IsSubscribed: yes When creating a complex number in Fortran, the types of the components should use the standard Fortran type names rather than the C type names. Special case the DWARF parser to use more appropriate types when creating a complex type for Fortran. gdb/ChangeLog: * dwarf2read.c (dwarf2_init_complex_target_type): Use different types for Fortran. gdb/testsuite/ChangeLog: * gdb.fortran/complex.exp: Expand. * gdb.fortran/complex.f: Renamed to... * gdb.fortran/complex.f90: ...this, and extended to add more complex values. --- gdb/ChangeLog | 6 +++++ gdb/dwarf2read.c | 35 +++++++++++++++++++++------- gdb/f-typeprint.c | 29 +++++++++++++++++++++++ gdb/testsuite/ChangeLog | 7 ++++++ gdb/testsuite/gdb.fortran/complex.exp | 41 +++++++++++++++++++++++++------- gdb/testsuite/gdb.fortran/complex.f | 24 ------------------- gdb/testsuite/gdb.fortran/complex.f90 | 44 +++++++++++++++++++++++++++++++++++ 7 files changed, 145 insertions(+), 41 deletions(-) delete mode 100644 gdb/testsuite/gdb.fortran/complex.f create mode 100644 gdb/testsuite/gdb.fortran/complex.f90 diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 6fcb1c630be..51bbc6ad333 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,9 @@ +2019-03-18 Andrew Burgess + Chris January + + * dwarf2read.c (dwarf2_init_complex_target_type): Use different + types for Fortran. + 2019-03-18 Andrew Burgess Chris January David Lecomber diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index d865ff1a2b2..f7cb7ed12f1 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -17547,16 +17547,35 @@ dwarf2_init_complex_target_type (struct dwarf2_cu *cu, gdbarch *gdbarch = get_objfile_arch (objfile); struct type *tt = nullptr; - switch (bits) + switch (cu->language) { - case 32: - tt = builtin_type (gdbarch)->builtin_float; - break; - case 64: - tt = builtin_type (gdbarch)->builtin_double; + case language_fortran: + switch (bits) + { + case 32: + tt = builtin_f_type (gdbarch)->builtin_real; + break; + case 64: + tt = builtin_f_type (gdbarch)->builtin_real_s8; + break; + case 128: + tt = builtin_f_type (gdbarch)->builtin_real_s16; + break; + } break; - case 128: - tt = builtin_type (gdbarch)->builtin_long_double; + default: + switch (bits) + { + case 32: + tt = builtin_type (gdbarch)->builtin_float; + break; + case 64: + tt = builtin_type (gdbarch)->builtin_double; + break; + case 128: + tt = builtin_type (gdbarch)->builtin_long_double; + break; + } break; } diff --git a/gdb/f-typeprint.c b/gdb/f-typeprint.c index 2dfae5803cd..30e0c4dcda1 100644 --- a/gdb/f-typeprint.c +++ b/gdb/f-typeprint.c @@ -400,6 +400,35 @@ f_type_print_base (struct type *type, struct ui_file *stream, int show, fprintfi_filtered (level, stream, "module %s", TYPE_NAME (type)); break; + case TYPE_CODE_FLT: + /* In the case where the float was extracted from a complex number + then the component part will not have a name set. Provide a + suitable name here. + + QUESTION: Maybe we should be forcing the type name in the DWARF + parser rather than fixing up the missing name at the last minute? + I couldn't see any precedent for such fixing up though. */ + if (TYPE_NAME (type) != NULL) + fprintfi_filtered (level, stream, "%s", TYPE_NAME (type)); + else + { + gdbarch *gdbarch = get_type_arch (type); + switch (TYPE_LENGTH (type)) + { + case 4: + type = builtin_f_type (gdbarch)->builtin_real; + break; + case 8: + type = builtin_f_type (gdbarch)->builtin_real_s8; + break; + case 16: + type = builtin_f_type (gdbarch)->builtin_real_s16; + break; + } + fprintfi_filtered (level, stream, "%s", TYPE_NAME (type)); + } + break; + default_case: default: /* Handle types not explicitly handled by the other cases, diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 31541d86374..83883cefd1e 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,10 @@ +2019-03-18 Andrew Burgess + + * gdb.fortran/complex.exp: Expand. + * gdb.fortran/complex.f: Renamed to... + * gdb.fortran/complex.f90: ...this, and extended to add more + complex values. + 2019-03-18 Andrew Burgess * gdb.fortran/intrinsics.exp: Extend to cover MOD, CEILING, FLOOR, diff --git a/gdb/testsuite/gdb.fortran/complex.exp b/gdb/testsuite/gdb.fortran/complex.exp index 3fbbf7154d9..136f1c4df79 100644 --- a/gdb/testsuite/gdb.fortran/complex.exp +++ b/gdb/testsuite/gdb.fortran/complex.exp @@ -13,7 +13,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -standard_testfile .f +standard_testfile .f90 if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug f90 quiet}]} { return -1 @@ -24,13 +24,36 @@ if ![runto MAIN__] then { continue } -set bp_location [gdb_get_line_number "stop"] -gdb_test "break $bp_location" \ - "Breakpoint.*at.* file .*$srcfile, line $bp_location\\." \ - "breakpoint at stop" -gdb_test "continue" \ - "Continuing\\..*Breakpoint.*" \ - "continue to breakpoint" +gdb_breakpoint [gdb_get_line_number "stop"] +gdb_continue_to_breakpoint "continue" + +gdb_test "print c" " = \\(1000,-50\\)" +gdb_test "print c4" " = \\(1000,-50\\)" +gdb_test "print c8" " = \\(321,-22\\)" +gdb_test "print dc" " = \\(321,-22\\)" + +setup_kfail gdb/18644 "*-*-*" +gdb_test "print c16" " = \\(-874,19\\)" + +gdb_test "whatis c" "type = complex\\(kind=4\\)" +gdb_test "print \$_creal (c)" " = 1000" +gdb_test "whatis \$" " = real" + +gdb_test "whatis c4" "type = complex\\(kind=4\\)" +gdb_test "print \$_creal (c4)" " = 1000" +gdb_test "whatis \$" " = real" + +gdb_test "whatis c8" "type = complex\\(kind=8\\)" +gdb_test "print \$_creal (c8)" " = 321" +gdb_test "whatis \$" " = real\\*8" + +gdb_test "whatis dc" "type = complex\\(kind=8\\)" +gdb_test "print \$_creal (dc)" " = 321" +gdb_test "whatis \$" " = real\\*8" + +gdb_test "whatis c16" "type = complex\\(kind=16\\)" +setup_kfail gdb/18644 "*-*-*" +gdb_test "print \$_creal (c16)" " = -874" +gdb_test "whatis \$" " = real\\*16" -gdb_test "print c" "\\\$$decimal = \\(1000,-50\\)" diff --git a/gdb/testsuite/gdb.fortran/complex.f b/gdb/testsuite/gdb.fortran/complex.f deleted file mode 100644 index 2f1a7879f9e..00000000000 --- a/gdb/testsuite/gdb.fortran/complex.f +++ /dev/null @@ -1,24 +0,0 @@ -c Copyright 2007-2019 Free Software Foundation, Inc. - -c This program is free software; you can redistribute it and/or modify -c it under the terms of the GNU General Public License as published by -c the Free Software Foundation; either version 3 of the License, or -c (at your option) any later version. -c -c This program is distributed in the hope that it will be useful, -c but WITHOUT ANY WARRANTY; without even the implied warranty of -c MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -c GNU General Public License for more details. -c -c You should have received a copy of the GNU General Public License -c along with this program. If not, see . - - real*8 a,b - complex*16 c - - a = 1000 - b = -50 - c = cmplx(a,b) - write(*,*) s - stop - end diff --git a/gdb/testsuite/gdb.fortran/complex.f90 b/gdb/testsuite/gdb.fortran/complex.f90 new file mode 100644 index 00000000000..2b88c1ee0bb --- /dev/null +++ b/gdb/testsuite/gdb.fortran/complex.f90 @@ -0,0 +1,44 @@ +! Copyright 2007-2019 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 . + +program test_complex + real*4 r4a, r4b + real*8 r8a, r8b + real*16 r16a, r16b + + complex c + complex(kind=4) c4 + complex(kind=8) c8 + double complex dc + complex(kind=16) c16 + + r4a = 1000 + r4b = -50 + r8a = 321 + r8b = -22 + r16a = -874 + r16b = 19 + + c = cmplx(r4a,r4b) + c4 = cmplx(r4a,r4b) + c8 = cmplx(r8a, r8b) + dc = cmplx(r8a, r8b) + c16 = cmplx(r16a, r16b) + + print *, c, c4, c8, dc, c16 ! stop + print *, r4a, r4b + print *, r8a, r8b + print *, r16a, r16b +end program test_complex