public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [V4 00/21] Fortran dynamic array support
@ 2015-01-14 13:49 Keven Boell
  2015-01-14 13:49 ` [V4 07/18] test: evaluating allocation/association status Keven Boell
                   ` (20 more replies)
  0 siblings, 21 replies; 53+ messages in thread
From: Keven Boell @ 2015-01-14 13:49 UTC (permalink / raw)
  To: gdb-patches; +Cc: Keven Boell

This patch series add Fortran dynamic array support to gdb.

It allows the user to evaluate a dynamic array like an ordinary static array
e.g. print its elements instead of printing the pointer to the array.
In addition the size of a dynamic array can be retrieved with gdbs builtin
sizeof operator. Furthermore this series add support for Fortran stride support.

	1| integer, allocatable :: ary(:)
	2| allocate(ary(5))
	3| ary(:) = 42

	(gdb) print ary
	$1 = (42, 42, 42, 42, 42)

	(gdb) print sizeof (ary)
	$2 = 20

	(gdb) ptype ary
	type = integer(kind=4) (5)

This series is a follow up for the following C99 variable length array
support series:
	https://sourceware.org/ml/gdb-patches/2013-12/msg00625.html

Patch series V4 restructures the patches into more logical parts. Tests
were added directly to the functional changes, instead of the main dynamic
array tests to avoid one huge patch.

Keven Boell (18):
  vla: introduce allocated/associated flags
  vla: make dynamic fortran arrays functional.
  test: basic tests for dynamic array evaluations in Fortran.
  test: evaluate dynamic arrays using Fortran primitives.
  test: dynamic arrays passed to subroutines.
  test: correct ptype of dynamic arrays in Fortran.
  test: evaluating allocation/association status
  test: dynamic arrays passed to functions.
  test: accessing dynamic array history values.
  test: basic MI test for the dynamic array support.
  test: test sizeof for dynamic fortran arrays.
  test: add archer dynamic other frame test
  vla: reconstruct value to compute bounds of target type
  vla: use value constructor instead of raw-buffer manipulation
  vla: get dynamic array corner cases to work
  vla: Fortran dynamic string support
  vla: add stride support to fortran arrays.
  vla: add NEWS entry for dynamic array support

 gdb/NEWS                                           |    3 +
 gdb/c-valprint.c                                   |   11 +-
 gdb/dwarf2loc.c                                    |   16 ++
 gdb/dwarf2loc.h                                    |    6 +
 gdb/dwarf2read.c                                   |  181 +++++++++++++++++--
 gdb/f-typeprint.c                                  |   68 +++++---
 gdb/f-valprint.c                                   |  124 +++++--------
 gdb/gdbtypes.c                                     |  167 ++++++++++++++++--
 gdb/gdbtypes.h                                     |   43 +++++
 .../gdb.fortran/dynamic-other-frame-stub.f90       |   24 +++
 gdb/testsuite/gdb.fortran/dynamic-other-frame.exp  |   39 +++++
 gdb/testsuite/gdb.fortran/dynamic-other-frame.f90  |   36 ++++
 gdb/testsuite/gdb.fortran/vla-alloc-assoc.exp      |   65 +++++++
 gdb/testsuite/gdb.fortran/vla-datatypes.exp        |   82 +++++++++
 gdb/testsuite/gdb.fortran/vla-datatypes.f90        |   51 ++++++
 gdb/testsuite/gdb.fortran/vla-func.exp             |   61 +++++++
 gdb/testsuite/gdb.fortran/vla-func.f90             |   71 ++++++++
 gdb/testsuite/gdb.fortran/vla-history.exp          |   62 +++++++
 gdb/testsuite/gdb.fortran/vla-ptr-info.exp         |   32 ++++
 gdb/testsuite/gdb.fortran/vla-ptype-sub.exp        |   87 ++++++++++
 gdb/testsuite/gdb.fortran/vla-ptype.exp            |   96 +++++++++++
 gdb/testsuite/gdb.fortran/vla-sizeof.exp           |   46 +++++
 gdb/testsuite/gdb.fortran/vla-stride.exp           |   44 +++++
 gdb/testsuite/gdb.fortran/vla-stride.f90           |   30 ++++
 gdb/testsuite/gdb.fortran/vla-strings.exp          |  104 +++++++++++
 gdb/testsuite/gdb.fortran/vla-strings.f90          |   40 +++++
 gdb/testsuite/gdb.fortran/vla-sub.f90              |   82 +++++++++
 .../gdb.fortran/vla-value-sub-arbitrary.exp        |   35 ++++
 gdb/testsuite/gdb.fortran/vla-value-sub-finish.exp |   49 ++++++
 gdb/testsuite/gdb.fortran/vla-value-sub.exp        |   90 ++++++++++
 gdb/testsuite/gdb.fortran/vla-value.exp            |  148 ++++++++++++++++
 gdb/testsuite/gdb.fortran/vla.f90                  |   56 ++++++
 gdb/testsuite/gdb.mi/mi-vla-fortran.exp            |  182 ++++++++++++++++++++
 gdb/testsuite/gdb.mi/vla.f90                       |   42 +++++
 gdb/typeprint.c                                    |    7 +
 gdb/valarith.c                                     |   23 ++-
 gdb/valprint.c                                     |   40 +++++
 gdb/valprint.h                                     |    4 +
 gdb/value.c                                        |   23 ++-
 39 files changed, 2231 insertions(+), 139 deletions(-)
 create mode 100644 gdb/testsuite/gdb.fortran/dynamic-other-frame-stub.f90
 create mode 100644 gdb/testsuite/gdb.fortran/dynamic-other-frame.exp
 create mode 100644 gdb/testsuite/gdb.fortran/dynamic-other-frame.f90
 create mode 100644 gdb/testsuite/gdb.fortran/vla-alloc-assoc.exp
 create mode 100644 gdb/testsuite/gdb.fortran/vla-datatypes.exp
 create mode 100644 gdb/testsuite/gdb.fortran/vla-datatypes.f90
 create mode 100644 gdb/testsuite/gdb.fortran/vla-func.exp
 create mode 100644 gdb/testsuite/gdb.fortran/vla-func.f90
 create mode 100644 gdb/testsuite/gdb.fortran/vla-history.exp
 create mode 100644 gdb/testsuite/gdb.fortran/vla-ptr-info.exp
 create mode 100644 gdb/testsuite/gdb.fortran/vla-ptype-sub.exp
 create mode 100644 gdb/testsuite/gdb.fortran/vla-ptype.exp
 create mode 100644 gdb/testsuite/gdb.fortran/vla-sizeof.exp
 create mode 100644 gdb/testsuite/gdb.fortran/vla-stride.exp
 create mode 100644 gdb/testsuite/gdb.fortran/vla-stride.f90
 create mode 100644 gdb/testsuite/gdb.fortran/vla-strings.exp
 create mode 100644 gdb/testsuite/gdb.fortran/vla-strings.f90
 create mode 100644 gdb/testsuite/gdb.fortran/vla-sub.f90
 create mode 100644 gdb/testsuite/gdb.fortran/vla-value-sub-arbitrary.exp
 create mode 100644 gdb/testsuite/gdb.fortran/vla-value-sub-finish.exp
 create mode 100644 gdb/testsuite/gdb.fortran/vla-value-sub.exp
 create mode 100644 gdb/testsuite/gdb.fortran/vla-value.exp
 create mode 100644 gdb/testsuite/gdb.fortran/vla.f90
 create mode 100644 gdb/testsuite/gdb.mi/mi-vla-fortran.exp
 create mode 100644 gdb/testsuite/gdb.mi/vla.f90

-- 
1.7.9.5

^ permalink raw reply	[flat|nested] 53+ messages in thread

* [V4 04/18] test: evaluate dynamic arrays using Fortran primitives.
  2015-01-14 13:49 [V4 00/21] Fortran dynamic array support Keven Boell
  2015-01-14 13:49 ` [V4 07/18] test: evaluating allocation/association status Keven Boell
@ 2015-01-14 13:49 ` Keven Boell
  2015-01-14 13:49 ` [V4 01/18] vla: introduce allocated/associated flags Keven Boell
                   ` (18 subsequent siblings)
  20 siblings, 0 replies; 53+ messages in thread
From: Keven Boell @ 2015-01-14 13:49 UTC (permalink / raw)
  To: gdb-patches; +Cc: Keven Boell

Tests ensure that Fortran primitives can be evaluated
correctly when used as a dynamic array.

2014-05-28  Keven Boell  <keven.boell@intel.com>
            Sanimir Agovic  <sanimir.agovic@intel.com>

testsuite/gdb.fortran/:

	* vla-datatypes.f90: New file.
	* vla-datatypes.exp: New file.



Signed-off-by: Keven Boell <keven.boell@intel.com>
---
 gdb/testsuite/gdb.fortran/vla-datatypes.exp |   82 +++++++++++++++++++++++++++
 gdb/testsuite/gdb.fortran/vla-datatypes.f90 |   51 +++++++++++++++++
 2 files changed, 133 insertions(+)
 create mode 100644 gdb/testsuite/gdb.fortran/vla-datatypes.exp
 create mode 100644 gdb/testsuite/gdb.fortran/vla-datatypes.f90

diff --git a/gdb/testsuite/gdb.fortran/vla-datatypes.exp b/gdb/testsuite/gdb.fortran/vla-datatypes.exp
new file mode 100644
index 0000000..a61cb70
--- /dev/null
+++ b/gdb/testsuite/gdb.fortran/vla-datatypes.exp
@@ -0,0 +1,82 @@
+# Copyright 2015 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/>.
+
+standard_testfile ".f90"
+
+if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile} \
+    {debug f90 quiet}] } {
+    return -1
+}
+
+# check that all fortran standard datatypes will be
+# handled correctly when using as VLA's
+
+if ![runto MAIN__] then {
+    perror "couldn't run to breakpoint MAIN__"
+    continue
+}
+
+gdb_breakpoint [gdb_get_line_number "vlas-allocated"]
+gdb_continue_to_breakpoint "vlas-allocated"
+gdb_test "next" " = allocated\\\(realvla\\\)" \
+  "next to allocation status of intvla"
+gdb_test "print l" " = \\.TRUE\\." "intvla allocated"
+gdb_test "next" " = allocated\\\(complexvla\\\)" \
+  "next to allocation status of realvla"
+gdb_test "print l" " = \\.TRUE\\." "realvla allocated"
+gdb_test "next" " = allocated\\\(logicalvla\\\)" \
+  "next to allocation status of complexvla"
+gdb_test "print l" " = \\.TRUE\\." "complexvla allocated"
+gdb_test "next" " = allocated\\\(charactervla\\\)" \
+  "next to allocation status of logicalvla"
+gdb_test "print l" " = \\.TRUE\\." "logicalvla allocated"
+gdb_test "next" "intvla\\\(:,:,:\\\) = 1" \
+  "next to allocation status of charactervla"
+gdb_test "print l" " = \\.TRUE\\." "charactervla allocated"
+
+gdb_breakpoint [gdb_get_line_number "vlas-initialized"]
+gdb_continue_to_breakpoint "vlas-initialized"
+gdb_test "ptype intvla" "type = integer\\\(kind=4\\\) \\\(11,22,33\\\)" \
+  "ptype intvla"
+gdb_test "ptype realvla" "type = real\\\(kind=4\\\) \\\(11,22,33\\\)" \
+  "ptype realvla"
+gdb_test "ptype complexvla" "type = complex\\\(kind=4\\\) \\\(11,22,33\\\)" \
+  "ptype complexvla"
+gdb_test "ptype logicalvla" "type = logical\\\(kind=4\\\) \\\(11,22,33\\\)" \
+  "ptype logicalvla"
+gdb_test "ptype charactervla" "type = character\\\*1 \\\(11,22,33\\\)" \
+  "ptype charactervla"
+
+gdb_test "print intvla(5,5,5)" " = 1" "print intvla(5,5,5) (1st)"
+gdb_test "print realvla(5,5,5)" " = 3.14\\d+" \
+  "print realvla(5,5,5) (1st)"
+gdb_test "print complexvla(5,5,5)" " = \\\(2,-3\\\)" \
+  "print complexvla(5,5,5) (1st)"
+gdb_test "print logicalvla(5,5,5)" " = \\.TRUE\\." \
+  "print logicalvla(5,5,5) (1st)"
+gdb_test "print charactervla(5,5,5)" " = 'K'" \
+  "print charactervla(5,5,5) (1st)"
+
+gdb_breakpoint [gdb_get_line_number "vlas-modified"]
+gdb_continue_to_breakpoint "vlas-modified"
+gdb_test "print intvla(5,5,5)" " = 42" "print intvla(5,5,5) (2nd)"
+gdb_test "print realvla(5,5,5)" " = 4.13\\d+" \
+  "print realvla(5,5,5) (2nd)"
+gdb_test "print complexvla(5,5,5)" " = \\\(-3,2\\\)" \
+  "print complexvla(5,5,5) (2nd)"
+gdb_test "print logicalvla(5,5,5)" " = \\.FALSE\\." \
+  "print logicalvla(5,5,5) (2nd)"
+gdb_test "print charactervla(5,5,5)" " = 'X'" \
+  "print charactervla(5,5,5) (2nd)"
diff --git a/gdb/testsuite/gdb.fortran/vla-datatypes.f90 b/gdb/testsuite/gdb.fortran/vla-datatypes.f90
new file mode 100644
index 0000000..db25695
--- /dev/null
+++ b/gdb/testsuite/gdb.fortran/vla-datatypes.f90
@@ -0,0 +1,51 @@
+! Copyright 2015 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 2 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, write to the Free Software
+! Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+program vla_primitives
+  integer, allocatable    :: intvla(:, :, :)
+  real, allocatable       :: realvla(:, :, :)
+  complex, allocatable    :: complexvla(:, :, :)
+  logical, allocatable    :: logicalvla(:, :, :)
+  character, allocatable  :: charactervla(:, :, :)
+  logical                 :: l
+
+  allocate (intvla (11,22,33))
+  allocate (realvla (11,22,33))
+  allocate (complexvla (11,22,33))
+  allocate (logicalvla (11,22,33))
+  allocate (charactervla (11,22,33))
+
+  l = allocated(intvla)                   ! vlas-allocated
+  l = allocated(realvla)
+  l = allocated(complexvla)
+  l = allocated(logicalvla)
+  l = allocated(charactervla)
+
+  intvla(:,:,:) = 1
+  realvla(:,:,:) = 3.14
+  complexvla(:,:,:) = cmplx(2.0,-3.0)
+  logicalvla(:,:,:) = .TRUE.
+  charactervla(:,:,:) = char(75)
+
+  intvla(5,5,5) = 42                      ! vlas-initialized
+  realvla(5,5,5) = 4.13
+  complexvla(5,5,5) = cmplx(-3.0,2.0)
+  logicalvla(5,5,5) = .FALSE.
+  charactervla(5,5,5) = 'X'
+
+  ! dummy statement for bp
+  l = .FALSE.                             ! vlas-modified
+end program vla_primitives
-- 
1.7.9.5

^ permalink raw reply	[flat|nested] 53+ messages in thread

* [V4 01/18] vla: introduce allocated/associated flags
  2015-01-14 13:49 [V4 00/21] Fortran dynamic array support Keven Boell
  2015-01-14 13:49 ` [V4 07/18] test: evaluating allocation/association status Keven Boell
  2015-01-14 13:49 ` [V4 04/18] test: evaluate dynamic arrays using Fortran primitives Keven Boell
@ 2015-01-14 13:49 ` Keven Boell
  2015-02-09  6:52   ` Joel Brobecker
  2015-01-14 13:50 ` [V4 06/18] test: correct ptype of dynamic arrays in Fortran Keven Boell
                   ` (17 subsequent siblings)
  20 siblings, 1 reply; 53+ messages in thread
From: Keven Boell @ 2015-01-14 13:49 UTC (permalink / raw)
  To: gdb-patches; +Cc: Keven Boell

Fortran 90 provide types whose values may be dynamically
allocated or associated with a variable under explicit
program control. The purpose of this commit is to read
allocated/associated DWARF tags and store them to the
main_type.

2014-05-28  Keven Boell  <keven.boell@intel.com>
            Sanimir Agovic  <sanimir.agovic@intel.com>

	* dwarf2read.c (set_die_type): Add reading of
	allocated/associated flags.
	* gdbtypes.h (struct main_type): Add allocated/
	associated dwarf2_prop attributes.
	(TYPE_ALLOCATED_PROP): New macro.
	(TYPE_ASSOCIATED_PROP): New macro.
	(TYPE_NOT_ALLOCATED): New macro.
	(TYPE_NOT_ASSOCIATED): New macro.



Signed-off-by: Keven Boell <keven.boell@intel.com>
---
 gdb/dwarf2read.c |   28 ++++++++++++++++++++++++++++
 gdb/gdbtypes.h   |   26 ++++++++++++++++++++++++++
 2 files changed, 54 insertions(+)

diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 86c3a73..df3ada1 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -21857,6 +21857,34 @@ set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
       && !HAVE_GNAT_AUX_INFO (type))
     INIT_GNAT_SPECIFIC (type);
 
+  /* Read DW_AT_allocated and set in type.  */
+  attr = dwarf2_attr (die, DW_AT_allocated, cu);
+  if (attr_form_is_block (attr))
+    {
+      struct dynamic_prop prop;
+
+      if (attr_to_dynamic_prop (attr, die, cu, &prop))
+        {
+          TYPE_ALLOCATED_PROP (type)
+            = obstack_alloc (&objfile->objfile_obstack, sizeof (prop));
+          *TYPE_ALLOCATED_PROP (type) = prop;
+        }
+    }
+
+  /* Read DW_AT_associated and set in type.  */
+  attr = dwarf2_attr (die, DW_AT_associated, cu);
+  if (attr_form_is_block (attr))
+    {
+      struct dynamic_prop prop;
+
+      if (attr_to_dynamic_prop (attr, die, cu, &prop))
+        {
+          TYPE_ASSOCIATED_PROP (type)
+            = obstack_alloc (&objfile->objfile_obstack, sizeof (prop));
+          *TYPE_ASSOCIATED_PROP (type) = prop;
+        }
+    }
+
   /* Read DW_AT_data_location and set in type.  */
   attr = dwarf2_attr (die, DW_AT_data_location, cu);
   if (attr_to_dynamic_prop (attr, die, cu, &prop))
diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
index 7c06a4f..6a8a74d 100644
--- a/gdb/gdbtypes.h
+++ b/gdb/gdbtypes.h
@@ -720,6 +720,18 @@ struct main_type
      this field yields to the location of the data for an object.  */
 
   struct dynamic_prop *data_location;
+
+  /* Structure for DW_AT_allocated.
+     The presence of this attribute indicates that the object of the type
+     can be allocated/deallocated.  The value can be a dwarf expression,
+     reference, or a constant.  */
+  struct dynamic_prop *allocated;
+
+  /* Structure for DW_AT_associated.
+     The presence of this attribute indicated that the object of the type
+     can be associated.  The value can be a dwarf expression,
+     reference, or a constant.  */
+  struct dynamic_prop *associated;
 };
 
 /* * A ``struct type'' describes a particular instance of a type, with
@@ -1208,6 +1220,20 @@ extern void allocate_gnat_aux_type (struct type *);
   TYPE_DATA_LOCATION (thistype)->data.const_val
 #define TYPE_DATA_LOCATION_KIND(thistype) \
   TYPE_DATA_LOCATION (thistype)->kind
+#define TYPE_ALLOCATED_PROP(thistype) TYPE_MAIN_TYPE(thistype)->allocated
+#define TYPE_ASSOCIATED_PROP(thistype) TYPE_MAIN_TYPE(thistype)->associated
+
+/* Allocated status of type object.  If set to non-zero it means the object
+   is allocated. A zero value means it is not allocated.  */
+#define TYPE_NOT_ALLOCATED(t)  (TYPE_ALLOCATED_PROP (t) \
+  && TYPE_ALLOCATED_PROP (t)->kind == PROP_CONST \
+  && !TYPE_ALLOCATED_PROP (t)->data.const_val)
+
+/* Associated status of type object.  If set to non-zero it means the object
+   is associated. A zero value means it is not associated.  */
+#define TYPE_NOT_ASSOCIATED(t)  (TYPE_ASSOCIATED_PROP (t) \
+  && TYPE_ASSOCIATED_PROP (t)->kind == PROP_CONST \
+  && !TYPE_ASSOCIATED_PROP (t)->data.const_val)
 
 /* Moto-specific stuff for FORTRAN arrays.  */
 
-- 
1.7.9.5

^ permalink raw reply	[flat|nested] 53+ messages in thread

* [V4 07/18] test: evaluating allocation/association status
  2015-01-14 13:49 [V4 00/21] Fortran dynamic array support Keven Boell
@ 2015-01-14 13:49 ` Keven Boell
  2015-01-14 13:49 ` [V4 04/18] test: evaluate dynamic arrays using Fortran primitives Keven Boell
                   ` (19 subsequent siblings)
  20 siblings, 0 replies; 53+ messages in thread
From: Keven Boell @ 2015-01-14 13:49 UTC (permalink / raw)
  To: gdb-patches; +Cc: Keven Boell

Tests ensure that dynamic arrays in different states
(allocated/associated) can be evaluated.

2014-05-28  Keven Boell  <keven.boell@intel.com>
            Sanimir Agovic  <sanimir.agovic@intel.com>

testsuite/gdb.fortran/:

	* vla-alloc-assoc.exp: New file.



Signed-off-by: Keven Boell <keven.boell@intel.com>
---
 gdb/testsuite/gdb.fortran/vla-alloc-assoc.exp |   65 +++++++++++++++++++++++++
 1 file changed, 65 insertions(+)
 create mode 100644 gdb/testsuite/gdb.fortran/vla-alloc-assoc.exp

diff --git a/gdb/testsuite/gdb.fortran/vla-alloc-assoc.exp b/gdb/testsuite/gdb.fortran/vla-alloc-assoc.exp
new file mode 100644
index 0000000..542b65c
--- /dev/null
+++ b/gdb/testsuite/gdb.fortran/vla-alloc-assoc.exp
@@ -0,0 +1,65 @@
+# Copyright 2015 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/>.
+
+standard_testfile "vla.f90"
+
+if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile} \
+    {debug f90 quiet}] } {
+    return -1
+}
+
+if ![runto MAIN__] then {
+    perror "couldn't run to breakpoint MAIN__"
+    continue
+}
+
+# Check the association status of various types of VLA's
+# and pointer to VLA's.
+gdb_breakpoint [gdb_get_line_number "vla1-allocated"]
+gdb_continue_to_breakpoint "vla1-allocated"
+gdb_test "print l" " = \\.TRUE\\." \
+  "print vla1 allocation status (allocated)"
+
+gdb_breakpoint [gdb_get_line_number "vla2-allocated"]
+gdb_continue_to_breakpoint "vla2-allocated"
+gdb_test "print l" " = \\.TRUE\\." \
+  "print vla2 allocation status (allocated)"
+
+gdb_breakpoint [gdb_get_line_number "pvla-associated"]
+gdb_continue_to_breakpoint "pvla-associated"
+gdb_test "print l" " = \\.TRUE\\." \
+  "print pvla associated status (associated)"
+
+gdb_breakpoint [gdb_get_line_number "pvla-re-associated"]
+gdb_continue_to_breakpoint "pvla-re-associated"
+gdb_test "print l" " = \\.TRUE\\." \
+  "print pvla associated status (re-associated)"
+
+gdb_breakpoint [gdb_get_line_number "pvla-deassociated"]
+gdb_continue_to_breakpoint "pvla-deassociated"
+gdb_test "print l" " = \\.FALSE\\." \
+  "print pvla allocation status (deassociated)"
+
+gdb_breakpoint [gdb_get_line_number "vla1-deallocated"]
+gdb_continue_to_breakpoint "vla1-deallocated"
+gdb_test "print l" " = \\.FALSE\\." \
+  "print vla1 allocation status (deallocated)"
+gdb_test "print vla1" " = <not allocated>" \
+  "print deallocated vla1"
+
+gdb_breakpoint [gdb_get_line_number "vla2-deallocated"]
+gdb_continue_to_breakpoint "vla2-deallocated"
+gdb_test "print l" " = \\.FALSE\\." "print vla2 deallocated"
+gdb_test "print vla2" " = <not allocated>" "print deallocated vla2"
-- 
1.7.9.5

^ permalink raw reply	[flat|nested] 53+ messages in thread

* [V4 09/18] test: accessing dynamic array history values.
  2015-01-14 13:49 [V4 00/21] Fortran dynamic array support Keven Boell
                   ` (6 preceding siblings ...)
  2015-01-14 13:50 ` [V4 13/18] vla: reconstruct value to compute bounds of target type Keven Boell
@ 2015-01-14 13:50 ` Keven Boell
  2015-01-14 13:50 ` [V4 18/18] vla: add NEWS entry for dynamic array support Keven Boell
                   ` (12 subsequent siblings)
  20 siblings, 0 replies; 53+ messages in thread
From: Keven Boell @ 2015-01-14 13:50 UTC (permalink / raw)
  To: gdb-patches; +Cc: Keven Boell

Tests if the history values of dynamic arrays can be
accessed and printed again with the correct values.

2014-05-28  Keven Boell  <keven.boell@intel.com>
            Sanimir Agovic  <sanimir.agovic@intel.com>

testsuite/gdb.fortran/:

	* vla-history.exp: New file.



Signed-off-by: Keven Boell <keven.boell@intel.com>
---
 gdb/testsuite/gdb.fortran/vla-history.exp |   62 +++++++++++++++++++++++++++++
 1 file changed, 62 insertions(+)
 create mode 100644 gdb/testsuite/gdb.fortran/vla-history.exp

diff --git a/gdb/testsuite/gdb.fortran/vla-history.exp b/gdb/testsuite/gdb.fortran/vla-history.exp
new file mode 100644
index 0000000..d56519c
--- /dev/null
+++ b/gdb/testsuite/gdb.fortran/vla-history.exp
@@ -0,0 +1,62 @@
+# Copyright 2015 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/>.
+
+standard_testfile "vla.f90"
+
+if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile} \
+    {debug f90 quiet}] } {
+    return -1
+}
+
+if ![runto MAIN__] then {
+    perror "couldn't run to breakpoint MAIN__"
+    continue
+}
+
+# Set some breakpoints and print complete vla.
+gdb_breakpoint [gdb_get_line_number "vla1-init"]
+gdb_continue_to_breakpoint "vla1-init"
+gdb_test "print vla1" " = <not allocated>" "print non-allocated vla1"
+
+gdb_breakpoint [gdb_get_line_number "vla2-allocated"]
+gdb_continue_to_breakpoint "vla2-allocated"
+gdb_test "print vla1" " = \\( *\\( *\\( *0, *0, *0,\[()0, .\]*\\)" \
+  "print vla1 allocated"
+gdb_test "print vla2" " = \\( *\\( *\\( *0, *0, *0,\[()0, .\]*\\)" \
+  "print vla2 allocated"
+
+gdb_breakpoint [gdb_get_line_number "vla1-filled"]
+gdb_continue_to_breakpoint "vla1-filled"
+gdb_test "print vla1" \
+  " = \\( *\\( *\\( *1311, *1311, *1311,\[()1311, .\]*\\)" \
+  "print vla1 filled"
+
+# Try to access history values for full vla prints.
+gdb_test "print \$1" " = <not allocated>" "print \$1"
+gdb_test "print \$2" " = \\( *\\( *\\( *0, *0, *0,\[()0, .\]*\\)" \
+  "print \$2"
+gdb_test "print \$3" " = \\( *\\( *\\( *0, *0, *0,\[()0, .\]*\\)" \
+  "print \$3"
+gdb_test "print \$4" \
+  " = \\( *\\( *\\( *1311, *1311, *1311,\[()1311, .\]*\\)" "print \$4"
+
+gdb_breakpoint [gdb_get_line_number "vla2-filled"]
+gdb_continue_to_breakpoint "vla2-filled"
+gdb_test "print vla2(1,43,20)" " = 1311" "print vla2(1,43,20)"
+gdb_test "print vla1(1,3,8)" " = 1001" "print vla2(1,3,8)"
+
+# Try to access history values for vla values.
+gdb_test "print \$9" " = 1311" "print \$9"
+gdb_test "print \$10" " = 1001" "print \$10"
-- 
1.7.9.5

^ permalink raw reply	[flat|nested] 53+ messages in thread

* [V4 11/18] test: test sizeof for dynamic fortran arrays.
  2015-01-14 13:49 [V4 00/21] Fortran dynamic array support Keven Boell
                   ` (3 preceding siblings ...)
  2015-01-14 13:50 ` [V4 06/18] test: correct ptype of dynamic arrays in Fortran Keven Boell
@ 2015-01-14 13:50 ` Keven Boell
  2015-01-14 13:50 ` [V4 15/18] vla: get dynamic array corner cases to work Keven Boell
                   ` (15 subsequent siblings)
  20 siblings, 0 replies; 53+ messages in thread
From: Keven Boell @ 2015-01-14 13:50 UTC (permalink / raw)
  To: gdb-patches; +Cc: Keven Boell

Tests sizeof output of dynamic arrays in various states.

2014-05-28  Keven Boell  <keven.boell@intel.com>
            Sanimir Agovic  <sanimir.agovic@intel.com>

testsuite/gdb.fortran/:

	* vla-sizeof.exp: New file.



Signed-off-by: Keven Boell <keven.boell@intel.com>
---
 gdb/testsuite/gdb.fortran/vla-sizeof.exp |   46 ++++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)
 create mode 100644 gdb/testsuite/gdb.fortran/vla-sizeof.exp

diff --git a/gdb/testsuite/gdb.fortran/vla-sizeof.exp b/gdb/testsuite/gdb.fortran/vla-sizeof.exp
new file mode 100644
index 0000000..8281425
--- /dev/null
+++ b/gdb/testsuite/gdb.fortran/vla-sizeof.exp
@@ -0,0 +1,46 @@
+# Copyright 2015 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/>.
+
+standard_testfile "vla.f90"
+
+if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile} \
+    {debug f90 quiet}] } {
+    return -1
+}
+
+if ![runto MAIN__] then {
+    perror "couldn't run to breakpoint MAIN__"
+    continue
+}
+
+# Try to access values in non allocated VLA
+gdb_breakpoint [gdb_get_line_number "vla1-init"]
+gdb_continue_to_breakpoint "vla1-init"
+gdb_test "print sizeof(vla1)" " = 0" "print sizeof non-allocated vla1"
+
+# Try to access value in allocated VLA
+gdb_breakpoint [gdb_get_line_number "vla2-allocated"]
+gdb_continue_to_breakpoint "vla2-allocated"
+gdb_test "print sizeof(vla1)" " = 4000" "print sizeof allocated vla1"
+
+# Try to access values in undefined pointer to VLA (dangling)
+gdb_breakpoint [gdb_get_line_number "vla1-filled"]
+gdb_continue_to_breakpoint "vla1-filled"
+gdb_test "print sizeof(pvla)" " = 0" "print sizeof non-associated pvla"
+
+# Try to access values in pointer to VLA and compare them
+gdb_breakpoint [gdb_get_line_number "pvla-associated"]
+gdb_continue_to_breakpoint "pvla-associated"
+gdb_test "print sizeof(pvla)" " = 4000" "print sizeof associated pvla"
-- 
1.7.9.5

^ permalink raw reply	[flat|nested] 53+ messages in thread

* [V4 14/18] vla: use value constructor instead of raw-buffer manipulation
  2015-01-14 13:49 [V4 00/21] Fortran dynamic array support Keven Boell
                   ` (14 preceding siblings ...)
  2015-01-14 13:50 ` [V4 10/18] test: basic MI test for the dynamic array support Keven Boell
@ 2015-01-14 13:50 ` Keven Boell
  2015-01-14 13:50 ` [V4 12/18] test: add archer dynamic other frame test Keven Boell
                   ` (4 subsequent siblings)
  20 siblings, 0 replies; 53+ messages in thread
From: Keven Boell @ 2015-01-14 13:50 UTC (permalink / raw)
  To: gdb-patches; +Cc: Keven Boell

Instead of pre-computing indices into a fortran array re-use
the value_* interfaces to subscript a fortran array.

2014-05-28  Sanimir Agovic  <sanimir.agovic@intel.com>
            Keven Boell  <keven.boell@intel.com>

	* f-valprint.c (f77_create_arrayprint_offset_tbl): Remove
	function.
	(F77_DIM_SIZE, F77_DIM_OFFSET): Remove macro.
	(f77_print_array_1): Use value_subscript to subscript a
	value array.
	(f77_print_array): Remove call to f77_create_arrayprint_offset_tbl.
	(f_val_print): Use value_field to construct a field value.



Signed-off-by: Keven Boell <keven.boell@intel.com>
---
 gdb/f-valprint.c |  118 ++++++++++++++++++------------------------------------
 1 file changed, 39 insertions(+), 79 deletions(-)

diff --git a/gdb/f-valprint.c b/gdb/f-valprint.c
index c2aca71..40fa319 100644
--- a/gdb/f-valprint.c
+++ b/gdb/f-valprint.c
@@ -36,8 +36,6 @@
 
 extern void _initialize_f_valprint (void);
 static void info_common_command (char *, int);
-static void f77_create_arrayprint_offset_tbl (struct type *,
-					      struct ui_file *);
 static void f77_get_dynamic_length_of_aggregate (struct type *);
 
 int f77_array_offset_tbl[MAX_FORTRAN_DIMS + 1][2];
@@ -45,15 +43,6 @@ int f77_array_offset_tbl[MAX_FORTRAN_DIMS + 1][2];
 /* Array which holds offsets to be applied to get a row's elements
    for a given array.  Array also holds the size of each subarray.  */
 
-/* The following macro gives us the size of the nth dimension, Where 
-   n is 1 based.  */
-
-#define F77_DIM_SIZE(n) (f77_array_offset_tbl[n][1])
-
-/* The following gives us the offset for row n where n is 1-based.  */
-
-#define F77_DIM_OFFSET(n) (f77_array_offset_tbl[n][0])
-
 int
 f77_get_lowerbound (struct type *type)
 {
@@ -111,47 +100,6 @@ f77_get_dynamic_length_of_aggregate (struct type *type)
     * TYPE_LENGTH (check_typedef (TYPE_TARGET_TYPE (type)));
 }
 
-/* Function that sets up the array offset,size table for the array 
-   type "type".  */
-
-static void
-f77_create_arrayprint_offset_tbl (struct type *type, struct ui_file *stream)
-{
-  struct type *tmp_type;
-  int eltlen;
-  int ndimen = 1;
-  int upper, lower;
-
-  tmp_type = type;
-
-  while (TYPE_CODE (tmp_type) == TYPE_CODE_ARRAY)
-    {
-      upper = f77_get_upperbound (tmp_type);
-      lower = f77_get_lowerbound (tmp_type);
-
-      F77_DIM_SIZE (ndimen) = upper - lower + 1;
-
-      tmp_type = TYPE_TARGET_TYPE (tmp_type);
-      ndimen++;
-    }
-
-  /* Now we multiply eltlen by all the offsets, so that later we 
-     can print out array elements correctly.  Up till now we 
-     know an offset to apply to get the item but we also 
-     have to know how much to add to get to the next item.  */
-
-  ndimen--;
-  eltlen = TYPE_LENGTH (tmp_type);
-  F77_DIM_OFFSET (ndimen) = eltlen;
-  while (--ndimen > 0)
-    {
-      eltlen *= F77_DIM_SIZE (ndimen + 1);
-      F77_DIM_OFFSET (ndimen) = eltlen;
-    }
-}
-
-
-
 /* Actual function which prints out F77 arrays, Valaddr == address in 
    the superior.  Address == the address in the inferior.  */
 
