Blame SOURCES/gdb-vla-intel-fortran-vla-strings.patch

5ad05e
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
5ad05e
From: Fedora GDB patches <invalid@email.com>
5ad05e
Date: Fri, 27 Oct 2017 21:07:50 +0200
5ad05e
Subject: gdb-vla-intel-fortran-vla-strings.patch
5ad05e
5ad05e
;;=push
5ad05e
5ad05e
git diff --stat -p gdb/master...gdb/users/bheckel/fortran-vla-strings
5ad05e
0ad7d8d1a3a36c6e04e3b6d37d8825f18d595723
5ad05e
5ad05e
 gdb/NEWS                                  |   2 +
5ad05e
 gdb/c-valprint.c                          |  22 +++++
5ad05e
 gdb/dwarf2read.c                          | 158 +++++++++++++++++++++++++-----
5ad05e
 gdb/f-typeprint.c                         |  93 +++++++++---------
5ad05e
 gdb/gdbtypes.c                            |  44 ++++++++-
5ad05e
 gdb/testsuite/gdb.cp/vla-cxx.cc           |   9 ++
5ad05e
 gdb/testsuite/gdb.cp/vla-cxx.exp          |   9 ++
5ad05e
 gdb/testsuite/gdb.fortran/pointers.exp    | 143 +++++++++++++++++++++++++++
5ad05e
 gdb/testsuite/gdb.fortran/pointers.f90    | 109 +++++++++++++++++++++
5ad05e
 gdb/testsuite/gdb.fortran/print_type.exp  | 100 +++++++++++++++++++
5ad05e
 gdb/testsuite/gdb.fortran/vla-ptype.exp   |  12 +--
5ad05e
 gdb/testsuite/gdb.fortran/vla-strings.exp | 103 +++++++++++++++++++
5ad05e
 gdb/testsuite/gdb.fortran/vla-strings.f90 |  39 ++++++++
5ad05e
 gdb/testsuite/gdb.fortran/vla-type.exp    |   7 +-
5ad05e
 gdb/testsuite/gdb.fortran/vla-value.exp   |  12 ++-
5ad05e
 gdb/testsuite/gdb.mi/mi-var-child-f.exp   |   7 +-
5ad05e
 gdb/testsuite/gdb.mi/mi-vla-fortran.exp   |  27 ++---
5ad05e
 gdb/typeprint.c                           |  19 ++++
5ad05e
 gdb/valops.c                              |  16 ++-
5ad05e
 gdb/valprint.c                            |   6 --
5ad05e
 20 files changed, 827 insertions(+), 110 deletions(-)
5ad05e
5ad05e
diff --git a/gdb/NEWS b/gdb/NEWS
5ad05e
--- a/gdb/NEWS
5ad05e
+++ b/gdb/NEWS
5ad05e
@@ -805,6 +805,8 @@ SH-5/SH64 running OpenBSD 	SH-5/SH64 support in sh*-*-openbsd*
5ad05e
 
5ad05e
 *** Changes in GDB 8.1
5ad05e
 
5ad05e
+* Fortran: Support pointers to dynamic types.
5ad05e
+
5ad05e
 * GDB now supports dynamically creating arbitrary register groups specified
5ad05e
   in XML target descriptions.  This allows for finer grain grouping of
5ad05e
   registers on systems with a large amount of registers.
5ad05e
diff --git a/gdb/c-valprint.c b/gdb/c-valprint.c
5ad05e
--- a/gdb/c-valprint.c
5ad05e
+++ b/gdb/c-valprint.c
5ad05e
@@ -649,6 +649,28 @@ c_value_print (struct value *val, struct ui_file *stream,
5ad05e
       else
5ad05e
 	{
5ad05e
 	  /* normal case */
5ad05e
+	  if (TYPE_CODE (type) == TYPE_CODE_PTR
5ad05e
+	      && 1 == is_dynamic_type (type))
5ad05e
+	    {
5ad05e
+	      CORE_ADDR addr;
5ad05e
+	      if (NULL != TYPE_DATA_LOCATION (TYPE_TARGET_TYPE (type)))
5ad05e
+		addr = value_address (val);
5ad05e
+	      else
5ad05e
+		addr = value_as_address (val);
5ad05e
+
5ad05e
+	      /* We resolve the target-type only when the
5ad05e
+	         pointer is associated.  */
5ad05e
+	      if ((addr != 0)
5ad05e
+		  && (0 == type_not_associated (type)))
5ad05e
+		  TYPE_TARGET_TYPE (type) =
5ad05e
+		      resolve_dynamic_type (TYPE_TARGET_TYPE (type),
5ad05e
+					    NULL, addr);
5ad05e
+	    }
5ad05e
+	  else
5ad05e
+	    {
5ad05e
+	      /* Do nothing. References are already resolved from the beginning,
5ad05e
+	         only pointers are resolved when we actual need the target.  */
5ad05e
+	    }
5ad05e
 	  fprintf_filtered (stream, "(");
5ad05e
 	  type_print (value_type (val), "", stream, -1);
5ad05e
 	  fprintf_filtered (stream, ") ");
5ad05e
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
5ad05e
--- a/gdb/dwarf2read.c
5ad05e
+++ b/gdb/dwarf2read.c
5ad05e
@@ -1827,7 +1827,10 @@ static void read_signatured_type (struct signatured_type *);
5ad05e
 
5ad05e
 static int attr_to_dynamic_prop (const struct attribute *attr,
5ad05e
 				 struct die_info *die, struct dwarf2_cu *cu,
5ad05e
-				 struct dynamic_prop *prop, struct type *type);
5ad05e
+				 struct dynamic_prop *prop,
5ad05e
+				 struct type *default_type,
5ad05e
+				 const gdb_byte *additional_data,
5ad05e
+				 int additional_data_size);
5ad05e
 
5ad05e
 /* memory allocation interface */
5ad05e
 
5ad05e
@@ -13799,7 +13802,7 @@ read_func_scope (struct die_info *die, struct dwarf2_cu *cu)
5ad05e
       newobj->static_link
5ad05e
 	= XOBNEW (&objfile->objfile_obstack, struct dynamic_prop);
5ad05e
       attr_to_dynamic_prop (attr, die, cu, newobj->static_link,
5ad05e
-			    dwarf2_per_cu_addr_type (cu->per_cu));
5ad05e
+			    dwarf2_per_cu_addr_type (cu->per_cu), NULL, 0);
5ad05e
     }
5ad05e
 
5ad05e
   cu->list_in_scope = cu->get_builder ()->get_local_symbols ();
5ad05e
@@ -16565,7 +16568,7 @@ read_array_type (struct die_info *die, struct dwarf2_cu *cu)
5ad05e
       byte_stride_prop
5ad05e
 	= (struct dynamic_prop *) alloca (sizeof (struct dynamic_prop));
5ad05e
       stride_ok = attr_to_dynamic_prop (attr, die, cu, byte_stride_prop,
5ad05e
-					prop_type);
5ad05e
+					prop_type, NULL, 0);
5ad05e
       if (!stride_ok)
5ad05e
 	{
5ad05e
 	  complaint (_("unable to read array DW_AT_byte_stride "
5ad05e
@@ -17325,7 +17328,7 @@ read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu)
5ad05e
   struct attribute *attr;
5ad05e
   struct dynamic_prop prop;
5ad05e
   bool length_is_constant = true;
5ad05e
-  LONGEST length;
5ad05e
+  ULONGEST length = UINT_MAX;
5ad05e
 
5ad05e
   /* There are a couple of places where bit sizes might be made use of
5ad05e
      when parsing a DW_TAG_string_type, however, no producer that we know
5ad05e
@@ -17346,6 +17349,10 @@ read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu)
5ad05e
 	}
5ad05e
     }
5ad05e
 
5ad05e
+  index_type = objfile_type (objfile)->builtin_int;
5ad05e
+  range_type = create_static_range_type (NULL, index_type, 1, length);
5ad05e
+
5ad05e
+  /* If DW_AT_string_length is defined, the length is stored in memory.  */
5ad05e
   attr = dwarf2_attr (die, DW_AT_string_length, cu);
5ad05e
   if (attr != nullptr && !attr_form_is_constant (attr))
5ad05e
     {
5ad05e
@@ -17372,13 +17379,71 @@ read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu)
5ad05e
 	}
5ad05e
 
5ad05e
       /* Convert the attribute into a dynamic property.  */
5ad05e
-      if (!attr_to_dynamic_prop (attr, die, cu, &prop, prop_type))
5ad05e
+      if (!attr_to_dynamic_prop (attr, die, cu, &prop, prop_type, NULL, 0))
5ad05e
 	length = 1;
5ad05e
       else
5ad05e
 	length_is_constant = false;
5ad05e
     }
