public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 2/3] Fortran: Resolve dynamic target types of pointers.
  2016-06-06 13:37 [PATCH 0/3] Fortran: Resolve target types of pointers Bernhard Heckel
  2016-06-06 13:37 ` [PATCH 3/3] Fortran: Handle cyclic pointers Bernhard Heckel
@ 2016-06-06 13:37 ` Bernhard Heckel
  2016-06-06 15:08   ` Eli Zaretskii
  2016-06-06 13:37 ` [PATCH 1/3] Fortran: Handle associated property of pointer types Bernhard Heckel
  2016-06-16 11:23 ` [PING][PATCH 0/3] Fortran: Resolve target types of pointers Bernhard Heckel
  3 siblings, 1 reply; 11+ messages in thread
From: Bernhard Heckel @ 2016-06-06 13:37 UTC (permalink / raw)
  To: qiyaoltc, eliz; +Cc: gdb-patches, Bernhard Heckel

Dynamic target types of pointers have to be resolved before
they can be further processed. If not, GDB will show wrong
boundaries, size,... or even crash as it will access some
random memory.

2016-05-25  Bernhard Heckel  <bernhard.heckel@intel.com>

gdb/Changelog:
	* NEWS: Added new fortran feature.
	* gdbtypes.c (resolve_dynamic_pointer_types): Resolve dynamic target types.
	* valops.c (address_of_value): Handle not allocated arrays.

gdb/Testsuite/Changelog:
	* gdb.fortran/pointers.f90: Add dynamic variables.
	* gdb.fortran/pointers.exp: Test dynamic variables.
	* gdb.fortran/vla-value.exp: Adapt error message.

---
 gdb/NEWS                                 |  2 ++
 gdb/gdbtypes.c                           | 18 +++++++++++++++
 gdb/testsuite/gdb.fortran/pointers.exp   | 34 ++++++++++++++++++++++++++++
 gdb/testsuite/gdb.fortran/pointers.f90   | 38 +++++++++++++++++++++++++++++++-
 gdb/testsuite/gdb.fortran/print_type.exp | 38 +++++++++++++++++++++++++++++++-
 gdb/testsuite/gdb.fortran/vla-value.exp  |  2 +-
 gdb/valops.c                             |  3 +++
 7 files changed, 132 insertions(+), 3 deletions(-)

diff --git a/gdb/NEWS b/gdb/NEWS
index 3e8e7a1..bea86d3 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -3,6 +3,8 @@
 
 *** Changes since GDB 7.11
 
+* Fortran: Support pointers to dynamic types.
+
 * Fortran: Support structures with fields of dynamic types and 
   arrays of dynamic types.
 
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index ae5b69a..061785e 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -2165,6 +2165,24 @@ resolve_dynamic_pointer (struct type *type,
 	 associated.  For example "print *((integer*) &intvla)".  */
     }
 
+  /* Don't resolve not associated pointers.  */
+  if (type_not_associated (type))
+    return type;
+
+  pinfo.type = check_typedef (TYPE_TARGET_TYPE (type));
+  pinfo.valaddr = NULL;
+  /* Data location attr. refers to the "address of the variable".
+     Therefore we don't derefence anything here but
+     keep the "address of the variable".  */
+  if (NULL != TYPE_DATA_LOCATION (pinfo.type))
+    pinfo.addr = addr_stack->addr;
+  else
+    pinfo.addr = read_memory_typed_address (addr_stack->addr, type);
+  pinfo.next = addr_stack;
+  TYPE_TARGET_TYPE (type) =
+      resolve_dynamic_type_internal (TYPE_TARGET_TYPE (type),
+				     &pinfo, 0);
+
   return type;
 }
 
diff --git a/gdb/testsuite/gdb.fortran/pointers.exp b/gdb/testsuite/gdb.fortran/pointers.exp
index 0ab08c0..ebb04a7 100644
--- a/gdb/testsuite/gdb.fortran/pointers.exp
+++ b/gdb/testsuite/gdb.fortran/pointers.exp
@@ -40,9 +40,17 @@ gdb_test "print charp" "= <not associated>" "print charp, not associated"
 gdb_test "print charap" "= <not associated>" "print charap, not associated"
 gdb_test "print intp" "= <not associated>" "print intp, not associated"
 gdb_test "print intap" "= <not associated>" "print intap, not associated"
+gdb_test "print intvlap" "= <not associated>" "print intvlap, not associated"
 gdb_test "print realp" "= <not associated>" "print realp, not associated"
+gdb_test "print twop" "= <not associated>" "print twop, not associated"
 gdb_test "print \$my_var = intp" "= <not associated>"
 
+gdb_breakpoint [gdb_get_line_number "Before value assignment"]
+gdb_continue_to_breakpoint "Before value assignment"
+gdb_test "print twop%ivla2" "= <not allocated>"
+gdb_test "print *((integer*) &intvla)" "Array \"intvla\" is not allocated." \
+   "print temporary pointer, not allocated vla"
+
 gdb_breakpoint [gdb_get_line_number "After value assignment"]
 gdb_continue_to_breakpoint "After value assignment"
 gdb_test "print logp" "= \\(PTR TO -> \\( $logical \\)\\) $hex\( <.*>\)?"  "print logp, associated"
@@ -50,5 +58,31 @@ gdb_test "print comp" "= \\(PTR TO -> \\( $complex \\)\\) $hex\( <.*>\)?"  "prin
 gdb_test "print charp" "= \\(PTR TO -> \\( character\\*1 \\)\\) $hex\( <.*>\)?" "print charp, associated"
 gdb_test "print charap" "= \\(PTR TO -> \\( character\\*3 \\)\\) $hex\( <.*>\)?" "print charap, associated"
 gdb_test "print intp" "= \\(PTR TO -> \\( $int \\)\\) $hex\( <.*>\)?"  "print intp, associated"
+set test_name "print intap, associated"
+gdb_test_multiple "print intap" $test_name {
+  -re "= \\(1, 1, 3(, 1){7}\\)\r\n$gdb_prompt $" {
+    pass $test_name
+  }
+  -re "= \\(PTR TO -> \\( $int \\(10\\)\\)\\) $hex\( <.*>\)?\r\n$gdb_prompt $" {
+    pass $test_name
+  }
+  timeout { fail "$test_name (timeout)" }
+}
+set test_name "print intvlap, associated"
+gdb_test_multiple "print intvlap" $test_name {
+  -re "= \\(2, 2, 2, 4(, 2){6}\\)\r\n$gdb_prompt $" {
+    pass $test_name
+  }
+  -re "= \\(PTR TO -> \\( $int \\(10\\)\\)\\) $hex\( <.*>\)?\r\n$gdb_prompt $" {
+    pass $test_name
+  }
+  timeout { fail "$test_name (timeout)" }
+}
 gdb_test "print realp" "= \\(PTR TO -> \\( $real \\)\\) $hex\( <.*>\)?"  "print realp, associated"
+gdb_test "print twop" "= \\(PTR TO -> \\( Type two \\)\\) $hex\( <.*>\)?"
+gdb_test "print arrayOfPtr(2)%p" "= \\(PTR TO -> \\( Type two \\)\\) $hex\( <.*>\)?"
+gdb_test "print arrayOfPtr(3)%p" "= <not associated>"
 gdb_test "print *((integer*) &inta + 2)" "= 3" "print temporary pointer, array"
+gdb_test "print *((integer*) &intvla + 3)" "= 4" "print temporary pointer, allocated vla"
+gdb_test "print \$pc" "= \\(PTR TO -> \\( void \\(\\)\\(\\)\\)\\) $hex <pointers\\+\\d+>" "Print program counter"
+
diff --git a/gdb/testsuite/gdb.fortran/pointers.f90 b/gdb/testsuite/gdb.fortran/pointers.f90
index fbfaed6..8b26959 100644
--- a/gdb/testsuite/gdb.fortran/pointers.f90
+++ b/gdb/testsuite/gdb.fortran/pointers.f90
@@ -15,13 +15,25 @@
 
 program pointers
 
+  type :: two
+    integer, allocatable :: ivla1 (:)
+    integer, allocatable :: ivla2 (:, :)
+  end type two
+
+  type :: twoPtr
+    type (two), pointer :: p
+  end type twoPtr
+
   logical, target :: logv
   complex, target :: comv
   character, target :: charv
   character (len=3), target :: chara
   integer, target :: intv
   integer, target :: inta (10)
+  integer, allocatable, target :: intvla (:)
   real, target    :: realv
+  type(two), target  :: twov
+  type(twoPtr) :: arrayOfPtr (3)
 
   logical, pointer :: logp
   complex, pointer :: comp
@@ -29,7 +41,9 @@ program pointers
   character (len=3), pointer:: charap
   integer, pointer :: intp
   integer, pointer :: intap (:)
+  integer, pointer :: intvlap (:)
   real, pointer :: realp
+  type(two), pointer :: twop
 
   nullify (logp)
   nullify (comp)
@@ -37,7 +51,12 @@ program pointers
   nullify (charap)
   nullify (intp)
   nullify (intap)
+  nullify (intvlap)
   nullify (realp)
+  nullify (twop)
+  nullify (arrayOfPtr(1)%p)
+  nullify (arrayOfPtr(2)%p)
+  nullify (arrayOfPtr(3)%p)
 
   logp => logv    ! Before pointer assignment
   comp => comv
@@ -45,7 +64,10 @@ program pointers
   charap => chara
   intp => intv
   intap => inta
+  intvlap => intvla
   realp => realv
+  twop => twov
+  arrayOfPtr(2)%p => twov
 
   logv = associated(logp)     ! Before value assignment
   comv = cmplx(1,2)
@@ -54,8 +76,22 @@ program pointers
   intv = 10
   inta(:) = 1
   inta(3) = 3
+  allocate (intvla(10))
+  intvla(:) = 2
+  intvla(4) = 4
+  intvlap => intvla
   realv = 3.14
- 
+
+  allocate (twov%ivla1(3))
+  allocate (twov%ivla2(2,2))
+  twov%ivla1(1) = 11
+  twov%ivla1(2) = 12
+  twov%ivla1(3) = 13
+  twov%ivla2(1,1) = 211
+  twov%ivla2(2,1) = 221
+  twov%ivla2(1,2) = 212
+  twov%ivla2(2,2) = 222
+
   intv = intv + 1 ! After value assignment
 
 end program pointers
diff --git a/gdb/testsuite/gdb.fortran/print_type.exp b/gdb/testsuite/gdb.fortran/print_type.exp
index 283cb24..e97fb42 100755
--- a/gdb/testsuite/gdb.fortran/print_type.exp
+++ b/gdb/testsuite/gdb.fortran/print_type.exp
@@ -41,7 +41,18 @@ gdb_test "ptype charp" "= <not associated>" "ptype charp, not associated"
 gdb_test "ptype charap" "= <not associated>" "ptype charap, not associated"
 gdb_test "ptype intp" "= <not associated>" "ptype intp, not associated"
 gdb_test "ptype intap" "= <not associated>" "ptype intap, not associated"
+gdb_test "ptype intvlap" "= <not associated>" "ptype intvlap, not associated"
 gdb_test "ptype realp" "= <not associated>" "ptype realp, not associated"
+gdb_test "ptype twop" "= <not associated>" "ptype twop, not associated"
+
+gdb_breakpoint [gdb_get_line_number "Before value assignment"]
+gdb_continue_to_breakpoint "Before value assignment"
+gdb_test "ptype twop" \
+    [multi_line "type = PTR TO -> \\( Type two" \
+    "    $int :: ivla1\\(<not allocated>\\)" \
+    "    $int :: ivla2\\(<not allocated>\\)" \
+    "End Type two \\)"] \
+    "ptype twop, members not allocated"
 
 gdb_breakpoint [gdb_get_line_number "After value assignment"]
 gdb_continue_to_breakpoint "After value assignment"
@@ -51,6 +62,7 @@ gdb_test "ptype charv" "type = character\\*1"
 gdb_test "ptype chara" "type = character\\*3"
 gdb_test "ptype intv" "type = $int"
 gdb_test "ptype inta" "type = $int \\(10\\)"
+gdb_test "ptype intvla" "type = $int \\(10\\)"
 gdb_test "ptype realv" "type = $real"
 
 gdb_test "ptype logp" "type = PTR TO -> \\( $logical \\)"
@@ -58,5 +70,29 @@ gdb_test "ptype comp" "type = PTR TO -> \\( $complex \\)"
 gdb_test "ptype charp" "type = PTR TO -> \\( character\\*1 \\)"
 gdb_test "ptype charap" "type = PTR TO -> \\( character\\*3 \\)"
 gdb_test "ptype intp" "type = PTR TO -> \\( $int \\)"
+set test "ptype intap"
+gdb_test_multiple $test $test {
+  -re "type = $int \\(10\\)\r\n$gdb_prompt $" {
+    pass $test
+  }
+  -re "type = PTR TO -> \\( $int \\(10\\)\\)\r\n$gdb_prompt $" {
+    pass $test
+  }
+  timeout { fail "$test (timeout)" }
+}
+set test "ptype intvlap"
+gdb_test_multiple $test $test {
+  -re "type = $int \\(10\\)\r\n$gdb_prompt $" {
+    pass $test
+  }
+  -re "type = PTR TO -> \\( $int \\(10\\)\\)\r\n$gdb_prompt $" {
+    pass $test
+  }
+  timeout { fail "$test (timeout)" }
+}
 gdb_test "ptype realp" "type = PTR TO -> \\( $real \\)"
-
+gdb_test "ptype twop" \
+    [multi_line "type = PTR TO -> \\( Type two" \
+    "    $int :: ivla1\\(3\\)" \
+    "    $int :: ivla2\\(2,2\\)" \
+    "End Type two \\)"]
diff --git a/gdb/testsuite/gdb.fortran/vla-value.exp b/gdb/testsuite/gdb.fortran/vla-value.exp
index 0945181..d12a335 100644
--- a/gdb/testsuite/gdb.fortran/vla-value.exp
+++ b/gdb/testsuite/gdb.fortran/vla-value.exp
@@ -30,7 +30,7 @@ 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" \
+  "Array \"vla1\" is not allocated." \
   "print non-allocated &vla1"
 gdb_test "print vla1(1,1,1)" "no such vector element \\\(vector not allocated\\\)" \
   "print member in non-allocated vla1 (1)"
diff --git a/gdb/valops.c b/gdb/valops.c
index 5ef0c65..5efe9b1 100644
--- a/gdb/valops.c
+++ b/gdb/valops.c
@@ -1314,6 +1314,9 @@ address_of_variable (struct symbol *var, const struct block *b)
   val = value_of_variable (var, b);
   type = value_type (val);
 
+  if (type_not_allocated (type))
+    error (_("Array \"%s\" is not allocated."), SYMBOL_PRINT_NAME (var));
+
   if ((VALUE_LVAL (val) == lval_memory && value_lazy (val))
       || TYPE_CODE (type) == TYPE_CODE_FUNC)
     {
-- 
2.7.1.339.g0233b80

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

* [PATCH 0/3] Fortran: Resolve target types of pointers.
@ 2016-06-06 13:37 Bernhard Heckel
  2016-06-06 13:37 ` [PATCH 3/3] Fortran: Handle cyclic pointers Bernhard Heckel
                   ` (3 more replies)
  0 siblings, 4 replies; 11+ messages in thread
From: Bernhard Heckel @ 2016-06-06 13:37 UTC (permalink / raw)
  To: qiyaoltc, eliz; +Cc: gdb-patches, Bernhard Heckel

This patch series handles dynamic target types of pointers
and resolve those types when possible (associated).

Bernhard Heckel (3):
  Fortran: Handle associated property of pointer types.
  Fortran: Resolve dynamic target types of pointers.
  Fortran: Handle cyclic pointers.

 gdb/NEWS                                 |   2 +
 gdb/gdbtypes.c                           |  93 +++++++++++++++++++++++++-
 gdb/testsuite/gdb.fortran/pointers.exp   |  91 ++++++++++++++++++++++++++
 gdb/testsuite/gdb.fortran/pointers.f90   | 109 +++++++++++++++++++++++++++++++
 gdb/testsuite/gdb.fortran/print_type.exp |  98 +++++++++++++++++++++++++++
 gdb/testsuite/gdb.fortran/vla-value.exp  |   2 +-
 gdb/valops.c                             |   6 ++
 7 files changed, 397 insertions(+), 4 deletions(-)
 create mode 100644 gdb/testsuite/gdb.fortran/pointers.exp
 create mode 100644 gdb/testsuite/gdb.fortran/pointers.f90
 create mode 100755 gdb/testsuite/gdb.fortran/print_type.exp

-- 
2.7.1.339.g0233b80

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

* [PATCH 3/3] Fortran: Handle cyclic pointers.
  2016-06-06 13:37 [PATCH 0/3] Fortran: Resolve target types of pointers Bernhard Heckel
@ 2016-06-06 13:37 ` Bernhard Heckel
  2016-06-17 15:16   ` Yao Qi
  2016-06-06 13:37 ` [PATCH 2/3] Fortran: Resolve dynamic target types of pointers Bernhard Heckel
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 11+ messages in thread
From: Bernhard Heckel @ 2016-06-06 13:37 UTC (permalink / raw)
  To: qiyaoltc, eliz; +Cc: gdb-patches, Bernhard Heckel