@@ -164,41 +112,56 @@ f77_print_array_1 (int nss, int ndimensions, struct type *type,
 		   const struct value_print_options *options,
 		   int *elts)
 {
+  struct type *range_type = TYPE_INDEX_TYPE (check_typedef (type));
+  CORE_ADDR addr = address + embedded_offset;
+  LONGEST lowerbound, upperbound;
   int i;
 
+  get_discrete_bounds (range_type, &lowerbound, &upperbound);
+
   if (nss != ndimensions)
     {
-      for (i = 0;
-	   (i < F77_DIM_SIZE (nss) && (*elts) < options->print_max);
+      size_t dim_size = TYPE_LENGTH (TYPE_TARGET_TYPE (type));
+      size_t offs = 0;
+
+      for (i = lowerbound;
+	   (i < upperbound + 1 && (*elts) < options->print_max);
 	   i++)
 	{
+	  struct value *subarray = value_from_contents_and_address
+	    (TYPE_TARGET_TYPE (type), value_contents_for_printing_const (val)
+	     + offs, addr + offs);
+
 	  fprintf_filtered (stream, "( ");
-	  f77_print_array_1 (nss + 1, ndimensions, TYPE_TARGET_TYPE (type),
-			     valaddr,
-			     embedded_offset + i * F77_DIM_OFFSET (nss),
-			     address,
-			     stream, recurse, val, options, elts);
+	  f77_print_array_1 (nss + 1, ndimensions, value_type (subarray),
+			     value_contents_for_printing (subarray),
+			     value_embedded_offset (subarray),
+			     value_address (subarray),
+			     stream, recurse, subarray, options, elts);
+	  offs += dim_size;
 	  fprintf_filtered (stream, ") ");
 	}
-      if (*elts >= options->print_max && i < F77_DIM_SIZE (nss)) 
+      if (*elts >= options->print_max && i < upperbound)
 	fprintf_filtered (stream, "...");
     }
   else
     {
-      for (i = 0; i < F77_DIM_SIZE (nss) && (*elts) < options->print_max;
+      for (i = lowerbound; i < upperbound + 1 && (*elts) < options->print_max;
 	   i++, (*elts)++)
 	{
-	  val_print (TYPE_TARGET_TYPE (type),
-		     valaddr,
-		     embedded_offset + i * F77_DIM_OFFSET (ndimensions),
-		     address, stream, recurse,
-		     val, options, current_language);
+	  struct value *elt = value_subscript ((struct value *)val, i);
+
+	  val_print (value_type (elt),
+		     value_contents_for_printing (elt),
+		     value_embedded_offset (elt),
+		     value_address (elt), stream, recurse,
+		     elt, options, current_language);
 
-	  if (i != (F77_DIM_SIZE (nss) - 1))
+	  if (i != upperbound)
 	    fprintf_filtered (stream, ", ");
 
 	  if ((*elts == options->print_max - 1)
-	      && (i != (F77_DIM_SIZE (nss) - 1)))
+	      && (i != upperbound))
 	    fprintf_filtered (stream, "...");
 	}
     }
@@ -225,12 +188,6 @@ f77_print_array (struct type *type, const gdb_byte *valaddr,
 Type node corrupt! F77 arrays cannot have %d subscripts (%d Max)"),
 	   ndimensions, MAX_FORTRAN_DIMS);
 
-  /* Since F77 arrays are stored column-major, we set up an 
-     offset table to get at the various row's elements.  The 
-     offset table contains entries for both offset and subarray size.  */
-
-  f77_create_arrayprint_offset_tbl (type, stream);
-
   f77_print_array_1 (1, ndimensions, type, valaddr, embedded_offset,
 		     address, stream, recurse, val, options, &elts);
 }
@@ -375,12 +332,15 @@ f_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset,
       fprintf_filtered (stream, "( ");
       for (index = 0; index < TYPE_NFIELDS (type); index++)
         {
-          int offset = TYPE_FIELD_BITPOS (type, index) / 8;
+	  struct value *field = value_field
+	    ((struct value *)original_value, index);
+
+          val_print (value_type (field),
+		     value_contents_for_printing (field),
+		     value_embedded_offset (field),
+		     value_address (field), stream, recurse + 1,
+		     field, options, current_language);
 
-          val_print (TYPE_FIELD_TYPE (type, index), valaddr,
-		     embedded_offset + offset,
-		     address, stream, recurse + 1,
-		     original_value, options, current_language);
           if (index != TYPE_NFIELDS (type) - 1)
             fputs_filtered (", ", stream);
         }
-- 
1.7.9.5

^ permalink raw reply	[flat|nested] 53+ messages in thread

* [V4 16/18] vla: Fortran dynamic string support
  2015-01-14 13:49 [V4 00/21] Fortran dynamic array support Keven Boell
                   ` (8 preceding siblings ...)
  2015-01-14 13:50 ` [V4 18/18] vla: add NEWS entry for dynamic array support Keven Boell
@ 2015-01-14 13:50 ` Keven Boell
  2015-01-14 13:50 ` [V4 03/18] test: basic tests for dynamic array evaluations in Fortran Keven Boell
                   ` (10 subsequent siblings)
  20 siblings, 0 replies; 53+ messages in thread
From: Keven Boell @ 2015-01-14 13:50 UTC (permalink / raw)
  To: gdb-patches; +Cc: Keven Boell

This patch changes the semantic of the Dwarf string length
attribute to reflect the standard as well as  enables
correct string length calculation of dynamic strings. Add
tests for varous dynamic string evaluations.

Old:
(gdb) p my_dyn_string
$1 = (PTR TO -> ( character*23959136 )) 0x605fc0

(gdb) p *my_dyn_string
Cannot access memory at address 0x605fc0

New:
(gdb) p my_dyn_string
$1 = (PTR TO -> ( character*10 )) 0x605fc0

(gdb) p *my_dyn_string
$2 = 'foo'

2014-05-28  Keven Boell  <keven.boell@intel.com>
            Sanimir Agovic  <sanimir.agovic@intel.com>

	* dwarf2read.c (read_tag_string_type): changed
	semantic of DW_AT_string_length to be able to
	handle Dwarf blocks as well. Support for
	DW_AT_byte_length added to get correct length
	if specified in combination with
	DW_AT_string_length.
	(attr_to_dynamic_prop): added
	functionality to add Dwarf operators to baton
	data attribute. Added post values to baton
	as required by the string evaluation case.
	(read_subrange_type): Adapt caller.
	(set_die_type): Adapt caller.
	(add_post_values_to_baton): New function.
	* dwarf2loc.c (dwarf2_evaluate_property): Evaluate
	post processing dwarf.
	* dwarf2loc.h (struct dwarf2_property_baton): Add
	post dwarf values attribute.
	* gdbtypes.c (resolve_dynamic_type): Add
	conditions to support string types.
	(resolve_dynamic_array): Add conditions for dynamic
	strings and create a new string type.
	(is_dynamic_type): Follow pointer if a string type
	was detected, as Fortran strings are represented
	as pointers to strings internally.

testsuite/gdb.fortran/:

	* vla-strings.f90: New file.
	* vla-strings.exp: New file.



Signed-off-by: Keven Boell <keven.boell@intel.com>
---
 gdb/dwarf2read.c                          |  144 +++++++++++++++++++++++++----
 gdb/gdbtypes.c                            |   31 +++++--
 gdb/testsuite/gdb.fortran/vla-strings.exp |  104 +++++++++++++++++++++
 gdb/testsuite/gdb.fortran/vla-strings.f90 |   40 ++++++++
 4 files changed, 295 insertions(+), 24 deletions(-)
 create mode 100644 gdb/testsuite/gdb.fortran/vla-strings.exp
 create mode 100644 gdb/testsuite/gdb.fortran/vla-strings.f90

diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index df3ada1..cfb22fe 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -1844,6 +1844,12 @@ static void free_dwo_file_cleanup (void *);
 static void process_cu_includes (void);
 
 static void check_producer (struct dwarf2_cu *cu);
+
+static int
+attr_to_dynamic_prop (const struct attribute *attr, struct die_info *die,
+		      struct dwarf2_cu *cu, struct dynamic_prop *prop,
+		      const gdb_byte *additional_data, int additional_data_size);
+
 \f
 /* Various complaints about symbol reading that don't abort the process.  */
 
@@ -14240,29 +14246,92 @@ read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu)
   struct gdbarch *gdbarch = get_objfile_arch (objfile);
   struct type *type, *range_type, *index_type, *char_type;
   struct attribute *attr;
-  unsigned int length;
+  unsigned int length = UINT_MAX;
 
+  index_type = objfile_type (objfile)->builtin_int;
+  range_type = create_static_range_type (NULL, index_type, 1, length);
+
+  /* If DW_AT_string_length is defined, the length is stored at some location
+   * in memory. */
   attr = dwarf2_attr (die, DW_AT_string_length, cu);
   if (attr)
     {
-      length = DW_UNSND (attr);
+      if (attr_form_is_block (attr))
+        {
+          struct attribute *byte_size, *bit_size;
+          struct dynamic_prop high;
+
+          byte_size = dwarf2_attr (die, DW_AT_byte_size, cu);
+          bit_size = dwarf2_attr (die, DW_AT_bit_size, cu);
+
+          /* DW_AT_byte_size should never occur together in combination with
+             DW_AT_string_length.  */
+          if ((byte_size == NULL && bit_size != NULL) ||
+                  (byte_size != NULL && bit_size == NULL))
+            complaint (&symfile_complaints, _("DW_AT_byte_size AND "
+                      "DW_AT_bit_size found together at the same time."));
+
+          /* If DW_AT_string_length AND DW_AT_byte_size exist together, it
+             describes the number of bytes that should be read from the length
+             memory location.  */
+          if (byte_size != NULL && bit_size == NULL)
+            {
+              /* Build new dwarf2_locexpr_baton structure with additions to the
+                 data attribute, to reflect DWARF specialities to get address
+                 sizes.  */
+              const gdb_byte append_ops[] = {
+                /* DW_OP_deref_size: size of an address on the target machine
+                   (bytes), where the size will be specified by the next
+                   operand.  */
+                DW_OP_deref_size,
+                /* Operand for DW_OP_deref_size.  */
+                DW_UNSND (byte_size) };
+
+              if (!attr_to_dynamic_prop (attr, die, cu, &high,
+                      append_ops, ARRAY_SIZE (append_ops)))
+                complaint (&symfile_complaints,
+                        _("Could not parse DW_AT_byte_size"));
+            }
+          else if (bit_size != NULL && byte_size == NULL)
+            complaint (&symfile_complaints, _("DW_AT_string_length AND "
+                      "DW_AT_bit_size found but not supported yet."));
+          /* If DW_AT_string_length WITHOUT DW_AT_byte_size exist, the default
+             is the address size of the target machine.  */
+          else
+            {
+              const gdb_byte append_ops[] = { DW_OP_deref };
+
+              if (!attr_to_dynamic_prop (attr, die, cu, &high, append_ops,
+                      ARRAY_SIZE (append_ops)))
+                complaint (&symfile_complaints,
+                        _("Could not parse DW_AT_string_length"));
+            }
+
+          TYPE_RANGE_DATA (range_type)->high = high;
+        }
+      else
+        {
+          TYPE_HIGH_BOUND (range_type) = DW_UNSND (attr);
+          TYPE_HIGH_BOUND_KIND (range_type) = PROP_CONST;
+        }
     }
   else
     {
-      /* Check for the DW_AT_byte_size attribute.  */
+      /* Check for the DW_AT_byte_size attribute, which represents the length
+         in this case.  */
       attr = dwarf2_attr (die, DW_AT_byte_size, cu);
       if (attr)
         {
-          length = DW_UNSND (attr);
+          TYPE_HIGH_BOUND (range_type) = DW_UNSND (attr);
+          TYPE_HIGH_BOUND_KIND (range_type) = PROP_CONST;
         }
       else
         {
-          length = 1;
+          TYPE_HIGH_BOUND (range_type) = 1;
+          TYPE_HIGH_BOUND_KIND (range_type) = PROP_CONST;
         }
     }
 
-  index_type = objfile_type (objfile)->builtin_int;
-  range_type = create_static_range_type (NULL, index_type, 1, length);
   char_type = language_string_char_type (cu->language_defn, gdbarch);
   type = create_string_type (NULL, char_type, range_type);
 
@@ -14579,13 +14648,15 @@ read_base_type (struct die_info *die, struct dwarf2_cu *cu)
   return set_die_type (die, type, cu);
 }
 
+
 /* Parse dwarf attribute if it's a block, reference or constant and put the
    resulting value of the attribute into struct bound_prop.
    Returns 1 if ATTR could be resolved into PROP, 0 otherwise.  */
 
 static int
 attr_to_dynamic_prop (const struct attribute *attr, struct die_info *die,
-		      struct dwarf2_cu *cu, struct dynamic_prop *prop)
+		      struct dwarf2_cu *cu, struct dynamic_prop *prop,
+		      const gdb_byte *additional_data, int additional_data_size)
 {
   struct dwarf2_property_baton *baton;
   struct obstack *obstack = &cu->objfile->objfile_obstack;
@@ -14598,8 +14669,25 @@ attr_to_dynamic_prop (const struct attribute *attr, struct die_info *die,
       baton = obstack_alloc (obstack, sizeof (*baton));
       baton->referenced_type = NULL;
       baton->locexpr.per_cu = cu->per_cu;
-      baton->locexpr.size = DW_BLOCK (attr)->size;
-      baton->locexpr.data = DW_BLOCK (attr)->data;
+
+      if (additional_data != NULL && additional_data_size > 0)
+        {
+          gdb_byte *data;
+
+          data = obstack_alloc (&cu->objfile->objfile_obstack,
+                  DW_BLOCK (attr)->size + additional_data_size);
+          memcpy (data, DW_BLOCK (attr)->data, DW_BLOCK (attr)->size);
+          memcpy (data + DW_BLOCK (attr)->size,
+                  additional_data, additional_data_size);
+
+          baton->locexpr.data = data;
+          baton->locexpr.size = DW_BLOCK (attr)->size + additional_data_size;
+        }
+      else
+        {
+          baton->locexpr.data = DW_BLOCK (attr)->data;
+          baton->locexpr.size = DW_BLOCK (attr)->size;
+        }
       prop->data.baton = baton;
       prop->kind = PROP_LOCEXPR;
       gdb_assert (prop->data.baton != NULL);
@@ -14629,8 +14717,28 @@ attr_to_dynamic_prop (const struct attribute *attr, struct die_info *die,
 	  baton = obstack_alloc (obstack, sizeof (*baton));
 	  baton->referenced_type = die_type (target_die, target_cu);
 	  baton->locexpr.per_cu = cu->per_cu;
-	  baton->locexpr.size = DW_BLOCK (target_attr)->size;
-	  baton->locexpr.data = DW_BLOCK (target_attr)->data;
+
+	  if (additional_data != NULL && additional_data_size > 0)
+	    {
+	      gdb_byte *data;
+
+	      data = obstack_alloc (&cu->objfile->objfile_obstack,
+	              DW_BLOCK (target_attr)->size + additional_data_size);
+	      memcpy (data, DW_BLOCK (target_attr)->data,
+	              DW_BLOCK (target_attr)->size);
+	      memcpy (data + DW_BLOCK (target_attr)->size,
+	              additional_data, additional_data_size);
+
+	      baton->locexpr.data = data;
+	      baton->locexpr.size = (DW_BLOCK (target_attr)->size
+	                             + additional_data_size);
+	    }
+	  else
+	    {
+	      baton->locexpr.data = DW_BLOCK (target_attr)->data;
+	      baton->locexpr.size = DW_BLOCK (target_attr)->size;
+	    }
+
 	  prop->data.baton = baton;
 	  prop->kind = PROP_LOCEXPR;
 	  gdb_assert (prop->data.baton != NULL);
@@ -14720,17 +14828,17 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
 
   attr = dwarf2_attr (die, DW_AT_lower_bound, cu);
   if (attr)
-    attr_to_dynamic_prop (attr, die, cu, &low);
+    attr_to_dynamic_prop (attr, die, cu, &low, NULL, 0);
   else if (!low_default_is_valid)
     complaint (&symfile_complaints, _("Missing DW_AT_lower_bound "
 				      "- DIE at 0x%x [in module %s]"),
 	       die->offset.sect_off, objfile_name (cu->objfile));
 
   attr = dwarf2_attr (die, DW_AT_upper_bound, cu);
-  if (!attr_to_dynamic_prop (attr, die, cu, &high))
+  if (!attr_to_dynamic_prop (attr, die, cu, &high, NULL, 0))
     {
       attr = dwarf2_attr (die, DW_AT_count, cu);
-      if (attr_to_dynamic_prop (attr, die, cu, &high))
+      if (attr_to_dynamic_prop (attr, die, cu, &high, NULL, 0))
 	{
 	  /* If bounds are constant do the final calculation here.  */
 	  if (low.kind == PROP_CONST && high.kind == PROP_CONST)
@@ -21863,7 +21971,7 @@ set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
     {
       struct dynamic_prop prop;
 
-      if (attr_to_dynamic_prop (attr, die, cu, &prop))
+      if (attr_to_dynamic_prop (attr, die, cu, &prop, NULL, 0))
         {
           TYPE_ALLOCATED_PROP (type)
             = obstack_alloc (&objfile->objfile_obstack, sizeof (prop));
@@ -21877,7 +21985,7 @@ set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
     {
       struct dynamic_prop prop;
 
-      if (attr_to_dynamic_prop (attr, die, cu, &prop))
+      if (attr_to_dynamic_prop (attr, die, cu, &prop, NULL, 0))
         {
           TYPE_ASSOCIATED_PROP (type)
             = obstack_alloc (&objfile->objfile_obstack, sizeof (prop));
@@ -21887,7 +21995,7 @@ set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
 
   /* Read DW_AT_data_location and set in type.  */
   attr = dwarf2_attr (die, DW_AT_data_location, cu);
-  if (attr_to_dynamic_prop (attr, die, cu, &prop))
+  if (attr_to_dynamic_prop (attr, die, cu, &prop, NULL, 0))
     {
       TYPE_DATA_LOCATION (type)
         = obstack_alloc (&objfile->objfile_obstack, sizeof (prop));
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index 6695adb..967b9e5 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -1693,6 +1693,17 @@ is_dynamic_type_internal (struct type *type, int top_level)
 	      && is_dynamic_type_internal (TYPE_FIELD_TYPE (type, i), 0))
 	    return 1;
       }
+    case TYPE_CODE_PTR:
+      {
+        if (TYPE_TARGET_TYPE (type)
+            && TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_STRING)
+          return is_dynamic_type (check_typedef (TYPE_TARGET_TYPE (type)));
+
+        return 0;
+        break;
+      }
+    default:
+      return 0;
       break;
     }
 
@@ -1775,7 +1786,8 @@ resolve_dynamic_array (struct type *type, CORE_ADDR addr)
   struct dynamic_prop *prop;
   struct type *copy = copy_type (type);
 
-  gdb_assert (TYPE_CODE (type) == TYPE_CODE_ARRAY);
+  gdb_assert (TYPE_CODE (type) == TYPE_CODE_ARRAY
+              || TYPE_CODE (type) == TYPE_CODE_STRING);
 
   elt_type = type;
   range_type = check_typedef (TYPE_INDEX_TYPE (elt_type));
@@ -1797,14 +1809,20 @@ resolve_dynamic_array (struct type *type, CORE_ADDR addr)
 
   ary_dim = check_typedef (TYPE_TARGET_TYPE (elt_type));
 
-  if (ary_dim != NULL && TYPE_CODE (ary_dim) == TYPE_CODE_ARRAY)
+  if (ary_dim != NULL && (TYPE_CODE (ary_dim) == TYPE_CODE_ARRAY
+          || TYPE_CODE (ary_dim) == TYPE_CODE_STRING))
     elt_type = resolve_dynamic_array (TYPE_TARGET_TYPE (copy), addr);
   else
     elt_type = TYPE_TARGET_TYPE (type);
 
-  return create_array_type (copy,
-			    elt_type,
-			    range_type);
+  if (TYPE_CODE (type) == TYPE_CODE_STRING)
+    return create_string_type (copy,
+            elt_type,
+            range_type);
+  else
+    return create_array_type (copy,
+            elt_type,
+            range_type);
 }
 
 /* Resolve dynamic bounds of members of the union TYPE to static
@@ -1948,8 +1966,9 @@ resolve_dynamic_type_internal (struct type *type, CORE_ADDR addr,
 	  }
 
 	case TYPE_CODE_ARRAY:
+	case TYPE_CODE_STRING:
 	  resolved_type = resolve_dynamic_array (type, addr);
-	  break;
+		break;
 
 	case TYPE_CODE_RANGE:
 	  resolved_type = resolve_dynamic_range (type, addr);
diff --git a/gdb/testsuite/gdb.fortran/vla-strings.exp b/gdb/testsuite/gdb.fortran/vla-strings.exp
new file mode 100644
index 0000000..1d41e41
--- /dev/null
+++ b/gdb/testsuite/gdb.fortran/vla-strings.exp
@@ -0,0 +1,104 @@
+# Copyright 2015 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/>.
+
+standard_testfile ".f90"
+
+if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile} \
+    {debug f90 quiet}] } {
+    return -1
+}
+
+# check that all fortran standard datatypes will be
+# handled correctly when using as VLA's
+
+if ![runto MAIN__] then {
+    perror "couldn't run to breakpoint MAIN__"
+    continue
+}
+
+gdb_breakpoint [gdb_get_line_number "var_char-allocated-1"]
+gdb_continue_to_breakpoint "var_char-allocated-1"
+gdb_test "print var_char" \
+  " = \\(PTR TO -> \\( character\\*10 \\)\\) ${hex}" \
+  "print var_char after allocated first time"
+gdb_test "print *var_char" \
+  " = '\\\\000\\\\000\\\\000\\\\000\\\\000\\\\000\\\\000\\\\000\\\\000\\\\000'" \
+  "print *var_char after allocated first time"
+gdb_test "whatis var_char" "type = PTR TO -> \\( character\\*10 \\)" \
+  "whatis var_char first time"
+gdb_test "ptype var_char" "type = PTR TO -> \\( character\\*10 \\)" \
+  "ptype var_char first time"
+gdb_test "next" "\\d+.*var_char = 'foo'.*" \
+  "next to allocation status of var_char"
+gdb_test "print l" " = .TRUE." "print allocation status first time"
+
+gdb_breakpoint [gdb_get_line_number "var_char-filled-1"]
+gdb_continue_to_breakpoint "var_char-filled-1"
+gdb_test "print var_char" \
+  " = \\(PTR TO -> \\( character\\*3 \\)\\) ${hex}" \
+  "print var_char after filled first time"
+gdb_test "print *var_char" " = 'foo'" \
+  "print *var_char after filled first time"
+gdb_test "whatis var_char" "type = PTR TO -> \\( character\\*3 \\)" \
+  "whatis var_char after filled first time"
+gdb_test "ptype var_char" "type = PTR TO -> \\( character\\*3 \\)" \
+  "ptype var_char after filled first time"
+gdb_test "print var_char(1)" " = 102 'f'" "print var_char(1)"
+gdb_test "print var_char(3)" " = 111 'o'" "print var_char(3)"
+
+gdb_breakpoint [gdb_get_line_number "var_char-filled-2"]
+gdb_continue_to_breakpoint "var_char-filled-2"
+gdb_test "print var_char" \
+  " = \\(PTR TO -> \\( character\\*6 \\)\\) ${hex}" \
+  "print var_char after allocated second time"
+gdb_test "print *var_char" " = 'foobar'" \
+  "print *var_char after allocated second time"
+gdb_test "whatis var_char" "type = PTR TO -> \\( character\\*6 \\)" \
+  "whatis var_char second time"
+gdb_test "ptype var_char" "type = PTR TO -> \\( character\\*6 \\)" \
+  "ptype var_char second time"
+
+gdb_breakpoint [gdb_get_line_number "var_char-empty"]
+gdb_continue_to_breakpoint "var_char-empty"
+gdb_test "print var_char" \
+  " = \\(PTR TO -> \\( character\\*0 \\)\\) ${hex}" \
+  "print var_char after set empty"
+gdb_test "print *var_char" " = \"\"" "print *var_char after set empty"
+gdb_test "whatis var_char" "type = PTR TO -> \\( character\\*0 \\)" \
+  "whatis var_char after set empty"
+gdb_test "ptype var_char" "type = PTR TO -> \\( character\\*0 \\)" \
+  "ptype var_char after set empty"
+
+gdb_breakpoint [gdb_get_line_number "var_char-allocated-3"]
+gdb_continue_to_breakpoint "var_char-allocated-3"
+gdb_test "print var_char" \
+  " = \\(PTR TO -> \\( character\\*21 \\)\\) ${hex}" \
+  "print var_char after allocated third time"
+gdb_test "whatis var_char" "type = PTR TO -> \\( character\\*21 \\)" \
+  "whatis var_char after allocated third time"
+gdb_test "ptype var_char" "type = PTR TO -> \\( character\\*21 \\)" \
+  "ptype var_char after allocated third time"
+
+gdb_breakpoint [gdb_get_line_number "var_char_p-associated"]
+gdb_continue_to_breakpoint "var_char_p-associated"
+gdb_test "print var_char_p" \
+  " = \\(PTR TO -> \\( character\\*7 \\)\\) ${hex}" \
+  "print var_char_p after associated"
+gdb_test "print *var_char_p" " = 'johndoe'" \
+  "print *var_char_ after associated"
+gdb_test "whatis var_char_p" "type = PTR TO -> \\( character\\*7 \\)" \
+  "whatis var_char_p after associated"
+gdb_test "ptype var_char_p" "type = PTR TO -> \\( character\\*7 \\)" \
+  "ptype var_char_p after associated"
diff --git a/gdb/testsuite/gdb.fortran/vla-strings.f90 b/gdb/testsuite/gdb.fortran/vla-strings.f90
new file mode 100644
index 0000000..98d48d6
--- /dev/null
+++ b/gdb/testsuite/gdb.fortran/vla-strings.f90
@@ -0,0 +1,40 @@
+! Copyright 2015 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 2 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, write to the Free Software
+! Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+program vla_strings
+  character(len=:), target, allocatable   :: var_char
+  character(len=:), pointer               :: var_char_p
+  logical                                 :: l
+
+  allocate(character(len=10) :: var_char)
+  l = allocated(var_char)                 ! var_char-allocated-1
+  var_char = 'foo'
+  deallocate(var_char)                    ! var_char-filled-1
+  l = allocated(var_char)                 ! var_char-deallocated
+  allocate(character(len=42) :: var_char)
+  l = allocated(var_char)
+  var_char = 'foobar'
+  var_char = ''                           ! var_char-filled-2
+  var_char = 'bar'                        ! var_char-empty
+  deallocate(var_char)
+  allocate(character(len=21) :: var_char)
+  l = allocated(var_char)                 ! var_char-allocated-3
+  var_char = 'johndoe'
+  var_char_p => var_char
+  l = associated(var_char_p)              ! var_char_p-associated
+  var_char_p => null()
+  l = associated(var_char_p)              ! var_char_p-not-associated
+end program vla_strings
-- 
1.7.9.5

^ permalink raw reply	[flat|nested] 53+ messages in thread

* [V4 05/18] test: dynamic arrays passed to subroutines.
  2015-01-14 13:49 [V4 00/21] Fortran dynamic array support Keven Boell
                   ` (12 preceding siblings ...)
  2015-01-14 13:50 ` [V4 17/18] vla: add stride support to fortran arrays Keven Boell
@ 2015-01-14 13:50 ` Keven Boell
  2015-01-14 13:50 ` [V4 10/18] test: basic MI test for the dynamic array support Keven Boell
                   ` (6 subsequent siblings)
  20 siblings, 0 replies; 53+ messages in thread
From: Keven Boell @ 2015-01-14 13:50 UTC (permalink / raw)
  To: gdb-patches; +Cc: Keven Boell

Tests dynamic arrays passed to subroutines and handled
in different ways inside the routine.

2014-05-28  Keven Boell  <keven.boell@intel.com>
            Sanimir Agovic  <sanimir.agovic@intel.com>

testsuite/gdb.fortran/:

	* vla-sub.f90: New file.
	* vla-ptype-sub.exp: New file.
	* vla-value-sub-arbitrary.exp: New file.
	* vla-value-sub-finish.exp: New file.
	* vla-value-sub.exp: New file.



Signed-off-by: Keven Boell <keven.boell@intel.com>
---
 gdb/testsuite/gdb.fortran/vla-ptype-sub.exp        |   87 +++++++++++++++++++
 gdb/testsuite/gdb.fortran/vla-sub.f90              |   82 ++++++++++++++++++
 .../gdb.fortran/vla-value-sub-arbitrary.exp        |   35 ++++++++
 gdb/testsuite/gdb.fortran/vla-value-sub-finish.exp |   49 +++++++++++
 gdb/testsuite/gdb.fortran/vla-value-sub.exp        |   90 ++++++++++++++++++++
 5 files changed, 343 insertions(+)
 create mode 100644 gdb/testsuite/gdb.fortran/vla-ptype-sub.exp
 create mode 100644 gdb/testsuite/gdb.fortran/vla-sub.f90
 create mode 100644 gdb/testsuite/gdb.fortran/vla-value-sub-arbitrary.exp
 create mode 100644 gdb/testsuite/gdb.fortran/vla-value-sub-finish.exp
 create mode 100644 gdb/testsuite/gdb.fortran/vla-value-sub.exp

diff --git a/gdb/testsuite/gdb.fortran/vla-ptype-sub.exp b/gdb/testsuite/gdb.fortran/vla-ptype-sub.exp
new file mode 100644
index 0000000..98fd663
--- /dev/null
+++ b/gdb/testsuite/gdb.fortran/vla-ptype-sub.exp
@@ -0,0 +1,87 @@
+# Copyright 2015 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/>.
+
+standard_testfile "vla-sub.f90"
+
+if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile} \
+    {debug f90 quiet}] } {
+    return -1
+}
+
+if ![runto MAIN__] then {
+    perror "couldn't run to breakpoint MAIN__"
+    continue
+}
+
+# Pass fixed array to function and handle them as vla in function.
+gdb_breakpoint [gdb_get_line_number "not-filled"]
+gdb_continue_to_breakpoint "not-filled (1st)"
+gdb_test "ptype array1" "type = integer\\\(kind=4\\\) \\\(42,42\\\)" \
+  "ptype array1 (passed fixed)"
+gdb_test "ptype array2" "type = real\\\(kind=4\\\) \\\(42,42,42\\\)" \
+  "ptype array2 (passed fixed)"
+gdb_test "ptype array1(40, 10)" "type = integer\\\(kind=4\\\)" \
+  "ptype array1(40, 10) (passed fixed)"
+gdb_test "ptype array2(13, 11, 5)" "type = real\\\(kind=4\\\)" \
+  "ptype array2(13, 11, 5) (passed fixed)"
+
+# Pass sub arrays to function and handle them as vla in function.
+gdb_continue_to_breakpoint "not-filled (2nd)"
+gdb_test "ptype array1" "type = integer\\\(kind=4\\\) \\\(6,6\\\)" \
+  "ptype array1 (passed sub-array)"
+gdb_test "ptype array2" "type = real\\\(kind=4\\\) \\\(6,6,6\\\)" \
+  "ptype array2 (passed sub-array)"
+gdb_test "ptype array1(3, 3)" "type = integer\\\(kind=4\\\)" \
+  "ptype array1(3, 3) (passed sub-array)"
+gdb_test "ptype array2(4, 4, 4)" "type = real\\\(kind=4\\\)" \
+  "ptype array2(4, 4, 4) (passed sub-array)"
+
+# Check ptype outside of bounds. This should not crash GDB.
+gdb_test "ptype array1(100, 100)" "no such vector element" \
+  "ptype array1(100, 100) subarray do not crash (passed sub-array)"
+gdb_test "ptype array2(100, 100, 100)" "no such vector element" \
+  "ptype array2(100, 100, 100) subarray do not crash (passed sub-array)"
+
+# Pass vla to function.
+gdb_continue_to_breakpoint "not-filled (3rd)"
+gdb_test "ptype array1" "type = integer\\\(kind=4\\\) \\\(20,20\\\)" \
+  "ptype array1 (passed vla)"
+gdb_test "ptype array2" "type = real\\\(kind=4\\\) \\\(10,10,10\\\)" \
+  "ptype array2 (passed vla)"
+gdb_test "ptype array1(3, 3)" "type = integer\\\(kind=4\\\)" \
+  "ptype array1(3, 3) (passed vla)"
+gdb_test "ptype array2(4, 4, 4)" "type = real\\\(kind=4\\\)" \
+  "ptype array2(4, 4, 4) (passed vla)"
+
+# Check ptype outside of bounds. This should not crash GDB.
+gdb_test "ptype array1(100, 100)" "no such vector element" \
+  "ptype array1(100, 100) VLA do not crash (passed vla)"
+gdb_test "ptype array2(100, 100, 100)" "no such vector element" \
+  "ptype array2(100, 100, 100) VLA do not crash (passed vla)"
+
+# Pass fixed array to function and handle it as VLA of arbitrary length in
+# function.
+gdb_breakpoint [gdb_get_line_number "end-of-bar"]
+gdb_continue_to_breakpoint "end-of-bar"
+gdb_test "ptype array1" \
+  "type = (PTR TO -> \\( )?integer(\\(kind=4\\)|\\*4) \\(\\*\\)\\)?" \
+  "ptype array1 (arbitrary length)"
+gdb_test "ptype array2" \
+  "type = (PTR TO -> \\( )?integer(\\(kind=4\\)|\\*4) \\(4:9,10:\\*\\)\\)?" \
+  "ptype array2 (arbitrary length)"
+gdb_test "ptype array1(100)" "type = integer\\\(kind=4\\\)" \
+  "ptype array1(100) (arbitrary length)"
+gdb_test "ptype array2(4,100)" "type = integer\\\(kind=4\\\)" \
+  "ptype array2(4,100) (arbitrary length)"
diff --git a/gdb/testsuite/gdb.fortran/vla-sub.f90 b/gdb/testsuite/gdb.fortran/vla-sub.f90
new file mode 100644
index 0000000..dfda411
--- /dev/null
+++ b/gdb/testsuite/gdb.fortran/vla-sub.f90
@@ -0,0 +1,82 @@
+! Copyright 2015 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 2 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, write to the Free Software
+! Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+!
+! Original file written by Jakub Jelinek <jakub@redhat.com> and
+! Jan Kratochvil <jan.kratochvil@redhat.com>.
+! Modified for the GDB testcases by Keven Boell <keven.boell@intel.com>.
+
+subroutine foo (array1, array2)
+  integer :: array1 (:, :)
+  real    :: array2 (:, :, :)
+
+  array1(:,:) = 5                       ! not-filled
+  array1(1, 1) = 30
+
+  array2(:,:,:) = 6                     ! array1-filled
+  array2(:,:,:) = 3
+  array2(1,1,1) = 30
+  array2(3,3,3) = 90                    ! array2-almost-filled
+end subroutine
+
+subroutine bar (array1, array2)
+  integer :: array1 (*)
+  integer :: array2 (4:9, 10:*)
+
+  array1(5:10) = 1311
+  array1(7) = 1
+  array1(100) = 100
+  array2(4,10) = array1(7)
+  array2(4,100) = array1(7)
+  return                                ! end-of-bar
+end subroutine
+
+program vla_sub
+  interface
+    subroutine foo (array1, array2)
+      integer :: array1 (:, :)
+      real :: array2 (:, :, :)
+    end subroutine
+  end interface
+  interface
+    subroutine bar (array1, array2)
+      integer :: array1 (*)
+      integer :: array2 (4:9, 10:*)
+    end subroutine
+  end interface
+
+  real, allocatable :: vla1 (:, :, :)
+  integer, allocatable :: vla2 (:, :)
+
+  ! used for subroutine
+  integer :: sub_arr1(42, 42)
+  real    :: sub_arr2(42, 42, 42)
+  integer :: sub_arr3(42)
+
+  sub_arr1(:,:) = 1                   ! vla2-deallocated
+  sub_arr2(:,:,:) = 2
+  sub_arr3(:) = 3
+
+  call foo(sub_arr1, sub_arr2)
+  call foo(sub_arr1(5:10, 5:10), sub_arr2(10:15,10:15,10:15))
+
+  allocate (vla1 (10,10,10))
+  allocate (vla2 (20,20))
+  vla1(:,:,:) = 1311
+  vla2(:,:) = 42
+  call foo(vla2, vla1)
+
+  call bar(sub_arr3, sub_arr1)
+end program vla_sub
diff --git a/gdb/testsuite/gdb.fortran/vla-value-sub-arbitrary.exp b/gdb/testsuite/gdb.fortran/vla-value-sub-arbitrary.exp
new file mode 100644
index 0000000..88defda
--- /dev/null
+++ b/gdb/testsuite/gdb.fortran/vla-value-sub-arbitrary.exp
@@ -0,0 +1,35 @@
+# Copyright 2015 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/>.
+
+standard_testfile "vla-sub.f90"
+
+if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile} \
+    {debug f90 quiet}] } {
+    return -1
+}
+
+if ![runto MAIN__] then {
+    perror "couldn't run to breakpoint MAIN__"
+    continue
+}
+
+# Check VLA with arbitary length and check that elements outside of
+# bounds of the passed VLA can be accessed correctly.
+gdb_breakpoint [gdb_get_line_number "end-of-bar"]
+gdb_continue_to_breakpoint "end-of-bar"
+gdb_test "p array1(42)" " = 3" "print arbitary array1(42)"
+gdb_test "p array1(100)" " = 100" "print arbitary array1(100)"
+gdb_test "p array2(4,10)" " = 1" "print arbitary array2(4,10)"
+gdb_test "p array2(4,100)" " = 1" "print arbitary array2(4,100)"
diff --git a/gdb/testsuite/gdb.fortran/vla-value-sub-finish.exp b/gdb/testsuite/gdb.fortran/vla-value-sub-finish.exp
new file mode 100644
index 0000000..6738875
--- /dev/null
+++ b/gdb/testsuite/gdb.fortran/vla-value-sub-finish.exp
@@ -0,0 +1,49 @@
+# Copyright 2015 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/>.
+
+standard_testfile "vla-sub.f90"
+
+if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile} \
+    {debug f90 quiet}] } {
+    return -1
+}
+
+if ![runto MAIN__] then {
+    perror "couldn't run to breakpoint MAIN__"
+    continue
+}
+
+# "up" works with GCC but other Fortran compilers may copy the values into the
+# outer function only on the exit of the inner function.
+# We need both variants as depending on the arch we optionally may still be
+# executing the caller line or not after `finish'.
+
+gdb_breakpoint [gdb_get_line_number "array2-almost-filled"]
+gdb_continue_to_breakpoint "array2-almost-filled"
+gdb_test "print array2" " = \\( *\\( *\\( *30, *3, *3,\[()3, .\]*\\)" \
+  "print array2 in foo after it was filled"
+gdb_test "print array2(2,1,1)=20" " = 20" \
+  "set array(2,2,2) to 20 in subroutine"
+gdb_test "print array2" " = \\( *\\( *\\( *30, *20, *3,\[()3, .\]*\\)" \
+  "print array2 in foo after it was mofified in debugger"
+
+gdb_test "finish" \
+  ".*(foo\\\(sub_arr1\\\(5:10, 5:10\\\), sub_arr2\\\(10:15,10:15,10:15\\\)\\\)|foo \\\(array1=..., array2=...\\\).*)" \
+  "finish function"
+gdb_test "p sub_arr1(5, 7)" " = 5" "sub_arr1(5, 7) after finish"
+gdb_test "p sub_arr1(1, 1)" " = 30" "sub_arr1(1, 1) after finish"
+gdb_test "p sub_arr2(1, 1, 1)" " = 30" "sub_arr2(1, 1, 1) after finish"
+gdb_test "p sub_arr2(2, 1, 1)" " = 20" "sub_arr2(2, 1, 1) after finish"
+
diff --git a/gdb/testsuite/gdb.fortran/vla-value-sub.exp b/gdb/testsuite/gdb.fortran/vla-value-sub.exp
new file mode 100644
index 0000000..de88333
--- /dev/null
+++ b/gdb/testsuite/gdb.fortran/vla-value-sub.exp
@@ -0,0 +1,90 @@
+# Copyright 2015 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/>.
+
+standard_testfile "vla-sub.f90"
+
+if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile} \
+    {debug f90 quiet}] } {
+    return -1
+}
+
+if ![runto MAIN__] then {
+    perror "couldn't run to breakpoint MAIN__"
+    continue
+}
+
+# Check the values of VLA's in subroutine can be evaluated correctly
+
+# Try to access values from a fixed array handled as VLA in subroutine.
+gdb_breakpoint [gdb_get_line_number "not-filled"]
+gdb_continue_to_breakpoint "not-filled (1st)"
+gdb_test "print array1" " = \\(\[()1, .\]*\\)" \
+  "print passed array1 in foo (passed fixed array)"
+
+gdb_breakpoint [gdb_get_line_number "array1-filled"]
+gdb_continue_to_breakpoint "array1-filled (1st)"
+gdb_test "print array1(5, 7)" " = 5" \
+  "print array1(5, 7) after filled in foo (passed fixed array)"
+gdb_test "print array1(1, 1)" " = 30" \
+  "print array1(1, 1) after filled in foo (passed fixed array)"
+
+gdb_breakpoint [gdb_get_line_number "array2-almost-filled"]
+gdb_continue_to_breakpoint "array2-almost-filled (1st)"
+gdb_test "print array2" " = \\( *\\( *\\( *30, *3, *3,\[()3, .\]*\\)" \
+  "print array2 in foo after it was filled (passed fixed array)"
+gdb_test "print array2(2,1,1)=20" " = 20" \
+  "set array(2,2,2) to 20 in subroutine (passed fixed array)"
+gdb_test "print array2" " = \\( *\\( *\\( *30, *20, *3,\[()3, .\]*\\)" \
+  "print array2 in foo after it was mofified in debugger (passed fixed array)"
+
+
+# Try to access values from a fixed sub-array handled as VLA in subroutine.
+gdb_continue_to_breakpoint "not-filled (2nd)"
+gdb_test "print array1" " = \\(\[()5, .\]*\\)" \
+  "print passed array1 in foo (passed sub-array)"
+
+gdb_continue_to_breakpoint "array1-filled (2nd)"
+gdb_test "print array1(5, 5)" " = 5" \
+  "print array1(5, 5) after filled in foo (passed sub-array)"
+gdb_test "print array1(1, 1)" " = 30" \
+  "print array1(1, 1) after filled in foo (passed sub-array)"
+
+gdb_continue_to_breakpoint "array2-almost-filled (2nd)"
+gdb_test "print array2" " = \\( *\\( *\\( *30, *3, *3,\[()3, .\]*\\)" \
+  "print array2 in foo after it was filled (passed sub-array)"
+gdb_test "print array2(2,1,1)=20" " = 20" \
+  "set array(2,2,2) to 20 in subroutine (passed sub-array)"
+gdb_test "print array2" " = \\( *\\( *\\( *30, *20, *3,\[()3, .\]*\\)" \
+  "print array2 in foo after it was mofified in debugger (passed sub-array)"
+
+
+# Try to access values from a VLA passed to subroutine.
+gdb_continue_to_breakpoint "not-filled (3rd)"
+gdb_test "print array1" " = \\(\[()42, .\]*\\)" \
+  "print passed array1 in foo (passed vla)"
+
+gdb_continue_to_breakpoint "array1-filled (3rd)"
+gdb_test "print array1(5, 5)" " = 5" \
+  "print array1(5, 5) after filled in foo (passed vla)"
+gdb_test "print array1(1, 1)" " = 30" \
+  "print array1(1, 1) after filled in foo (passed vla)"
+
+gdb_continue_to_breakpoint "array2-almost-filled (3rd)"
+gdb_test "print array2" " = \\( *\\( *\\( *30, *3, *3,\[()3, .\]*\\)" \
+  "print array2 in foo after it was filled (passed vla)"
+gdb_test "print array2(2,1,1)=20" " = 20" \
+  "set array(2,2,2) to 20 in subroutine (passed vla)"
+gdb_test "print array2" " = \\( *\\( *\\( *30, *20, *3,\[()3, .\]*\\)" \
+  "print array2 in foo after it was mofified in debugger (passed vla)"
-- 
1.7.9.5