5ad05e
   else if (attr != nullptr)
5ad05e
     {
5ad05e
+      if (attr_form_is_block (attr))
5ad05e
+	{
5ad05e
+	  struct attribute *byte_size, *bit_size;
5ad05e
+	  struct dynamic_prop high;
5ad05e
+
5ad05e
+	  byte_size = dwarf2_attr (die, DW_AT_byte_size, cu);
5ad05e
+	  bit_size = dwarf2_attr (die, DW_AT_bit_size, cu);
5ad05e
+
5ad05e
+	  /* DW_AT_byte_size should never occur in combination with
5ad05e
+	     DW_AT_bit_size.  */
5ad05e
+	  if (byte_size != NULL && bit_size != NULL)
5ad05e
+	    complaint (_("DW_AT_byte_size AND "
5ad05e
+			 "DW_AT_bit_size found together at the same time."));
5ad05e
+
5ad05e
+	  /* If DW_AT_string_length AND DW_AT_byte_size exist together,
5ad05e
+	     DW_AT_byte_size describes the number of bytes that should be read
5ad05e
+	     from the length memory location.  */
5ad05e
+	  if (byte_size != NULL)
5ad05e
+	    {
5ad05e
+	      /* Build new dwarf2_locexpr_baton structure with additions to the
5ad05e
+		 data attribute, to reflect DWARF specialities to get address
5ad05e
+		 sizes.  */
5ad05e
+	      const gdb_byte append_ops[] =
5ad05e
+		{
5ad05e
+		/* DW_OP_deref_size: size of an address on the target machine
5ad05e
+		   (bytes), where the size will be specified by the next
5ad05e
+		   operand.  */
5ad05e
+		DW_OP_deref_size,
5ad05e
+		/* Operand for DW_OP_deref_size.  */
5ad05e
+		(gdb_byte) DW_UNSND(byte_size) };
5ad05e
+
5ad05e
+	      if (!attr_to_dynamic_prop (attr, die, cu, &high, index_type,
5ad05e
+					 append_ops, ARRAY_SIZE(append_ops)))
5ad05e
+		complaint (_("Could not parse DW_AT_byte_size"));
5ad05e
+	    }
5ad05e
+	  else if (bit_size != NULL)
5ad05e
+	    complaint (_("DW_AT_string_length AND "
5ad05e
+			 "DW_AT_bit_size found but not supported yet."));
5ad05e
+	  /* If DW_AT_string_length WITHOUT DW_AT_byte_size exist, the default
5ad05e
+	     is the address size of the target machine.  */
5ad05e
+	  else
5ad05e
+	    {
5ad05e
+	      const gdb_byte append_ops[] =
5ad05e
+		{ DW_OP_deref };
5ad05e
+
5ad05e
+	      if (!attr_to_dynamic_prop (attr, die, cu, &high, index_type,
5ad05e
+					 append_ops, ARRAY_SIZE(append_ops)))
5ad05e
+		complaint (_("Could not parse DW_AT_string_length"));
5ad05e
+	    }
5ad05e
+
5ad05e
+	  TYPE_RANGE_DATA (range_type)->high = high;
5ad05e
+	}
5ad05e
+      else
5ad05e
+	{
5ad05e
+	  TYPE_HIGH_BOUND (range_type) = DW_UNSND(attr);
5ad05e
+	  TYPE_HIGH_BOUND_KIND (range_type) = PROP_CONST;
5ad05e
+	}
5ad05e
+
5ad05e
       /* This DW_AT_string_length just contains the length with no
5ad05e
 	 indirection.  There's no need to create a dynamic property in this
5ad05e
 	 case.  Pass 0 for the default value as we know it will not be
5ad05e
@@ -17392,6 +17457,20 @@ read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu)
5ad05e
     }
5ad05e
   else
5ad05e
     {
5ad05e
+      /* Check for the DW_AT_byte_size attribute, which represents the length
5ad05e
+	 in this case.  */
5ad05e
+      attr = dwarf2_attr (die, DW_AT_byte_size, cu);
5ad05e
+      if (attr)
5ad05e
+	{
5ad05e
+	  TYPE_HIGH_BOUND (range_type) = DW_UNSND(attr);
5ad05e
+	  TYPE_HIGH_BOUND_KIND (range_type) = PROP_CONST;
5ad05e
+	}
5ad05e
+      else
5ad05e
+	{
5ad05e
+	  TYPE_HIGH_BOUND (range_type) = 1;
5ad05e
+	  TYPE_HIGH_BOUND_KIND (range_type) = PROP_CONST;
5ad05e
+	}
5ad05e
+
5ad05e
       /* Use 1 as a fallback length if we have nothing else.  */
5ad05e
       length = 1;
5ad05e
     }
5ad05e
@@ -17407,6 +17486,7 @@ read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu)
5ad05e
       low_bound.data.const_val = 1;
5ad05e
       range_type = create_range_type (NULL, index_type, &low_bound, &prop, 0);
5ad05e
     }
5ad05e
+
5ad05e
   char_type = language_string_char_type (cu->language_defn, gdbarch);
5ad05e
   type = create_string_type (NULL, char_type, range_type);
5ad05e
 
5ad05e
@@ -17858,7 +17938,8 @@ read_base_type (struct die_info *die, struct dwarf2_cu *cu)
5ad05e
 static int
5ad05e
 attr_to_dynamic_prop (const struct attribute *attr, struct die_info *die,
5ad05e
 		      struct dwarf2_cu *cu, struct dynamic_prop *prop,
5ad05e
-		      struct type *default_type)
5ad05e
+		      struct type *default_type,
5ad05e
+		      const gdb_byte *additional_data, int additional_data_size)
5ad05e
 {
5ad05e
   struct dwarf2_property_baton *baton;
5ad05e
   struct obstack *obstack
5ad05e
@@ -17885,9 +17966,30 @@ attr_to_dynamic_prop (const struct attribute *attr, struct die_info *die,
5ad05e
 	  baton->locexpr.is_reference = false;
5ad05e
 	  break;
5ad05e
 	}
5ad05e
+
5ad05e
+      if (additional_data != NULL && additional_data_size > 0)
5ad05e
+	{
5ad05e
+	  gdb_byte *data;
5ad05e
+
5ad05e
+	  data = (gdb_byte *) obstack_alloc(
5ad05e
+	      &cu->per_cu->dwarf2_per_objfile->objfile->objfile_obstack,
5ad05e
+	      DW_BLOCK (attr)->size + additional_data_size);
5ad05e
+	  memcpy (data, DW_BLOCK (attr)->data, DW_BLOCK (attr)->size);
5ad05e
+	  memcpy (data + DW_BLOCK (attr)->size, additional_data,
5ad05e
+		  additional_data_size);
5ad05e
+
5ad05e
+	  baton->locexpr.data = data;
5ad05e
+	  baton->locexpr.size = DW_BLOCK (attr)->size + additional_data_size;
5ad05e
+	}
5ad05e
+      else
5ad05e
+	{
5ad05e
+	  baton->locexpr.data = DW_BLOCK (attr)->data;
5ad05e
+	  baton->locexpr.size = DW_BLOCK (attr)->size;
5ad05e
+	}
5ad05e
+
5ad05e
       prop->data.baton = baton;
5ad05e
       prop->kind = PROP_LOCEXPR;
5ad05e
-      gdb_assert (prop->data.baton != NULL);
5ad05e
+      gdb_assert(prop->data.baton != NULL);
5ad05e
     }
5ad05e
   else if (attr_form_is_ref (attr))