In order to avoid endless resolving of pointers pointing to itself,
only the outermost level of dynamic types are resolved. We do this
already for reference types as well.

2016-05-25  Bernhard Heckel  <bernhard.heckel@intel.com>

gdb/Changelog:
	* gdbtypes.c (is_dynamic_type_internal): Resolve pointers only
	at the outermost level.

gdb/testsuite/Changelog:
	* pointers.f90: Add cylic pointers.
	* pointers.exp: Add print of cyclic pointers.

---
 gdb/gdbtypes.c                         | 14 ++++++++------
 gdb/testsuite/gdb.fortran/pointers.exp |  5 ++++-
 gdb/testsuite/gdb.fortran/pointers.f90 | 12 ++++++++++++
 3 files changed, 24 insertions(+), 7 deletions(-)

diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index 061785e..6156806 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -2036,7 +2036,8 @@ resolve_dynamic_union (struct type *type,
 
 static struct type *
 resolve_dynamic_struct (struct type *type,
-			struct property_addr_info *addr_stack)
+			struct property_addr_info *addr_stack,
+			int top_level)
 {
   struct type *resolved_type;
   int i;
@@ -2081,7 +2082,7 @@ resolve_dynamic_struct (struct type *type,
 
       TYPE_FIELD_TYPE (resolved_type, i)
 	= resolve_dynamic_type_internal (TYPE_FIELD_TYPE (resolved_type, i),
-					 &pinfo, 0);
+					 &pinfo, top_level);
       gdb_assert (TYPE_FIELD_LOC_KIND (resolved_type, i)
 		  == FIELD_LOC_KIND_BITPOS);
 
@@ -2121,7 +2122,8 @@ resolve_dynamic_struct (struct type *type,
 
 static struct type *
 resolve_dynamic_pointer (struct type *type,
-			 struct property_addr_info *addr_stack)
+			 struct property_addr_info *addr_stack,
+			 int top_level)
 {
   struct property_addr_info pinfo;
 
@@ -2166,7 +2168,7 @@ resolve_dynamic_pointer (struct type *type,
     }
 
   /* Don't resolve not associated pointers.  */
-  if (type_not_associated (type))
+  if (type_not_associated (type) || 1 != top_level)
     return type;
 
   pinfo.type = check_typedef (TYPE_TARGET_TYPE (type));
@@ -2235,7 +2237,7 @@ resolve_dynamic_type_internal (struct type *type,
 	  }
 
         case TYPE_CODE_PTR:
- 	  resolved_type = resolve_dynamic_pointer (type, addr_stack);
+ 	  resolved_type = resolve_dynamic_pointer (type, addr_stack, top_level);
  	  break;
 
 	case TYPE_CODE_ARRAY:
@@ -2251,7 +2253,7 @@ resolve_dynamic_type_internal (struct type *type,
 	  break;
 
 	case TYPE_CODE_STRUCT:
-	  resolved_type = resolve_dynamic_struct (type, addr_stack);
+	  resolved_type = resolve_dynamic_struct (type, addr_stack, top_level);
 	  break;
 	}
     }
diff --git a/gdb/testsuite/gdb.fortran/pointers.exp b/gdb/testsuite/gdb.fortran/pointers.exp
index ebb04a7..3260c25 100644
--- a/gdb/testsuite/gdb.fortran/pointers.exp
+++ b/gdb/testsuite/gdb.fortran/pointers.exp
@@ -44,6 +44,8 @@ gdb_test "print intvlap" "= <not associated>" "print intvlap, not associated"
 gdb_test "print realp" "= <not associated>" "print realp, not associated"
 gdb_test "print twop" "= <not associated>" "print twop, not associated"
 gdb_test "print \$my_var = intp" "= <not associated>"
+gdb_test "print cyclicp1" "= \\( -?\\d+, <not associated> \\)" "print cyclip1 = not associated"
+gdb_test "print cyclicp1%p" "= <not associated>"
 
 gdb_breakpoint [gdb_get_line_number "Before value assignment"]
 gdb_continue_to_breakpoint "Before value assignment"
@@ -82,7 +84,8 @@ gdb_test "print realp" "= \\(PTR TO -> \\( $real \\)\\) $hex\( <.*>\)?"  "print
 gdb_test "print twop" "= \\(PTR TO -> \\( Type two \\)\\) $hex\( <.*>\)?"
 gdb_test "print arrayOfPtr(2)%p" "= \\(PTR TO -> \\( Type two \\)\\) $hex\( <.*>\)?"
 gdb_test "print arrayOfPtr(3)%p" "= <not associated>"
+gdb_test "print cyclicp1" "= \\( 1, $hex\( <.*>\)? \\)"
+gdb_test "print cyclicp1%p" "= \\(PTR TO -> \\( Type typewithpointer \\)\\) $hex\( <.*>\)?"
 gdb_test "print *((integer*) &inta + 2)" "= 3" "print temporary pointer, array"
 gdb_test "print *((integer*) &intvla + 3)" "= 4" "print temporary pointer, allocated vla"
 gdb_test "print \$pc" "= \\(PTR TO -> \\( void \\(\\)\\(\\)\\)\\) $hex <pointers\\+\\d+>" "Print program counter"
-
diff --git a/gdb/testsuite/gdb.fortran/pointers.f90 b/gdb/testsuite/gdb.fortran/pointers.f90
index 8b26959..548dd61 100644
--- a/gdb/testsuite/gdb.fortran/pointers.f90
+++ b/gdb/testsuite/gdb.fortran/pointers.f90
@@ -19,6 +19,11 @@ program pointers
     integer, allocatable :: ivla1 (:)
     integer, allocatable :: ivla2 (:, :)
   end type two
+  
+  type :: typeWithPointer
+    integer i
+    type(typeWithPointer), pointer:: p
+  end type typeWithPointer
 
   type :: twoPtr
     type (two), pointer :: p
@@ -34,6 +39,7 @@ program pointers
   real, target    :: realv
   type(two), target  :: twov
   type(twoPtr) :: arrayOfPtr (3)
+  type(typeWithPointer), target:: cyclicp1,cyclicp2
 
   logical, pointer :: logp
   complex, pointer :: comp
@@ -57,6 +63,8 @@ program pointers
   nullify (arrayOfPtr(1)%p)
   nullify (arrayOfPtr(2)%p)
   nullify (arrayOfPtr(3)%p)
+  nullify (cyclicp1%p)
+  nullify (cyclicp2%p)
 
   logp => logv    ! Before pointer assignment
   comp => comv
@@ -68,6 +76,10 @@ program pointers
   realp => realv
   twop => twov
   arrayOfPtr(2)%p => twov
+  cyclicp1%i = 1
+  cyclicp1%p => cyclicp2
+  cyclicp2%i = 2
+  cyclicp2%p => cyclicp1
 
   logv = associated(logp)     ! Before value assignment
   comv = cmplx(1,2)
-- 
2.7.1.339.g0233b80

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

* [PATCH 1/3] Fortran: Handle associated property of pointer types.
  2016-06-06 13:37 [PATCH 0/3] Fortran: Resolve target types of pointers Bernhard Heckel
  2016-06-06 13:37 ` [PATCH 3/3] Fortran: Handle cyclic pointers Bernhard Heckel
  2016-06-06 13:37 ` [PATCH 2/3] Fortran: Resolve dynamic target types of pointers Bernhard Heckel
@ 2016-06-06 13:37 ` Bernhard Heckel
  2016-06-17 11:28   ` Yao Qi
  2016-06-16 11:23 ` [PING][PATCH 0/3] Fortran: Resolve target types of pointers Bernhard Heckel
  3 siblings, 1 reply; 11+ messages in thread
From: Bernhard Heckel @ 2016-06-06 13:37 UTC (permalink / raw)
  To: qiyaoltc, eliz; +Cc: gdb-patches, Bernhard Heckel

Some fortran compiler don't create the associated property but
set the pointers content to zero. In order to have a common
way to handle not associated pointers, the missing associated
property is added.

Before:
(gdb) print *intp
Cannot access memory address 0x0

After:
(gdb) print *intp
$1 = <not associated>

2016-05-01  Bernhard Heckel  <bernhard.heckel@intel.com>

gdb/Changelog:
	* gdbtypes.c (is_dynamic_type_internal): Handle fortran pointers.
	  (resolve_dynamic_type_internal): Add pointer case.
          (resolve_dynamic_pointer_type): New.

gdb/Testsuite/Changelog:
	* gdb.fortran/pointers.f90: New.
	* gdb.fortran/pointers.exp: New.
	* gdb.fortran/print_type.exp: New.

---
 gdb/gdbtypes.c                           | 67 ++++++++++++++++++++++++++++++++
 gdb/testsuite/gdb.fortran/pointers.exp   | 54 +++++++++++++++++++++++++
 gdb/testsuite/gdb.fortran/pointers.f90   | 61 +++++++++++++++++++++++++++++
 gdb/testsuite/gdb.fortran/print_type.exp | 62 +++++++++++++++++++++++++++++
 gdb/valops.c                             |  3 ++
 5 files changed, 247 insertions(+)
 create mode 100644 gdb/testsuite/gdb.fortran/pointers.exp
 create mode 100644 gdb/testsuite/gdb.fortran/pointers.f90
 create mode 100755 gdb/testsuite/gdb.fortran/print_type.exp

diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index 9e1759b..ae5b69a 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -1828,6 +1828,18 @@ is_dynamic_type_internal (struct type *type, int top_level)
 
   switch (TYPE_CODE (type))
     {
+    case TYPE_CODE_PTR:
+      {
+	/* Some Fortran compiler don't create the associated property
+           which would cause a "return 1".
+           For a correct value/type print we have to treat
+	   every pointer as dynamic type to cover nullified pointers
+           as well as dynamic target types.  */
+	if (current_language->la_language == language_fortran)
+	  return 1;
+
+	return 0;
+      }
     case TYPE_CODE_RANGE:
       {
 	/* A range type is obviously dynamic if it has at least one
@@ -2105,6 +2117,57 @@ resolve_dynamic_struct (struct type *type,
   return resolved_type;
 }
 
+/* Worker for pointer types.  */
+
+static struct type *
+resolve_dynamic_pointer (struct type *type,
+			 struct property_addr_info *addr_stack)
+{
+  struct property_addr_info pinfo;
+
+  /* If valaddr is set, the type was already resolved
+     and assigned to an value.  */
+  if (0 != addr_stack->valaddr)
+    return type;
+
+  if (TYPE_OBJFILE_OWNED (type))
+    {
+      struct dynamic_prop * prop;
+      CORE_ADDR value;
+
+      type = copy_type (type);
+
+      /* Resolve associated property.  */
+      prop = TYPE_ASSOCIATED_PROP (type);
+      if (prop != NULL && dwarf2_evaluate_property (prop, NULL, addr_stack, &value))
+	{
+	  TYPE_DYN_PROP_ADDR (prop) = value;
+	  TYPE_DYN_PROP_KIND (prop) = PROP_CONST;
+	}
+      else
+	{
+	  /* Compiler doesn't create associated property for this pointer
+	     therefore we have to check wheater it is still null.  */
+	  struct dynamic_prop prop_asso;
+
+	  if (0 != read_memory_typed_address (addr_stack->addr, type))
+	    prop_asso.data.const_val = 1;
+	  else
+	    prop_asso.data.const_val = 0;
+
+	  prop_asso.kind = PROP_CONST;
+	  add_dyn_prop (DYN_PROP_ASSOCIATED, prop_asso, type, TYPE_OBJFILE(type));
+	}
+    }
+  else
+    {
+      /* Do nothing, as this pointer is created on the fly and therefore
+	 associated.  For example "print *((integer*) &intvla)".  */
+    }
+
+  return type;
+}
+
 /* Worker for resolved_dynamic_type.  */
 
 static struct type *
@@ -2153,6 +2216,10 @@ resolve_dynamic_type_internal (struct type *type,
 	    break;
 	  }
 
+        case TYPE_CODE_PTR:
+ 	  resolved_type = resolve_dynamic_pointer (type, addr_stack);
+ 	  break;
+
 	case TYPE_CODE_ARRAY:
 	  resolved_type = resolve_dynamic_array (type, addr_stack);
 	  break;
diff --git a/gdb/testsuite/gdb.fortran/pointers.exp b/gdb/testsuite/gdb.fortran/pointers.exp
new file mode 100644
index 0000000..0ab08c0
--- /dev/null
+++ b/gdb/testsuite/gdb.fortran/pointers.exp
@@ -0,0 +1,54 @@
+# Copyright 2016 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 "pointers.f90"
+load_lib fortran.exp
+
+if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile} \
+    {debug f90 quiet}] } {
+    return -1
+}
+
+if ![runto_main] {
+    untested "could not run to main"
+    return -1
+}
+
+# Depending on the compiler being used, the type names can be printed differently.
+set logical [fortran_logical4]
+set real [fortran_real4]
+set int [fortran_int4]
+set complex [fortran_complex4]
+
+gdb_breakpoint [gdb_get_line_number "Before pointer assignment"]
+gdb_continue_to_breakpoint "Before pointer assignment"
+gdb_test "print logp" "= <not associated>" "print logp, not associated"
+gdb_test "print comp" "= <not associated>" "print comp, not associated"
+gdb_test "print charp" "= <not associated>" "print charp, not associated"
+gdb_test "print charap" "= <not associated>" "print charap, not associated"
+gdb_test "print intp" "= <not associated>" "print intp, not associated"
+gdb_test "print intap" "= <not associated>" "print intap, not associated"
+gdb_test "print realp" "= <not associated>" "print realp, not associated"
+gdb_test "print \$my_var = intp" "= <not associated>"
+
+gdb_breakpoint [gdb_get_line_number "After value assignment"]
+gdb_continue_to_breakpoint "After value assignment"
+gdb_test "print logp" "= \\(PTR TO -> \\( $logical \\)\\) $hex\( <.*>\)?"  "print logp, associated"
+gdb_test "print comp" "= \\(PTR TO -> \\( $complex \\)\\) $hex\( <.*>\)?"  "print comp, associated"
+gdb_test "print charp" "= \\(PTR TO -> \\( character\\*1 \\)\\) $hex\( <.*>\)?" "print charp, associated"
+gdb_test "print charap" "= \\(PTR TO -> \\( character\\*3 \\)\\) $hex\( <.*>\)?" "print charap, associated"
+gdb_test "print intp" "= \\(PTR TO -> \\( $int \\)\\) $hex\( <.*>\)?"  "print intp, associated"
+gdb_test "print realp" "= \\(PTR TO -> \\( $real \\)\\) $hex\( <.*>\)?"  "print realp, associated"
+gdb_test "print *((integer*) &inta + 2)" "= 3" "print temporary pointer, array"
diff --git a/gdb/testsuite/gdb.fortran/pointers.f90 b/gdb/testsuite/gdb.fortran/pointers.f90
new file mode 100644
index 0000000..fbfaed6
--- /dev/null
+++ b/gdb/testsuite/gdb.fortran/pointers.f90
@@ -0,0 +1,61 @@
+! Copyright 2016 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 pointers
+
+  logical, target :: logv
+  complex, target :: comv
+  character, target :: charv
+  character (len=3), target :: chara
+  integer, target :: intv
+  integer, target :: inta (10)
+  real, target    :: realv
+
+  logical, pointer :: logp
+  complex, pointer :: comp
+  character, pointer:: charp
+  character (len=3), pointer:: charap
+  integer, pointer :: intp
+  integer, pointer :: intap (:)
+  real, pointer :: realp
+
+  nullify (logp)
+  nullify (comp)
+  nullify (charp)
+  nullify (charap)
+  nullify (intp)
+  nullify (intap)
+  nullify (realp)
+
+  logp => logv    ! Before pointer assignment
+  comp => comv
+  charp => charv
+  charap => chara
+  intp => intv
+  intap => inta
+  realp => realv
+
+  logv = associated(logp)     ! Before value assignment
+  comv = cmplx(1,2)
+  charv = "a"
+  chara = "abc"
+  intv = 10
+  inta(:) = 1
+  inta(3) = 3
+  realv = 3.14
+ 
+  intv = intv + 1 ! After value assignment
+
+end program pointers
diff --git a/gdb/testsuite/gdb.fortran/print_type.exp b/gdb/testsuite/gdb.fortran/print_type.exp
new file mode 100755
index 0000000..283cb24
--- /dev/null
+++ b/gdb/testsuite/gdb.fortran/print_type.exp
@@ -0,0 +1,62 @@
+# Copyright 2016 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 "pointers.f90"
+load_lib fortran.exp
+
+if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile} \
+    {debug f90 quiet}] } {
+    return -1
+}
+
+
+if ![runto_main] {
+    untested "could not run to main"
+    return -1
+}
+
+# Depending on the compiler being used, the type names can be printed differently.
+set logical [fortran_logical4]
+set real [fortran_real4]
+set int [fortran_int4]
+set complex [fortran_complex4]
+
+gdb_breakpoint [gdb_get_line_number "Before pointer assignment"]
+gdb_continue_to_breakpoint "Before pointer assignment"
+gdb_test "ptype logp" "= <not associated>" "ptype logp, not associated"
+gdb_test "ptype comp" "= <not associated>" "ptype comp, not associated"
+gdb_test "ptype charp" "= <not associated>" "ptype charp, not associated"
+gdb_test "ptype charap" "= <not associated>" "ptype charap, not associated"
+gdb_test "ptype intp" "= <not associated>" "ptype intp, not associated"
+gdb_test "ptype intap" "= <not associated>" "ptype intap, not associated"
+gdb_test "ptype realp" "= <not associated>" "ptype realp, not associated"
+
+gdb_breakpoint [gdb_get_line_number "After value assignment"]
+gdb_continue_to_breakpoint "After value assignment"
+gdb_test "ptype logv" "type = $logical"
+gdb_test "ptype comv" "type = $complex"
+gdb_test "ptype charv" "type = character\\*1"
+gdb_test "ptype chara" "type = character\\*3"
+gdb_test "ptype intv" "type = $int"
+gdb_test "ptype inta" "type = $int \\(10\\)"
+gdb_test "ptype realv" "type = $real"
+
+gdb_test "ptype logp" "type = PTR TO -> \\( $logical \\)"
+gdb_test "ptype comp" "type = PTR TO -> \\( $complex \\)"
+gdb_test "ptype charp" "type = PTR TO -> \\( character\\*1 \\)"
+gdb_test "ptype charap" "type = PTR TO -> \\( character\\*3 \\)"
+gdb_test "ptype intp" "type = PTR TO -> \\( $int \\)"
+gdb_test "ptype realp" "type = PTR TO -> \\( $real \\)"
+
diff --git a/gdb/valops.c b/gdb/valops.c
index 71fb1b3..5ef0c65 100644
--- a/gdb/valops.c
+++ b/gdb/valops.c
@@ -1554,6 +1554,9 @@ value_ind (struct value *arg1)
     {
       struct type *enc_type;
 
+      if (type_not_associated (base_type))
+        error (_("Attempt to take contents of a not associated pointer."));
+
       /* We may be pointing to something embedded in a larger object.
          Get the real type of the enclosing object.  */
       enc_type = check_typedef (value_enclosing_type (arg1));
-- 
2.7.1.339.g0233b80

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

* Re: [PATCH 2/3] Fortran: Resolve dynamic target types of pointers.
  2016-06-06 13:37 ` [PATCH 2/3] Fortran: Resolve dynamic target types of pointers Bernhard Heckel
@ 2016-06-06 15:08   ` Eli Zaretskii
  0 siblings, 0 replies; 11+ messages in thread
From: Eli Zaretskii @ 2016-06-06 15:08 UTC (permalink / raw)
  To: Bernhard Heckel; +Cc: qiyaoltc, gdb-patches

> From: Bernhard Heckel <bernhard.heckel@intel.com>
> Cc: gdb-patches@sourceware.org, Bernhard Heckel <bernhard.heckel@intel.com>
> Date: Mon,  6 Jun 2016 15:37:12 +0200
> 
> Dynamic target types of pointers have to be resolved before
> they can be further processed. If not, GDB will show wrong
> boundaries, size,... or even crash as it will access some
> random memory.
> 
> 2016-05-25  Bernhard Heckel  <bernhard.heckel@intel.com>
> 
> gdb/Changelog:
> 	* NEWS: Added new fortran feature.
> 	* gdbtypes.c (resolve_dynamic_pointer_types): Resolve dynamic target types.
> 	* valops.c (address_of_value): Handle not allocated arrays.
> 
> gdb/Testsuite/Changelog:
> 	* gdb.fortran/pointers.f90: Add dynamic variables.
> 	* gdb.fortran/pointers.exp: Test dynamic variables.
> 	* gdb.fortran/vla-value.exp: Adapt error message.
> 
> ---
>  gdb/NEWS                                 |  2 ++
>  gdb/gdbtypes.c                           | 18 +++++++++++++++
>  gdb/testsuite/gdb.fortran/pointers.exp   | 34 ++++++++++++++++++++++++++++
>  gdb/testsuite/gdb.fortran/pointers.f90   | 38 +++++++++++++++++++++++++++++++-
>  gdb/testsuite/gdb.fortran/print_type.exp | 38 +++++++++++++++++++++++++++++++-
>  gdb/testsuite/gdb.fortran/vla-value.exp  |  2 +-
>  gdb/valops.c                             |  3 +++
>  7 files changed, 132 insertions(+), 3 deletions(-)
> 
> diff --git a/gdb/NEWS b/gdb/NEWS
> index 3e8e7a1..bea86d3 100644
> --- a/gdb/NEWS
> +++ b/gdb/NEWS
> @@ -3,6 +3,8 @@
>  
>  *** Changes since GDB 7.11
>  
> +* Fortran: Support pointers to dynamic types.
> +
>  * Fortran: Support structures with fields of dynamic types and 
>    arrays of dynamic types.

The NEWS part is OK.

Thanks.

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

* [PING][PATCH 0/3] Fortran: Resolve target types of pointers.
  2016-06-06 13:37 [PATCH 0/3] Fortran: Resolve target types of pointers Bernhard Heckel
                   ` (2 preceding siblings ...)
  2016-06-06 13:37 ` [PATCH 1/3] Fortran: Handle associated property of pointer types Bernhard Heckel
@ 2016-06-16 11:23 ` Bernhard Heckel
  3 siblings, 0 replies; 11+ messages in thread
From: Bernhard Heckel @ 2016-06-16 11:23 UTC (permalink / raw)
  To: qiyaoltc; +Cc: gdb-patches

On 06/06/2016 15:37, Bernhard Heckel wrote:
> This patch series handles dynamic target types of pointers
> and resolve those types when possible (associated).
>
> Bernhard Heckel (3):
>    Fortran: Handle associated property of pointer types.
>    Fortran: Resolve dynamic target types of pointers.
>    Fortran: Handle cyclic pointers.
>
>   gdb/NEWS                                 |   2 +
>   gdb/gdbtypes.c                           |  93 +++++++++++++++++++++++++-
>   gdb/testsuite/gdb.fortran/pointers.exp   |  91 ++++++++++++++++++++++++++
>   gdb/testsuite/gdb.fortran/pointers.f90   | 109 +++++++++++++++++++++++++++++++
>   gdb/testsuite/gdb.fortran/print_type.exp |  98 +++++++++++++++++++++++++++
>   gdb/testsuite/gdb.fortran/vla-value.exp  |   2 +-
>   gdb/valops.c                             |   6 ++
>   7 files changed, 397 insertions(+), 4 deletions(-)
>   create mode 100644 gdb/testsuite/gdb.fortran/pointers.exp
>   create mode 100644 gdb/testsuite/gdb.fortran/pointers.f90
>   create mode 100755 gdb/testsuite/gdb.fortran/print_type.exp
>

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] 11+ messages in thread