^ permalink raw reply	[flat|nested] 53+ messages in thread

* [V4 02/18] vla: make dynamic fortran arrays functional.
  2015-01-14 13:49 [V4 00/21] Fortran dynamic array support Keven Boell
                   ` (10 preceding siblings ...)
  2015-01-14 13:50 ` [V4 03/18] test: basic tests for dynamic array evaluations in Fortran Keven Boell
@ 2015-01-14 13:50 ` Keven Boell
  2015-02-09  7:09   ` Joel Brobecker
  2015-01-14 13:50 ` [V4 17/18] vla: add stride support to fortran arrays Keven Boell
                   ` (8 subsequent siblings)
  20 siblings, 1 reply; 53+ messages in thread
From: Keven Boell @ 2015-01-14 13:50 UTC (permalink / raw)
  To: gdb-patches; +Cc: Keven Boell

This patch enables GDB to print the value of a dynamic
array (VLA) if allocated/associated in fortran. If not the
allocation status will be printed to the command line.

(gdb) p vla_not_allocated
$1 = <not allocated>

(gdb) p vla_allocated
$1 = (1, 2, 3)

(gdb) p vla_not_associated
$1 = <not associated>

(gdb) p vla_associated
$1 = (3, 2, 1)

The patch covers various locations where the allocation/
association status makes sense to print.

2014-05-28  Keven Boell  <keven.boell@intel.com>
            Sanimir Agovic  <sanimir.agovic@intel.com>

	* dwarf2loc.c (dwarf2_address_data_valid): New
	function.
	* dwarf2loc.h (dwarf2_address_data_valid): New
	function.
	* f-typeprint.c (f_print_type): Print allocation/
	association status.
	(f_type_print_varspec_suffix): Print allocation/
	association status for &-operator usages.
	* gdbtypes.c (create_array_type_with_stride): Add
	query for valid data location.
	(is_dynamic_type): Extend dynamic type detection
	with allocated/associated. Add type detection for
	fields.
	(resolve_dynamic_range): Copy type before resolving
	it as dynamic attributes need to be preserved.
	(resolve_dynamic_array): Copy type before resolving
	it as dynamic attributes need to be preserved. Add
	resolving of allocated/associated attributes.
	(resolve_dynamic_type): Add call to nested
	type resolving.
	(copy_type_recursive): Add allocated/associated
	attributes to be copied.
	(copy_type): Copy allocated/associated/data_location
	as well as the fields structure if available.
	* valarith.c (value_subscripted_rvalue): Print allocated/
	associated status when indexing a VLA.
	* valprint.c (valprint_check_validity): Print allocated/
	associated status.
	(val_print_not_allocated): New function.
	(val_print_not_associated): New function.
	* valprint.h (val_print_not_allocated): New function.
	(val_print_not_associated): New function.
	* value.c (set_value_component_location): Adjust the value
	address for single value prints.



Signed-off-by: Keven Boell <keven.boell@intel.com>
---
 gdb/dwarf2loc.c   |   16 +++++++++
 gdb/dwarf2loc.h   |    6 ++++
 gdb/f-typeprint.c |   62 +++++++++++++++++++++------------
 gdb/gdbtypes.c    |   99 ++++++++++++++++++++++++++++++++++++++++++++++++++---
 gdb/valarith.c    |    9 ++++-
 gdb/valprint.c    |   40 ++++++++++++++++++++++
 gdb/valprint.h    |    4 +++
 gdb/value.c       |   20 +++++++++++
 8 files changed, 229 insertions(+), 27 deletions(-)

diff --git a/gdb/dwarf2loc.c b/gdb/dwarf2loc.c
index 2bd12d6..c6802aa 100644
--- a/gdb/dwarf2loc.c
+++ b/gdb/dwarf2loc.c
@@ -2287,6 +2287,11 @@ dwarf2_evaluate_loc_desc_full (struct type *type, struct frame_info *frame,
 	    int in_stack_memory = dwarf_expr_fetch_in_stack_memory (ctx, 0);
 
 	    do_cleanups (value_chain);
+
+	    /* Select right frame to correctly evaluate VLA's during a backtrace.  */
+	    if (is_dynamic_type (type))
+	      select_frame (frame);
+
 	    retval = value_at_lazy (type, address + byte_offset);
 	    if (in_stack_memory)
 	      set_value_stack (retval, 1);
@@ -2546,6 +2551,17 @@ dwarf2_compile_property_to_c (struct ui_file *stream,
 			     data, data + size, per_cu);
 }
 
+int
+dwarf2_address_data_valid (const struct type *type)
+{
+  if (TYPE_NOT_ASSOCIATED (type))
+    return 0;
+
+  if (TYPE_NOT_ALLOCATED (type))
+    return 0;
+
+  return 1;
+}
 \f
 /* Helper functions and baton for dwarf2_loc_desc_needs_frame.  */
 
diff --git a/gdb/dwarf2loc.h b/gdb/dwarf2loc.h
index a369361..a1a059c 100644
--- a/gdb/dwarf2loc.h
+++ b/gdb/dwarf2loc.h
@@ -135,6 +135,12 @@ void dwarf2_compile_property_to_c (struct ui_file *stream,
 CORE_ADDR dwarf2_read_addr_index (struct dwarf2_per_cu_data *per_cu,
 				  unsigned int addr_index);
 
+/* Checks if a dwarf location definition is valid.
+   Returns 1 if valid; 0 otherwise.  */
+
+extern int dwarf2_address_data_valid (const struct type *type);
+
+
 /* The symbol location baton types used by the DWARF-2 reader (i.e.
    SYMBOL_LOCATION_BATON for a LOC_COMPUTED symbol).  "struct
    dwarf2_locexpr_baton" is for a symbol with a single location
diff --git a/gdb/f-typeprint.c b/gdb/f-typeprint.c
index 4957e1f..5754cd4 100644
--- a/gdb/f-typeprint.c
+++ b/gdb/f-typeprint.c
@@ -30,6 +30,7 @@
 #include "gdbcore.h"
 #include "target.h"
 #include "f-lang.h"
+#include "valprint.h"
 
 #if 0				/* Currently unused.  */
 static void f_type_print_args (struct type *, struct ui_file *);
@@ -53,6 +54,17 @@ f_print_type (struct type *type, const char *varstring, struct ui_file *stream,
   enum type_code code;
   int demangled_args;
 
+  if (TYPE_NOT_ASSOCIATED (type))
+    {
+      val_print_not_associated (stream);
+      return;
+    }
+  if (TYPE_NOT_ALLOCATED (type))
+    {
+      val_print_not_allocated (stream);
+      return;
+    }
+
   f_type_print_base (type, stream, show, level);
   code = TYPE_CODE (type);
   if ((varstring != NULL && *varstring != '\0')
@@ -167,28 +179,36 @@ f_type_print_varspec_suffix (struct type *type, struct ui_file *stream,
       if (arrayprint_recurse_level == 1)
 	fprintf_filtered (stream, "(");
 
-      if (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_ARRAY)
-	f_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 0, 0,
-				     arrayprint_recurse_level);
-
-      lower_bound = f77_get_lowerbound (type);
-      if (lower_bound != 1)	/* Not the default.  */
-	fprintf_filtered (stream, "%d:", lower_bound);
-
-      /* Make sure that, if we have an assumed size array, we
-         print out a warning and print the upperbound as '*'.  */
-
-      if (TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (type))
-	fprintf_filtered (stream, "*");
+      if (TYPE_NOT_ASSOCIATED (type))
+        val_print_not_associated (stream);
+      else if (TYPE_NOT_ALLOCATED (type))
+        val_print_not_allocated (stream);
       else
-	{
-	  upper_bound = f77_get_upperbound (type);
-	  fprintf_filtered (stream, "%d", upper_bound);
-	}
-
-      if (TYPE_CODE (TYPE_TARGET_TYPE (type)) != TYPE_CODE_ARRAY)
-	f_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 0, 0,
-				     arrayprint_recurse_level);
+        {
+
+          if (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_ARRAY)
+            f_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 0, 0,
+                 arrayprint_recurse_level);
+
+          lower_bound = f77_get_lowerbound (type);
+          if (lower_bound != 1)	/* Not the default.  */
+            fprintf_filtered (stream, "%d:", lower_bound);
+
+          /* Make sure that, if we have an assumed size array, we
+             print out a warning and print the upperbound as '*'.  */
+
+          if (TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (type))
+            fprintf_filtered (stream, "*");
+          else
+            {
+              upper_bound = f77_get_upperbound (type);
+              fprintf_filtered (stream, "%d", upper_bound);
+            }
+
+          if (TYPE_CODE (TYPE_TARGET_TYPE (type)) != TYPE_CODE_ARRAY)
+            f_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 0, 0,
+                 arrayprint_recurse_level);
+      }
       if (arrayprint_recurse_level == 1)
 	fprintf_filtered (stream, ")");
       else
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index 6d3c084..6695adb 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -1020,7 +1020,8 @@ create_array_type_with_stride (struct type *result_type,
 
   TYPE_CODE (result_type) = TYPE_CODE_ARRAY;
   TYPE_TARGET_TYPE (result_type) = element_type;
-  if (has_static_range (TYPE_RANGE_DATA (range_type)))
+  if (has_static_range (TYPE_RANGE_DATA (range_type))
+      && dwarf2_address_data_valid (result_type))
     {
       LONGEST low_bound, high_bound;
 
@@ -1630,6 +1631,11 @@ stub_noname_complaint (void)
 static int
 is_dynamic_type_internal (struct type *type, int top_level)
 {
+  int index;
+
+  if (!type)
+    return 0;
+
   type = check_typedef (type);
 
   /* We only want to recognize references at the outermost level.  */
@@ -1647,6 +1653,20 @@ is_dynamic_type_internal (struct type *type, int top_level)
 	  || TYPE_DATA_LOCATION_KIND (type) == PROP_LOCLIST))
     return 1;
 
+  if (TYPE_ASSOCIATED_PROP (type))
+    return 1;
+
+  if (TYPE_ALLOCATED_PROP (type))
+    return 1;
+
+  /* Scan field types in the Fortran case for nested dynamic types.
+     This will be done only for Fortran as in the C++ case an endless recursion
+     can occur in the area of classes.  */
+  if (current_language->la_language == language_fortran)
+    for (index = 0; index < TYPE_NFIELDS (type); index++)
+      if (is_dynamic_type (TYPE_FIELD_TYPE (type, index)))
+        return 1;
+
   switch (TYPE_CODE (type))
     {
     case TYPE_CODE_RANGE:
@@ -1702,6 +1722,7 @@ resolve_dynamic_range (struct type *dyn_range_type, CORE_ADDR addr)
   const struct dynamic_prop *prop;
   const struct dwarf2_locexpr_baton *baton;
   struct dynamic_prop low_bound, high_bound;
+  struct type *range_copy = copy_type (dyn_range_type);
 
   gdb_assert (TYPE_CODE (dyn_range_type) == TYPE_CODE_RANGE);
 
@@ -1733,8 +1754,8 @@ resolve_dynamic_range (struct type *dyn_range_type, CORE_ADDR addr)
       high_bound.data.const_val = 0;
     }
 
-  static_range_type = create_range_type (copy_type (dyn_range_type),
-					 TYPE_TARGET_TYPE (dyn_range_type),
+  static_range_type = create_range_type (range_copy,
+					 TYPE_TARGET_TYPE (range_copy),
 					 &low_bound, &high_bound);
   TYPE_RANGE_DATA (static_range_type)->flag_bound_evaluated = 1;
   return static_range_type;
@@ -1751,6 +1772,8 @@ resolve_dynamic_array (struct type *type, CORE_ADDR addr)
   struct type *elt_type;
   struct type *range_type;
   struct type *ary_dim;
+  struct dynamic_prop *prop;
+  struct type *copy = copy_type (type);
 
   gdb_assert (TYPE_CODE (type) == TYPE_CODE_ARRAY);
 
@@ -1758,14 +1781,28 @@ resolve_dynamic_array (struct type *type, CORE_ADDR addr)
   range_type = check_typedef (TYPE_INDEX_TYPE (elt_type));
   range_type = resolve_dynamic_range (range_type, addr);
 
+  prop = TYPE_ALLOCATED_PROP (type);
+  if (dwarf2_evaluate_property (prop, addr, &value))
+    {
+      TYPE_ALLOCATED_PROP (copy)->kind = PROP_CONST;
+      TYPE_ALLOCATED_PROP (copy)->data.const_val = value;
+    }
+
+  prop = TYPE_ASSOCIATED_PROP (type);
+  if (dwarf2_evaluate_property (prop, addr, &value))
+    {
+      TYPE_ASSOCIATED_PROP (copy)->kind = PROP_CONST;
+      TYPE_ASSOCIATED_PROP (copy)->data.const_val = value;
+    }
+
   ary_dim = check_typedef (TYPE_TARGET_TYPE (elt_type));
 
   if (ary_dim != NULL && TYPE_CODE (ary_dim) == TYPE_CODE_ARRAY)
-    elt_type = resolve_dynamic_array (TYPE_TARGET_TYPE (type), addr);
+    elt_type = resolve_dynamic_array (TYPE_TARGET_TYPE (copy), addr);
   else
     elt_type = TYPE_TARGET_TYPE (type);
 
-  return create_array_type (copy_type (type),
+  return create_array_type (copy,
 			    elt_type,
 			    range_type);
 }
@@ -4174,6 +4211,20 @@ copy_type_recursive (struct objfile *objfile,
 	      sizeof (struct dynamic_prop));
     }
 
+  /* Copy allocated information.  */
+  if (TYPE_ALLOCATED_PROP (type) != NULL)
+    {
+      TYPE_ALLOCATED_PROP (new_type) = xmalloc (sizeof (struct dynamic_prop));
+      *TYPE_ALLOCATED_PROP (new_type) = *TYPE_ALLOCATED_PROP (type);
+    }
+
+  /* Copy associated information.  */
+  if (TYPE_ASSOCIATED_PROP (type) != NULL)
+    {
+      TYPE_ASSOCIATED_PROP (new_type) = xmalloc (sizeof (struct dynamic_prop));
+      *TYPE_ASSOCIATED_PROP (new_type) = *TYPE_ASSOCIATED_PROP (type);
+    }
+
   /* Copy pointers to other types.  */
   if (TYPE_TARGET_TYPE (type))
     TYPE_TARGET_TYPE (new_type) = 
@@ -4227,6 +4278,44 @@ copy_type (const struct type *type)
 	      sizeof (struct dynamic_prop));
     }
 
+  if (TYPE_ALLOCATED_PROP (type))
+    {
+      TYPE_ALLOCATED_PROP (new_type)
+              = OBSTACK_ZALLOC (&TYPE_OWNER (type).objfile->objfile_obstack,
+                                struct dynamic_prop);
+      memcpy (TYPE_ALLOCATED_PROP (new_type), TYPE_ALLOCATED_PROP (type),
+        sizeof (struct dynamic_prop));
+    }
+
+  if (TYPE_ASSOCIATED_PROP (type))
+    {
+      TYPE_ASSOCIATED_PROP (new_type)
+              = OBSTACK_ZALLOC (&TYPE_OWNER (type).objfile->objfile_obstack,
+                                struct dynamic_prop);
+      memcpy (TYPE_ASSOCIATED_PROP (new_type), TYPE_ASSOCIATED_PROP (type),
+        sizeof (struct dynamic_prop));
+    }
+
+  if (TYPE_DATA_LOCATION (type))
+    {
+      TYPE_DATA_LOCATION (new_type)
+              = OBSTACK_ZALLOC (&TYPE_OWNER (type).objfile->objfile_obstack,
+                                struct dynamic_prop);
+      memcpy (TYPE_DATA_LOCATION (new_type), TYPE_DATA_LOCATION (type),
+        sizeof (struct dynamic_prop));
+    }
+
+  if (TYPE_NFIELDS (type))
+    {
+      int nfields = TYPE_NFIELDS (type);
+
+      TYPE_FIELDS (new_type)
+              = OBSTACK_CALLOC (&TYPE_OWNER (type).objfile->objfile_obstack,
+                                nfields, struct field);
+      memcpy (TYPE_FIELDS (new_type), TYPE_FIELDS (type),
+        nfields * sizeof (struct field));
+   }
+
   return new_type;
 }
 \f
diff --git a/gdb/valarith.c b/gdb/valarith.c
index f33515c..e2af354 100644
--- a/gdb/valarith.c
+++ b/gdb/valarith.c
@@ -198,7 +198,14 @@ value_subscripted_rvalue (struct value *array, LONGEST index, int lowerbound)
 
   if (index < lowerbound || (!TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (array_type)
 			     && elt_offs >= TYPE_LENGTH (array_type)))
-    error (_("no such vector element"));
+    {
+      if (TYPE_NOT_ASSOCIATED (array_type))
+        error (_("no such vector element because not associated"));
+      else if (TYPE_NOT_ALLOCATED (array_type))
+        error (_("no such vector element because not allocated"));
+      else
+        error (_("no such vector element"));
+    }
 
   if (VALUE_LVAL (array) == lval_memory && value_lazy (array))
     v = allocate_value_lazy (elt_type);
diff --git a/gdb/valprint.c b/gdb/valprint.c
index 29a3473..3ae8994 100644
--- a/gdb/valprint.c
+++ b/gdb/valprint.c
@@ -303,6 +303,18 @@ valprint_check_validity (struct ui_file *stream,
 {
   CHECK_TYPEDEF (type);
 
+  if (TYPE_NOT_ASSOCIATED (type))
+    {
+      val_print_not_associated (stream);
+      return 0;
+    }
+
+  if (TYPE_NOT_ALLOCATED (type))
+    {
+      val_print_not_allocated (stream);
+      return 0;
+    }
+
   if (TYPE_CODE (type) != TYPE_CODE_UNION
       && TYPE_CODE (type) != TYPE_CODE_STRUCT
       && TYPE_CODE (type) != TYPE_CODE_ARRAY)
@@ -359,6 +371,18 @@ val_print_invalid_address (struct ui_file *stream)
   fprintf_filtered (stream, _("<invalid address>"));
 }
 
+void
+val_print_not_allocated (struct ui_file *stream)
+{
+  fprintf_filtered (stream, _("<not allocated>"));
+}
+
+void
+val_print_not_associated (struct ui_file *stream)
+{
+  fprintf_filtered (stream, _("<not associated>"));
+}
+
 /* A generic val_print that is suitable for use by language
    implementations of the la_val_print method.  This function can
    handle most type codes, though not all, notably exception
@@ -800,12 +824,16 @@ static int
 value_check_printable (struct value *val, struct ui_file *stream,
 		       const struct value_print_options *options)
 {
+  const struct type *type;
+
   if (val == 0)
     {
       fprintf_filtered (stream, _("<address of value unknown>"));
       return 0;
     }
 
+  type = value_type (val);
+
   if (value_entirely_optimized_out (val))
     {
       if (options->summary && !val_print_scalar_type_p (value_type (val)))
@@ -831,6 +859,18 @@ value_check_printable (struct value *val, struct ui_file *stream,
       return 0;
     }
 
+  if (TYPE_NOT_ASSOCIATED (type))
+    {
+      val_print_not_associated (stream);
+      return 0;
+    }
+
+  if (TYPE_NOT_ALLOCATED (type))
+    {
+      val_print_not_allocated (stream);
+      return 0;
+    }
+
   return 1;
 }
 
diff --git a/gdb/valprint.h b/gdb/valprint.h
index e3d0137..46ca9c6 100644
--- a/gdb/valprint.h
+++ b/gdb/valprint.h
@@ -217,4 +217,8 @@ extern void output_command_const (const char *args, int from_tty);
 
 extern int val_print_scalar_type_p (struct type *type);
 
+extern void val_print_not_allocated (struct ui_file *stream);
+
+extern void val_print_not_associated (struct ui_file *stream);
+
 #endif
diff --git a/gdb/value.c b/gdb/value.c
index 9445f25..1a32347 100644
--- a/gdb/value.c
+++ b/gdb/value.c
@@ -40,6 +40,7 @@
 #include "tracepoint.h"
 #include "cp-abi.h"
 #include "user-regs.h"
+#include "dwarf2loc.h"
 
 /* Prototypes for exported functions.  */
 
@@ -1755,6 +1756,25 @@ set_value_component_location (struct value *component,
       if (funcs->copy_closure)
         component->location.computed.closure = funcs->copy_closure (whole);
     }
+
+  /* For dynamic types compute the address of the component value location in
+     sub range types based on the location of the sub range type, if not being
+     an internal GDB variable or parts of it.  */
+  if (VALUE_LVAL (component) != lval_internalvar
+      && VALUE_LVAL (component) != lval_internalvar_component)
+    {
+      CORE_ADDR addr;
+      struct type *type = value_type (whole);
+
+      addr = value_raw_address (component);
+
+      if (TYPE_DATA_LOCATION (type)
+          && TYPE_DATA_LOCATION_KIND (type) == PROP_CONST)
+        {
+          addr = TYPE_DATA_LOCATION_ADDR (type);
+          set_value_address (component, addr);
+        }
+    }
 }
 
 \f
-- 
1.7.9.5

^ permalink raw reply	[flat|nested] 53+ messages in thread

* [V4 12/18] test: add archer dynamic other frame test
  2015-01-14 13:49 [V4 00/21] Fortran dynamic array support Keven Boell
                   ` (15 preceding siblings ...)
  2015-01-14 13:50 ` [V4 14/18] vla: use value constructor instead of raw-buffer manipulation Keven Boell
@ 2015-01-14 13:50 ` Keven Boell
  2015-01-14 13:50 ` [V4 08/18] test: dynamic arrays passed to functions Keven Boell
                   ` (3 subsequent siblings)
  20 siblings, 0 replies; 53+ messages in thread
From: Keven Boell @ 2015-01-14 13:50 UTC (permalink / raw)
  To: gdb-patches; +Cc: Keven Boell

Add dynamic other frame test written by Jan
Kratochvil.

testsuite/gdb.fortran/:

	* dynamic-other-frame-stub.f90: New file.
	* dynamic-other-frame.exp: New file.
	* dynamic-other-frame.f90: New file.



Signed-off-by: Keven Boell <keven.boell@intel.com>
---
 .../gdb.fortran/dynamic-other-frame-stub.f90       |   24 ++++++++++++
 gdb/testsuite/gdb.fortran/dynamic-other-frame.exp  |   39 ++++++++++++++++++++
 gdb/testsuite/gdb.fortran/dynamic-other-frame.f90  |   36 ++++++++++++++++++
 3 files changed, 99 insertions(+)
 create mode 100644 gdb/testsuite/gdb.fortran/dynamic-other-frame-stub.f90
 create mode 100644 gdb/testsuite/gdb.fortran/dynamic-other-frame.exp
 create mode 100644 gdb/testsuite/gdb.fortran/dynamic-other-frame.f90

diff --git a/gdb/testsuite/gdb.fortran/dynamic-other-frame-stub.f90 b/gdb/testsuite/gdb.fortran/dynamic-other-frame-stub.f90
new file mode 100644
index 0000000..f9286cd
--- /dev/null
+++ b/gdb/testsuite/gdb.fortran/dynamic-other-frame-stub.f90
@@ -0,0 +1,24 @@
+! Copyright 2015 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 2 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, write to the Free Software
+! Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+!
+! Ihis file is the Fortran source file for dynamic.exp.
+! Original file written by Jakub Jelinek <jakub@redhat.com>.
+! Modified for the GDB testcase by Jan Kratochvil <jan.kratochvil@redhat.com>.
+
+subroutine bar
+  real :: dummy
+  dummy = 1
+end subroutine bar
diff --git a/gdb/testsuite/gdb.fortran/dynamic-other-frame.exp b/gdb/testsuite/gdb.fortran/dynamic-other-frame.exp
new file mode 100644
index 0000000..16227bb
--- /dev/null
+++ b/gdb/testsuite/gdb.fortran/dynamic-other-frame.exp
@@ -0,0 +1,39 @@
+# Copyright 2015 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 2 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, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  
+
+set testfile "dynamic-other-frame"
+set srcfile1 ${testfile}.f90
+set srcfile2 ${testfile}-stub.f90
+set objfile2 [standard_output_file ${testfile}-stub.o]
+set executable ${testfile}
+set binfile [standard_output_file ${executable}]
+
+if { [gdb_compile "${srcdir}/${subdir}/${srcfile2}" "${objfile2}" object {f90}] != ""
+     || [gdb_compile "${srcdir}/${subdir}/${srcfile1} ${objfile2}" "${binfile}" executable {debug f90}] != "" } {
+    untested "Couldn't compile ${srcfile1} or ${srcfile2}"
+    return -1
+}
+
+clean_restart ${executable}
+
+gdb_test_no_output "set print frame-arguments all"
+
+if ![runto bar_] then {
+    perror "couldn't run to bar_"
+    continue
+}
+
+gdb_test "bt" {foo \(string='hello'.*}
diff --git a/gdb/testsuite/gdb.fortran/dynamic-other-frame.f90 b/gdb/testsuite/gdb.fortran/dynamic-other-frame.f90
new file mode 100644
index 0000000..7ff3eda
--- /dev/null
+++ b/gdb/testsuite/gdb.fortran/dynamic-other-frame.f90
@@ -0,0 +1,36 @@
+! Copyright 2015 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 2 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, write to the Free Software
+! Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+!
+! Ihis file is the Fortran source file for dynamic.exp.
+! Original file written by Jakub Jelinek <jakub@redhat.com>.
+! Modified for the GDB testcase by Jan Kratochvil <jan.kratochvil@redhat.com>.
+
+subroutine foo (string)
+  interface
+    subroutine bar
+    end subroutine
+  end interface
+  character string*(*)
+  call bar                                ! stop-here
+end subroutine foo
+program test
+  interface
+    subroutine foo (string)
+    character string*(*)
+    end subroutine
+  end interface
+  call foo ('hello')
+end
-- 
1.7.9.5

^ permalink raw reply	[flat|nested] 53+ messages in thread

* [V4 10/18] test: basic MI test for the dynamic array support.
  2015-01-14 13:49 [V4 00/21] Fortran dynamic array support Keven Boell
                   ` (13 preceding siblings ...)
  2015-01-14 13:50 ` [V4 05/18] test: dynamic arrays passed to subroutines Keven Boell
@ 2015-01-14 13:50 ` Keven Boell
  2015-01-14 13:50 ` [V4 14/18] vla: use value constructor instead of raw-buffer manipulation Keven Boell
                   ` (5 subsequent siblings)
  20 siblings, 0 replies; 53+ messages in thread
From: Keven Boell @ 2015-01-14 13:50 UTC (permalink / raw)
  To: gdb-patches; +Cc: Keven Boell

Tests dynamic array evaluations using MI protocol.

2014-05-28  Keven Boell  <keven.boell@intel.com>
            Sanimir Agovic  <sanimir.agovic@intel.com>

testsuite/gdb.mi/:

	* mi-vla-fortran.exp: New file.
	* vla.f90: New file.



Signed-off-by: Keven Boell <keven.boell@intel.com>
---
 gdb/testsuite/gdb.mi/mi-vla-fortran.exp |  182 +++++++++++++++++++++++++++++++
 gdb/testsuite/gdb.mi/vla.f90            |   42 +++++++
 2 files changed, 224 insertions(+)
 create mode 100644 gdb/testsuite/gdb.mi/mi-vla-fortran.exp
 create mode 100644 gdb/testsuite/gdb.mi/vla.f90

diff --git a/gdb/testsuite/gdb.mi/mi-vla-fortran.exp b/gdb/testsuite/gdb.mi/mi-vla-fortran.exp
new file mode 100644
index 0000000..d191623
--- /dev/null
+++ b/gdb/testsuite/gdb.mi/mi-vla-fortran.exp
@@ -0,0 +1,182 @@
+# Copyright 2015 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/>.
+
+# Verify that, using the MI, we can evaluate a simple C Variable Length
+# Array (VLA).
+
+load_lib mi-support.exp
+set MIFLAGS "-i=mi"
+
+gdb_exit
+if [mi_gdb_start] {
+    continue
+}
+
+standard_testfile vla.f90
+
+if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable \
+     {debug f90}] != "" } {
+     untested mi-vla-fortran.exp
+     return -1
+}
+
+mi_delete_breakpoints
+mi_gdb_reinitialize_dir $srcdir/$subdir
+mi_gdb_load ${binfile}
+
+set bp_lineno [gdb_get_line_number "vla1-not-allocated"]
+mi_create_breakpoint "-t vla.f90:$bp_lineno" 1 "del" "vla" \
+  ".*vla.f90" $bp_lineno $hex \
+  "insert breakpoint at line $bp_lineno (vla not allocated)"
+mi_run_cmd
+mi_expect_stop "breakpoint-hit" "vla" "" ".*vla.f90" "$bp_lineno" \
+  { "" "disp=\"del\"" } "run to breakpoint at line $bp_lineno"
+mi_gdb_test "500-data-evaluate-expression vla1" \
+  "500\\^done,value=\"<not allocated>\"" "evaluate not allocated vla"
+
+mi_create_varobj_checked vla1_not_allocated vla1 "<not allocated>" \
+  "create local variable vla1_not_allocated"
+mi_gdb_test "501-var-info-type vla1_not_allocated" \
+  "501\\^done,type=\"<not allocated>\"" \
+  "info type variable vla1_not_allocated"
+mi_gdb_test "502-var-show-format vla1_not_allocated" \
+  "502\\^done,format=\"natural\"" \
+  "show format variable vla1_not_allocated"
+mi_gdb_test "503-var-evaluate-expression vla1_not_allocated" \
+  "503\\^done,value=\"\\\[0\\\]\"" \
+  "eval variable vla1_not_allocated"
+mi_list_array_varobj_children_with_index "vla1_not_allocated" "0" "1" \
+    "real\\\(kind=4\\\)" "get children of vla1_not_allocated"
+
+
+
+set bp_lineno [gdb_get_line_number "vla1-allocated"]
+mi_create_breakpoint "-t vla.f90:$bp_lineno" 2 "del" "vla" ".*vla.f90" \
+  $bp_lineno $hex "insert breakpoint at line $bp_lineno (vla allocated)"
+mi_run_cmd
+mi_expect_stop "breakpoint-hit" "vla" "" ".*vla.f90" "$bp_lineno" \
+  { "" "disp=\"del\"" } "run to breakpoint at line $bp_lineno"
+mi_gdb_test "510-data-evaluate-expression vla1" \
+  "510\\^done,value=\"\\(0, 0, 0, 0, 0\\)\"" "evaluate allocated vla"
+
+mi_create_varobj_checked vla1_allocated vla1 "real\\\(kind=4\\\) \\\(5\\\)" \
+  "create local variable vla1_allocated"
+mi_gdb_test "511-var-info-type vla1_allocated" \
+  "511\\^done,type=\"real\\\(kind=4\\\) \\\(5\\\)\"" \
+  "info type variable vla1_allocated"
+mi_gdb_test "512-var-show-format vla1_allocated" \
+  "512\\^done,format=\"natural\"" \
+  "show format variable vla1_allocated"
+mi_gdb_test "513-var-evaluate-expression vla1_allocated" \
+  "513\\^done,value=\"\\\[5\\\]\"" \
+  "eval variable vla1_allocated"
+mi_list_array_varobj_children_with_index "vla1_allocated" "5" "1" \
+    "real\\\(kind=4\\\)" "get children of vla1_allocated"
+
+
+set bp_lineno [gdb_get_line_number "vla1-filled"]
+mi_create_breakpoint "-t vla.f90:$bp_lineno" 3 "del" "vla" ".*vla.f90" \
+  $bp_lineno $hex "insert breakpoint at line $bp_lineno"
+mi_run_cmd
+mi_expect_stop "breakpoint-hit" "vla" "" ".*vla.f90" "$bp_lineno" \
+  { "" "disp=\"del\"" } "run to breakpoint at line $bp_lineno"
+mi_gdb_test "520-data-evaluate-expression vla1" \
+  "520\\^done,value=\"\\(1, 1, 1, 1, 1\\)\"" "evaluate filled vla"
+
+
+set bp_lineno [gdb_get_line_number "vla1-modified"]
+mi_create_breakpoint "-t vla.f90:$bp_lineno" 4 "del" "vla" ".*vla.f90" \
+  $bp_lineno $hex "insert breakpoint at line $bp_lineno"
+mi_run_cmd
+mi_expect_stop "breakpoint-hit" "vla" "" ".*vla.f90" "$bp_lineno" \
+  { "" "disp=\"del\"" } "run to breakpoint at line $bp_lineno"
+mi_gdb_test "530-data-evaluate-expression vla1" \
+  "530\\^done,value=\"\\(1, 42, 1, 24, 1\\)\"" "evaluate filled vla"
+mi_gdb_test "540-data-evaluate-expression vla1(1)" \
+  "540\\^done,value=\"1\"" "evaluate filled vla"
+mi_gdb_test "550-data-evaluate-expression vla1(2)" \
+  "550\\^done,value=\"42\"" "evaluate filled vla"
+mi_gdb_test "560-data-evaluate-expression vla1(4)" \
+  "560\\^done,value=\"24\"" "evaluate filled vla"
+
+
+set bp_lineno [gdb_get_line_number "vla1-deallocated"]
+mi_create_breakpoint "-t vla.f90:$bp_lineno" 5 "del" "vla" ".*vla.f90" \
+  $bp_lineno $hex "insert breakpoint at line $bp_lineno"
+mi_run_cmd
+mi_expect_stop "breakpoint-hit" "vla" "" ".*vla.f90" "$bp_lineno" \
+  { "" "disp=\"del\"" } "run to breakpoint at line $bp_lineno"
+mi_gdb_test "570-data-evaluate-expression vla1" \
+  "570\\^done,value=\"<not allocated>\"" "evaluate not allocated vla"
+
+
+set bp_lineno [gdb_get_line_number "pvla2-not-associated"]
+mi_create_breakpoint "-t vla.f90:$bp_lineno" 6 "del" "vla" ".*vla.f90" \
+  $bp_lineno $hex "insert breakpoint at line $bp_lineno"
+mi_run_cmd
+mi_expect_stop "breakpoint-hit" "vla" "" ".*vla.f90" "$bp_lineno" \
+  { "" "disp=\"del\"" } "run to breakpoint at line $bp_lineno"
+mi_gdb_test "580-data-evaluate-expression pvla2" \
+  "580\\^done,value=\"<not associated>\"" "evaluate not associated vla"
+
+mi_create_varobj_checked pvla2_not_associated pvla2 "<not associated>" \
+  "create local variable pvla2_not_associated"
+mi_gdb_test "581-var-info-type pvla2_not_associated" \
+  "581\\^done,type=\"<not associated>\"" \
+  "info type variable pvla2_not_associated"
+mi_gdb_test "582-var-show-format pvla2_not_associated" \
+  "582\\^done,format=\"natural\"" \
+  "show format variable pvla2_not_associated"
+mi_gdb_test "583-var-evaluate-expression pvla2_not_associated" \
+  "583\\^done,value=\"\\\[0\\\]\"" \
+  "eval variable pvla2_not_associated"
+mi_list_array_varobj_children_with_index "pvla2_not_associated" "0" "1" \
+    "real\\\(kind=4\\\)" "get children of pvla2_not_associated"
+
+
+set bp_lineno [gdb_get_line_number "pvla2-associated"]
+mi_create_breakpoint "-t vla.f90:$bp_lineno" 7 "del" "vla" ".*vla.f90" \
+  $bp_lineno $hex "insert breakpoint at line $bp_lineno"
+mi_run_cmd
+mi_expect_stop "breakpoint-hit" "vla" "" ".*vla.f90" "$bp_lineno" \
+  { "" "disp=\"del\"" } "run to breakpoint at line $bp_lineno"
+mi_gdb_test "590-data-evaluate-expression pvla2" \
+  "590\\^done,value=\"\\(\\( 2, 2, 2, 2, 2\\) \\( 2, 2, 2, 2, 2\\) \\)\"" \
+  "evaluate associated vla"
+
+mi_create_varobj_checked pvla2_associated pvla2 \
+  "real\\\(kind=4\\\) \\\(5,2\\\)" "create local variable pvla2_associated"
+mi_gdb_test "591-var-info-type pvla2_associated" \
+  "591\\^done,type=\"real\\\(kind=4\\\) \\\(5,2\\\)\"" \
+  "info type variable pvla2_associated"
+mi_gdb_test "592-var-show-format pvla2_associated" \
+  "592\\^done,format=\"natural\"" \
+  "show format variable pvla2_associated"
+mi_gdb_test "593-var-evaluate-expression pvla2_associated" \
+  "593\\^done,value=\"\\\[2\\\]\"" \
+  "eval variable pvla2_associated"
+
+
+set bp_lineno [gdb_get_line_number "pvla2-set-to-null"]
+mi_create_breakpoint "-t vla.f90:$bp_lineno" 8 "del" "vla" ".*vla.f90" \
+  $bp_lineno $hex "insert breakpoint at line $bp_lineno"
+mi_run_cmd
+mi_expect_stop "breakpoint-hit" "vla" "" ".*vla.f90" "$bp_lineno" \
+  { "" "disp=\"del\"" } "run to breakpoint at line $bp_lineno"
+mi_gdb_test "600-data-evaluate-expression pvla2" \
+  "600\\^done,value=\"<not associated>\"" "evaluate vla pointer set to null"
+
+mi_gdb_exit
+return 0
diff --git a/gdb/testsuite/gdb.mi/vla.f90 b/gdb/testsuite/gdb.mi/vla.f90
new file mode 100644
index 0000000..0b89d34
--- /dev/null
+++ b/gdb/testsuite/gdb.mi/vla.f90
@@ -0,0 +1,42 @@
+! Copyright 2015 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 vla
+  real, allocatable :: vla1 (:)
+  real, target, allocatable :: vla2(:, :)
+  real, pointer :: pvla2 (:, :)
+  logical :: l
+
+  allocate (vla1 (5))         ! vla1-not-allocated
+  l = allocated(vla1)         ! vla1-allocated
+
+  vla1(:) = 1
+  vla1(2) = 42                ! vla1-filled
+  vla1(4) = 24
+
+  deallocate (vla1)           ! vla1-modified
+  l = allocated(vla1)         ! vla1-deallocated
+
+  allocate (vla2 (5, 2))
+  vla2(:, :) = 2
+
+  pvla2 => vla2               ! pvla2-not-associated
+  l = associated(pvla2)       ! pvla2-associated
+
+  pvla2(2, 1) = 42
+
+  pvla2 => null()
+  l = associated(pvla2)       ! pvla2-set-to-null
+end program vla
-- 
1.7.9.5