5ad05e
     {
5ad05e
@@ -17920,9 +18022,29 @@ attr_to_dynamic_prop (const struct attribute *attr, struct die_info *die,
5ad05e
 		baton = XOBNEW (obstack, struct dwarf2_property_baton);
5ad05e
 		baton->property_type = die_type (target_die, target_cu);
5ad05e
 		baton->locexpr.per_cu = cu->per_cu;
5ad05e
-		baton->locexpr.size = DW_BLOCK (target_attr)->size;
5ad05e
-		baton->locexpr.data = DW_BLOCK (target_attr)->data;
5ad05e
 		baton->locexpr.is_reference = true;
5ad05e
+
5ad05e
+		if (additional_data != NULL && additional_data_size > 0)
5ad05e
+		  {
5ad05e
+		    gdb_byte *data;
5ad05e
+
5ad05e
+		    data = (gdb_byte *) obstack_alloc (&cu->per_cu->dwarf2_per_objfile->objfile->objfile_obstack,
5ad05e
+			    DW_BLOCK (target_attr)->size + additional_data_size);
5ad05e
+		    memcpy (data, DW_BLOCK (target_attr)->data,
5ad05e
+			    DW_BLOCK (target_attr)->size);
5ad05e
+		    memcpy (data + DW_BLOCK (target_attr)->size,
5ad05e
+			    additional_data, additional_data_size);
5ad05e
+
5ad05e
+		    baton->locexpr.data = data;
5ad05e
+		    baton->locexpr.size = (DW_BLOCK (target_attr)->size
5ad05e
+					   + additional_data_size);
5ad05e
+		  }
5ad05e
+		else
5ad05e
+		  {
5ad05e
+		    baton->locexpr.data = DW_BLOCK (target_attr)->data;
5ad05e
+		    baton->locexpr.size = DW_BLOCK (target_attr)->size;
5ad05e
+		  }
5ad05e
+
5ad05e
 		prop->data.baton = baton;
5ad05e
 		prop->kind = PROP_LOCEXPR;
5ad05e
 		gdb_assert (prop->data.baton != NULL);
5ad05e
@@ -18099,8 +18221,8 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
5ad05e
     }
5ad05e
 
5ad05e
   attr = dwarf2_attr (die, DW_AT_lower_bound, cu);
5ad05e
-  if (attr != nullptr)
5ad05e
-    attr_to_dynamic_prop (attr, die, cu, &low, base_type);
5ad05e
+  if (attr)
5ad05e
+    attr_to_dynamic_prop (attr, die, cu, &low, base_type, NULL, 0);
5ad05e
   else if (!low_default_is_valid)
5ad05e
     complaint (_("Missing DW_AT_lower_bound "
5ad05e
 				      "- DIE at %s [in module %s]"),
5ad05e
@@ -18109,10 +18231,10 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
5ad05e
 
5ad05e
   struct attribute *attr_ub, *attr_count;
5ad05e
   attr = attr_ub = dwarf2_attr (die, DW_AT_upper_bound, cu);
5ad05e
-  if (!attr_to_dynamic_prop (attr, die, cu, &high, base_type))
5ad05e
+  if (!attr_to_dynamic_prop (attr, die, cu, &high, base_type, NULL, 0))
5ad05e
     {
5ad05e
       attr = attr_count = dwarf2_attr (die, DW_AT_count, cu);
5ad05e
-      if (attr_to_dynamic_prop (attr, die, cu, &high, base_type))
5ad05e
+      if (attr_to_dynamic_prop (attr, die, cu, &high, base_type, NULL, 0))
5ad05e
 	{
5ad05e
 	  /* If bounds are constant do the final calculation here.  */
5ad05e
 	  if (low.kind == PROP_CONST && high.kind == PROP_CONST)
5ad05e
@@ -18164,7 +18286,7 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
5ad05e
       struct type *prop_type
5ad05e
 	= dwarf2_per_cu_addr_sized_int_type (cu->per_cu, false);
5ad05e
       attr_to_dynamic_prop (attr_byte_stride, die, cu, &byte_stride_prop,
5ad05e
-			    prop_type);
5ad05e
+			    prop_type, NULL, 0);
5ad05e
     }
5ad05e
 
5ad05e
   struct dynamic_prop bit_stride_prop;
5ad05e
@@ -18185,7 +18307,7 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
5ad05e
 	  struct type *prop_type
5ad05e
 	    = dwarf2_per_cu_addr_sized_int_type (cu->per_cu, false);
5ad05e
 	  attr_to_dynamic_prop (attr_bit_stride, die, cu, &bit_stride_prop,
5ad05e
-				prop_type);
5ad05e
+				prop_type, NULL, 0);
5ad05e
 	}
5ad05e
     }
5ad05e
 
5ad05e
@@ -25879,7 +26001,7 @@ set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
5ad05e
     {
5ad05e
       struct type *prop_type
5ad05e
 	= dwarf2_per_cu_addr_sized_int_type (cu->per_cu, false);
5ad05e
-      if (attr_to_dynamic_prop (attr, die, cu, &prop, prop_type))
5ad05e
+      if (attr_to_dynamic_prop (attr, die, cu, &prop, prop_type, NULL, 0))
5ad05e
         add_dyn_prop (DYN_PROP_ALLOCATED, prop, type);
5ad05e
     }
5ad05e
   else if (attr != NULL)
5ad05e
@@ -25895,7 +26017,7 @@ set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
5ad05e
     {
5ad05e
       struct type *prop_type
5ad05e
 	= dwarf2_per_cu_addr_sized_int_type (cu->per_cu, false);
5ad05e
-      if (attr_to_dynamic_prop (attr, die, cu, &prop, prop_type))
5ad05e
+      if (attr_to_dynamic_prop (attr, die, cu, &prop, prop_type, NULL, 0))
5ad05e
         add_dyn_prop (DYN_PROP_ASSOCIATED, prop, type);
5ad05e
     }
5ad05e
   else if (attr != NULL)
5ad05e
@@ -25908,7 +26030,7 @@ set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
5ad05e
   /* Read DW_AT_data_location and set in type.  */
5ad05e
   attr = dwarf2_attr (die, DW_AT_data_location, cu);
5ad05e
   if (attr_to_dynamic_prop (attr, die, cu, &prop,
5ad05e
-			    dwarf2_per_cu_addr_type (cu->per_cu)))
5ad05e
+			    dwarf2_per_cu_addr_type (cu->per_cu), NULL, 0))
5ad05e
     add_dyn_prop (DYN_PROP_DATA_LOCATION, prop, type);
5ad05e
 
5ad05e
   if (dwarf2_per_objfile->die_type_hash == NULL)
5ad05e
diff --git a/gdb/f-typeprint.c b/gdb/f-typeprint.c
5ad05e
--- a/gdb/f-typeprint.c
5ad05e
+++ b/gdb/f-typeprint.c
5ad05e
@@ -197,15 +197,14 @@ f_type_print_varspec_suffix (struct type *type, struct ui_file *stream,
5ad05e
 	print_rank_only = true;
5ad05e
       else if ((TYPE_ASSOCIATED_PROP (type)
5ad05e
 		&& PROP_CONST != TYPE_DYN_PROP_KIND (TYPE_ASSOCIATED_PROP (type)))
5ad05e
-	       || (TYPE_ALLOCATED_PROP (type)
5ad05e
-		   && PROP_CONST != TYPE_DYN_PROP_KIND (TYPE_ALLOCATED_PROP (type)))
5ad05e
-	       || (TYPE_DATA_LOCATION (type)
5ad05e
-		   && PROP_CONST != TYPE_DYN_PROP_KIND (TYPE_DATA_LOCATION (type))))
5ad05e
-	{
5ad05e
-	  /* This case exist when we ptype a typename which has the dynamic
5ad05e
-	     properties but cannot be resolved as there is no object.  */
5ad05e
-	  print_rank_only = true;
5ad05e
-	}
5ad05e
+	      || (TYPE_ALLOCATED_PROP (type)
5ad05e
+		&& PROP_CONST != TYPE_DYN_PROP_KIND (TYPE_ALLOCATED_PROP (type)))
5ad05e
+	      || (TYPE_DATA_LOCATION (type)
5ad05e
+		  && PROP_CONST != TYPE_DYN_PROP_KIND (TYPE_DATA_LOCATION (type))))
5ad05e
+	/* This case exist when we ptype a typename which has the
5ad05e
+	   dynamic properties but cannot be resolved as there is
5ad05e
+	   no object.  */
5ad05e
+	print_rank_only = true;
5ad05e
 
5ad05e
       if (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_ARRAY)
5ad05e
 	f_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0,