* Re: [PATCH 1/3] Fortran: Handle associated property of pointer types.
  2016-06-06 13:37 ` [PATCH 1/3] Fortran: Handle associated property of pointer types Bernhard Heckel
@ 2016-06-17 11:28   ` Yao Qi
  2016-06-21  9:17     ` Bernhard Heckel
  0 siblings, 1 reply; 11+ messages in thread
From: Yao Qi @ 2016-06-17 11:28 UTC (permalink / raw)
  To: Bernhard Heckel; +Cc: qiyaoltc, eliz, gdb-patches

Bernhard Heckel <bernhard.heckel@intel.com> writes:

> Some fortran compiler don't create the associated property but
> set the pointers content to zero. In order to have a common

Do you mean different compilers behave differently?  In the test case,

  logical, pointer :: logp
  nullify (logp)
  logp => logv    ! Before pointer assignment

what are these different behaviors with different compilers?  Isn't
correct that compiler doesn't create the associated property when
program stops on line "Before pointer associated"? because logp is not
associated to any target.

> way to handle not associated pointers, the missing associated
> property is added.
>
> Before:
> (gdb) print *intp
> Cannot access memory address 0x0
>
> After:
> (gdb) print *intp
> $1 = <not associated>
>

Do you mean "print intp" or "print *intp"?  in your patch below, I see
this,

> +gdb_test "print intp" "= <not associated>" "print intp, not associated"

> +
> +gdb_breakpoint [gdb_get_line_number "Before pointer assignment"]
> +gdb_continue_to_breakpoint "Before pointer assignment"
> +gdb_test "print logp" "= <not associated>" "print logp, not associated"
> +gdb_test "print comp" "= <not associated>" "print comp, not associated"
> +gdb_test "print charp" "= <not associated>" "print charp, not associated"
> +gdb_test "print charap" "= <not associated>" "print charap, not associated"
> +gdb_test "print intp" "= <not associated>" "print intp, not associated"
> +gdb_test "print intap" "= <not associated>" "print intap, not associated"
> +gdb_test "print realp" "= <not associated>" "print realp, not associated"
> +gdb_test "print \$my_var = intp" "= <not associated>"

What is the output without your fix?  IMO, "print POINTER" prints the
value of the pointer.  It doesn't matter whether the pointer is
associated with a target or not.

> +
> +gdb_breakpoint [gdb_get_line_number "After value assignment"]
> +gdb_continue_to_breakpoint "After value assignment"
> +gdb_test "print logp" "= \\(PTR TO -> \\( $logical \\)\\) $hex\( <.*>\)?"  "print logp, associated"
> +gdb_test "print comp" "= \\(PTR TO -> \\( $complex \\)\\) $hex\( <.*>\)?"  "print comp, associated"
> +gdb_test "print charp" "= \\(PTR TO -> \\( character\\*1 \\)\\) $hex\( <.*>\)?" "print charp, associated"
> +gdb_test "print charap" "= \\(PTR TO -> \\( character\\*3 \\)\\) $hex\( <.*>\)?" "print charap, associated"
> +gdb_test "print intp" "= \\(PTR TO -> \\( $int \\)\\) $hex\( <.*>\)?"  "print intp, associated"
> +gdb_test "print realp" "= \\(PTR TO -> \\( $real \\)\\) $hex\( <.*>\)?"  "print realp, associated"
> +gdb_test "print *((integer*) &inta + 2)" "= 3" "print temporary pointer, array"


> +
> +gdb_breakpoint [gdb_get_line_number "Before pointer assignment"]
> +gdb_continue_to_breakpoint "Before pointer assignment"
> +gdb_test "ptype logp" "= <not associated>" "ptype logp, not associated"
> +gdb_test "ptype comp" "= <not associated>" "ptype comp, not associated"
> +gdb_test "ptype charp" "= <not associated>" "ptype charp, not associated"
> +gdb_test "ptype charap" "= <not associated>" "ptype charap, not associated"
> +gdb_test "ptype intp" "= <not associated>" "ptype intp, not associated"
> +gdb_test "ptype intap" "= <not associated>" "ptype intap, not associated"
> +gdb_test "ptype realp" "= <not associated>" "ptype realp, not associated"
> +

The type of the pointer should be known regardless it is associated with
target or not, because in the source we have,

+  logical, pointer :: logp
+  complex, pointer :: comp
+  character, pointer:: charp
+  character (len=3), pointer:: charap
+  integer, pointer :: intp
+  integer, pointer :: intap (:)
+  real, pointer :: realp

we can tell the type of logp is "logical, pointer", right?

> +
> +gdb_test "ptype logp" "type = PTR TO -> \\( $logical \\)"
> +gdb_test "ptype comp" "type = PTR TO -> \\( $complex \\)"
> +gdb_test "ptype charp" "type = PTR TO -> \\( character\\*1 \\)"
> +gdb_test "ptype charap" "type = PTR TO -> \\( character\\*3 \\)"
> +gdb_test "ptype intp" "type = PTR TO -> \\( $int \\)"
> +gdb_test "ptype realp" "type = PTR TO -> \\( $real \\)"

-- 
Yao (齐尧)

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

* Re: [PATCH 3/3] Fortran: Handle cyclic pointers.
  2016-06-06 13:37 ` [PATCH 3/3] Fortran: Handle cyclic pointers Bernhard Heckel