^ permalink raw reply	[flat|nested] 53+ messages in thread

* [V4 17/18] vla: add stride support to fortran arrays.
  2015-01-14 13:49 [V4 00/21] Fortran dynamic array support Keven Boell
                   ` (11 preceding siblings ...)
  2015-01-14 13:50 ` [V4 02/18] vla: make dynamic fortran arrays functional Keven Boell
@ 2015-01-14 13:50 ` Keven Boell
  2015-01-14 13:50 ` [V4 05/18] test: dynamic arrays passed to subroutines Keven Boell
                   ` (7 subsequent siblings)
  20 siblings, 0 replies; 53+ messages in thread
From: Keven Boell @ 2015-01-14 13:50 UTC (permalink / raw)
  To: gdb-patches; +Cc: Keven Boell

Add stride support for dynamic fortran arrays.
Add tests for dynamic array stride use-cases.

2014-05-28  Sanimir Agovic  <sanimir.agovic@intel.com>
            Keven Boell  <keven.boell@intel.com>

	* dwarf2read.c (read_subrange_type): Read dynamic
	stride attributes.
	* gdbtypes.c (create_array_type_with_stride): Add
	stride support
	(create_range_type): Add stride parameter.
	(create_static_range_type): Pass default stride
	parameter.
	(resolve_dynamic_range): Evaluate stride baton.
	(resolve_dynamic_type): Adjust data location with
	the value of byte stride.
	* gdbtypes.h (TYPE_BYTE_STRIDE): New macro.
	(TYPE_BYTE_STRIDE_BLOCK): New macro.
	(TYPE_BYTE_STRIDE_LOCLIST): New macro.
	(TYPE_BYTE_STRIDE_KIND): New macro.
	* valarith.c (value_subscripted_rvalue): Use stride.

testsuite/gdb.fortran/:

	* vla-stride.exp: New file.
	* vla-stride.f90: New file.



Signed-off-by: Keven Boell <keven.boell@intel.com>
---
 gdb/dwarf2read.c                         |   13 +++++++--
 gdb/f-valprint.c                         |    8 +++++-
 gdb/gdbtypes.c                           |   39 ++++++++++++++++++++++----
 gdb/gdbtypes.h                           |   17 ++++++++++++
 gdb/testsuite/gdb.fortran/vla-stride.exp |   44 ++++++++++++++++++++++++++++++
 gdb/testsuite/gdb.fortran/vla-stride.f90 |   30 ++++++++++++++++++++
 gdb/valarith.c                           |   14 +++++++++-
 7 files changed, 155 insertions(+), 10 deletions(-)
 create mode 100644 gdb/testsuite/gdb.fortran/vla-stride.exp
 create mode 100644 gdb/testsuite/gdb.fortran/vla-stride.f90

diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index cfb22fe..6ee07e8 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -14773,7 +14773,7 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
   struct type *base_type, *orig_base_type;
   struct type *range_type;
   struct attribute *attr;
-  struct dynamic_prop low, high;
+  struct dynamic_prop low, high, stride;
   int low_default_is_valid;
   int high_bound_is_count = 0;
   const char *name;
@@ -14793,7 +14793,9 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
 
   low.kind = PROP_CONST;
   high.kind = PROP_CONST;
+  stride.kind = PROP_CONST;
   high.data.const_val = 0;
+  stride.data.const_val = 0;
 
   /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
      omitting DW_AT_lower_bound.  */
@@ -14826,6 +14828,13 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
       break;
     }
 
+  attr = dwarf2_attr (die, DW_AT_byte_stride, cu);
+  if (attr)
+    if (!attr_to_dynamic_prop (attr, die, cu, &stride, NULL, 0))
+        complaint (&symfile_complaints, _("Missing DW_AT_byte_stride "
+                  "- DIE at 0x%x [in module %s]"),
+             die->offset.sect_off, objfile_name (cu->objfile));
+
   attr = dwarf2_attr (die, DW_AT_lower_bound, cu);
   if (attr)
     attr_to_dynamic_prop (attr, die, cu, &low, NULL, 0);
@@ -14902,7 +14911,7 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
       && !TYPE_UNSIGNED (base_type) && (high.data.const_val & negative_mask))
     high.data.const_val |= negative_mask;
 
-  range_type = create_range_type (NULL, orig_base_type, &low, &high);
+  range_type = create_range_type (NULL, orig_base_type, &low, &high, &stride);
 
   if (high_bound_is_count)
     TYPE_RANGE_DATA (range_type)->flag_upper_bound_is_count = 1;
diff --git a/gdb/f-valprint.c b/gdb/f-valprint.c
index 40fa319..8cea9f7 100644
--- a/gdb/f-valprint.c
+++ b/gdb/f-valprint.c
@@ -121,8 +121,14 @@ f77_print_array_1 (int nss, int ndimensions, struct type *type,
 
   if (nss != ndimensions)
     {
-      size_t dim_size = TYPE_LENGTH (TYPE_TARGET_TYPE (type));
+      size_t dim_size;
       size_t offs = 0;
+      LONGEST byte_stride = abs (TYPE_BYTE_STRIDE (range_type));
+
+      if (byte_stride)
+        dim_size = byte_stride;
+      else
+        dim_size = TYPE_LENGTH (TYPE_TARGET_TYPE (type));
 
       for (i = lowerbound;
 	   (i < upperbound + 1 && (*elts) < options->print_max);
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index 967b9e5..dbfbadb 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -815,7 +815,8 @@ allocate_stub_method (struct type *type)
 struct type *
 create_range_type (struct type *result_type, struct type *index_type,
 		   const struct dynamic_prop *low_bound,
-		   const struct dynamic_prop *high_bound)
+		   const struct dynamic_prop *high_bound,
+		   const struct dynamic_prop *stride)
 {
   if (result_type == NULL)
     result_type = alloc_type_copy (index_type);
@@ -830,6 +831,7 @@ create_range_type (struct type *result_type, struct type *index_type,
     TYPE_ZALLOC (result_type, sizeof (struct range_bounds));
   TYPE_RANGE_DATA (result_type)->low = *low_bound;
   TYPE_RANGE_DATA (result_type)->high = *high_bound;
+  TYPE_RANGE_DATA (result_type)->stride = *stride;
 
   if (low_bound->kind == PROP_CONST && low_bound->data.const_val >= 0)
     TYPE_UNSIGNED (result_type) = 1;
@@ -858,7 +860,7 @@ struct type *
 create_static_range_type (struct type *result_type, struct type *index_type,
 			  LONGEST low_bound, LONGEST high_bound)
 {
-  struct dynamic_prop low, high;
+  struct dynamic_prop low, high, stride;
 
   low.kind = PROP_CONST;
   low.data.const_val = low_bound;
@@ -866,7 +868,11 @@ create_static_range_type (struct type *result_type, struct type *index_type,
   high.kind = PROP_CONST;
   high.data.const_val = high_bound;
 
-  result_type = create_range_type (result_type, index_type, &low, &high);
+  stride.kind = PROP_CONST;
+  stride.data.const_val = 0;
+
+  result_type = create_range_type (result_type, index_type,
+                                   &low, &high, &stride);
 
   return result_type;
 }
@@ -1023,16 +1029,21 @@ create_array_type_with_stride (struct type *result_type,
   if (has_static_range (TYPE_RANGE_DATA (range_type))
       && dwarf2_address_data_valid (result_type))
     {
-      LONGEST low_bound, high_bound;
+      LONGEST low_bound, high_bound, byte_stride;
 
       if (get_discrete_bounds (range_type, &low_bound, &high_bound) < 0)
 	low_bound = high_bound = 0;
       CHECK_TYPEDEF (element_type);
+
+      byte_stride = abs (TYPE_BYTE_STRIDE (range_type));
+
       /* Be careful when setting the array length.  Ada arrays can be
 	 empty arrays with the high_bound being smaller than the low_bound.
 	 In such cases, the array length should be zero.  */
       if (high_bound < low_bound)
 	TYPE_LENGTH (result_type) = 0;
+      else if (byte_stride > 0)
+	TYPE_LENGTH (result_type) = byte_stride * (high_bound - low_bound + 1);
       else if (bit_stride > 0)
 	TYPE_LENGTH (result_type) =
 	  (bit_stride * (high_bound - low_bound + 1) + 7) / 8;
@@ -1732,7 +1743,7 @@ resolve_dynamic_range (struct type *dyn_range_type, CORE_ADDR addr)
   struct type *static_range_type;
   const struct dynamic_prop *prop;
   const struct dwarf2_locexpr_baton *baton;
-  struct dynamic_prop low_bound, high_bound;
+  struct dynamic_prop low_bound, high_bound, stride;
   struct type *range_copy = copy_type (dyn_range_type);
 
   gdb_assert (TYPE_CODE (dyn_range_type) == TYPE_CODE_RANGE);
@@ -1764,10 +1775,17 @@ resolve_dynamic_range (struct type *dyn_range_type, CORE_ADDR addr)
       high_bound.kind = PROP_UNDEFINED;
       high_bound.data.const_val = 0;
     }
+  
+  prop = &TYPE_RANGE_DATA (dyn_range_type)->stride;
+  if (dwarf2_evaluate_property (prop, addr, &value))
+    {
+      stride.kind = PROP_CONST;
+      stride.data.const_val = value;
+    }
 
   static_range_type = create_range_type (range_copy,
 					 TYPE_TARGET_TYPE (range_copy),
-					 &low_bound, &high_bound);
+					 &low_bound, &high_bound, &stride);
   TYPE_RANGE_DATA (static_range_type)->flag_bound_evaluated = 1;
   return static_range_type;
 }
@@ -1988,6 +2006,15 @@ resolve_dynamic_type_internal (struct type *type, CORE_ADDR addr,
   prop = TYPE_DATA_LOCATION (resolved_type);
   if (dwarf2_evaluate_property (prop, addr, &value))
     {
+      struct type *range_type = TYPE_INDEX_TYPE (resolved_type);
+
+      /* Adjust the data location with the value of byte stride if set, which
+         can describe the separation between successive elements along the
+         dimension.  */
+      if (TYPE_BYTE_STRIDE (range_type) < 0)
+        value += (TYPE_HIGH_BOUND (range_type) - TYPE_LOW_BOUND (range_type))
+                  * TYPE_BYTE_STRIDE (range_type);
+
       TYPE_DATA_LOCATION_ADDR (resolved_type) = value;
       TYPE_DATA_LOCATION_KIND (resolved_type) = PROP_CONST;
     }
diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
index 6a8a74d..ad90da2 100644
--- a/gdb/gdbtypes.h
+++ b/gdb/gdbtypes.h
@@ -660,6 +660,10 @@ struct main_type
 
       struct dynamic_prop high;
 
+      /* * Stride of range.  */
+
+      struct dynamic_prop stride;
+
       /* True if HIGH range bound contains the number of elements in the
 	 subrange. This affects how the final hight bound is computed.  */
 
@@ -1210,6 +1214,15 @@ extern void allocate_gnat_aux_type (struct type *);
   TYPE_RANGE_DATA(range_type)->high.kind
 #define TYPE_LOW_BOUND_KIND(range_type) \
   TYPE_RANGE_DATA(range_type)->low.kind
+#define TYPE_BYTE_STRIDE(range_type) \
+  TYPE_RANGE_DATA(range_type)->stride.data.const_val
+#define TYPE_BYTE_STRIDE_BLOCK(range_type) \
+  TYPE_RANGE_DATA(range_type)->stride.data.locexpr
+#define TYPE_BYTE_STRIDE_LOCLIST(range_type) \
+  TYPE_RANGE_DATA(range_type)->stride.data.loclist
+#define TYPE_BYTE_STRIDE_KIND(range_type) \
+  TYPE_RANGE_DATA(range_type)->stride.kind
+
 
 /* Attribute accessors for the type data location.  */
 #define TYPE_DATA_LOCATION(thistype) \
@@ -1241,6 +1254,9 @@ extern void allocate_gnat_aux_type (struct type *);
    TYPE_HIGH_BOUND_UNDEFINED(TYPE_INDEX_TYPE(arraytype))
 #define TYPE_ARRAY_LOWER_BOUND_IS_UNDEFINED(arraytype) \
    TYPE_LOW_BOUND_UNDEFINED(TYPE_INDEX_TYPE(arraytype))
+#define TYPE_ARRAY_STRIDE_IS_UNDEFINED(arraytype) \
+   (TYPE_BYTE_STRIDE(TYPE_INDEX_TYPE(arraytype)) == 0)
+
 
 #define TYPE_ARRAY_UPPER_BOUND_VALUE(arraytype) \
    (TYPE_HIGH_BOUND(TYPE_INDEX_TYPE((arraytype))))
@@ -1711,6 +1727,7 @@ extern struct type *create_array_type_with_stride
 
 extern struct type *create_range_type (struct type *, struct type *,
 				       const struct dynamic_prop *,
+				       const struct dynamic_prop *,
 				       const struct dynamic_prop *);
 
 extern struct type *create_array_type (struct type *, struct type *,
diff --git a/gdb/testsuite/gdb.fortran/vla-stride.exp b/gdb/testsuite/gdb.fortran/vla-stride.exp
new file mode 100644
index 0000000..6df7951
--- /dev/null
+++ b/gdb/testsuite/gdb.fortran/vla-stride.exp
@@ -0,0 +1,44 @@
+# Copyright 2015 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/>.
+
+standard_testfile ".f90"
+
+if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile} \
+    {debug f90 quiet}] } {
+    return -1
+}
+
+if ![runto MAIN__] then {
+    perror "couldn't run to breakpoint MAIN__"
+    continue
+}
+
+gdb_breakpoint [gdb_get_line_number "re-reverse-elements"]
+gdb_continue_to_breakpoint "re-reverse-elements"
+gdb_test "print pvla" " = \\\(1, 2, 3, 4, 5, 6, 7, 8, 9, 10\\\)" \
+  "print re-reverse-elements"
+gdb_test "print pvla(1)" " = 1" "print first re-reverse-element"
+gdb_test "print pvla(10)" " = 10" "print last re-reverse-element"
+
+gdb_breakpoint [gdb_get_line_number "odd-elements"]
+gdb_continue_to_breakpoint "odd-elements"
+gdb_test "print pvla" " = \\\(1, 3, 5, 7, 9\\\)" "print odd-elements"
+gdb_test "print pvla(1)" " = 1" "print first odd-element"
+gdb_test "print pvla(5)" " = 9" "print last odd-element"
+
+gdb_breakpoint [gdb_get_line_number "single-element"]
+gdb_continue_to_breakpoint "single-element"
+gdb_test "print pvla" " = \\\(5\\\)" "print single-element"
+gdb_test "print pvla(1)" " = 5" "print one single-element"
diff --git a/gdb/testsuite/gdb.fortran/vla-stride.f90 b/gdb/testsuite/gdb.fortran/vla-stride.f90
new file mode 100644
index 0000000..a073235
--- /dev/null
+++ b/gdb/testsuite/gdb.fortran/vla-stride.f90
@@ -0,0 +1,30 @@
+! Copyright 2015 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 2 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, write to the Free Software
+! Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+program vla_stride
+  integer, target, allocatable :: vla (:)
+  integer, pointer :: pvla (:)
+
+  allocate(vla(10))
+  vla = (/ (I, I = 1,10) /)
+
+  pvla => vla(10:1:-1)
+  pvla => pvla(10:1:-1)
+  pvla => vla(1:10:2)   ! re-reverse-elements
+  pvla => vla(5:4:-2)   ! odd-elements
+
+  pvla => null()        ! single-element
+end program vla_stride
diff --git a/gdb/valarith.c b/gdb/valarith.c
index e2af354..bf54d03 100644
--- a/gdb/valarith.c
+++ b/gdb/valarith.c
@@ -193,9 +193,21 @@ value_subscripted_rvalue (struct value *array, LONGEST index, int lowerbound)
   struct type *array_type = check_typedef (value_type (array));
   struct type *elt_type = check_typedef (TYPE_TARGET_TYPE (array_type));
   unsigned int elt_size = TYPE_LENGTH (elt_type);
-  unsigned int elt_offs = elt_size * longest_to_int (index - lowerbound);
+  unsigned int elt_offs = longest_to_int (index - lowerbound);
+  LONGEST elt_stride = TYPE_BYTE_STRIDE (TYPE_INDEX_TYPE (array_type));
   struct value *v;
 
+  if (elt_stride > 0)
+    elt_offs *= elt_stride;
+  else if (elt_stride < 0)
+    {
+      int offs = (elt_offs + 1) * elt_stride;
+
+      elt_offs = TYPE_LENGTH (array_type) + offs;
+    }
+  else
+    elt_offs *= elt_size;
+
   if (index < lowerbound || (!TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (array_type)
 			     && elt_offs >= TYPE_LENGTH (array_type)))
     {
-- 
1.7.9.5

^ permalink raw reply	[flat|nested] 53+ messages in thread

* [V4 08/18] test: dynamic arrays passed to functions.
  2015-01-14 13:49 [V4 00/21] Fortran dynamic array support Keven Boell
                   ` (16 preceding siblings ...)
  2015-01-14 13:50 ` [V4 12/18] test: add archer dynamic other frame test Keven Boell
@ 2015-01-14 13:50 ` Keven Boell
  2015-05-28 20:36 ` [V4 00/21] Fortran dynamic array support Jan Kratochvil
                   ` (2 subsequent siblings)
  20 siblings, 0 replies; 53+ messages in thread
From: Keven Boell @ 2015-01-14 13:50 UTC (permalink / raw)
  To: gdb-patches; +Cc: Keven Boell

Tests for dynamic arrays passed to functions
and returned from functions.

2014-05-28  Keven Boell  <keven.boell@intel.com>
            Sanimir Agovic  <sanimir.agovic@intel.com>

testsuite/gdb.fortran/:

	* vla-func.f90: New file.
	* vla-func.exp: New file.



Signed-off-by: Keven Boell <keven.boell@intel.com>
---
 gdb/testsuite/gdb.fortran/vla-func.exp |   61 +++++++++++++++++++++++++++
 gdb/testsuite/gdb.fortran/vla-func.f90 |   71 ++++++++++++++++++++++++++++++++
 2 files changed, 132 insertions(+)
 create mode 100644 gdb/testsuite/gdb.fortran/vla-func.exp
 create mode 100644 gdb/testsuite/gdb.fortran/vla-func.f90

diff --git a/gdb/testsuite/gdb.fortran/vla-func.exp b/gdb/testsuite/gdb.fortran/vla-func.exp
new file mode 100644
index 0000000..1025cb8
--- /dev/null
+++ b/gdb/testsuite/gdb.fortran/vla-func.exp
@@ -0,0 +1,61 @@
+# Copyright 2015 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/>.
+
+standard_testfile ".f90"
+
+if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile} \
+    {debug f90 quiet}] } {
+    return -1
+}
+
+if ![runto MAIN__] then {
+    perror "couldn't run to breakpoint MAIN__"
+    continue
+}
+
+# Check VLA passed to first Fortran function.
+gdb_breakpoint [gdb_get_line_number "func1-vla-passed"]
+gdb_continue_to_breakpoint "func1-vla-passed"
+gdb_test "print vla" " = \\( *\\( *22, *22, *22,\[()22, .\]*\\)" \
+  "print vla (func1)"
+gdb_test "ptype vla" "type = integer\\\(kind=4\\\) \\\(10,10\\\)" \
+  "ptype vla (func1)"
+
+gdb_breakpoint [gdb_get_line_number "func1-vla-modified"]
+gdb_continue_to_breakpoint "func1-vla-modified"
+gdb_test "print vla(5,5)" " = 55" "print vla(5,5) (func1)"
+gdb_test "print vla(7,7)" " = 77" "print vla(5,5) (func1)"
+
+# Check if the values are correct after returning from func1
+gdb_breakpoint [gdb_get_line_number "func1-returned"]
+gdb_continue_to_breakpoint "func1-returned"
+gdb_test "print ret" " = .TRUE." "print ret after func1 returned"
+
+# Check VLA passed to second Fortran function
+gdb_breakpoint [gdb_get_line_number "func2-vla-passed"]
+gdb_continue_to_breakpoint "func2-vla-passed"
+gdb_test "print vla" \
+  " = \\\(44, 44, 44, 44, 44, 44, 44, 44, 44, 44\\\)" \
+  "print vla (func2)"
+gdb_test "ptype vla" "type = integer\\\(kind=4\\\) \\\(10\\\)" \
+  "ptype vla (func2)"
+
+# Check if the returned VLA has the correct values and ptype.
+gdb_breakpoint [gdb_get_line_number "func2-returned"]
+gdb_continue_to_breakpoint "func2-returned"
+gdb_test "print vla3" " = \\\(1, 2, 44, 4, 44, 44, 44, 8, 44, 44\\\)" \
+  "print vla3 (after func2)"
+gdb_test "ptype vla3" "type = integer\\\(kind=4\\\) \\\(10\\\)" \
+  "ptype vla3 (after func2)"
diff --git a/gdb/testsuite/gdb.fortran/vla-func.f90 b/gdb/testsuite/gdb.fortran/vla-func.f90
new file mode 100644
index 0000000..df847ca
--- /dev/null
+++ b/gdb/testsuite/gdb.fortran/vla-func.f90
@@ -0,0 +1,71 @@
+! Copyright 2015 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 2 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, write to the Free Software
+! Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+logical function func1 (vla)
+  implicit none
+  integer, allocatable :: vla (:, :)
+  func1 = allocated(vla)
+  vla(5,5) = 55               ! func1-vla-passed
+  vla(7,7) = 77
+  return                      ! func1-vla-modified
+end function func1
+
+function func2(vla)
+  implicit none
+  integer :: vla (:)
+  integer :: func2(size(vla))
+  integer :: k
+
+  vla(1) = 1                    ! func2-vla-passed
+  vla(2) = 2
+  vla(4) = 4
+  vla(8) = 8
+
+  func2 = vla
+end function func2
+
+program vla_func
+  implicit none
+  interface
+    logical function func1 (vla)
+      integer :: vla (:, :)
+    end function
+  end interface
+  interface
+    function func2 (vla)
+      integer :: vla (:)
+      integer func2(size(vla))
+    end function
+  end interface
+
+  logical :: ret
+  integer, allocatable :: vla1 (:, :)
+  integer, allocatable :: vla2 (:)
+  integer, allocatable :: vla3 (:)
+
+  ret = .FALSE.
+
+  allocate (vla1 (10,10))
+  vla1(:,:) = 22
+
+  allocate (vla2 (10))
+  vla2(:) = 44
+
+  ret = func1(vla1)
+  vla3 = func2(vla2)          ! func1-returned
+
+  ret = .TRUE.                ! func2-returned
+end program vla_func
-- 
1.7.9.5

^ permalink raw reply	[flat|nested] 53+ messages in thread

* [V4 15/18] vla: get dynamic array corner cases to work
  2015-01-14 13:49 [V4 00/21] Fortran dynamic array support Keven Boell
                   ` (4 preceding siblings ...)
  2015-01-14 13:50 ` [V4 11/18] test: test sizeof for dynamic fortran arrays Keven Boell
@ 2015-01-14 13:50 ` Keven Boell
  2015-01-14 13:50 ` [V4 13/18] vla: reconstruct value to compute bounds of target type Keven Boell
                   ` (14 subsequent siblings)
  20 siblings, 0 replies; 53+ messages in thread
From: Keven Boell @ 2015-01-14 13:50 UTC (permalink / raw)
  To: gdb-patches; +Cc: Keven Boell

This patch does not overwrite the value type in
case it is a dynamic type. For dynamic types GDB
resolved its dynamic values in a copy of the type.
The call to deprecated_set_value_type overwrites the
resolved type with the original type, which breaks
e.g. pointer to a Fortran type, which contains a dynamic
array.

Old:
(gdb) print &vla1
(PTR TO -> ( real(kind=4) (23959136:23959184))) 0x7fffffffd490

New:
(gdb) print &vla1
(PTR TO -> ( real(kind=4) (5))) 0x7fffffffd490

2014-05-28  Keven Boell  <keven.boell@intel.com>
            Sanimir Agovic  <sanimir.agovic@intel.com>

	* value.c (readjust_indirect_value_type): Add
	check for dynamic types.

testsuite/gdb.fortran:

	* vla-ptr-info.exp: New file.



Signed-off-by: Keven Boell <keven.boell@intel.com>
---
 gdb/testsuite/gdb.fortran/vla-ptr-info.exp |   32 ++++++++++++++++++++++++++++
 gdb/value.c                                |    3 ++-
 2 files changed, 34 insertions(+), 1 deletion(-)
 create mode 100644 gdb/testsuite/gdb.fortran/vla-ptr-info.exp

diff --git a/gdb/testsuite/gdb.fortran/vla-ptr-info.exp b/gdb/testsuite/gdb.fortran/vla-ptr-info.exp
new file mode 100644
index 0000000..b2d8f00
--- /dev/null
+++ b/gdb/testsuite/gdb.fortran/vla-ptr-info.exp
@@ -0,0 +1,32 @@
+# Copyright 2015 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/>.
+
+standard_testfile "vla.f90"
+
+if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile} \
+    {debug f90 quiet}] } {
+    return -1
+}
+
+if ![runto MAIN__] then {
+    perror "couldn't run to breakpoint MAIN__"
+    continue
+}
+
+# Check the status of a pointer to a dynamic array.
+gdb_breakpoint [gdb_get_line_number "pvla-associated"]
+gdb_continue_to_breakpoint "pvla-associated"
+gdb_test "print &pvla" " = \\(PTR TO -> \\( real\\(kind=4\\) \\(10,10,10\\)\\)\\) ${hex}" \
+  "print pvla pointer information"
diff --git a/gdb/value.c b/gdb/value.c
index 1a32347..002705a 100644
--- a/gdb/value.c
+++ b/gdb/value.c
@@ -3655,7 +3655,8 @@ readjust_indirect_value_type (struct value *value, struct type *enc_type,
 			      struct value *original_value)
 {
   /* Re-adjust type.  */
-  deprecated_set_value_type (value, TYPE_TARGET_TYPE (original_type));
+  if (!is_dynamic_type (TYPE_TARGET_TYPE (original_type)))
+    deprecated_set_value_type (value, TYPE_TARGET_TYPE (original_type));
 
   /* Add embedding info.  */
   set_value_enclosing_type (value, enc_type);
-- 
1.7.9.5

^ permalink raw reply	[flat|nested] 53+ messages in thread

* [V4 13/18] vla: reconstruct value to compute bounds of target type
  2015-01-14 13:49 [V4 00/21] Fortran dynamic array support Keven Boell
                   ` (5 preceding siblings ...)
  2015-01-14 13:50 ` [V4 15/18] vla: get dynamic array corner cases to work Keven Boell
@ 2015-01-14 13:50 ` Keven Boell
  2015-01-14 13:50 ` [V4 09/18] test: accessing dynamic array history values Keven Boell
                   ` (13 subsequent siblings)
  20 siblings, 0 replies; 53+ messages in thread
From: Keven Boell @ 2015-01-14 13:50 UTC (permalink / raw)
  To: gdb-patches; +Cc: Keven Boell

Printing a pointer to an array, gdb tries to print the
target type including its bounds. To follow this
semantic with vla, this patch re-constructs the value to
resolve the bounds of the target type.

2014-05-28  Sanimir Agovic  <sanimir.agovic@intel.com>
            Keven Boell  <keven.boell@intel.com>

	* typeprint.c (whatis_exp): Re-construct value to
	compute bounds of target type.
	* c-valprint.c (c_value_print): Re-construct value
	to compute bounds of target type.



Signed-off-by: Keven Boell <keven.boell@intel.com>
---
 gdb/c-valprint.c  |   11 ++++++++++-
 gdb/f-typeprint.c |    6 +++++-
 gdb/typeprint.c   |    7 +++++++
 3 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/gdb/c-valprint.c b/gdb/c-valprint.c
index 8d8b744..565730e 100644
--- a/gdb/c-valprint.c
+++ b/gdb/c-valprint.c
@@ -537,7 +537,16 @@ c_value_print (struct value *val, struct ui_file *stream,
 	{
 	  /* normal case */
 	  fprintf_filtered (stream, "(");
-	  type_print (value_type (val), "", stream, -1);
+	  if (is_dynamic_type (TYPE_TARGET_TYPE (type)))
+	    {
+	      struct value *v;
+
+	      v = value_ind (val);
+	      v = value_addr (v);
+	      type_print (value_type (v), "", stream, -1);
+	    }
+	  else
+	    type_print (value_type (val), "", stream, -1);
 	  fprintf_filtered (stream, ") ");
 	}
     }
diff --git a/gdb/f-typeprint.c b/gdb/f-typeprint.c
index 5754cd4..5d795f9 100644
--- a/gdb/f-typeprint.c
+++ b/gdb/f-typeprint.c
@@ -85,7 +85,11 @@ f_print_type (struct type *type, const char *varstring, struct ui_file *stream,
       /* For demangled function names, we have the arglist as part of the name,
          so don't print an additional pair of ()'s.  */
 
-      demangled_args = varstring[strlen (varstring) - 1] == ')'; 
+      if (strlen (varstring) > 0)
+        demangled_args = varstring[strlen (varstring) - 1] == ')';
+      else
+        demangled_args = 0;
+
       f_type_print_varspec_suffix (type, stream, show, 0, demangled_args, 0);
    }
 }
diff --git a/gdb/typeprint.c b/gdb/typeprint.c
index d39e2e3..b6ced51 100644
--- a/gdb/typeprint.c
+++ b/gdb/typeprint.c
@@ -456,6 +456,13 @@ whatis_exp (char *exp, int show)
 
   type = value_type (val);
 