5ad05e
@@ -217,8 +216,9 @@ f_type_print_varspec_suffix (struct type *type, struct ui_file *stream,
5ad05e
       else
5ad05e
 	{
5ad05e
 	  LONGEST lower_bound = f77_get_lowerbound (type);
5ad05e
+
5ad05e
 	  if (lower_bound != 1)	/* Not the default.  */
5ad05e
-            fprintf_filtered (stream, "%s:", plongest (lower_bound));
5ad05e
+	    fprintf_filtered (stream, "%s:", plongest (lower_bound));
5ad05e
 
5ad05e
 	  /* Make sure that, if we have an assumed size array, we
5ad05e
 	       print out a warning and print the upperbound as '*'.  */
5ad05e
@@ -229,7 +229,7 @@ f_type_print_varspec_suffix (struct type *type, struct ui_file *stream,
5ad05e
 	    {
5ad05e
 	      LONGEST upper_bound = f77_get_upperbound (type);
5ad05e
 
5ad05e
-              fputs_filtered (plongest (upper_bound), stream);
5ad05e
+	      fprintf_filtered (stream, "%s", plongest (upper_bound));
5ad05e
 	    }
5ad05e
 	}
5ad05e
 
5ad05e
@@ -249,7 +249,7 @@ f_type_print_varspec_suffix (struct type *type, struct ui_file *stream,
5ad05e
     case TYPE_CODE_REF:
5ad05e
       f_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 1, 0,
5ad05e
 				   arrayprint_recurse_level, false);
5ad05e
-      fprintf_filtered (stream, " )");
5ad05e
+      fprintf_filtered (stream, ")");
5ad05e
       break;
5ad05e
 
5ad05e
     case TYPE_CODE_FUNC:
5ad05e
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
5ad05e
--- a/gdb/gdbtypes.c
5ad05e
+++ b/gdb/gdbtypes.c
5ad05e
@@ -1939,7 +1939,8 @@ is_dynamic_type_internal (struct type *type, int top_level)
5ad05e
   type = check_typedef (type);
5ad05e
 
5ad05e
   /* We only want to recognize references at the outermost level.  */
5ad05e
-  if (top_level && TYPE_CODE (type) == TYPE_CODE_REF)
5ad05e
+  if (top_level &&
5ad05e
+      (TYPE_CODE (type) == TYPE_CODE_REF || TYPE_CODE (type) == TYPE_CODE_PTR))
5ad05e
     type = check_typedef (TYPE_TARGET_TYPE (type));
5ad05e
 
5ad05e
   /* Types that have a dynamic TYPE_DATA_LOCATION are considered
5ad05e
@@ -1972,10 +1973,10 @@ is_dynamic_type_internal (struct type *type, int top_level)
5ad05e
 		|| is_dynamic_type_internal (TYPE_TARGET_TYPE (type), 0));
5ad05e
       }
5ad05e
 
5ad05e
-    case TYPE_CODE_STRING:
5ad05e
       /* Strings are very much like an array of characters, and can be
5ad05e
 	 treated as one here.  */
5ad05e
     case TYPE_CODE_ARRAY:
5ad05e
+    case TYPE_CODE_STRING:
5ad05e
       {
5ad05e
 	gdb_assert (TYPE_NFIELDS (type) == 1);
5ad05e
 
5ad05e
@@ -2139,11 +2140,15 @@ resolve_dynamic_array_or_string (struct type *type,
5ad05e
 
5ad05e
   ary_dim = check_typedef (TYPE_TARGET_TYPE (elt_type));
5ad05e
 
5ad05e
-  if (ary_dim != NULL && TYPE_CODE (ary_dim) == TYPE_CODE_ARRAY)
5ad05e
+  if (ary_dim != NULL && (TYPE_CODE (ary_dim) == TYPE_CODE_ARRAY
5ad05e
+      || TYPE_CODE (ary_dim) == TYPE_CODE_STRING))
5ad05e
     elt_type = resolve_dynamic_array_or_string (ary_dim, addr_stack);
5ad05e
   else
5ad05e
     elt_type = TYPE_TARGET_TYPE (type);
5ad05e
 
5ad05e
+  if (TYPE_CODE (type) == TYPE_CODE_STRING)
5ad05e
+    return create_string_type (type, elt_type, range_type);
5ad05e
+
5ad05e
   prop = get_dyn_prop (DYN_PROP_BYTE_STRIDE, type);
5ad05e
   if (prop != NULL)
5ad05e
     {
5ad05e
@@ -2295,6 +2300,28 @@ resolve_dynamic_struct (struct type *type,
5ad05e
   return resolved_type;
5ad05e
 }
5ad05e
 
5ad05e
+/* Worker for pointer types.  */
5ad05e
+
5ad05e
+static struct type *
5ad05e
+resolve_dynamic_pointer (struct type *type,
5ad05e
+			 struct property_addr_info *addr_stack)
5ad05e
+{
5ad05e
+  struct dynamic_prop *prop;
5ad05e
+  CORE_ADDR value;
5ad05e
+
5ad05e
+  type = copy_type (type);
5ad05e
+
5ad05e
+  /* Resolve associated property.  */
5ad05e
+  prop = TYPE_ASSOCIATED_PROP (type);
5ad05e
+  if (prop != NULL && dwarf2_evaluate_property (prop, NULL, addr_stack, &value))
5ad05e
+    {
5ad05e
+      TYPE_DYN_PROP_ADDR (prop) = value;
5ad05e
+      TYPE_DYN_PROP_KIND (prop) = PROP_CONST;
5ad05e
+    }
5ad05e
+
5ad05e
+  return type;
5ad05e
+}
5ad05e
+
5ad05e
 /* Worker for resolved_dynamic_type.  */
5ad05e
 
5ad05e
 static struct type *
5ad05e
@@ -2349,6 +2376,9 @@ resolve_dynamic_type_internal (struct type *type,
5ad05e
 	case TYPE_CODE_ARRAY:
5ad05e
 	  resolved_type = resolve_dynamic_array_or_string (type, addr_stack);
5ad05e
 	  break;
5ad05e
+        case TYPE_CODE_PTR:
5ad05e
+ 	  resolved_type = resolve_dynamic_pointer (type, addr_stack);
5ad05e
+ 	  break;
5ad05e
 
5ad05e
 	case TYPE_CODE_RANGE:
5ad05e
 	  resolved_type = resolve_dynamic_range (type, addr_stack);
5ad05e
diff --git a/gdb/testsuite/gdb.cp/vla-cxx.cc b/gdb/testsuite/gdb.cp/vla-cxx.cc
5ad05e
--- a/gdb/testsuite/gdb.cp/vla-cxx.cc
5ad05e
+++ b/gdb/testsuite/gdb.cp/vla-cxx.cc
5ad05e
@@ -15,6 +15,10 @@
5ad05e
    You should have received a copy of the GNU General Public License
5ad05e
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
5ad05e
 
5ad05e
+extern "C" {
5ad05e
+#include <stddef.h>
5ad05e
+}
5ad05e
+
5ad05e
 struct container;
5ad05e
 
5ad05e
 struct element
5ad05e
@@ -40,11 +44,16 @@ int main(int argc, char **argv)
5ad05e
   typedef typeof (vla) &vlareftypedef;
5ad05e
   vlareftypedef vlaref2 (vla);
5ad05e
   container c;
5ad05e
+  typeof (vla) *ptr = NULL;
5ad05e
+
5ad05e
+  // Before pointer assignment
5ad05e
+  ptr = &vla;
5ad05e
 
5ad05e
   for (int i = 0; i < z; ++i)
5ad05e
     vla[i] = 5 + 2 * i;
5ad05e
 
5ad05e
   // vlas_filled
5ad05e
   vla[0] = 2 * vla[0];
5ad05e
+
5ad05e
   return vla[2];
5ad05e
 }
5ad05e
diff --git a/gdb/testsuite/gdb.cp/vla-cxx.exp b/gdb/testsuite/gdb.cp/vla-cxx.exp
5ad05e
--- a/gdb/testsuite/gdb.cp/vla-cxx.exp
5ad05e
+++ b/gdb/testsuite/gdb.cp/vla-cxx.exp
5ad05e
@@ -23,6 +23,12 @@ if ![runto_main] {
5ad05e
     return -1
5ad05e
 }
5ad05e
 
5ad05e
+gdb_breakpoint [gdb_get_line_number "Before pointer assignment"]
5ad05e
+gdb_continue_to_breakpoint "Before pointer assignment"
5ad05e
+gdb_test "ptype ptr" "int \\(\\*\\)\\\[variable length\\\]" "ptype ptr, Before pointer assignment"
5ad05e
+gdb_test "print ptr" "\\(int \\(\\*\\)\\\[variable length\\\]\\) 0x0" "print ptr, Before pointer assignment"
5ad05e
+gdb_test "print *ptr" "Cannot access memory at address 0x0" "print *ptr, Before pointer assignment"
5ad05e
+
5ad05e
 gdb_breakpoint [gdb_get_line_number "vlas_filled"]
5ad05e
 gdb_continue_to_breakpoint "vlas_filled"
5ad05e
 
5ad05e
@@ -33,3 +39,6 @@ gdb_test "print vlaref" " = \\(int \\(&\\)\\\[3\\\]\\) @$hex: \\{5, 7, 9\\}"
5ad05e
 # bug being tested, it's better not to depend on the exact spelling.
5ad05e
 gdb_test "print vlaref2" " = \\(.*\\) @$hex: \\{5, 7, 9\\}"
5ad05e
 gdb_test "print c" " = \\{e = \\{c = @$hex\\}\\}"
5ad05e
+gdb_test "ptype ptr" "int \\(\\*\\)\\\[3\\\]"
5ad05e
+gdb_test "print ptr" "\\(int \\(\\*\\)\\\[3\\\]\\) $hex"
5ad05e
+gdb_test "print *ptr" " = \\{5, 7, 9\\}"
5ad05e
diff --git a/gdb/testsuite/gdb.fortran/pointers.exp b/gdb/testsuite/gdb.fortran/pointers.exp
5ad05e
new file mode 100644
5ad05e
--- /dev/null
5ad05e
+++ b/gdb/testsuite/gdb.fortran/pointers.exp
5ad05e
@@ -0,0 +1,143 @@
5ad05e
+# Copyright 2016 Free Software Foundation, Inc.
5ad05e
+
5ad05e
+# This program is free software; you can redistribute it and/or modify
5ad05e
+# it under the terms of the GNU General Public License as published by
5ad05e
+# the Free Software Foundation; either version 3 of the License, or
5ad05e
+# (at your option) any later version.
5ad05e
+#
5ad05e
+# This program is distributed in the hope that it will be useful,
5ad05e
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
5ad05e
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
5ad05e
+# GNU General Public License for more details.
5ad05e
+#
5ad05e
+# You should have received a copy of the GNU General Public License
5ad05e
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
5ad05e
+
5ad05e
+standard_testfile "pointers.f90"
5ad05e
+load_lib fortran.exp
5ad05e
+
5ad05e
+if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile} \
5ad05e
+    {debug f90 quiet}] } {
5ad05e
+    return -1
5ad05e
+}
5ad05e
+
5ad05e
+if ![runto_main] {
5ad05e
+    untested "could not run to main"
5ad05e
+    return -1
5ad05e
+}
5ad05e
+
5ad05e
+# Depending on the compiler being used, the type names can be printed differently.
5ad05e
+set logical [fortran_logical4]
5ad05e
+set real [fortran_real4]
5ad05e
+set int [fortran_int4]
5ad05e
+set complex [fortran_complex4]
5ad05e
+
5ad05e
+
5ad05e
+gdb_breakpoint [gdb_get_line_number "Before pointer assignment"]
5ad05e
+gdb_continue_to_breakpoint "Before pointer assignment"
5ad05e
+gdb_test "print logp" "= \\(PTR TO -> \\( $logical\\)\\) 0x0" "print logp, not associated"
5ad05e
+gdb_test "print *logp" "Cannot access memory at address 0x0" "print *logp, not associated"
5ad05e
+gdb_test "print comp" "= \\(PTR TO -> \\( $complex\\)\\) 0x0" "print comp, not associated"
5ad05e
+gdb_test "print *comp" "Cannot access memory at address 0x0" "print *comp, not associated"
5ad05e
+gdb_test "print charp" "= \\(PTR TO -> \\( character\\*1\\)\\) 0x0" "print charp, not associated"
5ad05e
+gdb_test "print *charp" "Cannot access memory at address 0x0" "print *charp, not associated"
5ad05e
+gdb_test "print charap" "= \\(PTR TO -> \\( character\\*3\\)\\) 0x0" "print charap, not associated"
5ad05e
+gdb_test "print *charap" "Cannot access memory at address 0x0" "print *charap, not associated"
5ad05e
+gdb_test "print intp" "= \\(PTR TO -> \\( $int\\)\\) 0x0" "print intp, not associated"
5ad05e
+gdb_test "print *intp" "Cannot access memory at address 0x0" "print *intp, not associated"
5ad05e
+set test "print intap, not associated"
5ad05e
+gdb_test_multiple "print intap" $test {
5ad05e
+  -re " = \\(PTR TO -> \\( $int \\(:,:\\)\\)\\) <not associated>\r\n$gdb_prompt $" {
5ad05e
+    pass $test
5ad05e
+  }
5ad05e
+  -re " = <not associated>\r\n$gdb_prompt $" {
5ad05e
+    pass $test
5ad05e
+  }
5ad05e
+}
5ad05e
+gdb_test "print realp" "= \\(PTR TO -> \\( $real\\)\\) 0x0" "print realp, not associated"
5ad05e
+gdb_test "print *realp" "Cannot access memory at address 0x0" "print *realp, not associated"
5ad05e
+gdb_test "print \$my_var = intp" "= \\(PTR TO -> \\( $int\\)\\) 0x0"
5ad05e
+set test "print cyclicp1, not associated"
5ad05e
+gdb_test_multiple "print cyclicp1" $test {
5ad05e
+  -re "= \\( i = -?\\d+, p = 0x0 \\)\r\n$gdb_prompt $" {
5ad05e
+    pass $test
5ad05e
+  }
5ad05e
+  -re "= \\( i = -?\\d+, p = <not associated> \\)\r\n$gdb_prompt $" {
5ad05e
+    pass $test
5ad05e
+  }
5ad05e
+}
5ad05e
+set test "print cyclicp1%p, not associated"
5ad05e
+gdb_test_multiple "print cyclicp1%p" $test {
5ad05e
+  -re "= \\(PTR TO -> \\( Type typewithpointer\\)\\) 0x0\r\n$gdb_prompt $" {
5ad05e
+    pass $test
5ad05e
+  }
5ad05e
+  -re "= \\(PTR TO -> \\( Type typewithpointer\\)\\) <not associated>\r\n$gdb_prompt $" {
5ad05e
+    pass $test
5ad05e
+  }
5ad05e
+}
5ad05e
+
5ad05e
+
5ad05e
+gdb_breakpoint [gdb_get_line_number "Before value assignment"]
5ad05e
+gdb_continue_to_breakpoint "Before value assignment"
5ad05e
+gdb_test "print *(twop)%ivla2" "= <not allocated>"
5ad05e
+
5ad05e
+
5ad05e
+gdb_breakpoint [gdb_get_line_number "After value assignment"]
5ad05e
+gdb_continue_to_breakpoint "After value assignment"
5ad05e
+gdb_test "print logp" "= \\(PTR TO -> \\( $logical\\)\\) $hex\( <.*>\)?"
5ad05e
+gdb_test "print *logp" "= \\.TRUE\\."
5ad05e
+gdb_test "print comp" "= \\(PTR TO -> \\( $complex\\)\\) $hex\( <.*>\)?"
5ad05e
+gdb_test "print *comp" "= \\(1,2\\)"
5ad05e
+gdb_test "print charp" "= \\(PTR TO -> \\( character\\*1\\)\\) $hex\( <.*>\)?"
5ad05e
+gdb_test "print *charp" "= 'a'"
5ad05e
+gdb_test "print charap" "= \\(PTR TO -> \\( character\\*3\\)\\) $hex\( <.*>\)?"
5ad05e
+gdb_test "print *charap" "= 'abc'"
5ad05e
+gdb_test "print intp" "= \\(PTR TO -> \\( $int\\)\\) $hex\( <.*>\)?"
5ad05e
+gdb_test "print *intp" "= 10"
5ad05e
+set test_name "print intap, associated"
5ad05e
+gdb_test_multiple "print intap" $test_name {
5ad05e
+  -re "= \\(\\( 1, 1, 3(, 1){7}\\) \\( 1(, 1){9}\\) \\)\r\n$gdb_prompt $" {
5ad05e
+    pass $test_name
5ad05e
+  }
5ad05e
+  -re "= \\(PTR TO -> \\( $int \\(10,2\\)\\)\\) $hex\( <.*>\)?\r\n$gdb_prompt $" {
5ad05e
+    gdb_test "print *intap" "= \\(\\( 1, 1, 3(, 1){7}\\) \\( 1(, 1){9}\\) \\)"
5ad05e
+    pass $test_name
5ad05e
+  }
5ad05e
+}
5ad05e
+set test_name "print intvlap, associated"
5ad05e
+gdb_test_multiple "print intvlap" $test_name {
5ad05e
+  -re "= \\(2, 2, 2, 4(, 2){6}\\)\r\n$gdb_prompt $" {
5ad05e
+    pass $test_name
5ad05e
+  }
5ad05e
+  -re "= \\(PTR TO -> \\( $int \\(10\\)\\)\\) $hex\( <.*>\)?\r\n$gdb_prompt $" {
5ad05e
+    gdb_test "print *intvlap" "= \\(2, 2, 2, 4(, 2){6}\\)"
5ad05e
+    pass $test_name
5ad05e
+  }
5ad05e
+}
5ad05e
+gdb_test "print realp" "= \\(PTR TO -> \\( $real\\)\\) $hex\( <.*>\)?"
5ad05e
+gdb_test "print *realp" "= 3\\.14000\\d+"
5ad05e
+gdb_test "print arrayOfPtr(2)%p" "= \\(PTR TO -> \\( Type two\\)\\) $hex\( <.*>\)?"
5ad05e
+gdb_test "print *(arrayOfPtr(2)%p)" "= \\( ivla1 = \\(11, 12, 13\\), ivla2 = \\(\\( 211, 221\\) \\( 212, 222\\) \\) \\)"
5ad05e
+set test_name "print arrayOfPtr(3)%p"
5ad05e
+gdb_test_multiple $test_name $test_name {
5ad05e
+  -re "= \\(PTR TO -> \\( Type two\\)\\) <not associated>\r\n$gdb_prompt $" {
5ad05e
+    pass $test_name
5ad05e
+  }
5ad05e
+  -re "= \\(PTR TO -> \\( Type two\\)\\) 0x0\r\n$gdb_prompt $" {
5ad05e
+    pass $test_name
5ad05e
+  }
5ad05e
+}
5ad05e
+set test_name "print *(arrayOfPtr(3)%p), associated"
5ad05e
+gdb_test_multiple "print *(arrayOfPtr(3)%p)" $test_name {
5ad05e
+  -re "Cannot access memory at address 0x0\r\n$gdb_prompt $" {
5ad05e
+    pass $test_name
5ad05e
+  }
5ad05e
+  -re "Attempt to take contents of a not associated pointer.\r\n$gdb_prompt $" {
5ad05e
+    pass $test_name
5ad05e
+  }
5ad05e
+}
5ad05e
+gdb_test "print cyclicp1" "= \\( i = 1, p = $hex\( <.*>\)? \\)"
5ad05e
+gdb_test "print cyclicp1%p" "= \\(PTR TO -> \\( Type typewithpointer\\)\\) $hex\( <.*>\)?"
5ad05e
+gdb_test "print *((integer*) &inta + 2)" "= 3" "print temporary pointer, array"
5ad05e
+gdb_test "print *((integer*) &intvla + 3)" "= 4" "print temporary pointer, allocated vla"
5ad05e
+gdb_test "print \$pc" "= \\(PTR TO -> \\( void \\(\\) \\(\\)\\)\\) $hex <pointers\\+\\d+>" "Print program counter"
5ad05e
diff --git a/gdb/testsuite/gdb.fortran/pointers.f90 b/gdb/testsuite/gdb.fortran/pointers.f90
5ad05e
--- a/gdb/testsuite/gdb.fortran/pointers.f90
5ad05e
+++ b/gdb/testsuite/gdb.fortran/pointers.f90
5ad05e
@@ -20,21 +20,34 @@ program pointers
5ad05e
     integer, allocatable :: ivla2 (:, :)
5ad05e
   end type two
5ad05e
 
5ad05e
+  type :: typeWithPointer
5ad05e
+    integer i
5ad05e
+    type(typeWithPointer), pointer:: p
5ad05e
+  end type typeWithPointer
5ad05e
+
5ad05e
+  type :: twoPtr
5ad05e
+    type (two), pointer :: p
5ad05e
+  end type twoPtr
5ad05e
+
5ad05e
   logical, target :: logv
5ad05e
   complex, target :: comv
5ad05e
   character, target :: charv
5ad05e
   character (len=3), target :: chara
5ad05e
   integer, target :: intv
5ad05e
   integer, target, dimension (10,2) :: inta
5ad05e
-  real, target :: realv
5ad05e
-  type(two), target :: twov
5ad05e
+  integer, target, allocatable, dimension (:) :: intvla
5ad05e
+  real, target    :: realv
5ad05e
+  type(two), target  :: twov
5ad05e
+  type(twoPtr) :: arrayOfPtr (3)
5ad05e
+  type(typeWithPointer), target:: cyclicp1,cyclicp2
5ad05e
 
5ad05e
   logical, pointer :: logp
5ad05e
   complex, pointer :: comp
5ad05e
-  character, pointer :: charp
5ad05e
-  character (len=3), pointer :: charap
5ad05e
+  character, pointer:: charp
5ad05e
+  character (len=3), pointer:: charap
5ad05e
   integer, pointer :: intp
5ad05e
   integer, pointer, dimension (:,:) :: intap
5ad05e
+  integer, pointer, dimension (:) :: intvlap
5ad05e
   real, pointer :: realp
5ad05e
   type(two), pointer :: twop
5ad05e
 
5ad05e
@@ -44,8 +57,14 @@ program pointers
5ad05e
   nullify (charap)
5ad05e
   nullify (intp)
5ad05e
   nullify (intap)
5ad05e
+  nullify (intvlap)
5ad05e
   nullify (realp)
5ad05e
   nullify (twop)
5ad05e
+  nullify (arrayOfPtr(1)%p)
5ad05e
+  nullify (arrayOfPtr(2)%p)
5ad05e
+  nullify (arrayOfPtr(3)%p)
5ad05e
+  nullify (cyclicp1%p)
5ad05e
+  nullify (cyclicp2%p)
5ad05e
 
5ad05e
   logp => logv    ! Before pointer assignment
5ad05e
   comp => comv
5ad05e
@@ -53,8 +72,14 @@ program pointers
5ad05e
   charap => chara
5ad05e
   intp => intv
5ad05e
   intap => inta
5ad05e
+  intvlap => intvla
5ad05e
   realp => realv
5ad05e
   twop => twov
5ad05e
+  arrayOfPtr(2)%p => twov
5ad05e
+  cyclicp1%i = 1
5ad05e
+  cyclicp1%p => cyclicp2
5ad05e
+  cyclicp2%i = 2
5ad05e
+  cyclicp2%p => cyclicp1
5ad05e
 
5ad05e
   logv = associated(logp)     ! Before value assignment
5ad05e
   comv = cmplx(1,2)
5ad05e
@@ -63,6 +88,10 @@ program pointers
5ad05e
   intv = 10
5ad05e
   inta(:,:) = 1
5ad05e
   inta(3,1) = 3
5ad05e
+  allocate (intvla(10))
5ad05e
+  intvla(:) = 2
5ad05e
+  intvla(4) = 4
5ad05e
+  intvlap => intvla
5ad05e
   realv = 3.14
5ad05e
 
5ad05e
   allocate (twov%ivla1(3))
5ad05e
diff --git a/gdb/testsuite/gdb.fortran/print_type.exp b/gdb/testsuite/gdb.fortran/print_type.exp
5ad05e
--- a/gdb/testsuite/gdb.fortran/print_type.exp
5ad05e
+++ b/gdb/testsuite/gdb.fortran/print_type.exp
5ad05e
@@ -1,5 +1,6 @@
5ad05e
 # Copyright 2019-2020 Free Software Foundation, Inc.
5ad05e
 #
5ad05e
+
5ad05e
 # This program is free software; you can redistribute it and/or modify
5ad05e
 # it under the terms of the GNU General Public License as published by
5ad05e
 # the Free Software Foundation; either version 3 of the License, or
5ad05e
@@ -40,7 +41,7 @@ set complex [fortran_complex4]
5ad05e
 # matches the string TYPE.
5ad05e
 proc check_pointer_type { var_name type } {
5ad05e
     gdb_test "ptype ${var_name}" \
5ad05e
-	"type = PTR TO -> \\( ${type} \\)"
5ad05e
+	"type = PTR TO -> \\( ${type}\\)"
5ad05e
 }
5ad05e
 
5ad05e
 gdb_breakpoint [gdb_get_line_number "Before pointer assignment"]
5ad05e
@@ -85,7 +86,8 @@ gdb_test "ptype twop" \
5ad05e
     [multi_line "type = PTR TO -> \\( Type two" \
5ad05e
                 "    $int, allocatable :: ivla1\\(:\\)" \
5ad05e
                 "    $int, allocatable :: ivla2\\(:,:\\)" \
5ad05e
-                "End Type two \\)"]
5ad05e
+                "End Type two\\)"]
5ad05e
+
5ad05e
 
5ad05e
 gdb_breakpoint [gdb_get_line_number "After value assignment"]
5ad05e
 gdb_continue_to_breakpoint "After value assignment"
5ad05e
@@ -97,11 +99,11 @@ gdb_test "ptype intv" "type = $int"
5ad05e
 gdb_test "ptype inta" "type = $int \\(10,2\\)"
5ad05e
 gdb_test "ptype realv" "type = $real"
5ad05e
 
5ad05e
-gdb_test "ptype logp" "type = PTR TO -> \\( $logical \\)"
5ad05e
-gdb_test "ptype comp" "type = PTR TO -> \\( $complex \\)"
5ad05e
-gdb_test "ptype charp" "type = PTR TO -> \\( character\\*1 \\)"
5ad05e
-gdb_test "ptype charap" "type = PTR TO -> \\( character\\*3 \\)"
5ad05e
-gdb_test "ptype intp" "type = PTR TO -> \\( $int \\)"
5ad05e
+gdb_test "ptype logp" "type = PTR TO -> \\( $logical\\)"
5ad05e
+gdb_test "ptype comp" "type = PTR TO -> \\( $complex\\)"
5ad05e
+gdb_test "ptype charp" "type = PTR TO -> \\( character\\*1\\)"
5ad05e
+gdb_test "ptype charap" "type = PTR TO -> \\( character\\*3\\)"
5ad05e
+gdb_test "ptype intp" "type = PTR TO -> \\( $int\\)"
5ad05e
 set test "ptype intap"
5ad05e
 gdb_test_multiple $test $test {
5ad05e
     -re "type = $int \\(10,2\\)\r\n$gdb_prompt $" {
5ad05e
@@ -111,4 +113,4 @@ gdb_test_multiple $test $test {
5ad05e
         pass $test
5ad05e
     }
5ad05e
 }
5ad05e
-gdb_test "ptype realp" "type = PTR TO -> \\( $real \\)"
5ad05e
+gdb_test "ptype realp" "type = PTR TO -> \\( $real\\)"
5ad05e
diff --git a/gdb/testsuite/gdb.fortran/vla-strings.exp b/gdb/testsuite/gdb.fortran/vla-strings.exp
5ad05e
new file mode 100644
5ad05e
--- /dev/null
5ad05e
+++ b/gdb/testsuite/gdb.fortran/vla-strings.exp
5ad05e
@@ -0,0 +1,103 @@
5ad05e
+# Copyright 2016 Free Software Foundation, Inc.
5ad05e
+
5ad05e
+# This program is free software; you can redistribute it and/or modify
5ad05e
+# it under the terms of the GNU General Public License as published by
5ad05e
+# the Free Software Foundation; either version 3 of the License, or
5ad05e
+# (at your option) any later version.
5ad05e
+#
5ad05e
+# This program is distributed in the hope that it will be useful,
5ad05e
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
5ad05e
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
5ad05e
+# GNU General Public License for more details.
5ad05e
+#
5ad05e
+# You should have received a copy of the GNU General Public License
5ad05e
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
5ad05e
+
5ad05e
+standard_testfile ".f90"
5ad05e
+
5ad05e
+if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile} \
5ad05e
+    {debug f90 quiet}] } {
5ad05e
+    return -1
5ad05e
+}
5ad05e
+
5ad05e
+# check that all fortran standard datatypes will be
5ad05e
+# handled correctly when using as VLA's
5ad05e
+
5ad05e
+if ![runto_main] {
5ad05e
+    untested "could not run to main"
5ad05e
+    return -1
5ad05e
+}
5ad05e
+
5ad05e
+gdb_breakpoint [gdb_get_line_number "var_char-allocated-1"]
5ad05e
+gdb_continue_to_breakpoint "var_char-allocated-1"
5ad05e
+set test "whatis var_char first time"
5ad05e
+gdb_test_multiple "whatis var_char" $test {
5ad05e
+    -re "type = PTR TO -> \\( character\\*10\\)\r\n$gdb_prompt $" {
5ad05e
+	    pass $test
5ad05e
+    }
5ad05e
+    -re "type = character\\*10\r\n$gdb_prompt $" {
5ad05e
+	    pass $test
5ad05e
+    }
5ad05e
+}
5ad05e
+set test "ptype var_char first time"
5ad05e
+gdb_test_multiple "ptype var_char" $test {
5ad05e
+    -re "type = PTR TO -> \\( character\\*10\\)\r\n$gdb_prompt $" {
5ad05e
+	    pass $test
5ad05e
+    }
5ad05e
+    -re "type = character\\*10\r\n$gdb_prompt $" {
5ad05e
+	    pass $test
5ad05e
+    }
5ad05e
+}
5ad05e
+
5ad05e
+
5ad05e
+gdb_test "next" "\\d+.*var_char = 'foo'.*" \
5ad05e
+  "next to allocation status of var_char"
5ad05e
+gdb_test "print l" " = \\.TRUE\\." "print allocation status first time"
5ad05e
+
5ad05e
+
5ad05e
+gdb_breakpoint [gdb_get_line_number "var_char-filled-1"]
5ad05e
+gdb_continue_to_breakpoint "var_char-filled-1"
5ad05e
+set test "print var_char, var_char-filled-1"
5ad05e
+gdb_test_multiple "print var_char" $test {
5ad05e
+    -re "= \\(PTR TO -> \\( character\\*3\\)\\) $hex\r\n$gdb_prompt $" {
5ad05e
+        gdb_test "print *var_char" "= 'foo'" "print *var_char, var_char-filled-1"
5ad05e
+	    pass $test
5ad05e
+    }
5ad05e
+    -re "= 'foo'\r\n$gdb_prompt $" {
5ad05e
+	    pass $test
5ad05e
+    }
5ad05e
+}
5ad05e
+set test "ptype var_char, var_char-filled-1"
5ad05e
+gdb_test_multiple "ptype var_char" $test {
5ad05e
+    -re "type = PTR TO -> \\( character\\*3\\)\r\n$gdb_prompt $" {
5ad05e
+	    pass $test
5ad05e
+    }
5ad05e
+    -re "type = character\\*3\r\n$gdb_prompt $" {
5ad05e
+	    pass $test
5ad05e
+    }
5ad05e
+}
5ad05e
+gdb_test "print var_char(1)" " = 102 'f'" "print var_char(1)"
5ad05e
+gdb_test "print var_char(3)" " = 111 'o'" "print var_char(3)"
5ad05e
+
5ad05e
+
5ad05e
+gdb_breakpoint [gdb_get_line_number "var_char-filled-2"]
5ad05e
+gdb_continue_to_breakpoint "var_char-filled-2"
5ad05e
+set test "print var_char, var_char-filled-2"
5ad05e
+gdb_test_multiple "print var_char" $test {
5ad05e
+    -re "= \\(PTR TO -> \\( character\\*6\\)\\) $hex\r\n$gdb_prompt $" {
5ad05e
+        gdb_test "print *var_char" "= 'foobar'" "print *var_char, var_char-filled-2"
5ad05e
+	    pass $test
5ad05e
+    }
5ad05e
+    -re "= 'foobar'\r\n$gdb_prompt $" {
5ad05e
+	    pass $test
5ad05e
+    }
5ad05e
+}
5ad05e
+set test "ptype var_char, var_char-filled-2"
5ad05e
+gdb_test_multiple "ptype var_char" $test {
5ad05e
+    -re "type = PTR TO -> \\( character\\*6\\)\r\n$gdb_prompt $" {
5ad05e
+	    pass $test
5ad05e
+    }
5ad05e
+    -re "type = character\\*6\r\n$gdb_prompt $" {
5ad05e
+	    pass $test
5ad05e
+    }
5ad05e
+}
5ad05e
diff --git a/gdb/testsuite/gdb.fortran/vla-strings.f90 b/gdb/testsuite/gdb.fortran/vla-strings.f90
5ad05e
new file mode 100644
5ad05e
--- /dev/null
5ad05e
+++ b/gdb/testsuite/gdb.fortran/vla-strings.f90
5ad05e
@@ -0,0 +1,39 @@
5ad05e
+! Copyright 2016 Free Software Foundation, Inc.
5ad05e
+!
5ad05e
+! This program is free software; you can redistribute it and/or modify
5ad05e
+! it under the terms of the GNU General Public License as published by
5ad05e
+! the Free Software Foundation; either version 3 of the License, or
5ad05e
+! (at your option) any later version.
5ad05e
+!
5ad05e
+! This program is distributed in the hope that it will be useful,
5ad05e
+! but WITHOUT ANY WARRANTY; without even the implied warranty of
5ad05e
+! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
5ad05e
+! GNU General Public License for more details.
5ad05e
+!
5ad05e
+! You should have received a copy of the GNU General Public License
5ad05e
+! along with this program.  If not, see <http://www.gnu.org/licenses/>.
5ad05e
+
5ad05e
+program vla_strings
5ad05e
+  character(len=:), target, allocatable   :: var_char
5ad05e
+  character(len=:), pointer               :: var_char_p
5ad05e
+  logical                                 :: l
5ad05e
+
5ad05e
+  allocate(character(len=10) :: var_char)
5ad05e
+  l = allocated(var_char)                 ! var_char-allocated-1
5ad05e
+  var_char = 'foo'
5ad05e
+  deallocate(var_char)                    ! var_char-filled-1
5ad05e
+  l = allocated(var_char)                 ! var_char-deallocated
5ad05e
+  allocate(character(len=42) :: var_char)
5ad05e
+  l = allocated(var_char)
5ad05e
+  var_char = 'foobar'
5ad05e
+  var_char = ''                           ! var_char-filled-2
5ad05e
+  var_char = 'bar'                        ! var_char-empty
5ad05e
+  deallocate(var_char)
5ad05e
+  allocate(character(len=21) :: var_char)
5ad05e
+  l = allocated(var_char)                 ! var_char-allocated-3
5ad05e
+  var_char = 'johndoe'
5ad05e
+  var_char_p => var_char
5ad05e
+  l = associated(var_char_p)              ! var_char_p-associated
5ad05e
+  var_char_p => null()
5ad05e
+  l = associated(var_char_p)              ! var_char_p-not-associated
5ad05e
+end program vla_strings
5ad05e
diff --git a/gdb/testsuite/gdb.fortran/vla-value.exp b/gdb/testsuite/gdb.fortran/vla-value.exp
5ad05e
--- a/gdb/testsuite/gdb.fortran/vla-value.exp
5ad05e
+++ b/gdb/testsuite/gdb.fortran/vla-value.exp
5ad05e
@@ -35,7 +35,7 @@ gdb_breakpoint [gdb_get_line_number "vla1-init"]
5ad05e
 gdb_continue_to_breakpoint "vla1-init"