@ 2016-06-17 15:16   ` Yao Qi
  0 siblings, 0 replies; 11+ messages in thread
From: Yao Qi @ 2016-06-17 15:16 UTC (permalink / raw)
  To: Bernhard Heckel; +Cc: qiyaoltc, eliz, gdb-patches

Bernhard Heckel <bernhard.heckel@intel.com> writes:

Patch is a good to me, a nit below,

>    /* Don't resolve not associated pointers.  */
> -  if (type_not_associated (type))
> +  if (type_not_associated (type) || 1 != top_level)
>      return type;

top_level is used as a boolean, so " || !top_level" is better IMO.
We also need to add comments on why do we do so.

-- 
Yao (齐尧)

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

* Re: [PATCH 1/3] Fortran: Handle associated property of pointer types.
  2016-06-17 11:28   ` Yao Qi
@ 2016-06-21  9:17     ` Bernhard Heckel
  2016-06-21 10:04       ` Yao Qi
  0 siblings, 1 reply; 11+ messages in thread
From: Bernhard Heckel @ 2016-06-21  9:17 UTC (permalink / raw)
  To: Yao Qi; +Cc: eliz, gdb-patches

On 17/06/2016 13:28, Yao Qi wrote:
> Bernhard Heckel <bernhard.heckel@intel.com> writes:
>
>> Some fortran compiler don't create the associated property but
>> set the pointers content to zero. In order to have a common
> Do you mean different compilers behave differently?  In the test case,
>
>    logical, pointer :: logp
>    nullify (logp)
>    logp => logv    ! Before pointer assignment
>
> what are these different behaviors with different compilers?  Isn't
> correct that compiler doesn't create the associated property when
> program stops on line "Before pointer associated"? because logp is not
> associated to any target.
Some compilers create the associated property some not. If not, we have 
always to check
the content of the pointer if it is null. The associated property is not 
created dynamically,
therefore it doesn't matter where we stop. Only the property value is 
different, depending
where we stop.
>> way to handle not associated pointers, the missing associated
>> property is added.
>>
>> Before:
>> (gdb) print *intp
>> Cannot access memory address 0x0
>>
>> After:
>> (gdb) print *intp
>> $1 = <not associated>
>>
> Do you mean "print intp" or "print *intp"?  in your patch below, I see
> this,
Same for ptype. Current & prev. implementation shortcut's further 
printing in case
the pointer is not associated.