+  if (TYPE_CODE (type) == TYPE_CODE_PTR)
+    if (is_dynamic_type (TYPE_TARGET_TYPE (type)))
+      {
+	val = value_addr (value_ind (val));
+	type = value_type (val);
+      }
+
   get_user_print_options (&opts);
   if (opts.objectprint)
     {
-- 
1.7.9.5

^ permalink raw reply	[flat|nested] 53+ messages in thread

* [V4 18/18] vla: add NEWS entry for dynamic array support
  2015-01-14 13:49 [V4 00/21] Fortran dynamic array support Keven Boell
                   ` (7 preceding siblings ...)
  2015-01-14 13:50 ` [V4 09/18] test: accessing dynamic array history values Keven Boell
@ 2015-01-14 13:50 ` Keven Boell
  2015-01-14 18:01   ` Eli Zaretskii
  2015-01-14 13:50 ` [V4 16/18] vla: Fortran dynamic string support Keven Boell
                   ` (11 subsequent siblings)
  20 siblings, 1 reply; 53+ messages in thread
From: Keven Boell @ 2015-01-14 13:50 UTC (permalink / raw)
  To: gdb-patches; +Cc: Keven Boell

2014-06-27  Keven Boell  <keven.boell@intel.com>
            Sanimir Agovic  <sanimir.agovic@intel.com>

	* NEWS: Add entry for dynamic array support
	in Fortran.



Signed-off-by: Keven Boell <keven.boell@intel.com>
---
 gdb/NEWS |    3 +++
 1 file changed, 3 insertions(+)

diff --git a/gdb/NEWS b/gdb/NEWS
index 9a668c4..4266b68 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -3,6 +3,9 @@
 
 *** Changes since GDB 7.8
 
+* Fortran dynamic array support: It allows the user to evaluate
+  dynamic arrays like an ordinary static array.
+
 * GDB now supports hardware watchpoints on x86 GNU Hurd.
 
 * Python Scripting
-- 
1.7.9.5

^ permalink raw reply	[flat|nested] 53+ messages in thread

* [V4 06/18] test: correct ptype of dynamic arrays in Fortran.
  2015-01-14 13:49 [V4 00/21] Fortran dynamic array support Keven Boell
                   ` (2 preceding siblings ...)
  2015-01-14 13:49 ` [V4 01/18] vla: introduce allocated/associated flags Keven Boell
@ 2015-01-14 13:50 ` Keven Boell
  2015-01-14 13:50 ` [V4 11/18] test: test sizeof for dynamic fortran arrays Keven Boell
                   ` (16 subsequent siblings)
  20 siblings, 0 replies; 53+ messages in thread
From: Keven Boell @ 2015-01-14 13:50 UTC (permalink / raw)
  To: gdb-patches; +Cc: Keven Boell

Tests ensure that the ptype of dynamic arrays in
Fortran can be printed in GDB correctly.

2014-05-28  Keven Boell  <keven.boell@intel.com>
            Sanimir Agovic  <sanimir.agovic@intel.com>

testsuite/gdb.fortran/:

	* vla-ptype.exp: New file.



Signed-off-by: Keven Boell <keven.boell@intel.com>
---
 gdb/testsuite/gdb.fortran/vla-ptype.exp |   96 +++++++++++++++++++++++++++++++
 1 file changed, 96 insertions(+)
 create mode 100644 gdb/testsuite/gdb.fortran/vla-ptype.exp

diff --git a/gdb/testsuite/gdb.fortran/vla-ptype.exp b/gdb/testsuite/gdb.fortran/vla-ptype.exp
new file mode 100644
index 0000000..cd47bbe
--- /dev/null
+++ b/gdb/testsuite/gdb.fortran/vla-ptype.exp
@@ -0,0 +1,96 @@
+# Copyright 2015 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/>.
+
+standard_testfile "vla.f90"
+
+if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile} \
+    {debug f90 quiet}] } {
+    return -1
+}
+
+if ![runto MAIN__] then {
+    perror "couldn't run to breakpoint MAIN__"
+    continue
+}
+
+# Check the ptype of various VLA states and pointer to VLA's.
+gdb_breakpoint [gdb_get_line_number "vla1-init"]
+gdb_continue_to_breakpoint "vla1-init"
+gdb_test "ptype vla1" "type = <not allocated>" "ptype vla1 not initialized"
+gdb_test "ptype vla2" "type = <not allocated>" "ptype vla2 not initialized"
+gdb_test "ptype pvla" "type = <not associated>" "ptype pvla not initialized"
+gdb_test "ptype vla1(3, 6, 9)" "no such vector element because not allocated" \
+  "ptype vla1(3, 6, 9) not initialized"
+gdb_test "ptype vla2(5, 45, 20)" \
+  "no such vector element because not allocated" \
+  "ptype vla1(5, 45, 20) not initialized"
+
+gdb_breakpoint [gdb_get_line_number "vla1-allocated"]
+gdb_continue_to_breakpoint "vla1-allocated"
+gdb_test "ptype vla1" "type = real\\\(kind=4\\\) \\\(10,10,10\\\)" \
+  "ptype vla1 allocated"
+
+gdb_breakpoint [gdb_get_line_number "vla2-allocated"]
+gdb_continue_to_breakpoint "vla2-allocated"
+gdb_test "ptype vla2" "type = real\\\(kind=4\\\) \\\(7,42:50,13:35\\\)" \
+  "ptype vla2 allocated"
+
+gdb_breakpoint [gdb_get_line_number "vla1-filled"]
+gdb_continue_to_breakpoint "vla1-filled"
+gdb_test "ptype vla1" "type = real\\\(kind=4\\\) \\\(10,10,10\\\)" \
+  "ptype vla1 filled"
+gdb_test "ptype vla1(3, 6, 9)" "type = real\\\(kind=4\\\)" \
+  "ptype vla1(3, 6, 9)"
+
+gdb_breakpoint [gdb_get_line_number "vla2-filled"]
+gdb_continue_to_breakpoint "vla2-filled"
+gdb_test "ptype vla2" "type = real\\\(kind=4\\\) \\\(7,42:50,13:35\\\)" \
+  "ptype vla2 filled"
+gdb_test "ptype vla2(5, 45, 20)" "type = real\\\(kind=4\\\)" \
+  "ptype vla1(5, 45, 20) filled"
+
+gdb_breakpoint [gdb_get_line_number "pvla-associated"]
+gdb_continue_to_breakpoint "pvla-associated"
+gdb_test "ptype pvla" "type = real\\\(kind=4\\\) \\\(10,10,10\\\)" \
+  "ptype pvla associated"
+gdb_test "ptype pvla(3, 6, 9)" "type = real\\\(kind=4\\\)" \
+  "ptype pvla(3, 6, 9)"
+
+gdb_breakpoint [gdb_get_line_number "pvla-re-associated"]
+gdb_continue_to_breakpoint "pvla-re-associated"
+gdb_test "ptype pvla" "type = real\\\(kind=4\\\) \\\(7,42:50,13:35\\\)" \
+  "ptype pvla re-associated"
+gdb_test "ptype vla2(5, 45, 20)" "type = real\\\(kind=4\\\)" \
+  "ptype vla1(5, 45, 20) re-associated"
+
+gdb_breakpoint [gdb_get_line_number "pvla-deassociated"]
+gdb_continue_to_breakpoint "pvla-deassociated"
+gdb_test "ptype pvla" "type = <not associated>" "ptype pvla deassociated"
+gdb_test "ptype pvla(5, 45, 20)" \
+  "no such vector element because not associated" \
+  "ptype pvla(5, 45, 20) not associated"
+
+gdb_breakpoint [gdb_get_line_number "vla1-deallocated"]
+gdb_continue_to_breakpoint "vla1-deallocated"
+gdb_test "ptype vla1" "type = <not allocated>" "ptype vla1 not allocated"
+gdb_test "ptype vla1(3, 6, 9)" "no such vector element because not allocated" \
+  "ptype vla1(3, 6, 9) not allocated"
+
+gdb_breakpoint [gdb_get_line_number "vla2-deallocated"]
+gdb_continue_to_breakpoint "vla2-deallocated"
+gdb_test "ptype vla2" "type = <not allocated>" "ptype vla2 not allocated"
+gdb_test "ptype vla2(5, 45, 20)" \
+  "no such vector element because not allocated" \
+  "ptype vla2(5, 45, 20) not allocated"
-- 
1.7.9.5

^ permalink raw reply	[flat|nested] 53+ messages in thread

* [V4 03/18] test: basic tests for dynamic array evaluations in Fortran.
  2015-01-14 13:49 [V4 00/21] Fortran dynamic array support Keven Boell
                   ` (9 preceding siblings ...)
  2015-01-14 13:50 ` [V4 16/18] vla: Fortran dynamic string support Keven Boell
@ 2015-01-14 13:50 ` Keven Boell
  2015-01-14 13:50 ` [V4 02/18] vla: make dynamic fortran arrays functional Keven Boell
                   ` (9 subsequent siblings)
  20 siblings, 0 replies; 53+ messages in thread
From: Keven Boell @ 2015-01-14 13:50 UTC (permalink / raw)
  To: gdb-patches; +Cc: Keven Boell

Tests ensure that values of Fortran dynamic arrays
can be evaluated correctly in various ways and states.

2014-05-28  Keven Boell  <keven.boell@intel.com>
            Sanimir Agovic  <sanimir.agovic@intel.com>

testsuite/gdb.fortran/:

	* vla.f90: New file.
	* vla-value.exp: New file.



Signed-off-by: Keven Boell <keven.boell@intel.com>
---
 gdb/testsuite/gdb.fortran/vla-value.exp |  148 +++++++++++++++++++++++++++++++
 gdb/testsuite/gdb.fortran/vla.f90       |   56 ++++++++++++
 2 files changed, 204 insertions(+)
 create mode 100644 gdb/testsuite/gdb.fortran/vla-value.exp
 create mode 100644 gdb/testsuite/gdb.fortran/vla.f90

diff --git a/gdb/testsuite/gdb.fortran/vla-value.exp b/gdb/testsuite/gdb.fortran/vla-value.exp
new file mode 100644
index 0000000..6ea1eff
--- /dev/null
+++ b/gdb/testsuite/gdb.fortran/vla-value.exp
@@ -0,0 +1,148 @@
+# Copyright 2015 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/>.
+
+standard_testfile "vla.f90"
+
+if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile} \
+     {debug f90 quiet}] } {
+    return -1
+}
+
+if ![runto MAIN__] then {
+    perror "couldn't run to breakpoint MAIN__"
+    continue
+}
+
+# Try to access values in non allocated VLA
+gdb_breakpoint [gdb_get_line_number "vla1-init"]
+gdb_continue_to_breakpoint "vla1-init"
+gdb_test "print vla1" " = <not allocated>" "print non-allocated vla1"
+gdb_test "print &vla1" \
+  " = \\\(PTR TO -> \\\( real\\\(kind=4\\\) \\\(<not allocated>\\\)\\\)\\\) $hex" \
+  "print non-allocated &vla1"
+gdb_test "print vla1(1,1,1)" "no such vector element because not allocated" \
+  "print member in non-allocated vla1 (1)"
+gdb_test "print vla1(101,202,303)" \
+  "no such vector element because not allocated" \
+  "print member in non-allocated vla1 (2)"
+gdb_test "print vla1(5,2,18)=1" "no such vector element because not allocated" \
+  "set member in non-allocated vla1"
+
+# Try to access value in allocated VLA
+gdb_breakpoint [gdb_get_line_number "vla2-allocated"]
+gdb_continue_to_breakpoint "vla2-allocated"
+gdb_test "next" "\\d+(\\t|\\s)+vla1\\\(3, 6, 9\\\) = 42" \
+  "step over value assignment of vla1"
+gdb_test "print &vla1" \
+  " = \\\(PTR TO -> \\\( real\\\(kind=4\\\) \\\(10,10,10\\\)\\\)\\\) $hex" \
+  "print allocated &vla1"
+gdb_test "print vla1(3, 6, 9)" " = 1311" "print allocated vla1(3,6,9)"
+gdb_test "print vla1(1, 3, 8)" " = 1311" "print allocated vla1(1,3,8)"
+gdb_test "print vla1(9, 9, 9) = 999" " = 999" \
+  "print allocated vla1(9,9,9)=1"
+
+# Try to access values in allocated VLA after specific assignment
+gdb_breakpoint [gdb_get_line_number "vla1-filled"]
+gdb_continue_to_breakpoint "vla1-filled"
+gdb_test "print vla1(3, 6, 9)" " = 42" \
+  "print allocated vla1(3,6,9) after specific assignment (filled)"
+gdb_test "print vla1(1, 3, 8)" " = 1001" \
+  "print allocated vla1(1,3,8) after specific assignment (filled)"
+gdb_test "print vla1(9, 9, 9)" " = 999" \
+  "print allocated vla1(9,9,9) after assignment in debugger (filled)"
+
+# Try to access values in undefined pointer to VLA (dangling)
+gdb_test "print pvla" " = <not associated>" "print undefined pvla"
+gdb_test "print &pvla" \
+  " = \\\(PTR TO -> \\\( real\\\(kind=4\\\) \\\(<not associated>\\\)\\\)\\\) $hex" \
+  "print non-associated &pvla"
+gdb_test "print pvla(1, 3, 8)" "no such vector element because not associated" \
+  "print undefined pvla(1,3,8)"
+
+# Try to access values in pointer to VLA and compare them
+gdb_breakpoint [gdb_get_line_number "pvla-associated"]
+gdb_continue_to_breakpoint "pvla-associated"
+gdb_test "print &pvla" \
+  " = \\\(PTR TO -> \\\( real\\\(kind=4\\\) \\\(10,10,10\\\)\\\)\\\) $hex" \
+  "print associated &pvla"
+gdb_test "print pvla(3, 6, 9)" " = 42" "print associated pvla(3,6,9)"
+gdb_test "print pvla(1, 3, 8)" " = 1001" "print associated pvla(1,3,8)"
+gdb_test "print pvla(9, 9, 9)" " = 999" "print associated pvla(9,9,9)"
+
+# Fill values to VLA using pointer and check
+gdb_breakpoint [gdb_get_line_number "pvla-re-associated"]
+gdb_continue_to_breakpoint "pvla-re-associated"
+gdb_test "print pvla(5, 45, 20)" \
+  " = 1" "print pvla(5, 45, 20) after filled using pointer"
+gdb_test "print vla2(5, 45, 20)" \
+  " = 1" "print vla2(5, 45, 20) after filled using pointer"
+gdb_test "print pvla(7, 45, 14)" " = 2" \
+  "print pvla(7, 45, 14) after filled using pointer"
+gdb_test "print vla2(7, 45, 14)" " = 2" \
+  "print vla2(7, 45, 14) after filled using pointer"
+
+# Try to access values of deassociated VLA pointer
+gdb_breakpoint [gdb_get_line_number "pvla-deassociated"]
+gdb_continue_to_breakpoint "pvla-deassociated"
+gdb_test "print pvla(5, 45, 20)" \
+  "no such vector element because not associated" \
+  "print pvla(5, 45, 20) after deassociated"
+gdb_test "print pvla(7, 45, 14)" \
+  "no such vector element because not associated" \
+  "print pvla(7, 45, 14) after dissasociated"
+gdb_test "print pvla" " = <not associated>" \
+  "print vla1 after deassociated"
+
+# Try to access values of deallocated VLA
+gdb_breakpoint [gdb_get_line_number "vla1-deallocated"]
+gdb_continue_to_breakpoint "vla1-deallocated"
+gdb_test "print vla1(3, 6, 9)" "no such vector element because not allocated" \
+  "print allocated vla1(3,6,9) after specific assignment (deallocated)"
+gdb_test "print vla1(1, 3, 8)" "no such vector element because not allocated" \
+  "print allocated vla1(1,3,8) after specific assignment (deallocated)"
+gdb_test "print vla1(9, 9, 9)" "no such vector element because not allocated" \
+  "print allocated vla1(9,9,9) after assignment in debugger (deallocated)"
+
+
+# Try to assign VLA to user variable
+clean_restart ${testfile}
+
+if ![runto MAIN__] then {
+    perror "couldn't run to breakpoint MAIN__"
+    continue
+}
+gdb_breakpoint [gdb_get_line_number "vla2-allocated"]
+gdb_continue_to_breakpoint "vla2-allocated"
+gdb_test "next" "\\d+.*vla1\\(3, 6, 9\\) = 42" "next (1)"
+
+gdb_test_no_output "set \$myvar = vla1" "set \$myvar = vla1"
+gdb_test "print \$myvar" \
+  " = \\( *\\( *\\( *1311, *1311, *1311,\[()1311, .\]*\\)" \
+  "print \$myvar set to vla1"
+
+gdb_test "next" "\\d+.*vla1\\(1, 3, 8\\) = 1001" "next (2)"
+gdb_test "print \$myvar(3,6,9)" " = 1311" "print \$myvar(3,6,9)"
+
+gdb_breakpoint [gdb_get_line_number "pvla-associated"]
+gdb_continue_to_breakpoint "pvla-associated"
+gdb_test_no_output "set \$mypvar = pvla" "set \$mypvar = pvla"
+gdb_test "print \$mypvar(1,3,8)" " = 1001" "print \$mypvar(1,3,8)"
+
+# deallocate pointer and make sure user defined variable still has the
+# right value.
+gdb_breakpoint [gdb_get_line_number "pvla-deassociated"]
+gdb_continue_to_breakpoint "pvla-deassociated"
+gdb_test "print \$mypvar(1,3,8)" " = 1001" \
+  "print \$mypvar(1,3,8) after deallocated"
diff --git a/gdb/testsuite/gdb.fortran/vla.f90 b/gdb/testsuite/gdb.fortran/vla.f90
new file mode 100644
index 0000000..61e22b9
--- /dev/null
+++ b/gdb/testsuite/gdb.fortran/vla.f90
@@ -0,0 +1,56 @@
+! Copyright 2015 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 vla
+  real, target, allocatable :: vla1 (:, :, :)
+  real, target, allocatable :: vla2 (:, :, :)
+  real, target, allocatable :: vla3 (:, :)
+  real, pointer :: pvla (:, :, :)
+  logical :: l
+
+  allocate (vla1 (10,10,10))          ! vla1-init
+  l = allocated(vla1)
+
+  allocate (vla2 (1:7,42:50,13:35))   ! vla1-allocated
+  l = allocated(vla2)
+
+  vla1(:, :, :) = 1311                ! vla2-allocated
+  vla1(3, 6, 9) = 42
+  vla1(1, 3, 8) = 1001
+  vla1(6, 2, 7) = 13
+
+  vla2(:, :, :) = 1311                ! vla1-filled
+  vla2(5, 45, 20) = 42
+
+  pvla => vla1                        ! vla2-filled
+  l = associated(pvla)
+
+  pvla => vla2                        ! pvla-associated
+  l = associated(pvla)
+  pvla(5, 45, 20) = 1
+  pvla(7, 45, 14) = 2
+
+  pvla => null()                      ! pvla-re-associated
+  l = associated(pvla)
+
+  deallocate (vla1)                   ! pvla-deassociated
+  l = allocated(vla1)
+
+  deallocate (vla2)                   ! vla1-deallocated
+  l = allocated(vla2)
+
+  allocate (vla3 (2,2))               ! vla2-deallocated
+  vla3(:,:) = 13
+end program vla
-- 
1.7.9.5

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [V4 18/18] vla: add NEWS entry for dynamic array support
  2015-01-14 13:50 ` [V4 18/18] vla: add NEWS entry for dynamic array support Keven Boell
@ 2015-01-14 18:01   ` Eli Zaretskii
  0 siblings, 0 replies; 53+ messages in thread
From: Eli Zaretskii @ 2015-01-14 18:01 UTC (permalink / raw)
  To: Keven Boell; +Cc: gdb-patches, keven.boell

> From: Keven Boell <keven.boell@intel.com>
> Cc: Keven Boell <keven.boell@intel.com>
> Date: Wed, 14 Jan 2015 14:49:50 +0100
> 
> 2014-06-27  Keven Boell  <keven.boell@intel.com>
>             Sanimir Agovic  <sanimir.agovic@intel.com>
> 
> 	* NEWS: Add entry for dynamic array support
> 	in Fortran.

OK.

Thanks.

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [V4 01/18] vla: introduce allocated/associated flags
  2015-01-14 13:49 ` [V4 01/18] vla: introduce allocated/associated flags Keven Boell
@ 2015-02-09  6:52   ` Joel Brobecker
  2015-02-09 23:37     ` Doug Evans
  2015-02-18 15:54     ` Keven Boell
  0 siblings, 2 replies; 53+ messages in thread
From: Joel Brobecker @ 2015-02-09  6:52 UTC (permalink / raw)
  To: Keven Boell; +Cc: gdb-patches, Doug Evans

[Copying Doug, as I think Doug has experience in this area, and is
also dealing with the kind of giant programs where size of types
really make a big difference]

> Fortran 90 provide types whose values may be dynamically
> allocated or associated with a variable under explicit
> program control. The purpose of this commit is to read
> allocated/associated DWARF tags and store them to the
> main_type.
> 
> 2014-05-28  Keven Boell  <keven.boell@intel.com>
>             Sanimir Agovic  <sanimir.agovic@intel.com>
> 
> 	* dwarf2read.c (set_die_type): Add reading of
> 	allocated/associated flags.
> 	* gdbtypes.h (struct main_type): Add allocated/
> 	associated dwarf2_prop attributes.
> 	(TYPE_ALLOCATED_PROP): New macro.
> 	(TYPE_ASSOCIATED_PROP): New macro.
> 	(TYPE_NOT_ALLOCATED): New macro.
> 	(TYPE_NOT_ASSOCIATED): New macro.

struct main_type is size-critical, so we simply cannot add
fields to it that only a very small minority of instances
will actually be using..

To avoid the size increase, I propose that we turn...

  struct dynamic_prop *data_location;

... into a chained list of dynamic properties. To determine
which type of property each element in the list is, we'll need
to introduce an enumerated type to be used as discriminant.

So, I propose something like that:

/* FIXME: Add comment.  */

enum dynamic_prop_kind
{
  /* FIXME: Document.  */
  DYNAMIC_PROP_DATA_LOCATION,
  /* FIXME: Document.  */
  DYNAMIC_PROP_ALLOCATED,
  /* FIXME: Document.  */
  DYNAMIC_PROP_ASSOCIATED,
};

/* FIXME: Document.  */

struct dynamic_prop_list
{
  enum dynamic_prop_kind kind;
  struct dynamic_prop *prop;
  struct dynamic_prop_list *next;
};

... then replace...

  struct dynamic_prop *data_location;

... into ...

  struct dynamic_prop_list *dyn_prop_list;

... and finally adjust the macros to go through the list instead of
accessing the data through the dedicated fields. Using a function
which does the search for a given kind will probably be useful.

I think you might find it easier to do it in 2 stages (and therefore
two patches):

  1. Convert the current "data_location" field to the list scheme;
  2. Then add the two new kinds of properties, which should then
     be fairly straightforward.

-- 
Joel

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [V4 02/18] vla: make dynamic fortran arrays functional.
  2015-01-14 13:50 ` [V4 02/18] vla: make dynamic fortran arrays functional Keven Boell
@ 2015-02-09  7:09   ` Joel Brobecker
  2015-02-18 16:02     ` Keven Boell
  0 siblings, 1 reply; 53+ messages in thread
From: Joel Brobecker @ 2015-02-09  7:09 UTC (permalink / raw)
  To: Keven Boell; +Cc: gdb-patches

On Wed, Jan 14, 2015 at 02:49:34PM +0100, Keven Boell wrote:
> This patch enables GDB to print the value of a dynamic
> array (VLA) if allocated/associated in fortran. If not the
> allocation status will be printed to the command line.
> 
> (gdb) p vla_not_allocated
> $1 = <not allocated>
> 
> (gdb) p vla_allocated
> $1 = (1, 2, 3)
> 
> (gdb) p vla_not_associated
> $1 = <not associated>
> 
> (gdb) p vla_associated
> $1 = (3, 2, 1)
> 
> The patch covers various locations where the allocation/
> association status makes sense to print.

There may be places where it easily makes sense, but there are
several hunks that I do not understand. I suspect that those
bits may have something to do with the 10 testcases that follow
this patch.

First of all, it's unclear to me which pieces of functionality
this patch is trying to address: It's clear that handling of
non-associated & non-allocated types is one. But are there
other pieces of functionality being added here as well?

What I propose is that we first clarify the question above, and
that once the question above is clarified, we work on the bare
minimum patch to provide the first piece of functionality on
the list, whichever one makes most sence to you. That patch
should provide not just this bare-minimum set of code changes,
but also the corresponding tests that verify the new piece of
functionality.That way, I can review code and test together,
and see why certain hunks are necessary.

Limitations that allow us to reduce the size of each patch are OK.
We can then have small patches at each iteration that lifts one
limitation at a time.

During this iterative process, I would stop and wait at each
iterative process. I think you'll be wasting a fair amout of
time at each iteration if you try to submit 20 patches each time.

Some general comments below:

> 2014-05-28  Keven Boell  <keven.boell@intel.com>
>             Sanimir Agovic  <sanimir.agovic@intel.com>
> 
> 	* dwarf2loc.c (dwarf2_address_data_valid): New
> 	function.
> 	* dwarf2loc.h (dwarf2_address_data_valid): New
> 	function.
> 	* f-typeprint.c (f_print_type): Print allocation/
> 	association status.
> 	(f_type_print_varspec_suffix): Print allocation/
> 	association status for &-operator usages.
> 	* gdbtypes.c (create_array_type_with_stride): Add
> 	query for valid data location.
> 	(is_dynamic_type): Extend dynamic type detection
> 	with allocated/associated. Add type detection for
> 	fields.
> 	(resolve_dynamic_range): Copy type before resolving
> 	it as dynamic attributes need to be preserved.
> 	(resolve_dynamic_array): Copy type before resolving
> 	it as dynamic attributes need to be preserved. Add
> 	resolving of allocated/associated attributes.
> 	(resolve_dynamic_type): Add call to nested
> 	type resolving.
> 	(copy_type_recursive): Add allocated/associated
> 	attributes to be copied.
> 	(copy_type): Copy allocated/associated/data_location
> 	as well as the fields structure if available.
> 	* valarith.c (value_subscripted_rvalue): Print allocated/
> 	associated status when indexing a VLA.
> 	* valprint.c (valprint_check_validity): Print allocated/
> 	associated status.
> 	(val_print_not_allocated): New function.
> 	(val_print_not_associated): New function.
> 	* valprint.h (val_print_not_allocated): New function.
> 	(val_print_not_associated): New function.
> 	* value.c (set_value_component_location): Adjust the value
> 	address for single value prints.
>  	    do_cleanups (value_chain);
> +
> +	    /* Select right frame to correctly evaluate VLA's during a backtrace.  */
> +	    if (is_dynamic_type (type))
> +	      select_frame (frame);

The comment has a line that's too long. There are several other
parts of this patch where lines are too long too.

> +
>  	    retval = value_at_lazy (type, address + byte_offset);
>  	    if (in_stack_memory)
>  	      set_value_stack (retval, 1);
> @@ -2546,6 +2551,17 @@ dwarf2_compile_property_to_c (struct ui_file *stream,
>  			     data, data + size, per_cu);
>  }
>  
> +int
> +dwarf2_address_data_valid (const struct type *type)

When the function documentation is in the .h file, we prefer
that comment explains where the function is documented. Eg:

/* See dwarf2loc.h.  */

This way, we do know at a single glance that the function is
documented, and where that documentation is.

> +{
> +  if (TYPE_NOT_ASSOCIATED (type))
> +    return 0;
> +
> +  if (TYPE_NOT_ALLOCATED (type))
> +    return 0;

Based on the implementation of those macros, you are definitely
making an assumption that for types that do have these properties,
those properties have been resolved. This needs to be documented,
and I am also wondering whether an assert might also be appropriate.

-- 
Joel

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [V4 01/18] vla: introduce allocated/associated flags
  2015-02-09  6:52   ` Joel Brobecker
@ 2015-02-09 23:37     ` Doug Evans
  2015-02-11  8:44       ` Joel Brobecker
  2015-02-18 15:54     ` Keven Boell
  1 sibling, 1 reply; 53+ messages in thread
From: Doug Evans @ 2015-02-09 23:37 UTC (permalink / raw)
  To: Joel Brobecker; +Cc: Keven Boell, gdb-patches

On Sun, Feb 8, 2015 at 10:52 PM, Joel Brobecker <brobecker@adacore.com> wrote:
> [Copying Doug, as I think Doug has experience in this area, and is
> also dealing with the kind of giant programs where size of types
> really make a big difference]

Thanks!

>> Fortran 90 provide types whose values may be dynamically
>> allocated or associated with a variable under explicit
>> program control. The purpose of this commit is to read
>> allocated/associated DWARF tags and store them to the
>> main_type.
>>
>> 2014-05-28  Keven Boell  <keven.boell@intel.com>
>>             Sanimir Agovic  <sanimir.agovic@intel.com>
>>
>>       * dwarf2read.c (set_die_type): Add reading of
>>       allocated/associated flags.
>>       * gdbtypes.h (struct main_type): Add allocated/
>>       associated dwarf2_prop attributes.
>>       (TYPE_ALLOCATED_PROP): New macro.
>>       (TYPE_ASSOCIATED_PROP): New macro.
>>       (TYPE_NOT_ALLOCATED): New macro.
>>       (TYPE_NOT_ASSOCIATED): New macro.
>
> struct main_type is size-critical, so we simply cannot add
> fields to it that only a very small minority of instances
> will actually be using..

Yeah.
Plus it can be really hard to get rid of them, especially as
years go by and stuff gets built on top, so best be especially
conservative when adding them.

> To avoid the size increase, I propose that we turn...
>
>   struct dynamic_prop *data_location;
>
> ... into a chained list of dynamic properties. To determine
> which type of property each element in the list is, we'll need
> to introduce an enumerated type to be used as discriminant.

I don't know the details enough at the moment to help much here,
but *some* extension of data_location does sound reasonable, and
certainly ok from the standpoint of not growing main_type. :-)

I can even imagine removing data_location from the main_type "base class"
[see below].  But I'm not advocating that that needs to be done
now or even soon.

> So, I propose something like that:
>
> /* FIXME: Add comment.  */
>
> enum dynamic_prop_kind
> {
>   /* FIXME: Document.  */
>   DYNAMIC_PROP_DATA_LOCATION,
>   /* FIXME: Document.  */
>   DYNAMIC_PROP_ALLOCATED,
>   /* FIXME: Document.  */
>   DYNAMIC_PROP_ASSOCIATED,
> };
>
> /* FIXME: Document.  */
>
> struct dynamic_prop_list
> {
>   enum dynamic_prop_kind kind;
>   struct dynamic_prop *prop;
>   struct dynamic_prop_list *next;
> };
>
> ... then replace...
>
>   struct dynamic_prop *data_location;
>
> ... into ...
>
>   struct dynamic_prop_list *dyn_prop_list;
>
> ... and finally adjust the macros to go through the list instead of
> accessing the data through the dedicated fields. Using a function
> which does the search for a given kind will probably be useful.
>
> I think you might find it easier to do it in 2 stages (and therefore
> two patches):
>
>   1. Convert the current "data_location" field to the list scheme;
>   2. Then add the two new kinds of properties, which should then
>      be fairly straightforward.

Now that vptr_fieldno is gone we've got more room in the bitfields
section of struct main_type. I can imagine having a bit there that
says that data_location lives just after the struct.
We do similar things with other space-important types.
And if data_location has iterators for read access then it'd be trivial
to first check that bit. But again I'm not suggesting that needs to
be done now (or even soon).
I like the list-with-accessor-fns approach being proposed though because
I suspect it would make removing data_location from struct main_type
straightforward if/when there's a need for it.

One can imagine, of course, that if it were easier to subclass
in the language then such things would fall out naturally instead of
needing such attention and hacks.
There's another 8 bytes in main_type, type_specific, that could go away
if the data being pointed to followed the "base class".

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [V4 01/18] vla: introduce allocated/associated flags
  2015-02-09 23:37     ` Doug Evans
@ 2015-02-11  8:44       ` Joel Brobecker
  2015-02-11 17:36         ` Doug Evans
  0 siblings, 1 reply; 53+ messages in thread
From: Joel Brobecker @ 2015-02-11  8:44 UTC (permalink / raw)
  To: Doug Evans; +Cc: Keven Boell, gdb-patches

> I can even imagine removing data_location from the main_type "base class"
> [see below].  But I'm not advocating that that needs to be done
> now or even soon.

I thought of that, also, and in the end, decided not to suggest it
because it is slightly more complex to implement. In particular,
you'd need to know whether you'll neex some extra room at the end
before you allocate the type (or else, you'll have to realloc it
later on, and this might not be easy to do when it is allocated on
an obstack). There were also minor difficulties associated to
debugging and pretty-printing, but nothing necessarily unsurmountable.

Probably, as you suggest also, sub-classing would help more.

-- 
Joel

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [V4 01/18] vla: introduce allocated/associated flags
  2015-02-11  8:44       ` Joel Brobecker
@ 2015-02-11 17:36         ` Doug Evans
  0 siblings, 0 replies; 53+ messages in thread
From: Doug Evans @ 2015-02-11 17:36 UTC (permalink / raw)
  To: Joel Brobecker; +Cc: Keven Boell, gdb-patches

On Wed, Feb 11, 2015 at 12:43 AM, Joel Brobecker <brobecker@adacore.com> wrote:
>> I can even imagine removing data_location from the main_type "base class"
>> [see below].  But I'm not advocating that that needs to be done
>> now or even soon.
>
> I thought of that, also, and in the end, decided not to suggest it
> because it is slightly more complex to implement. In particular,
> you'd need to know whether you'll neex some extra room at the end
> before you allocate the type (or else, you'll have to realloc it
> later on, and this might not be easy to do when it is allocated on
> an obstack).

Yep. 'twas on my mind as well, it's something I'd like to see
looked into.

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [V4 01/18] vla: introduce allocated/associated flags
  2015-02-09  6:52   ` Joel Brobecker
  2015-02-09 23:37     ` Doug Evans
@ 2015-02-18 15:54     ` Keven Boell
  1 sibling, 0 replies; 53+ messages in thread
From: Keven Boell @ 2015-02-18 15:54 UTC (permalink / raw)
  To: Joel Brobecker, Keven Boell; +Cc: gdb-patches, Doug Evans

On 09.02.2015 07:52, Joel Brobecker wrote:
> [Copying Doug, as I think Doug has experience in this area, and is
> also dealing with the kind of giant programs where size of types
> really make a big difference]
> 
>> Fortran 90 provide types whose values may be dynamically
>> allocated or associated with a variable under explicit
>> program control. The purpose of this commit is to read
>> allocated/associated DWARF tags and store them to the
>> main_type.
>>
>> 2014-05-28  Keven Boell  <keven.boell@intel.com>
>>             Sanimir Agovic  <sanimir.agovic@intel.com>
>>
>> 	* dwarf2read.c (set_die_type): Add reading of
>> 	allocated/associated flags.
>> 	* gdbtypes.h (struct main_type): Add allocated/
>> 	associated dwarf2_prop attributes.
>> 	(TYPE_ALLOCATED_PROP): New macro.
>> 	(TYPE_ASSOCIATED_PROP): New macro.
>> 	(TYPE_NOT_ALLOCATED): New macro.
>> 	(TYPE_NOT_ASSOCIATED): New macro.
> 
> struct main_type is size-critical, so we simply cannot add
> fields to it that only a very small minority of instances
> will actually be using..
> 
> To avoid the size increase, I propose that we turn...
> 
>   struct dynamic_prop *data_location;
> 
> ... into a chained list of dynamic properties. To determine
> which type of property each element in the list is, we'll need
> to introduce an enumerated type to be used as discriminant.
> 
> So, I propose something like that:
> 
> /* FIXME: Add comment.  */
> 
> enum dynamic_prop_kind
> {
>   /* FIXME: Document.  */
>   DYNAMIC_PROP_DATA_LOCATION,
>   /* FIXME: Document.  */
>   DYNAMIC_PROP_ALLOCATED,
>   /* FIXME: Document.  */
>   DYNAMIC_PROP_ASSOCIATED,
> };
> 
> /* FIXME: Document.  */
> 
> struct dynamic_prop_list
> {
>   enum dynamic_prop_kind kind;
>   struct dynamic_prop *prop;
>   struct dynamic_prop_list *next;
> };
> 
> ... then replace...
> 
>   struct dynamic_prop *data_location;
> 
> ... into ...
> 
>   struct dynamic_prop_list *dyn_prop_list;
> 
> ... and finally adjust the macros to go through the list instead of
> accessing the data through the dedicated fields. Using a function
> which does the search for a given kind will probably be useful.
> 
> I think you might find it easier to do it in 2 stages (and therefore
> two patches):
> 
>   1. Convert the current "data_location" field to the list scheme;
>   2. Then add the two new kinds of properties, which should then
>      be fairly straightforward.
> 

Hi Joel,

Thanks for your reply. Appreciate the time you invested for reviewing the patches.
I will re-work this part to have the new attributes as a linked list as you proposed and will come up with an updated patch series.

Thanks,
Keven

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [V4 02/18] vla: make dynamic fortran arrays functional.
  2015-02-09  7:09   ` Joel Brobecker
@ 2015-02-18 16:02     ` Keven Boell
  2015-02-22  4:23       ` Joel Brobecker
  0 siblings, 1 reply; 53+ messages in thread
From: Keven Boell @ 2015-02-18 16:02 UTC (permalink / raw)
  To: Joel Brobecker, Keven Boell; +Cc: gdb-patches

On 09.02.2015 08:09, Joel Brobecker wrote:
> On Wed, Jan 14, 2015 at 02:49:34PM +0100, Keven Boell wrote:
>> This patch enables GDB to print the value of a dynamic
>> array (VLA) if allocated/associated in fortran. If not the
>> allocation status will be printed to the command line.
>>
>> (gdb) p vla_not_allocated
>> $1 = <not allocated>
>>
>> (gdb) p vla_allocated
>> $1 = (1, 2, 3)
>>
>> (gdb) p vla_not_associated
>> $1 = <not associated>
>>
>> (gdb) p vla_associated
>> $1 = (3, 2, 1)
>>
>> The patch covers various locations where the allocation/
>> association status makes sense to print.
> 
> There may be places where it easily makes sense, but there are
> several hunks that I do not understand. I suspect that those
> bits may have something to do with the 10 testcases that follow
> this patch.
> 
> First of all, it's unclear to me which pieces of functionality
> this patch is trying to address: It's clear that handling of
> non-associated & non-allocated types is one. But are there
> other pieces of functionality being added here as well?

Basically the whole support for Fortran dynamic arrays is covered in this patch, not only the support allocated/associated states.

> 
> What I propose is that we first clarify the question above, and
> that once the question above is clarified, we work on the bare
> minimum patch to provide the first piece of functionality on
> the list, whichever one makes most sence to you. That patch
> should provide not just this bare-minimum set of code changes,
> but also the corresponding tests that verify the new piece of
> functionality.That way, I can review code and test together,
> and see why certain hunks are necessary.

I thought it would be good to have one patch, which enables the dynamic array support completely and not having individual small patches, which might not functional at all. All the tests following this patch are testing various functionality in the area of dynamic arrays.
I will think about it if it's possible to split them.

> 
> Limitations that allow us to reduce the size of each patch are OK.
> We can then have small patches at each iteration that lifts one
> limitation at a time.
> 
> During this iterative process, I would stop and wait at each
> iterative process. I think you'll be wasting a fair amout of
> time at each iteration if you try to submit 20 patches each time.

I see, sounds reasonable to me.