5ad05e
 gdb_test "print vla1" " = <not allocated>" "print non-allocated vla1"
5ad05e
 gdb_test "print &vla1" \
5ad05e
-  " = \\\(PTR TO -> \\\( $real, allocatable \\\(:,:,:\\\) \\\)\\\) $hex" \
5ad05e
+  " = \\\(PTR TO -> \\\( $real, allocatable \\\(:,:,:\\\)\\\)\\\) $hex" \
5ad05e
   "print non-allocated &vla1"
5ad05e
 gdb_test "print vla1(1,1,1)" "no such vector element \\\(vector not allocated\\\)" \
5ad05e
   "print member in non-allocated vla1 (1)"
5ad05e
@@ -56,7 +56,7 @@ with_timeout_factor 15 {
5ad05e
 	"step over value assignment of vla1"
5ad05e
 }
5ad05e
 gdb_test "print &vla1" \
5ad05e
-  " = \\\(PTR TO -> \\\( $real, allocatable \\\(10,10,10\\\) \\\)\\\) $hex" \
5ad05e
+  " = \\\(PTR TO -> \\\( $real, allocatable \\\(10,10,10\\\)\\\)\\\) $hex" \
5ad05e
   "print allocated &vla1"
5ad05e
 gdb_test "print vla1(3, 6, 9)" " = 1311" "print allocated vla1(3,6,9)"