>
>> +gdb_test "print intp" "= <not associated>" "print intp, not associated"
>> +
>> +gdb_breakpoint [gdb_get_line_number "Before pointer assignment"]
>> +gdb_continue_to_breakpoint "Before pointer assignment"
>> +gdb_test "print logp" "= <not associated>" "print logp, not associated"
>> +gdb_test "print comp" "= <not associated>" "print comp, not associated"
>> +gdb_test "print charp" "= <not associated>" "print charp, not associated"
>> +gdb_test "print charap" "= <not associated>" "print charap, not associated"
>> +gdb_test "print intp" "= <not associated>" "print intp, not associated"
>> +gdb_test "print intap" "= <not associated>" "print intap, not associated"
>> +gdb_test "print realp" "= <not associated>" "print realp, not associated"
>> +gdb_test "print \$my_var = intp" "= <not associated>"
> What is the output without your fix?  IMO, "print POINTER" prints the
> value of the pointer.  It doesn't matter whether the pointer is
> associated with a target or not.
For compilers creating the property, the output is like above.
For missing property, it is:

gdb_test "print logp" "= (PTR TO -> ( $logical )) 0x0"

Based on your input I would like to propose:
gdb_test "print logp" "= (PTR TO -> ( $logical )) <not associated>"

>
>> +
>> +gdb_breakpoint [gdb_get_line_number "After value assignment"]
>> +gdb_continue_to_breakpoint "After value assignment"
>> +gdb_test "print logp" "= \\(PTR TO -> \\( $logical \\)\\) $hex\( <.*>\)?"  "print logp, associated"
>> +gdb_test "print comp" "= \\(PTR TO -> \\( $complex \\)\\) $hex\( <.*>\)?"  "print comp, associated"
>> +gdb_test "print charp" "= \\(PTR TO -> \\( character\\*1 \\)\\) $hex\( <.*>\)?" "print charp, associated"
>> +gdb_test "print charap" "= \\(PTR TO -> \\( character\\*3 \\)\\) $hex\( <.*>\)?" "print charap, associated"
>> +gdb_test "print intp" "= \\(PTR TO -> \\( $int \\)\\) $hex\( <.*>\)?"  "print intp, associated"
>> +gdb_test "print realp" "= \\(PTR TO -> \\( $real \\)\\) $hex\( <.*>\)?"  "print realp, associated"
>> +gdb_test "print *((integer*) &inta + 2)" "= 3" "print temporary pointer, array"
>
>> +
>> +gdb_breakpoint [gdb_get_line_number "Before pointer assignment"]
>> +gdb_continue_to_breakpoint "Before pointer assignment"
>> +gdb_test "ptype logp" "= <not associated>" "ptype logp, not associated"
>> +gdb_test "ptype comp" "= <not associated>" "ptype comp, not associated"
>> +gdb_test "ptype charp" "= <not associated>" "ptype charp, not associated"
>> +gdb_test "ptype charap" "= <not associated>" "ptype charap, not associated"
>> +gdb_test "ptype intp" "= <not associated>" "ptype intp, not associated"
>> +gdb_test "ptype intap" "= <not associated>" "ptype intap, not associated"
>> +gdb_test "ptype realp" "= <not associated>" "ptype realp, not associated"
>> +
> The type of the pointer should be known regardless it is associated with
> target or not, because in the source we have,
>
> +  logical, pointer :: logp
> +  complex, pointer :: comp
> +  character, pointer:: charp
> +  character (len=3), pointer:: charap
> +  integer, pointer :: intp
> +  integer, pointer :: intap (:)
> +  real, pointer :: realp
>
> we can tell the type of logp is "logical, pointer", right?
Correct, this should be doable. The prev. & current implementation stops 
further printing
of pointers in case they are not associated. I will change this.
>
>> +
>> +gdb_test "ptype logp" "type = PTR TO -> \\( $logical \\)"
>> +gdb_test "ptype comp" "type = PTR TO -> \\( $complex \\)"
>> +gdb_test "ptype charp" "type = PTR TO -> \\( character\\*1 \\)"
>> +gdb_test "ptype charap" "type = PTR TO -> \\( character\\*3 \\)"
>> +gdb_test "ptype intp" "type = PTR TO -> \\( $int \\)"
>> +gdb_test "ptype realp" "type = PTR TO -> \\( $real \\)"

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] 11+ messages in thread

