This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[PATCH v2 1/2] Fixed indentation for printing Fortran types with pointers
- From: Christoph Weinmann <christoph dot t dot weinmann at intel dot com>
- To: tromey at redhat dot com
- Cc: gdb-patches at sourceware dot org
- Date: Fri, 13 Sep 2013 15:36:22 +0200
- Subject: [PATCH v2 1/2] Fixed indentation for printing Fortran types with pointers
- Authentication-results: sourceware.org; auth=none
- References: <1379079383-20685-1-git-send-email-christoph dot t dot weinmann at intel dot com>
From: Frank Penczek <frank.penczek@intel.com>
Printing the prefix "PTR TO -> (" resp. "REF TO ->(" ignored the
active indentation level. This caused inconsistent appearance of
user-defined Fortran types containing pointers. Fixed by using
"fprintfi_filtered" with the current indentation level for
outputting the prefix string. Added test case ptr-indentation.
Example using 'ptype' on object of type:
type TypeWithPointer
integer i
integer, pointer:: p
end type TypeWithPointer
old>
type = Type typewithpointer
integer(kind=4) :: i
PTR TO -> ( integer(kind=4) :: p)
End Type typewithpointer
new>
type = Type typewithpointer
integer(kind=4) :: i
PTR TO -> ( integer(kind=4) :: p)
End Type typewithpointer
Changelog:
2013-09-12 Frank Penczek <frank.penczek@intel.com>
Christoph Weinmann <christoph.t.weinmann@intel.com>
* f-typeprint.c (f_type_print_base): Use fprintfi_filtered to
maintain proper indentation when printing pointers/refs.
testsuite/
* gdb.fortran/ptr-indentation.f90: Add Fortran example for
testing the indentation when printing user-defined types
with pointers.
* gdb.fortran/ptr-indentation.exp: Add test case for the
indentation when printing pointers in user-defined types.
Change-Id: I3bb607e3044e29b0a10fd6c6ea25c20e14882320
Signed-off-by: Frank Penczek <frank.penczek@intel.com>
---
gdb/f-typeprint.c | 4 +-
gdb/testsuite/gdb.fortran/ptr-indentation.exp | 53 +++++++++++++++++++++++++
gdb/testsuite/gdb.fortran/ptr-indentation.f90 | 33 +++++++++++++++
3 files changed, 88 insertions(+), 2 deletions(-)
create mode 100644 gdb/testsuite/gdb.fortran/ptr-indentation.exp
create mode 100644 gdb/testsuite/gdb.fortran/ptr-indentation.f90
diff --git a/gdb/f-typeprint.c b/gdb/f-typeprint.c
index aa33231..71fe869 100644
--- a/gdb/f-typeprint.c
+++ b/gdb/f-typeprint.c
@@ -290,12 +290,12 @@ f_type_print_base (struct type *type, struct ui_file *stream, int show,
break;
case TYPE_CODE_PTR:
- fprintf_filtered (stream, "PTR TO -> ( ");
+ fprintfi_filtered (level, stream, "PTR TO -> ( ");
f_type_print_base (TYPE_TARGET_TYPE (type), stream, 0, level);
break;
case TYPE_CODE_REF:
- fprintf_filtered (stream, "REF TO -> ( ");
+ fprintfi_filtered (level, stream, "REF TO -> ( ");
f_type_print_base (TYPE_TARGET_TYPE (type), stream, 0, level);
break;
diff --git a/gdb/testsuite/gdb.fortran/ptr-indentation.exp b/gdb/testsuite/gdb.fortran/ptr-indentation.exp
new file mode 100644
index 0000000..51148ad
--- /dev/null
+++ b/gdb/testsuite/gdb.fortran/ptr-indentation.exp
@@ -0,0 +1,53 @@
+# Copyright 2013 Free Software Foundation, Inc.
+#
+# Contributed by Intel Corp.<christoph.t.weinmann@intel.com>
+#
+# 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 <http://www.gnu.org/licenses/>.
+
+if {[skip_fortran_tests]} {
+ return -1
+}
+
+standard_testfile .f90
+
+if {[prepare_for_testing $testfile.exp $testfile $srcfile {debug f90}]} {
+ return -1
+}
+
+if {![runto MAIN__]} then {
+ perror "couldn't run to breakpoint MAIN__"
+ continue
+}
+
+# Depending on the compiler version being used, the name of the 4-byte integer
+# types can be printed differently. For instance, gfortran-4.1 uses "int4"
+# whereas gfortran-4.3 uses "int(kind=4)".
+set int4 "(int4|integer\\(kind=4\\))"
+
+gdb_breakpoint [gdb_get_line_number "BP1"]
+gdb_continue_to_breakpoint "BP1"
+
+# Check the indentation when using ptype on pointers in user-defined types.
+set test "type-printing for type with pointers"
+gdb_test_multiple "whatis ta" $test {
+ -re "type = tudf.*$gdb_prompt $" {
+ pass $test
+ }
+}
+gdb_test_multiple "ptype ta" $test {
+ -re ".*type = Type tudf\r\n *${int4} :: i\r\n PTR TO \-\> \\( tudf :: ptr\\)\r\n.*End Type tudf.*$gdb_prompt $" {
+ pass $test
+ }
+}
+
diff --git a/gdb/testsuite/gdb.fortran/ptr-indentation.f90 b/gdb/testsuite/gdb.fortran/ptr-indentation.f90
new file mode 100644
index 0000000..7bd63b9
--- /dev/null
+++ b/gdb/testsuite/gdb.fortran/ptr-indentation.f90
@@ -0,0 +1,33 @@
+! Test program for printing indentation of pointers in user-defined
+! types.
+!
+! Copyright 2013 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 <http://www.gnu.org/licenses/>.
+
+program main
+ implicit none
+
+ type tudf
+ integer :: i
+ type (tudf), pointer :: ptr
+ end type tudf
+
+ type(tudf), target:: ta,tb,tc
+
+ ta%ptr => tb
+ tb%ptr => tc !BP1
+
+end program main
+
--
1.7.0.7