5ad05e
 gdb_test "print vla1(1, 3, 8)" " = 1311" "print allocated vla1(1,3,8)"
5ad05e
@@ -76,7 +76,7 @@ gdb_test "print vla1(9, 9, 9)" " = 999" \
5ad05e
 # Try to access values in undefined pointer to VLA (dangling)
5ad05e
 gdb_test "print pvla" " = <not associated>" "print undefined pvla"
5ad05e
 gdb_test "print &pvla" \
5ad05e
-  " = \\\(PTR TO -> \\\( $real \\\(:,:,:\\\) \\\)\\\) $hex" \
5ad05e
+  " = \\\(PTR TO -> \\\( $real \\\(:,:,:\\\)\\\)\\\) $hex" \
5ad05e
   "print non-associated &pvla"
5ad05e
 gdb_test "print pvla(1, 3, 8)" "no such vector element \\\(vector not associated\\\)" \
5ad05e
   "print undefined pvla(1,3,8)"
5ad05e
@@ -85,7 +85,7 @@ gdb_test "print pvla(1, 3, 8)" "no such vector element \\\(vector not associated
5ad05e
 gdb_breakpoint [gdb_get_line_number "pvla-associated"]
5ad05e
 gdb_continue_to_breakpoint "pvla-associated"
5ad05e
 gdb_test "print &pvla" \