* Re: [PATCH 1/3] Fortran: Handle associated property of pointer types.
  2016-06-21  9:17     ` Bernhard Heckel
@ 2016-06-21 10:04       ` Yao Qi
  2016-06-24  5:38         ` Bernhard Heckel
  0 siblings, 1 reply; 11+ messages in thread
From: Yao Qi @ 2016-06-21 10:04 UTC (permalink / raw)
  To: Bernhard Heckel; +Cc: Yao Qi, eliz, gdb-patches

Bernhard Heckel <bernhard.heckel@intel.com> writes:

>>> +gdb_test "print intp" "= <not associated>" "print intp, not associated"
>>> +
>>> +gdb_breakpoint [gdb_get_line_number "Before pointer assignment"]
>>> +gdb_continue_to_breakpoint "Before pointer assignment"
>>> +gdb_test "print logp" "= <not associated>" "print logp, not associated"
>>> +gdb_test "print comp" "= <not associated>" "print comp, not associated"
>>> +gdb_test "print charp" "= <not associated>" "print charp, not associated"
>>> +gdb_test "print charap" "= <not associated>" "print charap, not associated"
>>> +gdb_test "print intp" "= <not associated>" "print intp, not associated"
>>> +gdb_test "print intap" "= <not associated>" "print intap, not associated"
>>> +gdb_test "print realp" "= <not associated>" "print realp, not associated"
>>> +gdb_test "print \$my_var = intp" "= <not associated>"
>> What is the output without your fix?  IMO, "print POINTER" prints the
>> value of the pointer.  It doesn't matter whether the pointer is
>> associated with a target or not.
> For compilers creating the property, the output is like above.
> For missing property, it is:
>
> gdb_test "print logp" "= (PTR TO -> ( $logical )) 0x0"
>
> Based on your input I would like to propose:
> gdb_test "print logp" "= (PTR TO -> ( $logical )) <not associated>"

I don't want GDB to carry some knowledge to guess the pointer is not
associated.  If compiler creates the property, gdb uses it, otherwise,
simply prints 0x0, which is right to me.  I don't understand the point
of changing the output "0x0" -> "<not associated>".

-- 
Yao (齐尧)

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

* Re: [PATCH 1/3] Fortran: Handle associated property of pointer types.
  2016-06-21 10:04       ` Yao Qi