> 
> Some general comments below:
> 
>> 2014-05-28  Keven Boell  <keven.boell@intel.com>
>>             Sanimir Agovic  <sanimir.agovic@intel.com>
>>
>> 	* dwarf2loc.c (dwarf2_address_data_valid): New
>> 	function.
>> 	* dwarf2loc.h (dwarf2_address_data_valid): New
>> 	function.
>> 	* f-typeprint.c (f_print_type): Print allocation/
>> 	association status.
>> 	(f_type_print_varspec_suffix): Print allocation/
>> 	association status for &-operator usages.
>> 	* gdbtypes.c (create_array_type_with_stride): Add
>> 	query for valid data location.
>> 	(is_dynamic_type): Extend dynamic type detection
>> 	with allocated/associated. Add type detection for
>> 	fields.
>> 	(resolve_dynamic_range): Copy type before resolving
>> 	it as dynamic attributes need to be preserved.
>> 	(resolve_dynamic_array): Copy type before resolving
>> 	it as dynamic attributes need to be preserved. Add
>> 	resolving of allocated/associated attributes.
>> 	(resolve_dynamic_type): Add call to nested
>> 	type resolving.
>> 	(copy_type_recursive): Add allocated/associated
>> 	attributes to be copied.
>> 	(copy_type): Copy allocated/associated/data_location
>> 	as well as the fields structure if available.
>> 	* valarith.c (value_subscripted_rvalue): Print allocated/
>> 	associated status when indexing a VLA.
>> 	* valprint.c (valprint_check_validity): Print allocated/
>> 	associated status.
>> 	(val_print_not_allocated): New function.
>> 	(val_print_not_associated): New function.
>> 	* valprint.h (val_print_not_allocated): New function.
>> 	(val_print_not_associated): New function.
>> 	* value.c (set_value_component_location): Adjust the value
>> 	address for single value prints.
>>  	    do_cleanups (value_chain);
>> +
>> +	    /* Select right frame to correctly evaluate VLA's during a backtrace.  */
>> +	    if (is_dynamic_type (type))
>> +	      select_frame (frame);
> 
> The comment has a line that's too long. There are several other
> parts of this patch where lines are too long too.
> 
>> +
>>  	    retval = value_at_lazy (type, address + byte_offset);
>>  	    if (in_stack_memory)
>>  	      set_value_stack (retval, 1);
>> @@ -2546,6 +2551,17 @@ dwarf2_compile_property_to_c (struct ui_file *stream,
>>  			     data, data + size, per_cu);
>>  }
>>  
>> +int
>> +dwarf2_address_data_valid (const struct type *type)
> 
> When the function documentation is in the .h file, we prefer
> that comment explains where the function is documented. Eg:
> 
> /* See dwarf2loc.h.  */
> 
> This way, we do know at a single glance that the function is
> documented, and where that documentation is.
> 
>> +{
>> +  if (TYPE_NOT_ASSOCIATED (type))
>> +    return 0;
>> +
>> +  if (TYPE_NOT_ALLOCATED (type))
>> +    return 0;
> 
> Based on the implementation of those macros, you are definitely
> making an assumption that for types that do have these properties,
> those properties have been resolved. This needs to be documented,
> and I am also wondering whether an assert might also be appropriate.
> 

Yes, this assumption is done as this is the main idea behind the implementation.
Will add add an assert.

Thanks,
Keven

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [V4 02/18] vla: make dynamic fortran arrays functional.
  2015-02-18 16:02     ` Keven Boell
@ 2015-02-22  4:23       ` Joel Brobecker
  0 siblings, 0 replies; 53+ messages in thread
From: Joel Brobecker @ 2015-02-22  4:23 UTC (permalink / raw)
  To: Keven Boell; +Cc: Keven Boell, gdb-patches

> Basically the whole support for Fortran dynamic arrays is covered in
> this patch, not only the support allocated/associated states.

That's just too much for me to grok, and I think that's also going
to make it harder later on to figure out why a certain piece of
your changes is needed or not. When testing is fairly complete
and it is affecting a mainstream language such as C, commenting
the code out can help figure things out. But this is still sub-
optimal, and nearly out of reach for less available languages such
as Fortran.

To give you an example showing that this is very necessary, we are
currently trying to figure out, at AdaCore, why reference types
are considered dynamic if their target type is dynamic. If I had
asked that question earlier on, we wouldn't be trying to find
the info a posteriori.

> I thought it would be good to have one patch, which enables the
> dynamic array support completely and not having individual small
> patches, which might not functional at all. All the tests following
> this patch are testing various functionality in the area of dynamic
> arrays.

Here's a suggestion of how I sometimes approach that problem.

Start from a clean checkout and build it. Then use a program
that has the simplest situation of an associated array, and
start by adding the code that reads the DWARF info, and then
keep adding code until GDB is able to print "<unassociated>"
for that array.

If you need additional changes to be able to print the correct
value of associated arrays, leave those for later. We can deal
deal with that as a separate patch (assuming no regression
elsewhere, but I don't see how this could happen).

Once we have that, we can start working on your testcase, and
test the feature that you just introduced, within the limitations
that your simplified patch currently have. Make that one patch,
and send it.

Once we have the first patch reviewed, and pushed to the GDB
repository, we can claim that as first progress, and show
that we have something for our efforts. Then we iterate, piece
by piece, feature by feature, special-case by special-case.
Each time, we need to handle the bare minimum, and have
a corresponding new set of tests. Note that the new tests do
not need to be in a new testcase - it is perfectly fine to
add tests to a pre-existing testcase too.

I apologize if it seems a little painful for you to be working
this way, but I truly believe that it'll make things a lot easier
to review, and as a result, I believe that it'll actually take
less time to get that code accepted.

-- 
Joel

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [V4 00/21] Fortran dynamic array support
  2015-01-14 13:49 [V4 00/21] Fortran dynamic array support Keven Boell
                   ` (17 preceding siblings ...)
  2015-01-14 13:50 ` [V4 08/18] test: dynamic arrays passed to functions Keven Boell
@ 2015-05-28 20:36 ` Jan Kratochvil
  2015-05-28 20:52   ` Joel Brobecker
  2015-06-14  8:15 ` Jan Kratochvil
  2016-07-07  8:30 ` Jan Kratochvil
  20 siblings, 1 reply; 53+ messages in thread
From: Jan Kratochvil @ 2015-05-28 20:36 UTC (permalink / raw)
  To: Keven Boell; +Cc: gdb-patches, Pedro Alves

Hello,

On Wed, 14 Jan 2015 14:49:32 +0100, Keven Boell wrote:
> This patch series add Fortran dynamic array support to gdb.

I think this patch series is still not checked in, is it right?

Do you have its more recent / rebased variant?


Thanks,
Jan

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [V4 00/21] Fortran dynamic array support
  2015-05-28 20:36 ` [V4 00/21] Fortran dynamic array support Jan Kratochvil
@ 2015-05-28 20:52   ` Joel Brobecker
  0 siblings, 0 replies; 53+ messages in thread
From: Joel Brobecker @ 2015-05-28 20:52 UTC (permalink / raw)
  To: Jan Kratochvil; +Cc: Keven Boell, gdb-patches, Pedro Alves

> > This patch series add Fortran dynamic array support to gdb.
> I think this patch series is still not checked in, is it right?

The latest update on the patch series is that we worked towards
having a way to add dynamic attributes without always adding
an extra field in (space-critical) struct type. The next step
was to create a minimalistic patch that adds support for one
of the array properties, and then work our way up. This is to
allow both of us to understand the circumstances that explained
the need for each hunk, because I couldn't figure it out myself.

-- 
Joel

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [V4 00/21] Fortran dynamic array support
  2015-01-14 13:49 [V4 00/21] Fortran dynamic array support Keven Boell
                   ` (18 preceding siblings ...)
  2015-05-28 20:36 ` [V4 00/21] Fortran dynamic array support Jan Kratochvil
@ 2015-06-14  8:15 ` Jan Kratochvil
  2015-06-17 11:42   ` Boell, Keven
  2016-07-07  8:30 ` Jan Kratochvil
  20 siblings, 1 reply; 53+ messages in thread
From: Jan Kratochvil @ 2015-06-14  8:15 UTC (permalink / raw)
  To: Keven Boell; +Cc: gdb-patches

Hello,

On Wed, 14 Jan 2015 14:49:32 +0100, Keven Boell wrote:
> This patch series add Fortran dynamic array support to gdb.

does Intel some work in progress or plans for slices/subsets?  It is a working
feature in gfortran but currently not in GDB:
	http://pkgs.fedoraproject.org/cgit/gdb.git/tree/gdb-archer-vla-tests.patch#n2295
	p var(1, 2:) = (21, 31)
	p var(:, :) = ((11, 12, 13, 14) (21, 22, 23, 24) (31, 32, 33, 34))
	p var(:) = Wrong number of subscripts
	p var(:, :, :) = Wrong number of subscripts


Jan

^ permalink raw reply	[flat|nested] 53+ messages in thread

* RE: [V4 00/21] Fortran dynamic array support
  2015-06-14  8:15 ` Jan Kratochvil
@ 2015-06-17 11:42   ` Boell, Keven
  2015-07-01 12:43     ` Keven Boell
  0 siblings, 1 reply; 53+ messages in thread
From: Boell, Keven @ 2015-06-17 11:42 UTC (permalink / raw)
  To: Jan Kratochvil; +Cc: gdb-patches


[-- Attachment #1.1: Type: text/plain, Size: 915 bytes --]

Hi Jan,

I didn't have much time to work on an updated VLA series. However, as there
seems to be demand, I'll try to get an update to the mailing list by next
week.

Keven

-----Original Message-----
From: Jan Kratochvil [mailto:jan.kratochvil@redhat.com] 
Sent: Sunday, June 14, 2015 10:15 AM
To: Boell, Keven
Cc: gdb-patches@sourceware.org
Subject: Re: [V4 00/21] Fortran dynamic array support

Hello,

On Wed, 14 Jan 2015 14:49:32 +0100, Keven Boell wrote:
> This patch series add Fortran dynamic array support to gdb.

does Intel some work in progress or plans for slices/subsets?  It is a
working
feature in gfortran but currently not in GDB:
	
http://pkgs.fedoraproject.org/cgit/gdb.git/tree/gdb-archer-vla-tests.patch#n
2295
	p var(1, 2:) = (21, 31)
	p var(:, :) = ((11, 12, 13, 14) (21, 22, 23, 24) (31, 32, 33, 34))
	p var(:) = Wrong number of subscripts
	p var(:, :, :) = Wrong number of subscripts


Jan

[-- Attachment #1.2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 6608 bytes --]

[-- Attachment #2: Type: text/plain, Size: 331 bytes --]

Intel GmbH
Dornacher Strasse 1
85622 Feldkirchen/Muenchen, Deutschland
Sitz der Gesellschaft: Feldkirchen bei Muenchen
Geschaeftsfuehrer: Christian Lamprechter, Hannes Schwaderer, Douglas Lusk
Registergericht: Muenchen HRB 47456
Ust.-IdNr./VAT Registration No.: DE129385895
Citibank Frankfurt a.M. (BLZ 502 109 00) 600119052

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [V4 00/21] Fortran dynamic array support
  2015-06-17 11:42   ` Boell, Keven
@ 2015-07-01 12:43     ` Keven Boell
  0 siblings, 0 replies; 53+ messages in thread
From: Keven Boell @ 2015-07-01 12:43 UTC (permalink / raw)
  To: Boell, Keven, Jan Kratochvil; +Cc: gdb-patches

https://sourceware.org/ml/gdb-patches/2015-07/msg00019.html

Keven

On 17.06.2015 13:41, Boell, Keven wrote:
> Hi Jan,
> 
> I didn't have much time to work on an updated VLA series. However, as there
> seems to be demand, I'll try to get an update to the mailing list by next
> week.
> 
> Keven
> 
> -----Original Message-----
> From: Jan Kratochvil [mailto:jan.kratochvil@redhat.com] 
> Sent: Sunday, June 14, 2015 10:15 AM
> To: Boell, Keven
> Cc: gdb-patches@sourceware.org
> Subject: Re: [V4 00/21] Fortran dynamic array support
> 
> Hello,
> 
> On Wed, 14 Jan 2015 14:49:32 +0100, Keven Boell wrote:
>> This patch series add Fortran dynamic array support to gdb.
> 
> does Intel some work in progress or plans for slices/subsets?  It is a
> working
> feature in gfortran but currently not in GDB:
> 	
> http://pkgs.fedoraproject.org/cgit/gdb.git/tree/gdb-archer-vla-tests.patch#n
> 2295
> 	p var(1, 2:) = (21, 31)
> 	p var(:, :) = ((11, 12, 13, 14) (21, 22, 23, 24) (31, 32, 33, 34))
> 	p var(:) = Wrong number of subscripts
> 	p var(:, :, :) = Wrong number of subscripts
> 
> 
> Jan
> 
> 
> 
> Intel GmbH
> Dornacher Strasse 1
> 85622 Feldkirchen/Muenchen, Deutschland
> Sitz der Gesellschaft: Feldkirchen bei Muenchen
> Geschaeftsfuehrer: Christian Lamprechter, Hannes Schwaderer, Douglas Lusk
> Registergericht: Muenchen HRB 47456
> Ust.-IdNr./VAT Registration No.: DE129385895
> Citibank Frankfurt a.M. (BLZ 502 109 00) 600119052
> 

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [V4 00/21] Fortran dynamic array support
  2015-01-14 13:49 [V4 00/21] Fortran dynamic array support Keven Boell
                   ` (19 preceding siblings ...)
  2015-06-14  8:15 ` Jan Kratochvil
@ 2016-07-07  8:30 ` Jan Kratochvil
  2016-07-07  9:16   ` Bernhard Heckel
  20 siblings, 1 reply; 53+ messages in thread
From: Jan Kratochvil @ 2016-07-07  8:30 UTC (permalink / raw)
  To: Keven Boell; +Cc: gdb-patches

Hello Keven,

On Wed, 14 Jan 2015 14:49:32 +0100, Keven Boell wrote:
> This patch series add Fortran dynamic array support to gdb.

this series is 1.5 years old and some partial upstreaming is also 1 year old,
do you have some up-to-date remaining parts against FSF GDB trunk?

I am trying to rebase it myself but just if you do not have it prepared
already.


Thanks,
Jan

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [V4 00/21] Fortran dynamic array support
  2016-07-07  8:30 ` Jan Kratochvil
@ 2016-07-07  9:16   ` Bernhard Heckel
  2016-07-07  9:23     ` Jan Kratochvil
  0 siblings, 1 reply; 53+ messages in thread
From: Bernhard Heckel @ 2016-07-07  9:16 UTC (permalink / raw)
  To: Jan Kratochvil, Keven Boell; +Cc: gdb-patches

On 07/07/2016 10:30, Jan Kratochvil wrote:
> Hello Keven,
>
> On Wed, 14 Jan 2015 14:49:32 +0100, Keven Boell wrote:
>> This patch series add Fortran dynamic array support to gdb.
> this series is 1.5 years old and some partial upstreaming is also 1 year old,
> do you have some up-to-date remaining parts against FSF GDB trunk?
>
> I am trying to rebase it myself but just if you do not have it prepared
> already.
>
>
> Thanks,
> Jan
Hi Jan,

I took over the Fortran patches from Keven and drive implementation of 
new features and bugfixes.

I propose to create a branch on the GDB repo, containing all the 
bugfixes and features I have.
=> users/bheckel/fortran

List of features, working on current mainline code:
- Pointers, under review at the moment
- Variable Length Strings
- Alternative Entry Points
- Extended types, Access members via fully qualified name
- Setting breakpoints on internal subroutines
- OOP, print access label of types (private, public)

Bugfix:
- Handle nameless block-data, GDB will crash during read of DWARF content.

TBD:
- Intrinsic's are in the series from Keven, but I haven't took a look on 
those.


Regards,
Bernhard
Intel Deutschland GmbH
Registered Address: Am Campeon 10-12, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de
Managing Directors: Christin Eisenschmid, Christian Lamprechter
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [V4 00/21] Fortran dynamic array support
  2016-07-07  9:16   ` Bernhard Heckel
@ 2016-07-07  9:23     ` Jan Kratochvil
  0 siblings, 0 replies; 53+ messages in thread
From: Jan Kratochvil @ 2016-07-07  9:23 UTC (permalink / raw)
  To: Bernhard Heckel; +Cc: Keven Boell, gdb-patches

Hello Bernhard,

On Thu, 07 Jul 2016 11:16:05 +0200, Bernhard Heckel wrote:
> I propose to create a branch on the GDB repo, containing all the bugfixes
> and features I have.
> => users/bheckel/fortran

that is a great idea,

> List of features, working on current mainline code:
> - Pointers, under review at the moment
> - Variable Length Strings

just I would prefer a separate branch for each of these features.

Besides more flexible upstreaming personally I am interested now in off-trunk
VLA branch but probably not in the other off-trunk branches (as that
functionality was not present in current/former Fedora GDB versions so missing
those features is not a regression).


Thanks,
Jan

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [V4 00/21] Fortran dynamic array support
  2016-09-14  7:24                                     ` Bernhard Heckel
@ 2016-09-14 12:53                                       ` Jan Kratochvil
  0 siblings, 0 replies; 53+ messages in thread
From: Jan Kratochvil @ 2016-09-14 12:53 UTC (permalink / raw)
  To: Bernhard Heckel; +Cc: Weinmann, Christoph T, gdb-patches

On Wed, 14 Sep 2016 09:24:15 +0200, Bernhard Heckel wrote:
> With Fedora24, GCC 6.1.1 I see the same results as you. Investigation is
> showing that
> GCC 6.1.1 doesn't provide the stride information (DWARF) which results in
> incorrect offsets.
> 
> Are you going to file a bug for GCC?

Thanks for the investigation, sorry I did not verify that myself.

I have filed it as:
	https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77589


Thanks,
Jan

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [V4 00/21] Fortran dynamic array support
  2016-09-12 21:05                                   ` Jan Kratochvil
@ 2016-09-14  7:24                                     ` Bernhard Heckel
  2016-09-14 12:53                                       ` Jan Kratochvil
  0 siblings, 1 reply; 53+ messages in thread
From: Bernhard Heckel @ 2016-09-14  7:24 UTC (permalink / raw)
  To: Jan Kratochvil; +Cc: Weinmann, Christoph T, gdb-patches

On 12/09/2016 23:04, Jan Kratochvil wrote:
> On Wed, 07 Sep 2016 12:29:06 +0200, Bernhard Heckel wrote:
>> I just recreated my two user branches.
> I see a regression against former Intel VLA patchset for the attached testcase.
>
> gdb_test "p c40pt(2)" " = '1-hello.*"
> p c40pt(2)^M
> $2 = '\001\000\000\000\061-hello', ' ' <repeats 29 times>^M
> (gdb) FAIL: gdb.fortran/dwarf-stride.exp: p c40pt(2)
>
>
> Thanks,
> Jan
Hi Jan,

I tested with GCC 4.8.3 and IFORT 17.0.0. Both passes.

With Fedora24, GCC 6.1.1 I see the same results as you. Investigation is 
showing that
GCC 6.1.1 doesn't provide the stride information (DWARF) which results 
in incorrect offsets.

Are you going to file a bug for GCC?


BTW: Nice testcase
Intel Deutschland GmbH
Registered Address: Am Campeon 10-12, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de
Managing Directors: Christin Eisenschmid, Christian Lamprechter
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [V4 00/21] Fortran dynamic array support
  2016-09-07 10:29                                 ` Bernhard Heckel
  2016-09-07 20:05                                   ` Jan Kratochvil
@ 2016-09-12 21:05                                   ` Jan Kratochvil
  2016-09-14  7:24                                     ` Bernhard Heckel
  1 sibling, 1 reply; 53+ messages in thread
From: Jan Kratochvil @ 2016-09-12 21:05 UTC (permalink / raw)
  To: Bernhard Heckel; +Cc: Weinmann, Christoph T, gdb-patches

[-- Attachment #1: Type: text/plain, Size: 360 bytes --]

On Wed, 07 Sep 2016 12:29:06 +0200, Bernhard Heckel wrote:
> I just recreated my two user branches.

I see a regression against former Intel VLA patchset for the attached testcase.

gdb_test "p c40pt(2)" " = '1-hello.*"
p c40pt(2)^M
$2 = '\001\000\000\000\061-hello', ' ' <repeats 29 times>^M
(gdb) FAIL: gdb.fortran/dwarf-stride.exp: p c40pt(2)


Thanks,
Jan

[-- Attachment #2: 1 --]
[-- Type: text/plain, Size: 3338 bytes --]

diff --git a/gdb/testsuite/gdb.fortran/dwarf-stride.exp b/gdb/testsuite/gdb.fortran/dwarf-stride.exp
new file mode 100644
index 0000000..d7b8bea
--- /dev/null
+++ b/gdb/testsuite/gdb.fortran/dwarf-stride.exp
@@ -0,0 +1,42 @@
+# Copyright 2009 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 2 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, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  
+
+# This file was written by Jan Kratochvil <jan.kratochvil@redhat.com>.
+
+# This file is part of the gdb testsuite.  Array element stride must not be
+# specified in the number of elements but in a number of bytes instead.
+# Original problem:
+# (gdb) p c40pt(1)
+# $1 = '0-hello', ' ' <repeats 33 times>
+# (gdb) p c40pt(2)
+# warning: Fortran array stride not divisible by the element size
+
+set testfile dwarf-stride
+set srcfile ${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
+}
+
+gdb_breakpoint [gdb_get_line_number "break-here"]
+gdb_continue_to_breakpoint "break-here" ".*break-here.*"
+gdb_test "p c40pt(1)" " = '0-hello.*"
+gdb_test "p c40pt(2)" " = '1-hello.*"
diff --git a/gdb/testsuite/gdb.fortran/dwarf-stride.f90 b/gdb/testsuite/gdb.fortran/dwarf-stride.f90
new file mode 100644
index 0000000..e492b3a
--- /dev/null
+++ b/gdb/testsuite/gdb.fortran/dwarf-stride.f90
@@ -0,0 +1,40 @@
+! Copyright 2009 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 2 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, write to the Free Software
+! Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+!
+! File written by Alan Matsuoka.
+
+program repro
+
+  type small_stride
+     character*40 long_string
+     integer      small_pad
+  end type small_stride
+
+  type(small_stride), dimension (20), target :: unpleasant
+  character*40, pointer, dimension(:):: c40pt
+
+  integer i
+
+  do i = 0,19
+     unpleasant(i+1)%small_pad = i+1
+     unpleasant(i+1)%long_string = char (ichar('0') + i) // '-hello'
+  end do
+
+  c40pt => unpleasant%long_string
+
+  print *, c40pt  ! break-here
+
+end program repro

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [V4 00/21] Fortran dynamic array support
  2016-09-04 17:15                               ` Jan Kratochvil
  2016-09-07 10:29                                 ` Bernhard Heckel
@ 2016-09-07 20:24                                 ` Jan Kratochvil
  1 sibling, 0 replies; 53+ messages in thread
From: Jan Kratochvil @ 2016-09-07 20:24 UTC (permalink / raw)
  To: Bernhard Heckel; +Cc: Weinmann, Christoph T, gdb-patches

On Sun, 04 Sep 2016 19:14:53 +0200, Jan Kratochvil wrote:
> On Fri, 02 Sep 2016 15:44:15 +0200, Bernhard Heckel wrote:
> > dynamic properties in GDB is done via CORE_ADDR which is unsigned.
> > This causes the issue that the type length seems to be way to big.
> 
> Maybe that explains also a regression visible only on i686 (32-bit host).
> It still PASSes on x86_64 (64-bit host) with either native od 32-bit inferior
> (-m32):
> 
> The length is bogus (it is %rax or %eax) but it should be some number.
> 
> i686:
> ptype reg_string^M
> type = char [variable length]^M
>              ^^^^^^^^^^^^^^^
> (gdb) FAIL: gdb.dwarf2/dw2-bound-loclist.exp: ptype reg_string
> p reg_string^M
> Insufficient memory in host GDB for object of size 4160138653 bytes, maximum allowed 536870911 bytes.^M
> 
> x86_64 or x86_64 -m32:
> ptype reg_string^M
> type = char [4160048541]^M
> (gdb) PASS: gdb.dwarf2/dw2-bound-loclist.exp: ptype reg_string

Confirming also this specific issue got fixed today, great!


Thanks,
Jan

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [V4 00/21] Fortran dynamic array support
  2016-09-07 10:29                                 ` Bernhard Heckel
@ 2016-09-07 20:05                                   ` Jan Kratochvil
  2016-09-12 21:05                                   ` Jan Kratochvil
  1 sibling, 0 replies; 53+ messages in thread
From: Jan Kratochvil @ 2016-09-07 20:05 UTC (permalink / raw)
  To: Bernhard Heckel; +Cc: Weinmann, Christoph T, gdb-patches

On Wed, 07 Sep 2016 12:29:06 +0200, Bernhard Heckel wrote:
> I just recreated my two user branches.

users/bheckel/fortran-strides
users/bheckel/fortran-vla-strings


> - Fixed should be "Werror indentation" on the vla-string branch
> - Stride issues you reported in general (stride branch)
> - Stride issues on 32bit appl. running on 64bit system (gdb) (stride branch)
> - Fixed also neg. bounds on 32bit appl. running on 64bit system (stride
> branch)

Yes, confirming the 32-bit strides issues seem to be fixed, thank you very
much.

FYI I still need to carry this "selected_frame" patch for Fortran backtraces:
	https://sourceware.org/ml/gdb-patches/2016-09/msg00011.html
But I will need to reproduce it with FSF GDB sources first.


Thanks,
Jan

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [V4 00/21] Fortran dynamic array support
  2016-09-04 17:15                               ` Jan Kratochvil
@ 2016-09-07 10:29                                 ` Bernhard Heckel
  2016-09-07 20:05                                   ` Jan Kratochvil
  2016-09-12 21:05                                   ` Jan Kratochvil
  2016-09-07 20:24                                 ` Jan Kratochvil
  1 sibling, 2 replies; 53+ messages in thread
From: Bernhard Heckel @ 2016-09-07 10:29 UTC (permalink / raw)
  To: Jan Kratochvil; +Cc: Weinmann, Christoph T, gdb-patches

On 04/09/2016 19:14, Jan Kratochvil wrote:
> On Fri, 02 Sep 2016 15:44:15 +0200, Bernhard Heckel wrote:
>> dynamic properties in GDB is done via CORE_ADDR which is unsigned.
>> This causes the issue that the type length seems to be way to big.
> Maybe that explains also a regression visible only on i686 (32-bit host).
> It still PASSes on x86_64 (64-bit host) with either native od 32-bit inferior
> (-m32):
>
> The length is bogus (it is %rax or %eax) but it should be some number.
>
> i686:
> ptype reg_string^M
> type = char [variable length]^M
>               ^^^^^^^^^^^^^^^
> (gdb) FAIL: gdb.dwarf2/dw2-bound-loclist.exp: ptype reg_string
> p reg_string^M
> Insufficient memory in host GDB for object of size 4160138653 bytes, maximum allowed 536870911 bytes.^M
>
> x86_64 or x86_64 -m32:
> ptype reg_string^M
> type = char [4160048541]^M
> (gdb) PASS: gdb.dwarf2/dw2-bound-loclist.exp: ptype reg_string
>
> Attaching the Fedora testcase.
>
>
> Thanks,
> Jan
Hi Jan,

I just recreated my two user branches.
- Fixed should be "Werror indentation" on the vla-string branch
- Stride issues you reported in general (stride branch)
- Stride issues on 32bit appl. running on 64bit system (gdb) (stride branch)
- Fixed also neg. bounds on 32bit appl. running on 64bit system (stride 
branch)

Let me know your results for the two branches.


Intel Deutschland GmbH
Registered Address: Am Campeon 10-12, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de
Managing Directors: Christin Eisenschmid, Christian Lamprechter
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [V4 00/21] Fortran dynamic array support
  2016-09-02 13:44                             ` Bernhard Heckel
@ 2016-09-04 17:15                               ` Jan Kratochvil
  2016-09-07 10:29                                 ` Bernhard Heckel
  2016-09-07 20:24                                 ` Jan Kratochvil
  0 siblings, 2 replies; 53+ messages in thread
From: Jan Kratochvil @ 2016-09-04 17:15 UTC (permalink / raw)
  To: Bernhard Heckel; +Cc: Weinmann, Christoph T, gdb-patches

[-- Attachment #1: Type: text/plain, Size: 878 bytes --]

On Fri, 02 Sep 2016 15:44:15 +0200, Bernhard Heckel wrote:
> dynamic properties in GDB is done via CORE_ADDR which is unsigned.
> This causes the issue that the type length seems to be way to big.

Maybe that explains also a regression visible only on i686 (32-bit host).
It still PASSes on x86_64 (64-bit host) with either native od 32-bit inferior
(-m32):

The length is bogus (it is %rax or %eax) but it should be some number.

i686:
ptype reg_string^M
type = char [variable length]^M
             ^^^^^^^^^^^^^^^
(gdb) FAIL: gdb.dwarf2/dw2-bound-loclist.exp: ptype reg_string
p reg_string^M
Insufficient memory in host GDB for object of size 4160138653 bytes, maximum allowed 536870911 bytes.^M

x86_64 or x86_64 -m32:
ptype reg_string^M
type = char [4160048541]^M
(gdb) PASS: gdb.dwarf2/dw2-bound-loclist.exp: ptype reg_string

Attaching the Fedora testcase.


Thanks,
Jan

[-- Attachment #2: dw2-bound-loclist.patch --]
[-- Type: text/plain, Size: 10906 bytes --]

--- /dev/null	2016-08-23 22:46:08.455975850 +0200
+++ gdb-7.11.90.20160904/gdb/testsuite/gdb.dwarf2/dw2-bound-loclist.exp	2016-09-04 19:09:23.719880045 +0200
@@ -0,0 +1,66 @@
+# Copyright 2010 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/>.
+
+# Test printing variable with dynamic bounds which reference a different
+# (artificial in the GCC case) variable containing loclist as its location.
+# This testcase uses value (not address) of the referenced variable:
+# http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43762
+
+# This test can only be run on targets which support DWARF-2 and use gas.
+# For now pick a sampling of likely targets.
+if {![istarget *-*-linux*]
+    && ![istarget *-*-gnu*]
+    && ![istarget *-*-elf*]
+    && ![istarget *-*-openbsd*]
+    && ![istarget arm-*-eabi*]
+    && ![istarget powerpc-*-eabi*]} {
+    return 0
+}
+
+set testfile dw2-bound-loclist
+if { [prepare_for_testing ${testfile}.exp ${testfile} [list ${testfile}.S main.c] {}] } {
+    return -1
+}
+
+# Verify it behaves at least as an unbound array without inferior.
+
+# FIXME: FSF GDB crashes due to !has_stack_frames ().
+# But in practice that should not happen.
+# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=43762
+#set test "p a_string"
+#gdb_test_multiple $test $test {
+#    -re " = 0x\[0-9a-f\]+ \"seennotseen\"\r\n$gdb_prompt $" {
+#	pass $test
+#    }
+#    -re "No registers\\.\r\n$gdb_prompt $" {
+#	kfail "vlaregression" $test
+#    }
+#}
+#
+#gdb_test "ptype a_string" {type = char \[variable length\]}
+
+# Not runto_main as dw2-bound-loclist.S handles only the first byte of main.
+if ![runto "*main"] {
+    return -1
+}
+
+gdb_test "p a_string" { = "seen"}
+gdb_test "ptype a_string" {type = char \[4\]}
+
+gdb_test "p b_string" { = (0x[0-9a-f]+ )?"seennotseen"}
+gdb_test "ptype b_string" {type = char \[\]}
+
+# The register contains unpredictable value - the array size.
+gdb_test "ptype reg_string" {type = char \[-?[0-9]+\]}
--- /dev/null	2016-08-23 22:46:08.455975850 +0200
+++ gdb-7.11.90.20160904/gdb/testsuite/gdb.dwarf2/dw2-bound-loclist.S	2016-09-04 19:09:23.719880045 +0200
@@ -0,0 +1,246 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2010 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/>.  */
+
+/* Debug information */
+
+/* We will `break *main' at the very first instruction.  */
+#define main_length 1
+
+	.section	.data
+vardata:
+	/* See DW_OP_lit3 + 1 (0-based).  */
+	.string		"seennotseen"
+
+	.section	.debug_info
+.Lcu1_begin:
+	.4byte		.Lcu1_end - .Lcu1_start	/* Length of Compilation Unit */
+.Lcu1_start:
+	.2byte		2			/* DWARF version number */
+	.4byte		.Ldebug_abbrev0		/* Offset Into Abbrev. Section */
+	.byte		4			/* Pointer Size (in bytes) */
+
+	/* CU die */
+	.uleb128	1			/* Abbrev: DW_TAG_compile_unit */
+	.4byte		.Lproducer		/* DW_AT_producer */
+	/* Use C++ to exploit a bug in parsing DW_AT_name "".  */
+	.byte		4			/* DW_AT_language (C++) -  */
+	.4byte		main			/* DW_AT_low_pc */
+	.byte		main_length		/* DW_AT_high_pc */
+
+.Larray_type:
+	.uleb128	2			/* Abbrev: DW_TAG_array_type */
+	.4byte		.Lchar_type-.Lcu1_begin	/* DW_AT_type */
+
+	.uleb128	3			/* Abbrev: DW_TAG_subrange_type */
+	.4byte		.Luint_type-.Lcu1_begin	/* DW_AT_type */
+	.byte		0			/* DW_AT_lower_bound */
+	.4byte		.Llen_var-.Lcu1_begin	/* DW_AT_upper_bound */
+	.byte		0			/* End of children of die */
+
+	/* DW_AT_upper_bound is referencing an optimized-out variable.  */
+.Larrayb_type:
+	.uleb128	2			/* Abbrev: DW_TAG_array_type */
+	.4byte		.Lchar_type-.Lcu1_begin	/* DW_AT_type */
+
+	.uleb128	3			/* Abbrev: DW_TAG_subrange_type */
+	.4byte		.Luint_type-.Lcu1_begin	/* DW_AT_type */
+	.byte		0			/* DW_AT_lower_bound */
+	.4byte		.Llenb_var-.Lcu1_begin	/* DW_AT_upper_bound */
+	.byte		0			/* End of children of die */
+
+	/* DW_AT_upper_bound is referencing register.  */
+.Larrayreg_type:
+	.uleb128	2			/* Abbrev: DW_TAG_array_type */
+	.4byte		.Lchar_type-.Lcu1_begin	/* DW_AT_type */
+
+	.uleb128	8			/* Abbrev: DW_TAG_subrange_type with block */
+	.4byte		.Luint_type-.Lcu1_begin	/* DW_AT_type */
+	.byte		0			/* DW_AT_lower_bound */
+	.byte		2f - 1f			/* DW_AT_upper_bound */
+1:	.byte		0x50			/* DW_OP_reg0 */
+2:
+	.byte		0			/* End of children of die */
+
+.Luint_type:
+	.uleb128	4			/* Abbrev: DW_TAG_base_type */
+	.4byte		.Luint_str		/* DW_AT_name */
+	.byte		4			/* DW_AT_byte_size */
+	.byte		7			/* DW_AT_encoding */
+
+.Lchar_type:
+	.uleb128	4			/* Abbrev: DW_TAG_base_type */
+	.4byte		.Lchar_str		/* DW_AT_name */
+	.byte		1			/* DW_AT_byte_size */
+	.byte		6			/* DW_AT_encoding */
+
+.Llen_var:
+	.uleb128	5			/* Abbrev: DW_TAG_variable artificial */
+	.byte		1			/* DW_AT_artificial */
+	.4byte		.Luint_type-.Lcu1_begin	/* DW_AT_type */
+	.4byte		.Llen_loclist-.Lloclist	/* DW_AT_location */
+
+	/* optimized-out variable for b_string.  */
+.Llenb_var:
+	.uleb128	7			/* Abbrev: DW_TAG_variable artificial no DW_AT_location */
+	.byte		1			/* DW_AT_artificial */
+	.4byte		.Luint_type-.Lcu1_begin	/* DW_AT_type */
+
+	.uleb128	6			/* Abbrev: DW_TAG_variable DW_FORM_string */
+	.string		"a_string"		/* DW_AT_name */
+	.4byte		.Larray_type-.Lcu1_begin /* DW_AT_type */
+	.byte		2f - 1f			/* DW_AT_location */
+1:	.byte		3			/*   DW_OP_addr */
+	.4byte		vardata			/*   <addr> */
+2:
+
+	/* DW_AT_upper_bound is referencing an optimized-out variable.  */
+	.uleb128	6			/* Abbrev: DW_TAG_variable DW_FORM_string */
+	.string		"b_string"		/* DW_AT_name */
+	.4byte		.Larrayb_type-.Lcu1_begin /* DW_AT_type */
+	.byte		2f - 1f			/* DW_AT_location */
+1:	.byte		3			/*   DW_OP_addr */
+	.4byte		vardata			/*   <addr> */
+2:
+
+	/* DW_AT_upper_bound is referencing register.  */
+	.uleb128	6			/* Abbrev: DW_TAG_variable DW_FORM_string */
+	.string		"reg_string"		/* DW_AT_name */
+	.4byte		.Larrayreg_type-.Lcu1_begin /* DW_AT_type */
+	.byte		2f - 1f			/* DW_AT_location */
+1:	.byte		3			/*   DW_OP_addr */
+	.4byte		vardata			/*   <addr> */
+2:
+
+	.byte		0			/* End of children of CU */
+.Lcu1_end:
+
+	.section	.debug_loc
+.Lloclist:
+.Llen_loclist:
+	.4byte	0			# Location list begin address
+	.4byte	main_length		# Location list end address
+	.value	2f-1f	# Location expression size
+1:	.byte	0x33	# DW_OP_lit3
+	.byte	0x9f	# DW_OP_stack_value
+2:
+	.quad	0x0	# Location list terminator begin (*.LLST2)
+	.quad	0x0	# Location list terminator end (*.LLST2)
+
+	.section .debug_abbrev
+.Ldebug_abbrev0:
+	.uleb128	1			/* Abbrev code */
+	.uleb128	0x11			/* DW_TAG_compile_unit */
+	.byte		0x1			/* has_children */
+	.uleb128	0x25			/* DW_AT_producer */
+	.uleb128	0xe			/* DW_FORM_strp */
+	.uleb128	0x13			/* DW_AT_language */
+	.uleb128	0xb			/* DW_FORM_data1 */
+	.uleb128	0x11			/* DW_AT_low_pc */
+	.uleb128	0x1			/* DW_FORM_addr */
+	.uleb128	0x12			/* DW_AT_high_pc */
+	.uleb128	0xb			/* DW_FORM_data1 */
+	.byte		0x0			/* Terminator */
+	.byte		0x0			/* Terminator */
+
+	.uleb128	2			/* Abbrev code */
+	.uleb128	0x1			/* TAG: DW_TAG_array_type */
+	.byte		0x1			/* DW_children_yes */
+	.uleb128	0x49			/* DW_AT_type */
+	.uleb128	0x13			/* DW_FORM_ref4 */
+	.byte		0x0			/* Terminator */
+	.byte		0x0			/* Terminator */
+
+	.uleb128	3			/* Abbrev code */
+	.uleb128	0x21			/* DW_TAG_subrange_type */
+	.byte		0x0			/* no children */
+	.uleb128	0x49			/* DW_AT_type */
+	.uleb128	0x13			/* DW_FORM_ref4 */
+	.uleb128	0x22			/* DW_AT_lower_bound */
+	.uleb128	0xb			/* DW_FORM_data1 */
+	.uleb128	0x2f			/* DW_AT_upper_bound */
+	.uleb128	0x13			/* DW_FORM_ref4 */
+	.byte		0x0			/* Terminator */
+	.byte		0x0			/* Terminator */
+
+	.uleb128	4			/* Abbrev code */
+	.uleb128	0x24			/* DW_TAG_base_type */
+	.byte		0x0			/* no_children */
+	.uleb128	0x3			/* DW_AT_name */
+	.uleb128	0xe			/* DW_FORM_strp */
+	.uleb128	0xb			/* DW_AT_byte_size */
+	.uleb128	0xb			/* DW_FORM_data1 */
+	.uleb128	0x3e			/* DW_AT_encoding */
+	.uleb128	0xb			/* DW_FORM_data1 */
+	.byte		0x0			/* Terminator */
+	.byte		0x0			/* Terminator */
+
+	.uleb128	5			/* Abbrev code */
+	.uleb128	0x34			/* DW_TAG_variable */
+	.byte		0x0			/* no_children */
+	.uleb128	0x34			/* DW_AT_artificial */
+	.uleb128	0x0c			/* DW_FORM_flag */
+	.uleb128	0x49			/* DW_AT_type */
+	.uleb128	0x13			/* DW_FORM_ref4 */
+	.uleb128	0x02			/* DW_AT_location */
+	.uleb128	0x06			/* DW_FORM_data4 */
+	.byte		0x0			/* Terminator */
+	.byte		0x0			/* Terminator */
+
+	.uleb128	6			/* Abbrev code */
+	.uleb128	0x34			/* DW_TAG_variable */
+	.byte		0x0			/* no_children */
+	.uleb128	0x3			/* DW_AT_name */
+	.uleb128	0x8			/* DW_FORM_string */
+	.uleb128	0x49			/* DW_AT_type */
+	.uleb128	0x13			/* DW_FORM_ref4 */
+	.uleb128	0x2			/* DW_AT_location */
+	.uleb128	0xa			/* DW_FORM_block1 */
+	.byte		0x0			/* Terminator */
+	.byte		0x0			/* Terminator */
+
+	.uleb128	7			/* Abbrev code */
+	.uleb128	0x34			/* DW_TAG_variable */
+	.byte		0x0			/* no_children */
+	.uleb128	0x34			/* DW_AT_artificial */
+	.uleb128	0x0c			/* DW_FORM_flag */
+	.uleb128	0x49			/* DW_AT_type */
+	.uleb128	0x13			/* DW_FORM_ref4 */
+	.byte		0x0			/* Terminator */
+	.byte		0x0			/* Terminator */
+
+	.uleb128	8			/* Abbrev code */
+	.uleb128	0x21			/* DW_TAG_subrange_type with block */
+	.byte		0x0			/* no children */
+	.uleb128	0x49			/* DW_AT_type */
+	.uleb128	0x13			/* DW_FORM_ref4 */
+	.uleb128	0x22			/* DW_AT_lower_bound */
+	.uleb128	0xb			/* DW_FORM_data1 */
+	.uleb128	0x2f			/* DW_AT_upper_bound */
+	.uleb128	0xa			/* DW_FORM_block1 */
+	.byte		0x0			/* Terminator */
+	.byte		0x0			/* Terminator */
+
+	.byte		0x0			/* Terminator */
+
+/* String table */
+	.section .debug_str
+.Lproducer:
+	.string		"GNU C 3.3.3"
+.Lchar_str:
+	.string		"char"
+.Luint_str:
+	.string		"unsigned int"

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [V4 00/21] Fortran dynamic array support
  2016-08-25 17:06                           ` Jan Kratochvil
  2016-08-25 17:22                             ` Jan Kratochvil
@ 2016-09-02 13:44                             ` Bernhard Heckel
  2016-09-04 17:15                               ` Jan Kratochvil
  1 sibling, 1 reply; 53+ messages in thread
From: Bernhard Heckel @ 2016-09-02 13:44 UTC (permalink / raw)
  To: Jan Kratochvil; +Cc: Weinmann, Christoph T, gdb-patches

On 25/08/2016 19:06, Jan Kratochvil wrote:
> On Tue, 23 Aug 2016 15:34:09 +0200, Bernhard Heckel wrote:
>> created a branch with all stride patches.
> users/bheckel/fortran-strides
> 2c392d41a3f2e38deeb9db5b7a93ca45682bbe3b
>
>> I don't see regression on RH7.1, gcc 4.8.3-9
> I see a regression for 32-bit targets (x86_64-m32 or native i686)
> on Fedora 24 (gcc-gfortran-6.1.1-3.fc24.x86_64).  I do not see the regression
> on CentOS-7.2 (x86_64-m32).
>
> print pvla^M
> value requires 4294967288 bytes, which is more than max-value-size^M
> (gdb) FAIL: gdb.fortran/vla-stride.exp: print single-element
>
> I have attached a fix.
>
> It is because:
>      <115>   DW_AT_lower_bound : 4 byte block: 97 23 10 6        (DW_OP_push_object_address; DW_OP_plus_uconst: 16; DW_OP_deref)
>      <11a>   DW_AT_upper_bound : 4 byte block: 97 23 14 6        (DW_OP_push_object_address; DW_OP_plus_uconst: 20; DW_OP_deref)
>      <11f>   DW_AT_byte_stride : 6 byte block: 97 23 c 6 34 1e   (DW_OP_push_object_address; DW_OP_plus_uconst: 12; DW_OP_deref; DW_OP_lit4; DW_OP_mul)
> 	DW_AT_lower_bound == 1
> 	DW_AT_upper_bound == 1
> 	DW_AT_byte_stride == (-2) * 4 == -8
>
> I am not sure if gfortran is really wrong or not but a stride does not make
> sense for me for a single row array.
>
> Attaching also gdb.fortran/vla-stride.f90 from your branch built with
> gcc-gfortran-6.1.1-3.fc24.x86_64 on Fedora 24 x86_64 in -m32 mode.
>
> Besides that I see on all archs
> 	-FAIL: gdb.pascal/arrays.exp: Print dynamic array of string
> 	+FAIL: gdb.pascal/arrays.exp: Print dynamic array of string (GDB internal error)
> but that testcase is only in Fedora and the Pascal (fpc) support has been not
> well maintained so far so I am OK with that.
>
>
> Thanks,
> Jan
Hi Jan,

found the root cause of the issue on 32bit inferior.
According to DWARF4 (Page 100) strides can be negative but evaluation of 
dynamic properties in GDB is done via CORE_ADDR which is unsigned.
This causes the issue that the type length seems to be way to big.

The following code is not claimed to be a fix, just want to point you to 
the right direction.
In gdbtypes.c:
   prop = &TYPE_RANGE_DATA (dyn_range_type)->stride;
   if (dwarf2_evaluate_property (prop, NULL, addr_stack, &value))
     {
       /* if target is 32bit, execute next if clause  */
       if (value > (2^31))
     value += 2^32;

       stride.kind = PROP_CONST;
       stride.data.const_val = value;
     }
Also, in dwarf2read.c all DW_AT_...STRIDE 's are handles as unsigned. 
This has to be fixed as well.

I will investigate more on the stride topic next week.


Intel Deutschland GmbH
Registered Address: Am Campeon 10-12, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de
Managing Directors: Christin Eisenschmid, Christian Lamprechter
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [V4 00/21] Fortran dynamic array support
  2016-08-26  7:17                               ` Jan Kratochvil
@ 2016-09-01 10:11                                 ` Bernhard Heckel
  0 siblings, 0 replies; 53+ messages in thread
From: Bernhard Heckel @ 2016-09-01 10:11 UTC (permalink / raw)
  To: Jan Kratochvil; +Cc: Weinmann, Christoph T, gdb-patches

On 26/08/2016 09:17, Jan Kratochvil wrote:
> On Thu, 25 Aug 2016 19:22:17 +0200, Jan Kratochvil wrote:
>> I see the source handles negative stide specially.  Particularly the comment
>> here does not explain the code it comments:
> With the attached patch disabling these cases still the supplied
> gdb.fortran/static-arrays.exp and gdb.fortran/vla-stride.exp PASS (on Fedora 24
> x86_64).
>
>
> Jan
Hi Jan,

I am just setting up a Fedora24 environment. I will look into this 
stride issue and update the branch
with your current findings.


Intel Deutschland GmbH
Registered Address: Am Campeon 10-12, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de
Managing Directors: Christin Eisenschmid, Christian Lamprechter
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [V4 00/21] Fortran dynamic array support
  2016-08-23 13:34                         ` Bernhard Heckel
  2016-08-25 17:06                           ` Jan Kratochvil
@ 2016-09-01  9:48                           ` Jan Kratochvil
  1 sibling, 0 replies; 53+ messages in thread
From: Jan Kratochvil @ 2016-09-01  9:48 UTC (permalink / raw)
  To: Bernhard Heckel; +Cc: Weinmann, Christoph T, gdb-patches

[-- Attachment #1: Type: text/plain, Size: 522 bytes --]

On Tue, 23 Aug 2016 15:34:09 +0200, Bernhard Heckel wrote:
> created a branch with all stride patches.

users/bheckel/fortran-strides
2c392d41a3f2e38deeb9db5b7a93ca45682bbe3b


> I don't see regression on RH7.1, gcc 4.8.3-9

I see a regression in Fedora-specific testcase, attaching it also with a fix.

Although it does not work just on your branch, apparently it has some
dependency on other Fedora patches.
	http://pkgs.fedoraproject.org/cgit/rpms/gdb.git/tree/
It can be resolved later for upstream GDB I guess.


Jan

[-- Attachment #2: gdb-vla-intel-stringbt-fix.patch --]
[-- Type: text/plain, Size: 6873 bytes --]

http://sourceware.org/ml/gdb-patches/2014-08/msg00025.html
Subject: [patch 1/2] Re: Crash regression(?) printing Fortran strings in bt  [Re: [V2 00/23] Fortran dynamic array support]


--FCuugMFkClbJLl1L
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

On Fri, 01 Aug 2014 09:20:19 +0200, Keven Boell wrote:
> I just tried it on Fedora 20 i686.  Applied the patch, you mentioned, on top of
> the Fortran VLA series and executed your dynamic-other-frame test.  Everything
> is working fine here, I cannot reproduce the crash.

I have it reproducible on Fedora 20 i686 with plain
CFLAGS=-g ./configure;make;cd gdb/testsuite;make site.exp;runtest gdb.fortran/dynamic-other-frame.exp

Besides that I have updated the testcase with
	gdb_test_no_output "set print frame-arguments all"
so that there is no longer needed the patch:
	[patch] Display Fortran strings in backtraces
	https://sourceware.org/ml/gdb-patches/2014-07/msg00709.html

The fix below has no regressions for me.  Unfortunately I do not see why you
cannot reproduce it.


Thanks,
Jan

--- ./gdb/dwarf2loc.c	2016-08-29 04:01:25.000000000 +0200
+++ ./gdb/dwarf2loc.c	2016-09-01 11:00:20.258909494 +0200
@@ -2289,6 +2289,15 @@ const struct dwarf_expr_context_funcs dw
   dwarf_expr_get_obj_addr
 };
 
+static void
+select_frame_cleanup (void *arg)
+{
+  struct frame_info *frame = (struct frame_info *) arg;
+
+  if (frame != NULL)
+    select_frame (frame);
+}
+
 /* Evaluate a location description, starting at DATA and with length
    SIZE, to find the current location of variable of TYPE in the
    context of FRAME.  BYTE_OFFSET is applied after the contents are
@@ -2318,6 +2327,11 @@ dwarf2_evaluate_loc_desc_full (struct ty
 
   ctx = new_dwarf_expr_context ();
   old_chain = make_cleanup_free_dwarf_expr_context (ctx);
+
+  make_cleanup (select_frame_cleanup, deprecated_safe_get_selected_frame ());
+  if (frame != NULL)
+    select_frame (frame);
+
   value_chain = make_cleanup_value_free_to_mark (value_mark ());
 
   ctx->gdbarch = get_objfile_arch (objfile);
Index: gdb-7.9.50.20150520/gdb/testsuite/gdb.fortran/dynamic-other-frame-stub.f90
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ gdb-7.9.50.20150520/gdb/testsuite/gdb.fortran/dynamic-other-frame-stub.f90	2015-05-31 16:14:05.844545344 +0200
@@ -0,0 +1,24 @@
+! Copyright 2010 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 2 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, write to the Free Software
+! Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+!
+! Ihis file is the Fortran source file for dynamic.exp.
+! Original file written by Jakub Jelinek <jakub@redhat.com>.
+! Modified for the GDB testcase by Jan Kratochvil <jan.kratochvil@redhat.com>.
+
+subroutine bar
+  real :: dummy
+  dummy = 1
+end subroutine bar
Index: gdb-7.9.50.20150520/gdb/testsuite/gdb.fortran/dynamic-other-frame.exp
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ gdb-7.9.50.20150520/gdb/testsuite/gdb.fortran/dynamic-other-frame.exp	2015-05-31 16:14:05.845545351 +0200
@@ -0,0 +1,39 @@
+# Copyright 2010 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 2 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, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  
+
+set testfile "dynamic-other-frame"
+set srcfile1 ${testfile}.f90
+set srcfile2 ${testfile}-stub.f90
+set objfile2 [standard_output_file ${testfile}-stub.o]
+set executable ${testfile}
+set binfile [standard_output_file ${executable}]
+
+if { [gdb_compile "${srcdir}/${subdir}/${srcfile2}" "${objfile2}" object {f90}] != ""
+     || [gdb_compile "${srcdir}/${subdir}/${srcfile1} ${objfile2}" "${binfile}" executable {debug f90}] != "" } {
+    untested "Couldn't compile ${srcfile1} or ${srcfile2}"
+    return -1
+}
+
+clean_restart ${executable}
+
+gdb_test_no_output "set print frame-arguments all"
+
+if ![runto bar_] then {
+    perror "couldn't run to bar_"
+    continue
+}
+
+gdb_test "bt" {foo \(string='hello'.*}
Index: gdb-7.9.50.20150520/gdb/testsuite/gdb.fortran/dynamic-other-frame.f90
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ gdb-7.9.50.20150520/gdb/testsuite/gdb.fortran/dynamic-other-frame.f90	2015-05-31 16:14:05.845545351 +0200
@@ -0,0 +1,36 @@
+! Copyright 2010 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 2 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, write to the Free Software
+! Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+!
+! Ihis file is the Fortran source file for dynamic.exp.
+! Original file written by Jakub Jelinek <jakub@redhat.com>.
+! Modified for the GDB testcase by Jan Kratochvil <jan.kratochvil@redhat.com>.
+
+subroutine foo (string)
+  interface
+    subroutine bar
+    end subroutine
+  end interface
+  character string*(*)
+  call bar                                ! stop-here
+end subroutine foo
+program test
+  interface
+    subroutine foo (string)
+    character string*(*)
+    end subroutine
+  end interface
+  call foo ('hello')
+end

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [V4 00/21] Fortran dynamic array support
  2016-08-25 17:22                             ` Jan Kratochvil
@ 2016-08-26  7:17                               ` Jan Kratochvil
  2016-09-01 10:11                                 ` Bernhard Heckel
  0 siblings, 1 reply; 53+ messages in thread
From: Jan Kratochvil @ 2016-08-26  7:17 UTC (permalink / raw)
  To: Bernhard Heckel; +Cc: Weinmann, Christoph T, gdb-patches

[-- Attachment #1: Type: text/plain, Size: 344 bytes --]

On Thu, 25 Aug 2016 19:22:17 +0200, Jan Kratochvil wrote:
> I see the source handles negative stide specially.  Particularly the comment
> here does not explain the code it comments:

With the attached patch disabling these cases still the supplied
gdb.fortran/static-arrays.exp and gdb.fortran/vla-stride.exp PASS (on Fedora 24
x86_64).


Jan

[-- Attachment #2: 1 --]
[-- Type: text/plain, Size: 1222 bytes --]

diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index 88801ac..695825a 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -2197,12 +2197,14 @@ resolve_dynamic_type_internal (struct type *type,
     {
       struct type *range_type = TYPE_INDEX_TYPE (resolved_type);
 
+#if 0
       /* Adjust the data location with the value of byte stride if set, which
          can describe the separation between successive elements along the
          dimension.  */
       if (TYPE_BYTE_STRIDE (range_type) < 0)
         value += (TYPE_HIGH_BOUND (range_type) - TYPE_LOW_BOUND (range_type))
                   * TYPE_BYTE_STRIDE (range_type);
+#endif
 
       TYPE_DATA_LOCATION_ADDR (resolved_type) = value;
       TYPE_DATA_LOCATION_KIND (resolved_type) = PROP_CONST;
diff --git a/gdb/valarith.c b/gdb/valarith.c
index 9093969..eca7992 100644
--- a/gdb/valarith.c
+++ b/gdb/valarith.c
@@ -199,12 +199,14 @@ value_subscripted_rvalue (struct value *array, LONGEST index, int lowerbound)
 
   if (elt_stride > 0)
     elt_offs *= elt_stride;
+#if 0
   else if (elt_stride < 0)
     {
       int offs = (elt_offs + 1) * elt_stride;
 
       elt_offs = TYPE_LENGTH (array_type) + offs;
     }
+#endif
   else
     elt_offs *= elt_size;
 

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [V4 00/21] Fortran dynamic array support
  2016-08-25 17:06                           ` Jan Kratochvil
@ 2016-08-25 17:22                             ` Jan Kratochvil
  2016-08-26  7:17                               ` Jan Kratochvil
  2016-09-02 13:44                             ` Bernhard Heckel
  1 sibling, 1 reply; 53+ messages in thread
From: Jan Kratochvil @ 2016-08-25 17:22 UTC (permalink / raw)
  To: Bernhard Heckel; +Cc: Weinmann, Christoph T, gdb-patches

On Thu, 25 Aug 2016 19:06:26 +0200, Jan Kratochvil wrote:
> I have attached a fix.

That fix has a regression for normal (64-bit) inferiors.

I see the source handles negative stide specially.  Particularly the comment
here does not explain the code it comments:

      /* Adjust the data location with the value of byte stride if set, which
         can describe the separation between successive elements along the
         dimension.  */
      if (TYPE_BYTE_STRIDE (range_type) < 0)
        value += (TYPE_HIGH_BOUND (range_type) - TYPE_LOW_BOUND (range_type))
                  * TYPE_BYTE_STRIDE (range_type);
  else if (elt_stride < 0)
    {
      int offs = (elt_offs + 1) * elt_stride;

      elt_offs = TYPE_LENGTH (array_type) + offs;
    }

But I do not negative stride values described in DWARF-4 anyhow.  When it is
used?  With this interpretation of stride the gfortran random(?) stride value
for arrays with single row would be really wrong.  But I do not see
a definition of negative stride in DWARF.


Thanks,
Jan

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [V4 00/21] Fortran dynamic array support
  2016-08-23 13:34                         ` Bernhard Heckel
@ 2016-08-25 17:06                           ` Jan Kratochvil
  2016-08-25 17:22                             ` Jan Kratochvil
  2016-09-02 13:44                             ` Bernhard Heckel
  2016-09-01  9:48                           ` Jan Kratochvil
  1 sibling, 2 replies; 53+ messages in thread
From: Jan Kratochvil @ 2016-08-25 17:06 UTC (permalink / raw)
  To: Bernhard Heckel; +Cc: Weinmann, Christoph T, gdb-patches

[-- Attachment #1: Type: text/plain, Size: 1637 bytes --]

On Tue, 23 Aug 2016 15:34:09 +0200, Bernhard Heckel wrote:
> created a branch with all stride patches.

users/bheckel/fortran-strides
2c392d41a3f2e38deeb9db5b7a93ca45682bbe3b

> I don't see regression on RH7.1, gcc 4.8.3-9

I see a regression for 32-bit targets (x86_64-m32 or native i686)
on Fedora 24 (gcc-gfortran-6.1.1-3.fc24.x86_64).  I do not see the regression
on CentOS-7.2 (x86_64-m32).

print pvla^M
value requires 4294967288 bytes, which is more than max-value-size^M
(gdb) FAIL: gdb.fortran/vla-stride.exp: print single-element

I have attached a fix.

It is because:
    <115>   DW_AT_lower_bound : 4 byte block: 97 23 10 6        (DW_OP_push_object_address; DW_OP_plus_uconst: 16; DW_OP_deref)
    <11a>   DW_AT_upper_bound : 4 byte block: 97 23 14 6        (DW_OP_push_object_address; DW_OP_plus_uconst: 20; DW_OP_deref)
    <11f>   DW_AT_byte_stride : 6 byte block: 97 23 c 6 34 1e   (DW_OP_push_object_address; DW_OP_plus_uconst: 12; DW_OP_deref; DW_OP_lit4; DW_OP_mul)
	DW_AT_lower_bound == 1
	DW_AT_upper_bound == 1
	DW_AT_byte_stride == (-2) * 4 == -8

I am not sure if gfortran is really wrong or not but a stride does not make
sense for me for a single row array.

Attaching also gdb.fortran/vla-stride.f90 from your branch built with
gcc-gfortran-6.1.1-3.fc24.x86_64 on Fedora 24 x86_64 in -m32 mode.

Besides that I see on all archs
	-FAIL: gdb.pascal/arrays.exp: Print dynamic array of string
	+FAIL: gdb.pascal/arrays.exp: Print dynamic array of string (GDB internal error)
but that testcase is only in Fedora and the Pascal (fpc) support has been not
well maintained so far so I am OK with that.


Thanks,
Jan

[-- Attachment #2: 1 --]
[-- Type: text/plain, Size: 797 bytes --]

diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index 88801ac..1fbf69a 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -1103,10 +1103,12 @@ create_array_type_with_stride (struct type *result_type,
       if (high_bound < low_bound)
 	TYPE_LENGTH (result_type) = 0;
       else if (byte_stride > 0)
-	TYPE_LENGTH (result_type) = byte_stride * (high_bound - low_bound + 1);
+	TYPE_LENGTH (result_type) = (byte_stride * (high_bound - low_bound)
+				     + TYPE_LENGTH (element_type));
       else if (bit_stride > 0)
 	TYPE_LENGTH (result_type) =
-	  (bit_stride * (high_bound - low_bound + 1) + 7) / 8;
+	  ((bit_stride * (high_bound - low_bound) + 7) / 8
+	   + TYPE_LENGTH (element_type));
       else
 	TYPE_LENGTH (result_type) =
 	  TYPE_LENGTH (element_type) * (high_bound - low_bound + 1);

[-- Attachment #3: vla-stride.s --]
[-- Type: text/plain, Size: 21421 bytes --]

	.file	"vla-stride.f90"
	.text
.Ltext0:
	.section	.rodata
	.align 4
.LC0:
	.string	"Integer overflow when calculating the amount of memory to allocate"
.LC1:
	.string	"vla"
	.align 4
.LC2:
	.string	"Attempting to allocate already allocated variable '%s'"
	.align 4
.LC3:
	.string	"At line 20 of file gdb.fortran/vla-stride.f90"
	.align 4
.LC4:
	.string	"Allocation would exceed memory limit"
	.text
	.type	MAIN__, @function
MAIN__:
.LFB0:
	.file 1 "gdb.fortran/vla-stride.f90"
	# gdb.fortran/vla-stride.f90:16
	.loc 1 16 0
	.cfi_startproc
# BLOCK 2 seq:0
# PRED: ENTRY (FALLTHRU)
	pushl	%ebp
	.cfi_def_cfa_offset 8
	.cfi_offset 5, -8
	movl	%esp, %ebp
	.cfi_def_cfa_register 5
	pushl	%edi
	pushl	%esi
	pushl	%ebx
	subl	$60, %esp
	.cfi_offset 7, -12
	.cfi_offset 6, -16
	.cfi_offset 3, -20
	# gdb.fortran/vla-stride.f90:17
	.loc 1 17 0
	movl	$0, -72(%ebp)
.LBB2:
	# gdb.fortran/vla-stride.f90:20
	.loc 1 20 0
	movl	$0, %eax
	testl	%eax, %eax
# SUCC: 3 (FALLTHRU) 4
	je	.L2
# BLOCK 3 seq:1
# PRED: 2 (FALLTHRU)
	# gdb.fortran/vla-stride.f90:20
	.loc 1 20 0 is_stmt 0 discriminator 1
	subl	$12, %esp
	pushl	$.LC0
# SUCC:
	call	_gfortran_runtime_error
# BLOCK 4 seq:2
# PRED: 2
.L2:
	# gdb.fortran/vla-stride.f90:20
	.loc 1 20 0 discriminator 2
	movl	-72(%ebp), %eax
	testl	%eax, %eax
# SUCC: 5 (FALLTHRU) 6
	je	.L3
# BLOCK 5 seq:3
# PRED: 4 (FALLTHRU)
	# gdb.fortran/vla-stride.f90:20
	.loc 1 20 0 discriminator 3
	subl	$4, %esp
	pushl	$.LC1
	pushl	$.LC2
	pushl	$.LC3
# SUCC:
	call	_gfortran_runtime_error_at
# BLOCK 6 seq:4
# PRED: 4
.L3:
	# gdb.fortran/vla-stride.f90:20
	.loc 1 20 0 discriminator 4
	subl	$12, %esp
	pushl	$40
	call	malloc
	addl	$16, %esp
	movl	%eax, -72(%ebp)
	movl	-72(%ebp), %eax
	testl	%eax, %eax
# SUCC: 7 (FALLTHRU) 8
	jne	.L4
# BLOCK 7 seq:5
# PRED: 6 (FALLTHRU)
	# gdb.fortran/vla-stride.f90:20
	.loc 1 20 0 discriminator 5
	subl	$12, %esp
	pushl	$.LC4
# SUCC:
	call	_gfortran_os_error
# BLOCK 8 seq:6
# PRED: 6
.L4:
	# gdb.fortran/vla-stride.f90:20
	.loc 1 20 0 discriminator 6
	movl	$265, -64(%ebp)
	movl	$1, -56(%ebp)
	movl	$10, -52(%ebp)
	movl	$1, -60(%ebp)
	movl	$-1, -68(%ebp)
.LBB3:
	# gdb.fortran/vla-stride.f90:21
	.loc 1 21 0 is_stmt 1 discriminator 6
	movl	-72(%ebp), %edx
	movl	-68(%ebp), %esi
	movl	-56(%ebp), %ebx
.LBB4:
.LBB5:
	movl	-72(%ebp), %eax
	testl	%eax, %eax
	sete	%al
	movzbl	%al, %eax
	testl	%eax, %eax
# SUCC: 10 9 (FALLTHRU)
	jne	.L5
# BLOCK 9 seq:7
# PRED: 8 (FALLTHRU)
	# gdb.fortran/vla-stride.f90:21
	.loc 1 21 0 is_stmt 0 discriminator 2
	movl	-56(%ebp), %ecx
	leal	9(%ecx), %edi
	movl	-52(%ebp), %ecx
	cmpl	%ecx, %edi
# SUCC: 10 (FALLTHRU) 18
	je	.L6
# BLOCK 10 seq:8
# PRED: 8 9 (FALLTHRU)
.L5:
	# gdb.fortran/vla-stride.f90:21
	.loc 1 21 0 discriminator 3
	testl	%eax, %eax
# SUCC: 11 (FALLTHRU) 12
	je	.L7
# BLOCK 11 seq:9
# PRED: 10 (FALLTHRU)
	# gdb.fortran/vla-stride.f90:21
	.loc 1 21 0 discriminator 4
	movl	$0, %eax
# SUCC: 13 [100.0%] 
	jmp	.L8
# BLOCK 12 seq:10
# PRED: 10
.L7:
	# gdb.fortran/vla-stride.f90:21
	.loc 1 21 0 discriminator 5
	movl	-52(%ebp), %edx
	movl	-56(%ebp), %eax
	subl	%eax, %edx
	movl	%edx, %eax
	addl	$1, %eax
	movl	$0, %edx
	testl	%eax, %eax
# SUCC: 13 (FALLTHRU)
	cmovs	%edx, %eax
# BLOCK 13 seq:11
# PRED: 12 (FALLTHRU) 11 [100.0%] 
.L8:
	# gdb.fortran/vla-stride.f90:21
	.loc 1 21 0 discriminator 7
	cmpl	$10, %eax
	setne	%al
	movzbl	%al, %eax
	movl	$1, -56(%ebp)
	movl	$10, -52(%ebp)
	movl	$1, -60(%ebp)
	movl	-56(%ebp), %edx
	negl	%edx
	movl	%edx, -68(%ebp)
	movl	-68(%ebp), %esi
	movl	-56(%ebp), %ebx
	movl	-72(%ebp), %edx
	testl	%edx, %edx
# SUCC: 14 (FALLTHRU) 15
	jne	.L9
# BLOCK 14 seq:12
# PRED: 13 (FALLTHRU)
	# gdb.fortran/vla-stride.f90:21
	.loc 1 21 0 discriminator 8
	subl	$12, %esp
	pushl	$40
	call	malloc
	addl	$16, %esp
	movl	%eax, -72(%ebp)
	movl	$265, -64(%ebp)
# SUCC: 17 [100.0%] 
	jmp	.L10
# BLOCK 15 seq:13
# PRED: 13
.L9:
	# gdb.fortran/vla-stride.f90:21
	.loc 1 21 0 discriminator 9
	testl	%eax, %eax
# SUCC: 16 (FALLTHRU) 17
	je	.L10
# BLOCK 16 seq:14
# PRED: 15 (FALLTHRU)
	# gdb.fortran/vla-stride.f90:21
	.loc 1 21 0 discriminator 11
	movl	-72(%ebp), %eax
	subl	$8, %esp
	pushl	$40
	pushl	%eax
	call	realloc
	addl	$16, %esp
# SUCC: 17 (FALLTHRU)
	movl	%eax, -72(%ebp)
# BLOCK 17 seq:15
# PRED: 16 (FALLTHRU) 15 14 [100.0%] 
.L10:
# SUCC: 18 (FALLTHRU)
	# gdb.fortran/vla-stride.f90:21
	.loc 1 21 0 discriminator 13
	movl	-72(%ebp), %edx
# BLOCK 18 seq:16
# PRED: 9 17 (FALLTHRU)
.L6:
.LBE5:
# SUCC: 19 (FALLTHRU)
	# gdb.fortran/vla-stride.f90:21
	.loc 1 21 0 discriminator 14
	movl	$0, %eax
# BLOCK 19 seq:17
# PRED: 18 (FALLTHRU) 20 [100.0%] 
.L12:
	# gdb.fortran/vla-stride.f90:21
	.loc 1 21 0 discriminator 17
	cmpl	$9, %eax
# SUCC: 21 20 (FALLTHRU)
	jg	.L11
# BLOCK 20 seq:18
# PRED: 19 (FALLTHRU)
	# gdb.fortran/vla-stride.f90:21
	.loc 1 21 0 discriminator 16
	leal	(%eax,%ebx), %ecx
	leal	(%ecx,%esi), %edi
	movl	A.1.3368(,%eax,4), %ecx
	movl	%ecx, (%edx,%edi,4)
	addl	$1, %eax
# SUCC: 19 [100.0%] 
	jmp	.L12
# BLOCK 21 seq:19
# PRED: 19
.L11:
.LBE4:
.LBE3:
	# gdb.fortran/vla-stride.f90:23
	.loc 1 23 0 is_stmt 1
	movl	$265, -40(%ebp)
	movl	$1, -32(%ebp)
	movl	$10, -28(%ebp)
	movl	$-1, -36(%ebp)
	movl	-72(%ebp), %eax
	movl	-56(%ebp), %edx
	movl	$10, %ecx
	subl	%edx, %ecx
	movl	%ecx, %edx
	sall	$2, %edx
	addl	%edx, %eax
	movl	%eax, -48(%ebp)
	movl	$1, -44(%ebp)
.LBB6:
	# gdb.fortran/vla-stride.f90:24
	.loc 1 24 0
	movl	$265, -40(%ebp)
	movl	-36(%ebp), %eax
	movl	$1, -32(%ebp)
	movl	$10, -28(%ebp)
	movl	%eax, %edx
	negl	%edx
	movl	%edx, -36(%ebp)
	movl	-48(%ebp), %edx
	movl	-32(%ebp), %ecx
	movl	$10, %ebx
	subl	%ecx, %ebx
	movl	%ebx, %ecx
	imull	%eax, %ecx
	sall	$2, %ecx
	addl	%ecx, %edx
	movl	%edx, -48(%ebp)
	movl	%eax, -44(%ebp)
.LBE6:
	# gdb.fortran/vla-stride.f90:25
	.loc 1 25 0
	movl	$265, -40(%ebp)
	movl	$1, -32(%ebp)
	movl	$5, -28(%ebp)
	movl	$2, -36(%ebp)
	movl	-72(%ebp), %eax
	movl	-56(%ebp), %edx
	movl	$1, %ecx
	subl	%edx, %ecx
	movl	%ecx, %edx
	sall	$2, %edx
	addl	%edx, %eax
	movl	%eax, -48(%ebp)
	movl	$-2, -44(%ebp)
	# gdb.fortran/vla-stride.f90:26
	.loc 1 26 0
	movl	$265, -40(%ebp)
	movl	$1, -32(%ebp)
	movl	$1, -28(%ebp)
	movl	$-2, -36(%ebp)
	movl	-72(%ebp), %eax
	movl	-56(%ebp), %edx
	movl	$5, %ecx
	subl	%edx, %ecx
	movl	%ecx, %edx
	sall	$2, %edx
	addl	%edx, %eax
	movl	%eax, -48(%ebp)
	movl	$2, -44(%ebp)
	# gdb.fortran/vla-stride.f90:28
	.loc 1 28 0
	movl	$0, -48(%ebp)
.LBE2:
	# gdb.fortran/vla-stride.f90:29
	.loc 1 29 0
	nop
	leal	-12(%ebp), %esp
	popl	%ebx
	.cfi_restore 3
	popl	%esi
	.cfi_restore 6
	popl	%edi
	.cfi_restore 7
	popl	%ebp
	.cfi_restore 5
	.cfi_def_cfa 4, 4
# SUCC: EXIT [100.0%] 
	ret
	.cfi_endproc
.LFE0:
	.size	MAIN__, .-MAIN__
	.globl	main
	.type	main, @function
main:
.LFB1:
	# gdb.fortran/vla-stride.f90:29
	.loc 1 29 0
	.cfi_startproc
# BLOCK 2 seq:0
# PRED: ENTRY (FALLTHRU)
	leal	4(%esp), %ecx
	.cfi_def_cfa 1, 0
	andl	$-16, %esp
	pushl	-4(%ecx)
	pushl	%ebp
	.cfi_escape 0x10,0x5,0x2,0x75,0
	movl	%esp, %ebp
	pushl	%ecx
	.cfi_escape 0xf,0x3,0x75,0x7c,0x6
	subl	$4, %esp
	movl	%ecx, %eax
	# gdb.fortran/vla-stride.f90:29
	.loc 1 29 0
	subl	$8, %esp
	pushl	4(%eax)
	pushl	(%eax)
	call	_gfortran_set_args
	addl	$16, %esp
	subl	$8, %esp
	pushl	$options.3.3382
	pushl	$9
	call	_gfortran_set_options
	addl	$16, %esp
	call	MAIN__
	movl	$0, %eax
	movl	-4(%ebp), %ecx
	.cfi_def_cfa 1, 0
	leave
	.cfi_restore 5
	leal	-4(%ecx), %esp
	.cfi_def_cfa 4, 4
# SUCC: EXIT [100.0%] 
	ret
	.cfi_endproc
.LFE1:
	.size	main, .-main
	.section	.rodata
	.align 32
	.type	A.1.3368, @object
	.size	A.1.3368, 40
A.1.3368:
	.long	1
	.long	2
	.long	3
	.long	4
	.long	5
	.long	6
	.long	7
	.long	8
	.long	9
	.long	10
	.align 32
	.type	options.3.3382, @object
	.size	options.3.3382, 36
options.3.3382:
	.long	68
	.long	1023
	.long	0
	.long	0
	.long	1
	.long	1
	.long	0
	.long	0
	.long	31
	.text
.Letext0:
	.section	.debug_info,"",@progbits
.Ldebug_info0:
	.long	0x128	# Length of Compilation Unit Info
	.value	0x4	# DWARF version number
	.long	.Ldebug_abbrev0	# Offset Into Abbrev. Section
	.byte	0x4	# Pointer Size (in bytes)
	.uleb128 0x1	# (DIE (0xb) DW_TAG_compile_unit)
	.long	.LASF5	# DW_AT_producer: "GNU Fortran2008 6.1.1 20160621 (Red Hat 6.1.1-3) -m32 -mtune=generic -march=i686 -g -fintrinsic-modules-path /usr/lib/gcc/x86_64-redhat-linux/6.1.1/32/finclude"
	.byte	0xe	# DW_AT_language
	.byte	0x2	# DW_AT_identifier_case
	.long	.LASF6	# DW_AT_name: "gdb.fortran/vla-stride.f90"
	.long	.LASF7	# DW_AT_comp_dir: "/home/jkratoch/redhat/gdb-clean/gdb/testsuite"
	.long	.Ltext0	# DW_AT_low_pc
	.long	.Letext0-.Ltext0	# DW_AT_high_pc
	.long	.Ldebug_line0	# DW_AT_stmt_list
	.uleb128 0x2	# (DIE (0x26) DW_TAG_base_type)
	.byte	0x4	# DW_AT_byte_size
	.byte	0x5	# DW_AT_encoding
	.long	.LASF2	# DW_AT_name: "integer(kind=4)"
	.uleb128 0x3	# (DIE (0x2d) DW_TAG_const_type)
	.long	0x26	# DW_AT_type
	.uleb128 0x4	# (DIE (0x32) DW_TAG_subprogram)
			# DW_AT_external
	.long	.LASF8	# DW_AT_name: "main"
	.byte	0x1	# DW_AT_decl_file (gdb.fortran/vla-stride.f90)
	.byte	0x1d	# DW_AT_decl_line
	.long	0x26	# DW_AT_type
	.long	.LFB1	# DW_AT_low_pc
	.long	.LFE1-.LFB1	# DW_AT_high_pc
	.uleb128 0x1	# DW_AT_frame_base
	.byte	0x9c	# DW_OP_call_frame_cfa
			# DW_AT_GNU_all_tail_call_sites
	.long	0x69	# DW_AT_sibling
	.uleb128 0x5	# (DIE (0x4b) DW_TAG_formal_parameter)
	.long	.LASF0	# DW_AT_name: "argc"
	.byte	0x1	# DW_AT_decl_file (gdb.fortran/vla-stride.f90)
	.byte	0x1d	# DW_AT_decl_line
	.long	0x2d	# DW_AT_type
	.uleb128 0x2	# DW_AT_location
	.byte	0x91	# DW_OP_fbreg
	.sleb128 0
	.uleb128 0x5	# (DIE (0x59) DW_TAG_formal_parameter)
	.long	.LASF1	# DW_AT_name: "argv"
	.byte	0x1	# DW_AT_decl_file (gdb.fortran/vla-stride.f90)
	.byte	0x1d	# DW_AT_decl_line
	.long	0x69	# DW_AT_type
	.uleb128 0x3	# DW_AT_location
	.byte	0x91	# DW_OP_fbreg
	.sleb128 4
	.byte	0x6	# DW_OP_deref
	.byte	0	# end of children of DIE 0x32
	.uleb128 0x6	# (DIE (0x69) DW_TAG_pointer_type)
	.byte	0x4	# DW_AT_byte_size
	.long	0x6f	# DW_AT_type
	.uleb128 0x2	# (DIE (0x6f) DW_TAG_base_type)
	.byte	0x1	# DW_AT_byte_size
	.byte	0x8	# DW_AT_encoding
	.long	.LASF3	# DW_AT_name: "character(kind=1)"
	.uleb128 0x7	# (DIE (0x76) DW_TAG_subprogram)
	.long	.LASF9	# DW_AT_name: "vla_stride"
	.byte	0x1	# DW_AT_decl_file (gdb.fortran/vla-stride.f90)
	.byte	0x10	# DW_AT_decl_line
			# DW_AT_main_subprogram
	.byte	0x2	# DW_AT_calling_convention
	.long	.LFB0	# DW_AT_low_pc
	.long	.LFE0-.LFB0	# DW_AT_high_pc
	.uleb128 0x1	# DW_AT_frame_base
	.byte	0x9c	# DW_OP_call_frame_cfa
			# DW_AT_GNU_all_tail_call_sites
	.long	0xe7	# DW_AT_sibling
	.uleb128 0x8	# (DIE (0x8c) DW_TAG_variable)
	.ascii "i\0"	# DW_AT_name
	.byte	0x1	# DW_AT_decl_file (gdb.fortran/vla-stride.f90)
	.byte	0x15	# DW_AT_decl_line
	.long	0x26	# DW_AT_type
	.uleb128 0x9	# (DIE (0x95) DW_TAG_variable)
	.long	.LASF4	# DW_AT_name: "pvla"
	.byte	0x1	# DW_AT_decl_file (gdb.fortran/vla-stride.f90)
	.byte	0x12	# DW_AT_decl_line
	.long	0xe7	# DW_AT_type
	.uleb128 0x2	# DW_AT_location
	.byte	0x91	# DW_OP_fbreg
	.sleb128 -56
	.uleb128 0xa	# (DIE (0xa3) DW_TAG_variable)
	.ascii "vla\0"	# DW_AT_name
	.byte	0x1	# DW_AT_decl_file (gdb.fortran/vla-stride.f90)
	.byte	0x11	# DW_AT_decl_line
	.long	0x10b	# DW_AT_type
	.uleb128 0x3	# DW_AT_location
	.byte	0x91	# DW_OP_fbreg
	.sleb128 -80
	.uleb128 0xb	# (DIE (0xb2) DW_TAG_lexical_block)
	.long	.LBB2	# DW_AT_low_pc
	.long	.LBE2-.LBB2	# DW_AT_high_pc
	.uleb128 0xc	# (DIE (0xbb) DW_TAG_lexical_block)
	.long	.LBB3	# DW_AT_low_pc
	.long	.LBE3-.LBB3	# DW_AT_high_pc
	.long	0xdc	# DW_AT_sibling
	.uleb128 0xb	# (DIE (0xc8) DW_TAG_lexical_block)
	.long	.LBB4	# DW_AT_low_pc
	.long	.LBE4-.LBB4	# DW_AT_high_pc
	.uleb128 0xd	# (DIE (0xd1) DW_TAG_lexical_block)
	.long	.LBB5	# DW_AT_low_pc
	.long	.LBE5-.LBB5	# DW_AT_high_pc
	.byte	0	# end of children of DIE 0xc8
	.byte	0	# end of children of DIE 0xbb
	.uleb128 0xd	# (DIE (0xdc) DW_TAG_lexical_block)
	.long	.LBB6	# DW_AT_low_pc
	.long	.LBE6-.LBB6	# DW_AT_high_pc
	.byte	0	# end of children of DIE 0xb2
	.byte	0	# end of children of DIE 0x76
	.uleb128 0xe	# (DIE (0xe7) DW_TAG_array_type)
	.uleb128 0x2	# DW_AT_data_location
	.byte	0x97	# DW_OP_push_object_address
	.byte	0x6	# DW_OP_deref
	.uleb128 0x4	# DW_AT_associated
	.byte	0x97	# DW_OP_push_object_address
	.byte	0x6	# DW_OP_deref
	.byte	0x30	# DW_OP_lit0
	.byte	0x2e	# DW_OP_ne
	.long	0x26	# DW_AT_type
	.long	0x10b	# DW_AT_sibling
	.uleb128 0xf	# (DIE (0xf8) DW_TAG_subrange_type)
	.uleb128 0x4	# DW_AT_lower_bound
	.byte	0x97	# DW_OP_push_object_address
	.byte	0x23	# DW_OP_plus_uconst
	.uleb128 0x10
	.byte	0x6	# DW_OP_deref
	.uleb128 0x4	# DW_AT_upper_bound
	.byte	0x97	# DW_OP_push_object_address
	.byte	0x23	# DW_OP_plus_uconst
	.uleb128 0x14
	.byte	0x6	# DW_OP_deref
	.uleb128 0x6	# DW_AT_byte_stride
	.byte	0x97	# DW_OP_push_object_address
	.byte	0x23	# DW_OP_plus_uconst
	.uleb128 0xc
	.byte	0x6	# DW_OP_deref
	.byte	0x34	# DW_OP_lit4
	.byte	0x1e	# DW_OP_mul
	.byte	0	# end of children of DIE 0xe7
	.uleb128 0x10	# (DIE (0x10b) DW_TAG_array_type)
	.uleb128 0x2	# DW_AT_data_location
	.byte	0x97	# DW_OP_push_object_address
	.byte	0x6	# DW_OP_deref
	.uleb128 0x4	# DW_AT_allocated
	.byte	0x97	# DW_OP_push_object_address
	.byte	0x6	# DW_OP_deref
	.byte	0x30	# DW_OP_lit0
	.byte	0x2e	# DW_OP_ne
	.long	0x26	# DW_AT_type
	.uleb128 0xf	# (DIE (0x118) DW_TAG_subrange_type)
	.uleb128 0x4	# DW_AT_lower_bound
	.byte	0x97	# DW_OP_push_object_address
	.byte	0x23	# DW_OP_plus_uconst
	.uleb128 0x10
	.byte	0x6	# DW_OP_deref
	.uleb128 0x4	# DW_AT_upper_bound
	.byte	0x97	# DW_OP_push_object_address
	.byte	0x23	# DW_OP_plus_uconst
	.uleb128 0x14
	.byte	0x6	# DW_OP_deref
	.uleb128 0x6	# DW_AT_byte_stride
	.byte	0x97	# DW_OP_push_object_address
	.byte	0x23	# DW_OP_plus_uconst
	.uleb128 0xc
	.byte	0x6	# DW_OP_deref
	.byte	0x34	# DW_OP_lit4
	.byte	0x1e	# DW_OP_mul
	.byte	0	# end of children of DIE 0x10b
	.byte	0	# end of children of DIE 0xb
	.section	.debug_abbrev,"",@progbits
.Ldebug_abbrev0:
	.uleb128 0x1	# (abbrev code)
	.uleb128 0x11	# (TAG: DW_TAG_compile_unit)
	.byte	0x1	# DW_children_yes
	.uleb128 0x25	# (DW_AT_producer)
	.uleb128 0xe	# (DW_FORM_strp)
	.uleb128 0x13	# (DW_AT_language)
	.uleb128 0xb	# (DW_FORM_data1)
	.uleb128 0x42	# (DW_AT_identifier_case)
	.uleb128 0xb	# (DW_FORM_data1)
	.uleb128 0x3	# (DW_AT_name)
	.uleb128 0xe	# (DW_FORM_strp)
	.uleb128 0x1b	# (DW_AT_comp_dir)
	.uleb128 0xe	# (DW_FORM_strp)
	.uleb128 0x11	# (DW_AT_low_pc)
	.uleb128 0x1	# (DW_FORM_addr)
	.uleb128 0x12	# (DW_AT_high_pc)
	.uleb128 0x6	# (DW_FORM_data4)
	.uleb128 0x10	# (DW_AT_stmt_list)
	.uleb128 0x17	# (DW_FORM_sec_offset)
	.byte	0
	.byte	0
	.uleb128 0x2	# (abbrev code)
	.uleb128 0x24	# (TAG: DW_TAG_base_type)
	.byte	0	# DW_children_no
	.uleb128 0xb	# (DW_AT_byte_size)
	.uleb128 0xb	# (DW_FORM_data1)
	.uleb128 0x3e	# (DW_AT_encoding)
	.uleb128 0xb	# (DW_FORM_data1)
	.uleb128 0x3	# (DW_AT_name)
	.uleb128 0xe	# (DW_FORM_strp)
	.byte	0
	.byte	0
	.uleb128 0x3	# (abbrev code)
	.uleb128 0x26	# (TAG: DW_TAG_const_type)
	.byte	0	# DW_children_no
	.uleb128 0x49	# (DW_AT_type)
	.uleb128 0x13	# (DW_FORM_ref4)
	.byte	0
	.byte	0
	.uleb128 0x4	# (abbrev code)
	.uleb128 0x2e	# (TAG: DW_TAG_subprogram)
	.byte	0x1	# DW_children_yes
	.uleb128 0x3f	# (DW_AT_external)
	.uleb128 0x19	# (DW_FORM_flag_present)
	.uleb128 0x3	# (DW_AT_name)
	.uleb128 0xe	# (DW_FORM_strp)
	.uleb128 0x3a	# (DW_AT_decl_file)
	.uleb128 0xb	# (DW_FORM_data1)
	.uleb128 0x3b	# (DW_AT_decl_line)
	.uleb128 0xb	# (DW_FORM_data1)
	.uleb128 0x49	# (DW_AT_type)
	.uleb128 0x13	# (DW_FORM_ref4)
	.uleb128 0x11	# (DW_AT_low_pc)
	.uleb128 0x1	# (DW_FORM_addr)
	.uleb128 0x12	# (DW_AT_high_pc)
	.uleb128 0x6	# (DW_FORM_data4)
	.uleb128 0x40	# (DW_AT_frame_base)
	.uleb128 0x18	# (DW_FORM_exprloc)
	.uleb128 0x2116	# (DW_AT_GNU_all_tail_call_sites)
	.uleb128 0x19	# (DW_FORM_flag_present)
	.uleb128 0x1	# (DW_AT_sibling)
	.uleb128 0x13	# (DW_FORM_ref4)
	.byte	0
	.byte	0
	.uleb128 0x5	# (abbrev code)
	.uleb128 0x5	# (TAG: DW_TAG_formal_parameter)
	.byte	0	# DW_children_no
	.uleb128 0x3	# (DW_AT_name)
	.uleb128 0xe	# (DW_FORM_strp)
	.uleb128 0x3a	# (DW_AT_decl_file)
	.uleb128 0xb	# (DW_FORM_data1)
	.uleb128 0x3b	# (DW_AT_decl_line)
	.uleb128 0xb	# (DW_FORM_data1)
	.uleb128 0x49	# (DW_AT_type)
	.uleb128 0x13	# (DW_FORM_ref4)
	.uleb128 0x2	# (DW_AT_location)
	.uleb128 0x18	# (DW_FORM_exprloc)
	.byte	0
	.byte	0
	.uleb128 0x6	# (abbrev code)
	.uleb128 0xf	# (TAG: DW_TAG_pointer_type)
	.byte	0	# DW_children_no
	.uleb128 0xb	# (DW_AT_byte_size)
	.uleb128 0xb	# (DW_FORM_data1)
	.uleb128 0x49	# (DW_AT_type)
	.uleb128 0x13	# (DW_FORM_ref4)
	.byte	0
	.byte	0
	.uleb128 0x7	# (abbrev code)
	.uleb128 0x2e	# (TAG: DW_TAG_subprogram)
	.byte	0x1	# DW_children_yes
	.uleb128 0x3	# (DW_AT_name)
	.uleb128 0xe	# (DW_FORM_strp)
	.uleb128 0x3a	# (DW_AT_decl_file)
	.uleb128 0xb	# (DW_FORM_data1)
	.uleb128 0x3b	# (DW_AT_decl_line)
	.uleb128 0xb	# (DW_FORM_data1)
	.uleb128 0x6a	# (DW_AT_main_subprogram)
	.uleb128 0x19	# (DW_FORM_flag_present)
	.uleb128 0x36	# (DW_AT_calling_convention)
	.uleb128 0xb	# (DW_FORM_data1)
	.uleb128 0x11	# (DW_AT_low_pc)
	.uleb128 0x1	# (DW_FORM_addr)
	.uleb128 0x12	# (DW_AT_high_pc)
	.uleb128 0x6	# (DW_FORM_data4)
	.uleb128 0x40	# (DW_AT_frame_base)
	.uleb128 0x18	# (DW_FORM_exprloc)
	.uleb128 0x2116	# (DW_AT_GNU_all_tail_call_sites)
	.uleb128 0x19	# (DW_FORM_flag_present)
	.uleb128 0x1	# (DW_AT_sibling)
	.uleb128 0x13	# (DW_FORM_ref4)
	.byte	0
	.byte	0
	.uleb128 0x8	# (abbrev code)
	.uleb128 0x34	# (TAG: DW_TAG_variable)
	.byte	0	# DW_children_no
	.uleb128 0x3	# (DW_AT_name)
	.uleb128 0x8	# (DW_FORM_string)
	.uleb128 0x3a	# (DW_AT_decl_file)
	.uleb128 0xb	# (DW_FORM_data1)
	.uleb128 0x3b	# (DW_AT_decl_line)
	.uleb128 0xb	# (DW_FORM_data1)
	.uleb128 0x49	# (DW_AT_type)
	.uleb128 0x13	# (DW_FORM_ref4)
	.byte	0
	.byte	0
	.uleb128 0x9	# (abbrev code)
	.uleb128 0x34	# (TAG: DW_TAG_variable)
	.byte	0	# DW_children_no
	.uleb128 0x3	# (DW_AT_name)
	.uleb128 0xe	# (DW_FORM_strp)
	.uleb128 0x3a	# (DW_AT_decl_file)
	.uleb128 0xb	# (DW_FORM_data1)
	.uleb128 0x3b	# (DW_AT_decl_line)
	.uleb128 0xb	# (DW_FORM_data1)
	.uleb128 0x49	# (DW_AT_type)
	.uleb128 0x13	# (DW_FORM_ref4)
	.uleb128 0x2	# (DW_AT_location)
	.uleb128 0x18	# (DW_FORM_exprloc)
	.byte	0
	.byte	0
	.uleb128 0xa	# (abbrev code)
	.uleb128 0x34	# (TAG: DW_TAG_variable)
	.byte	0	# DW_children_no
	.uleb128 0x3	# (DW_AT_name)
	.uleb128 0x8	# (DW_FORM_string)
	.uleb128 0x3a	# (DW_AT_decl_file)
	.uleb128 0xb	# (DW_FORM_data1)
	.uleb128 0x3b	# (DW_AT_decl_line)
	.uleb128 0xb	# (DW_FORM_data1)
	.uleb128 0x49	# (DW_AT_type)
	.uleb128 0x13	# (DW_FORM_ref4)
	.uleb128 0x2	# (DW_AT_location)
	.uleb128 0x18	# (DW_FORM_exprloc)
	.byte	0
	.byte	0
	.uleb128 0xb	# (abbrev code)
	.uleb128 0xb	# (TAG: DW_TAG_lexical_block)
	.byte	0x1	# DW_children_yes
	.uleb128 0x11	# (DW_AT_low_pc)
	.uleb128 0x1	# (DW_FORM_addr)
	.uleb128 0x12	# (DW_AT_high_pc)
	.uleb128 0x6	# (DW_FORM_data4)
	.byte	0
	.byte	0
	.uleb128 0xc	# (abbrev code)
	.uleb128 0xb	# (TAG: DW_TAG_lexical_block)
	.byte	0x1	# DW_children_yes
	.uleb128 0x11	# (DW_AT_low_pc)
	.uleb128 0x1	# (DW_FORM_addr)
	.uleb128 0x12	# (DW_AT_high_pc)
	.uleb128 0x6	# (DW_FORM_data4)
	.uleb128 0x1	# (DW_AT_sibling)
	.uleb128 0x13	# (DW_FORM_ref4)
	.byte	0
	.byte	0
	.uleb128 0xd	# (abbrev code)
	.uleb128 0xb	# (TAG: DW_TAG_lexical_block)
	.byte	0	# DW_children_no
	.uleb128 0x11	# (DW_AT_low_pc)
	.uleb128 0x1	# (DW_FORM_addr)
	.uleb128 0x12	# (DW_AT_high_pc)
	.uleb128 0x6	# (DW_FORM_data4)
	.byte	0
	.byte	0
	.uleb128 0xe	# (abbrev code)
	.uleb128 0x1	# (TAG: DW_TAG_array_type)
	.byte	0x1	# DW_children_yes
	.uleb128 0x50	# (DW_AT_data_location)
	.uleb128 0x18	# (DW_FORM_exprloc)
	.uleb128 0x4f	# (DW_AT_associated)
	.uleb128 0x18	# (DW_FORM_exprloc)
	.uleb128 0x49	# (DW_AT_type)
	.uleb128 0x13	# (DW_FORM_ref4)
	.uleb128 0x1	# (DW_AT_sibling)
	.uleb128 0x13	# (DW_FORM_ref4)
	.byte	0
	.byte	0
	.uleb128 0xf	# (abbrev code)
	.uleb128 0x21	# (TAG: DW_TAG_subrange_type)
	.byte	0	# DW_children_no
	.uleb128 0x22	# (DW_AT_lower_bound)
	.uleb128 0x18	# (DW_FORM_exprloc)
	.uleb128 0x2f	# (DW_AT_upper_bound)
	.uleb128 0x18	# (DW_FORM_exprloc)
	.uleb128 0x51	# (DW_AT_byte_stride)
	.uleb128 0x18	# (DW_FORM_exprloc)
	.byte	0
	.byte	0
	.uleb128 0x10	# (abbrev code)
	.uleb128 0x1	# (TAG: DW_TAG_array_type)
	.byte	0x1	# DW_children_yes
	.uleb128 0x50	# (DW_AT_data_location)
	.uleb128 0x18	# (DW_FORM_exprloc)
	.uleb128 0x4e	# (DW_AT_allocated)
	.uleb128 0x18	# (DW_FORM_exprloc)
	.uleb128 0x49	# (DW_AT_type)
	.uleb128 0x13	# (DW_FORM_ref4)
	.byte	0
	.byte	0
	.byte	0
	.section	.debug_aranges,"",@progbits
	.long	0x1c	# Length of Address Ranges Info
	.value	0x2	# DWARF Version
	.long	.Ldebug_info0	# Offset of Compilation Unit Info
	.byte	0x4	# Size of Address
	.byte	0	# Size of Segment Descriptor
	.value	0	# Pad to 8 byte boundary
	.value	0
	.long	.Ltext0	# Address
	.long	.Letext0-.Ltext0	# Length
	.long	0
	.long	0
	.section	.debug_line,"",@progbits
.Ldebug_line0:
	.section	.debug_str,"MS",@progbits,1
.LASF7:
	.string	"/home/jkratoch/redhat/gdb-clean/gdb/testsuite"
.LASF3:
	.string	"character(kind=1)"
.LASF0:
	.string	"argc"
.LASF9:
	.string	"vla_stride"
.LASF2:
	.string	"integer(kind=4)"
.LASF5:
	.string	"GNU Fortran2008 6.1.1 20160621 (Red Hat 6.1.1-3) -m32 -mtune=generic -march=i686 -g -fintrinsic-modules-path /usr/lib/gcc/x86_64-redhat-linux/6.1.1/32/finclude"
.LASF8:
	.string	"main"
.LASF4:
	.string	"pvla"
.LASF6:
	.string	"gdb.fortran/vla-stride.f90"
.LASF1:
	.string	"argv"
	.ident	"GCC: (GNU) 6.1.1 20160621 (Red Hat 6.1.1-3)"
	.section	.note.GNU-stack,"",@progbits

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [V4 00/21] Fortran dynamic array support
  2016-08-21 17:04                       ` Jan Kratochvil
@ 2016-08-23 13:34                         ` Bernhard Heckel
  2016-08-25 17:06                           ` Jan Kratochvil
  2016-09-01  9:48                           ` Jan Kratochvil
  0 siblings, 2 replies; 53+ messages in thread
From: Bernhard Heckel @ 2016-08-23 13:34 UTC (permalink / raw)
  To: Jan Kratochvil; +Cc: Weinmann, Christoph T, gdb-patches

On 21/08/2016 19:03, Jan Kratochvil wrote:
> On Fri, 19 Aug 2016 11:58:09 +0200, Bernhard Heckel wrote:
>> here is the missing patch in your environment.
>> https://sourceware.org/ml/gdb-patches/2015-01/msg00385.html
>> This patch handles strides in DWARF and your fortran program.
> OK, thanks, it does fix:
> 	-FAIL: gdb.fortran/dynamic.exp: p varw filled
> 	+PASS: gdb.fortran/dynamic.exp: p varw filled
> 	-FAIL: gdb.fortran/vla-stride.exp: print odd-elements
> 	+PASS: gdb.fortran/vla-stride.exp: print odd-elements
> 	-FAIL: gdb.fortran/vla-stride.exp: print last odd-element
> 	+PASS: gdb.fortran/vla-stride.exp: print last odd-element
>
> Although it regresses:
> 	 print pvla^M
> 	-$7 = (5)^M
> 	-(gdb) PASS: gdb.fortran/vla-stride.exp: print single-element
> 	+value requires 4294967288 bytes, which is more than max-value-size^M
> 	+(gdb) FAIL: gdb.fortran/vla-stride.exp: print single-element
> 	-$8 = 5^M
> 	-(gdb) PASS: gdb.fortran/vla-stride.exp: print one single-element
> 	+Insufficient memory in host GDB for object of size 4294967288 bytes, maximum allowed 536870911 bytes.^M
> 	+(gdb) FAIL: gdb.fortran/vla-stride.exp: print one single-element
>
>
>> I will create a branch about all stride patches in the next weeks.
> That would be probably best, thanks.
>
>
> Jan
Hi Jan,

created a branch with all stride patches.
I don't see regression on RH7.1, gcc 4.8.3-9


Intel Deutschland GmbH
Registered Address: Am Campeon 10-12, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de
Managing Directors: Christin Eisenschmid, Christian Lamprechter
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [V4 00/21] Fortran dynamic array support
  2016-08-19  9:58                     ` Bernhard Heckel
@ 2016-08-21 17:04                       ` Jan Kratochvil
  2016-08-23 13:34                         ` Bernhard Heckel
  0 siblings, 1 reply; 53+ messages in thread
From: Jan Kratochvil @ 2016-08-21 17:04 UTC (permalink / raw)
  To: Bernhard Heckel; +Cc: Weinmann, Christoph T, gdb-patches

On Fri, 19 Aug 2016 11:58:09 +0200, Bernhard Heckel wrote:
> here is the missing patch in your environment.
> https://sourceware.org/ml/gdb-patches/2015-01/msg00385.html
> This patch handles strides in DWARF and your fortran program.

OK, thanks, it does fix:
	-FAIL: gdb.fortran/dynamic.exp: p varw filled
	+PASS: gdb.fortran/dynamic.exp: p varw filled
	-FAIL: gdb.fortran/vla-stride.exp: print odd-elements
	+PASS: gdb.fortran/vla-stride.exp: print odd-elements
	-FAIL: gdb.fortran/vla-stride.exp: print last odd-element
	+PASS: gdb.fortran/vla-stride.exp: print last odd-element

Although it regresses:
	 print pvla^M
	-$7 = (5)^M
	-(gdb) PASS: gdb.fortran/vla-stride.exp: print single-element
	+value requires 4294967288 bytes, which is more than max-value-size^M
	+(gdb) FAIL: gdb.fortran/vla-stride.exp: print single-element
	-$8 = 5^M
	-(gdb) PASS: gdb.fortran/vla-stride.exp: print one single-element
	+Insufficient memory in host GDB for object of size 4294967288 bytes, maximum allowed 536870911 bytes.^M
	+(gdb) FAIL: gdb.fortran/vla-stride.exp: print one single-element


> I will create a branch about all stride patches in the next weeks.

That would be probably best, thanks.


Jan

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [V4 00/21] Fortran dynamic array support
  2016-08-16 13:59                   ` Jan Kratochvil
@ 2016-08-19  9:58                     ` Bernhard Heckel
  2016-08-21 17:04                       ` Jan Kratochvil
  0 siblings, 1 reply; 53+ messages in thread
From: Bernhard Heckel @ 2016-08-19  9:58 UTC (permalink / raw)
  To: Jan Kratochvil; +Cc: Weinmann, Christoph T, gdb-patches

On 16/08/2016 15:59, Jan Kratochvil wrote:
> Hi Bernhard,
>
> On Tue, 09 Aug 2016 09:55:05 +0200, Heckel, Bernhard wrote:
>> I took a look at "p varw" issue.
>>
>> >From my point of view, the debug information for  the location of varw is wrong.
>>
>> Set a breakpoint at line 68 and run.
>> "P &varw" in GDB gives me same location as the print of "loc(z(2,4,6))" out of the fortran testcase.
>> Nevertheless, "loc(varw)" shows me a different location. Investigating on the dwarf debug info, GDB address calculation
>> of "varw" is correct. From my point of view, the location expression of "varw" is wrong.
>>
>> If you manual examine the content at "loc(varw)" you see the right content.
>>
>> FYI: I added a variable "dummy" in subroutine "foo" in order to get the content of fbreg and do manual address calculation.
>>
>> I attached the testcase + dwarf
> primarily Fedora 24 GDB (and many Fedora releases back) - with the older Intel
> VLA patch series - does PASS the testcase fine with gfortran DWARF so
> completely wrong the DWARF is not.
>
> Also you talk here only about starting address of 'varw'.  But that is not
> a problem, the starting address in inferior + in GDB do match:
>    varw(1, 1, 1) = 6
> vs.
> $23 = (( ( 6, 5, 1, 5, 5) ( 3, 3, 3, 5, 5) ( 5, 5, 5, 3, 3) ( 3, 5, 5, 5, 5) ) ( ( 5, 3, 3, 3, 5) ( 5, 5, 5, 5, 3) ( 3, 3, 3, 3, 3) ( 3, 3, 3, 3, 3) ) ( ( 3, 3, 3, 3, 3) ( 3, 3, 3, 3, 3) ( 3, 3, 3, 3, 3) ( 3, 3, 3, 3, 3) ) )
> (gdb) FAIL: gdb.fortran/dynamic.exp: p varw filled
>   - the value 6 is really the first (1,1,1) value printed.
> The starting address is nothing special for GDB as starting address is
> adjusted/offseted by the inferior caller, GDB just reads the inferior-computed
> address.
>
> What is wrong is accessing 'varw' elements not in the first row of the array
> by GDB - because GDB needs to know the stride for it.
> Stride is described there in DWARF:
>      <231>   DW_AT_upper_bound : 11 byte block: 31 97 23 28 6 97 23 20 6 1c 22   (DW_OP_lit1; DW_OP_push_object_address; DW_OP_plus_uconst: 40; DW_OP_deref; DW_OP_push_object_address; DW_OP_plus_uconst: 32; DW_OP_deref; DW_OP_minus; DW_OP_plus)
>      <23d>   DW_AT_byte_stride : 6 byte block: 97 23 18 6 34 1e  (DW_OP_push_object_address; DW_OP_plus_uconst: 24; DW_OP_deref; DW_OP_lit4; DW_OP_mul)
> and that just fetches the values from gfortran array descriptor - otherwise the
> inferior Fortran function 'foo' would not work.
>
> Why do you think gfortran has the DWARF wrong?  Do your GDB patches PASS with
> ifort?  I no longer have ifort - I got a license from Markus Metzger many
> years ago, it was somehow complicated in Intel to get it for me and the
> license laster only one year.  You would have to send me the ifort-built
> binary (or .s file).
>
>
> I have tried now to re-apply a part of the old working Intel VLA patch of
> value_subscripted_rvalue():
>     unsigned int elt_size = TYPE_LENGTH (elt_type);
> -  unsigned int elt_offs = elt_size * longest_to_int (index - lowerbound);
> +  unsigned int elt_offs = longest_to_int (index - lowerbound);
> +  LONGEST elt_stride = TYPE_BYTE_STRIDE (TYPE_INDEX_TYPE (array_type));
>     struct value *v;
>
> +  if (elt_stride > 0)
> +    elt_offs *= elt_stride;
> +  else if (elt_stride < 0)
> +    {
> +      int offs = (elt_offs + 1) * elt_stride;
> +
> +      elt_offs = TYPE_LENGTH (array_type) + offs;
> +    }
> +  else
> +    elt_offs *= elt_size;
> +
>
> But it does not work (attached).  Maybe because the stride of an array now
> appears to be stored into TYPE_FIELD_BITSIZE of the array itself (not its type)
> while with old Intel VLA patchset there was a special field TYPE_BYTE_STRIDE
> for that.
>
>
> Thanks,
> Jan
Hi Jan,

here is the missing patch in your environment.
https://sourceware.org/ml/gdb-patches/2015-01/msg00385.html
This patch handles strides in DWARF and your fortran program.

Christoph's patch series was about strides in user input, for example 
"print my_vla(1:10:2)"

I will create a branch about all stride patches in the next weeks.



Intel Deutschland GmbH
Registered Address: Am Campeon 10-12, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de
Managing Directors: Christin Eisenschmid, Christian Lamprechter
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [V4 00/21] Fortran dynamic array support
       [not found]                 ` <88072818E0A3D742B2B1AF16BBEC65A7263F0988@IRSMSX107.ger.corp.intel.com>
@ 2016-08-16 13:59                   ` Jan Kratochvil
  2016-08-19  9:58                     ` Bernhard Heckel
  0 siblings, 1 reply; 53+ messages in thread
From: Jan Kratochvil @ 2016-08-16 13:59 UTC (permalink / raw)
  To: Heckel, Bernhard; +Cc: Weinmann, Christoph T, gdb-patches

[-- Attachment #1: Type: text/plain, Size: 3530 bytes --]

Hi Bernhard,

On Tue, 09 Aug 2016 09:55:05 +0200, Heckel, Bernhard wrote:
> I took a look at "p varw" issue.
> 
> >From my point of view, the debug information for  the location of varw is wrong. 
> 
> Set a breakpoint at line 68 and run.
> "P &varw" in GDB gives me same location as the print of "loc(z(2,4,6))" out of the fortran testcase.
> Nevertheless, "loc(varw)" shows me a different location. Investigating on the dwarf debug info, GDB address calculation
> of "varw" is correct. From my point of view, the location expression of "varw" is wrong.
> 
> If you manual examine the content at "loc(varw)" you see the right content.
> 
> FYI: I added a variable "dummy" in subroutine "foo" in order to get the content of fbreg and do manual address calculation. 
> 
> I attached the testcase + dwarf

primarily Fedora 24 GDB (and many Fedora releases back) - with the older Intel
VLA patch series - does PASS the testcase fine with gfortran DWARF so
completely wrong the DWARF is not.

Also you talk here only about starting address of 'varw'.  But that is not
a problem, the starting address in inferior + in GDB do match:
  varw(1, 1, 1) = 6
vs.
$23 = (( ( 6, 5, 1, 5, 5) ( 3, 3, 3, 5, 5) ( 5, 5, 5, 3, 3) ( 3, 5, 5, 5, 5) ) ( ( 5, 3, 3, 3, 5) ( 5, 5, 5, 5, 3) ( 3, 3, 3, 3, 3) ( 3, 3, 3, 3, 3) ) ( ( 3, 3, 3, 3, 3) ( 3, 3, 3, 3, 3) ( 3, 3, 3, 3, 3) ( 3, 3, 3, 3, 3) ) )
(gdb) FAIL: gdb.fortran/dynamic.exp: p varw filled
 - the value 6 is really the first (1,1,1) value printed.
The starting address is nothing special for GDB as starting address is
adjusted/offseted by the inferior caller, GDB just reads the inferior-computed
address.

What is wrong is accessing 'varw' elements not in the first row of the array
by GDB - because GDB needs to know the stride for it.
Stride is described there in DWARF:
    <231>   DW_AT_upper_bound : 11 byte block: 31 97 23 28 6 97 23 20 6 1c 22   (DW_OP_lit1; DW_OP_push_object_address; DW_OP_plus_uconst: 40; DW_OP_deref; DW_OP_push_object_address; DW_OP_plus_uconst: 32; DW_OP_deref; DW_OP_minus; DW_OP_plus)
    <23d>   DW_AT_byte_stride : 6 byte block: 97 23 18 6 34 1e  (DW_OP_push_object_address; DW_OP_plus_uconst: 24; DW_OP_deref; DW_OP_lit4; DW_OP_mul)
and that just fetches the values from gfortran array descriptor - otherwise the
inferior Fortran function 'foo' would not work.

Why do you think gfortran has the DWARF wrong?  Do your GDB patches PASS with
ifort?  I no longer have ifort - I got a license from Markus Metzger many
years ago, it was somehow complicated in Intel to get it for me and the
license laster only one year.  You would have to send me the ifort-built
binary (or .s file).


I have tried now to re-apply a part of the old working Intel VLA patch of
value_subscripted_rvalue():
   unsigned int elt_size = TYPE_LENGTH (elt_type);
-  unsigned int elt_offs = elt_size * longest_to_int (index - lowerbound);
+  unsigned int elt_offs = longest_to_int (index - lowerbound);
+  LONGEST elt_stride = TYPE_BYTE_STRIDE (TYPE_INDEX_TYPE (array_type));
   struct value *v;

+  if (elt_stride > 0)
+    elt_offs *= elt_stride;
+  else if (elt_stride < 0)
+    {
+      int offs = (elt_offs + 1) * elt_stride;
+
+      elt_offs = TYPE_LENGTH (array_type) + offs;
+    }
+  else
+    elt_offs *= elt_size;
+

But it does not work (attached).  Maybe because the stride of an array now
appears to be stored into TYPE_FIELD_BITSIZE of the array itself (not its type)
while with old Intel VLA patchset there was a special field TYPE_BYTE_STRIDE
for that.


Thanks,
Jan

[-- Attachment #2: 1 --]
[-- Type: text/plain, Size: 2181 bytes --]

--- ./gdb/valarith.c	2016-08-16 15:36:10.680313175 +0200
+++ ./gdb/valarith.c	2016-08-16 15:33:18.696930843 +0200
@@ -193,9 +193,22 @@ value_subscripted_rvalue (struct value *
   struct type *array_type = check_typedef (value_type (array));
   struct type *elt_type = check_typedef (TYPE_TARGET_TYPE (array_type));
   ULONGEST elt_size = type_length_units (elt_type);
-  ULONGEST elt_offs = elt_size * (index - lowerbound);
+  ULONGEST elt_offs = index - lowerbound;
+  LONGEST elt_stride = TYPE_FIELD_BITSIZE (array_type, 0);
   struct value *v;
 
+if (elt_stride) fprintf(stderr,"value_subscripted_rvalue: elt_stride=%ld\n",elt_stride);
+  if (elt_stride > 0)
+    elt_offs *= elt_stride;
+  else if (elt_stride < 0)
+    {
+      int offs = (elt_offs + 1) * elt_stride;
+
+      elt_offs = TYPE_LENGTH (array_type) + offs;
+    }
+  else
+    elt_offs *= elt_size;
+
   if (index < lowerbound || (!TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (array_type)
 			     && elt_offs >= type_length_units (array_type)))
     {
--- ./gdb/valops.c	2016-08-16 15:36:10.694313288 +0200
+++ ./gdb/valops.c	2016-08-16 15:04:54.963343948 +0200
@@ -3826,7 +3826,7 @@ value_slice_1 (struct value *array, int
   struct type *elt_type = check_typedef (TYPE_TARGET_TYPE (array_type));
   unsigned int elt_size, elt_offs;
   /* ATTRIBUTE_UNUSED: VLA bug: https://sourceware.org/ml/gdb-patches/2016-08/msg00099.html */
-  LONGEST elt_stride ATTRIBUTE_UNUSED, ary_high_bound, ary_low_bound;
+  LONGEST elt_stride, ary_high_bound, ary_low_bound;
   struct value *v;
   int slice_range_size, i = 0, row_count = 1, elem_count = 1;
 
@@ -3863,7 +3863,17 @@ value_slice_1 (struct value *array, int
   elt_offs = lowbound - ary_low_bound;
   elt_stride = TYPE_LENGTH (TYPE_INDEX_TYPE (array_type));
 
-  elt_offs *= elt_size;
+fprintf(stderr,"elt_stride=%d\n",elt_stride);
+  if (elt_stride > 0)
+    elt_offs *= elt_stride;
+  else if (elt_stride < 0)
+    {
+      int offs = (elt_offs + 1) * elt_stride;
+
+      elt_offs = TYPE_LENGTH (array_type) + offs;
+    }
+  else
+    elt_offs *= elt_size;
 
   /* Check for valid user input.  In case of Fortran this was already done
      in the calling function.  */

^ permalink raw reply	[flat|nested] 53+ messages in thread

end of thread, other threads:[~2016-09-14 12:53 UTC | newest]

Thread overview: 53+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-14 13:49 [V4 00/21] Fortran dynamic array support Keven Boell
2015-01-14 13:49 ` [V4 07/18] test: evaluating allocation/association status Keven Boell
2015-01-14 13:49 ` [V4 04/18] test: evaluate dynamic arrays using Fortran primitives Keven Boell
2015-01-14 13:49 ` [V4 01/18] vla: introduce allocated/associated flags Keven Boell
2015-02-09  6:52   ` Joel Brobecker
2015-02-09 23:37     ` Doug Evans
2015-02-11  8:44       ` Joel Brobecker
2015-02-11 17:36         ` Doug Evans
2015-02-18 15:54     ` Keven Boell
2015-01-14 13:50 ` [V4 06/18] test: correct ptype of dynamic arrays in Fortran Keven Boell
2015-01-14 13:50 ` [V4 11/18] test: test sizeof for dynamic fortran arrays Keven Boell
2015-01-14 13:50 ` [V4 15/18] vla: get dynamic array corner cases to work Keven Boell
2015-01-14 13:50 ` [V4 13/18] vla: reconstruct value to compute bounds of target type Keven Boell
2015-01-14 13:50 ` [V4 09/18] test: accessing dynamic array history values Keven Boell
2015-01-14 13:50 ` [V4 18/18] vla: add NEWS entry for dynamic array support Keven Boell
2015-01-14 18:01   ` Eli Zaretskii
2015-01-14 13:50 ` [V4 16/18] vla: Fortran dynamic string support Keven Boell
2015-01-14 13:50 ` [V4 03/18] test: basic tests for dynamic array evaluations in Fortran Keven Boell
2015-01-14 13:50 ` [V4 02/18] vla: make dynamic fortran arrays functional Keven Boell
2015-02-09  7:09   ` Joel Brobecker
2015-02-18 16:02     ` Keven Boell
2015-02-22  4:23       ` Joel Brobecker
2015-01-14 13:50 ` [V4 17/18] vla: add stride support to fortran arrays Keven Boell
2015-01-14 13:50 ` [V4 05/18] test: dynamic arrays passed to subroutines Keven Boell
2015-01-14 13:50 ` [V4 10/18] test: basic MI test for the dynamic array support Keven Boell
2015-01-14 13:50 ` [V4 14/18] vla: use value constructor instead of raw-buffer manipulation Keven Boell
2015-01-14 13:50 ` [V4 12/18] test: add archer dynamic other frame test Keven Boell
2015-01-14 13:50 ` [V4 08/18] test: dynamic arrays passed to functions Keven Boell
2015-05-28 20:36 ` [V4 00/21] Fortran dynamic array support Jan Kratochvil
2015-05-28 20:52   ` Joel Brobecker
2015-06-14  8:15 ` Jan Kratochvil
2015-06-17 11:42   ` Boell, Keven
2015-07-01 12:43     ` Keven Boell
2016-07-07  8:30 ` Jan Kratochvil
2016-07-07  9:16   ` Bernhard Heckel
2016-07-07  9:23     ` Jan Kratochvil
     [not found] <88072818E0A3D742B2B1AF16BBEC65A7263D8247@IRSMSX107.ger.corp.intel.com>
     [not found] ` <20160707095439.GA6792@host1.jankratochvil.net>
     [not found]   ` <88072818E0A3D742B2B1AF16BBEC65A7263D990E@IRSMSX107.ger.corp.intel.com>
     [not found]     ` <20160714182743.GA10672@host1.jankratochvil.net>
     [not found]       ` <88072818E0A3D742B2B1AF16BBEC65A7263E6F2E@IRSMSX107.ger.corp.intel.com>
     [not found]         ` <20160715091352.GA8059@host1.jankratochvil.net>
     [not found]           ` <88072818E0A3D742B2B1AF16BBEC65A7263E8FD9@IRSMSX107.ger.corp.intel.com>
     [not found]             ` <20160716151310.GA14331@host1.jankratochvil.net>
     [not found]               ` <20160716151837.GA797@host1.jankratochvil.net>
     [not found]                 ` <88072818E0A3D742B2B1AF16BBEC65A7263F0988@IRSMSX107.ger.corp.intel.com>
2016-08-16 13:59                   ` Jan Kratochvil
2016-08-19  9:58                     ` Bernhard Heckel
2016-08-21 17:04                       ` Jan Kratochvil
2016-08-23 13:34                         ` Bernhard Heckel
2016-08-25 17:06                           ` Jan Kratochvil
2016-08-25 17:22                             ` Jan Kratochvil
2016-08-26  7:17                               ` Jan Kratochvil
2016-09-01 10:11                                 ` Bernhard Heckel
2016-09-02 13:44                             ` Bernhard Heckel
2016-09-04 17:15                               ` Jan Kratochvil
2016-09-07 10:29                                 ` Bernhard Heckel
2016-09-07 20:05                                   ` Jan Kratochvil
2016-09-12 21:05                                   ` Jan Kratochvil
2016-09-14  7:24                                     ` Bernhard Heckel
2016-09-14 12:53                                       ` Jan Kratochvil
2016-09-07 20:24                                 ` Jan Kratochvil
2016-09-01  9:48                           ` Jan Kratochvil

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).