5ad05e
-  " = \\\(PTR TO -> \\\( $real \\\(10,10,10\\\) \\\)\\\) $hex" \
5ad05e
+  " = \\\(PTR TO -> \\\( $real \\\(10,10,10\\\)\\\)\\\) $hex" \
5ad05e
   "print associated &pvla"
5ad05e
 gdb_test "print pvla(3, 6, 9)" " = 42" "print associated pvla(3,6,9)"
5ad05e
 gdb_test "print pvla(1, 3, 8)" " = 1001" "print associated pvla(1,3,8)"
5ad05e
diff --git a/gdb/typeprint.c b/gdb/typeprint.c
5ad05e
--- a/gdb/typeprint.c
5ad05e
+++ b/gdb/typeprint.c
5ad05e
@@ -574,6 +574,25 @@ whatis_exp (const char *exp, int show)
5ad05e
       printf_filtered (" */\n");    
5ad05e
     }
5ad05e
 
5ad05e
+  /* Resolve any dynamic target type, as we might print
5ad05e
+     additional information about the target.
5ad05e
+     For example, in Fortran and C we are printing the dimension of the
5ad05e
+     dynamic array the pointer is pointing to.  */
5ad05e
+  if (TYPE_CODE (type) == TYPE_CODE_PTR
5ad05e
+      && is_dynamic_type (type) == 1)
5ad05e
+    {
5ad05e
+      CORE_ADDR addr;
5ad05e
+      if (NULL != TYPE_DATA_LOCATION (TYPE_TARGET_TYPE(type)))
5ad05e
+	addr = value_address (val);
5ad05e
+      else
5ad05e
+	addr = value_as_address (val);
5ad05e
+
5ad05e
+      if (addr != 0
5ad05e
+	  && type_not_associated (type) == 0)
5ad05e
+	TYPE_TARGET_TYPE (type) = resolve_dynamic_type (TYPE_TARGET_TYPE (type),
5ad05e
+							NULL, addr);
5ad05e
+    }
5ad05e
+
5ad05e
   LA_PRINT_TYPE (type, "", gdb_stdout, show, 0, &flags);
