diff mbox

[V2,10/23] vla: get Fortran dynamic strings working.

Message ID 1405070495-6948-11-git-send-email-keven.boell@intel.com
State New
Headers show

Commit Message

Keven Boell July 11, 2014, 9:21 a.m. UTC
This patch enables the correct calculation of dynamic
string length.

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>

	* 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.

Change-Id: I7d54d762a081ce034be37ac3e368bac8111dc4e6

Signed-off-by: Keven Boell <keven.boell@intel.com>
---
 gdb/gdbtypes.c |   29 ++++++++++++++++++++++++-----
 1 file changed, 24 insertions(+), 5 deletions(-)
diff mbox

Patch

diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index c7c5c3b..da773f6 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -1675,6 +1675,17 @@  is_dynamic_type (struct type *type)
 	      && is_dynamic_type (TYPE_FIELD_TYPE (type, i)))
 	    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;
     }
 
@@ -1745,7 +1756,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));
@@ -1767,14 +1779,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
@@ -1901,6 +1919,7 @@  resolve_dynamic_type (struct type *type, CORE_ADDR addr)
 	}
 
       case TYPE_CODE_ARRAY:
+      case TYPE_CODE_STRING:
 	resolved_type = resolve_dynamic_array (type, addr);
 	break;