@ 2016-06-24  5:38         ` Bernhard Heckel
  0 siblings, 0 replies; 11+ messages in thread
From: Bernhard Heckel @ 2016-06-24  5:38 UTC (permalink / raw)
  To: Yao Qi; +Cc: eliz, gdb-patches

On 21/06/2016 12:03, Yao Qi wrote:
> Bernhard Heckel <bernhard.heckel@intel.com> writes:
>
>>>> +gdb_test "print intp" "= <not associated>" "print intp, not associated"
>>>> +
>>>> +gdb_breakpoint [gdb_get_line_number "Before pointer assignment"]
>>>> +gdb_continue_to_breakpoint "Before pointer assignment"
>>>> +gdb_test "print logp" "= <not associated>" "print logp, not associated"
>>>> +gdb_test "print comp" "= <not associated>" "print comp, not associated"
>>>> +gdb_test "print charp" "= <not associated>" "print charp, not associated"
>>>> +gdb_test "print charap" "= <not associated>" "print charap, not associated"
>>>> +gdb_test "print intp" "= <not associated>" "print intp, not associated"
>>>> +gdb_test "print intap" "= <not associated>" "print intap, not associated"
>>>> +gdb_test "print realp" "= <not associated>" "print realp, not associated"
>>>> +gdb_test "print \$my_var = intp" "= <not associated>"
>>> What is the output without your fix?  IMO, "print POINTER" prints the
>>> value of the pointer.  It doesn't matter whether the pointer is
>>> associated with a target or not.
>> For compilers creating the property, the output is like above.
>> For missing property, it is:
>>
>> gdb_test "print logp" "= (PTR TO -> ( $logical )) 0x0"
>>
>> Based on your input I would like to propose:
>> gdb_test "print logp" "= (PTR TO -> ( $logical )) <not associated>"
> I don't want GDB to carry some knowledge to guess the pointer is not
> associated.  If compiler creates the property, gdb uses it, otherwise,
> simply prints 0x0, which is right to me.  I don't understand the point
> of changing the output "0x0" -> "<not associated>".
>
You are right, it is not necessarily needed to add this property in case 
it is not generated by the compiler.

Nevertheless, I did it for two reasons:

- My intention was to reflect the associated status to the user like 
described in the fortran standard.

The standard says: A nullified pointer is disassociated.

- Keep existing and future test cases simple, as there is no switch case 
needed for different compiler releases.

 From my point both behavior are fine, it's up to you to decide

BR

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] 11+ messages in thread

end of thread, other threads:[~2016-06-24  5:38 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-06 13:37 [PATCH 0/3] Fortran: Resolve target types of pointers Bernhard Heckel
2016-06-06 13:37 ` [PATCH 3/3] Fortran: Handle cyclic pointers Bernhard Heckel
2016-06-17 15:16   ` Yao Qi
2016-06-06 13:37 ` [PATCH 2/3] Fortran: Resolve dynamic target types of pointers Bernhard Heckel
2016-06-06 15:08   ` Eli Zaretskii
2016-06-06 13:37 ` [PATCH 1/3] Fortran: Handle associated property of pointer types Bernhard Heckel
2016-06-17 11:28   ` Yao Qi
2016-06-21  9:17     ` Bernhard Heckel
2016-06-21 10:04       ` Yao Qi
2016-06-24  5:38         ` Bernhard Heckel
2016-06-16 11:23 ` [PING][PATCH 0/3] Fortran: Resolve target types of pointers Bernhard Heckel

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