5ad05e
   printf_filtered ("\n");
5ad05e
 }
5ad05e
diff --git a/gdb/valops.c b/gdb/valops.c
5ad05e
--- a/gdb/valops.c
5ad05e
+++ b/gdb/valops.c
5ad05e
@@ -1553,6 +1553,19 @@ value_ind (struct value *arg1)
5ad05e
   if (TYPE_CODE (base_type) == TYPE_CODE_PTR)
5ad05e
     {
5ad05e
       struct type *enc_type;
5ad05e
+      CORE_ADDR addr;
5ad05e
+
5ad05e
+      if (type_not_associated (base_type))
5ad05e
+        error (_("Attempt to take contents of a not associated pointer."));
5ad05e
+
5ad05e
+      if (NULL != TYPE_DATA_LOCATION (TYPE_TARGET_TYPE (base_type)))
5ad05e
+	addr = value_address (arg1);
5ad05e
+      else
5ad05e
+	addr = value_as_address (arg1);
5ad05e
+
5ad05e
+      if (addr != 0)
5ad05e
+	TYPE_TARGET_TYPE (base_type) =
5ad05e
+	    resolve_dynamic_type (TYPE_TARGET_TYPE (base_type), NULL, addr);
5ad05e
 
5ad05e
       /* We may be pointing to something embedded in a larger object.
5ad05e
          Get the real type of the enclosing object.  */
5ad05e
@@ -1568,8 +1581,7 @@ value_ind (struct value *arg1)
5ad05e
       else
5ad05e
 	/* Retrieve the enclosing object pointed to.  */
5ad05e
 	arg2 = value_at_lazy (enc_type, 
5ad05e
-			      (value_as_address (arg1)
5ad05e
-			       - value_pointed_to_offset (arg1)));
5ad05e
+			      (addr - value_pointed_to_offset (arg1)));
5ad05e
 
5ad05e
       enc_type = value_type (arg2);
5ad05e
       return readjust_indirect_value_type (arg2, enc_type, base_type, arg1);
5ad05e
diff --git a/gdb/valprint.c b/gdb/valprint.c
5ad05e
--- a/gdb/valprint.c
5ad05e
+++ b/gdb/valprint.c
5ad05e
@@ -1149,12 +1149,6 @@ value_check_printable (struct value *val, struct ui_file *stream,
5ad05e
       return 0;
5ad05e
     }
5ad05e
 
5ad05e
-  if (type_not_associated (value_type (val)))
5ad05e
-    {
5ad05e
-      val_print_not_associated (stream);
5ad05e
-      return 0;
5ad05e
-    }
5ad05e
-
5ad05e
   if (type_not_allocated (value_type (val)))
5ad05e
     {
5ad05e
       val_print_not_allocated (stream);