public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [patch] DW_AT_byte_size for array type entries
@ 2010-10-19 11:24 Ken Werner
  2010-10-19 18:16 ` Ken Werner
  0 siblings, 1 reply; 20+ messages in thread
From: Ken Werner @ 2010-10-19 11:24 UTC (permalink / raw)
  To: gdb-patches

[-- Attachment #1: Type: Text/Plain, Size: 1108 bytes --]

Hi,

Section 5.4 of the DWARF standard allows to specify extra padding bytes for 
array type entries by using the DW_AT_byte_size attribute. This is used for 
example to specify the types for OpenCL 3-component vectors whose size and 
alignment are those of 4-component vectors. Currently the GDB does not 
understand this mechanism and the attached patch attempts to fix this. It 
extends the DWARF reader (dwarf2read.c:read_array_type) to respect the 
DW_AT_byte_size attribute and set the length of the array accordingly. This 
breaks the code that assumes that the number of elements of an array is simply 
the length of the array type divided by the length of the element type. 
Therefore the patch queries the number of array elements using the 
get_array_bounds function that has been enhanced to only return the bounds if 
they are defined (TYPE_ARRAY_[LOWER|UPPER]_BOUND_IS_UNDEFINED). In order to 
prevent the inclusion of the valprint.h header the get_array_bounds function 
has been moved from valprint.[c|h] to gdbtypes.[c|h].
Tested on i686-*-linux-gnu with no regressions.

Regards
Ken Werner

[-- Attachment #2: DW_AT_byte_size.patch --]
[-- Type: text/x-patch, Size: 13890 bytes --]

ChangeLog:

2010-10-19  Ken Werner  <ken.werner@de.ibm.com>

	* dwarf2read.c (read_array_type): Read the DW_AT_byte_size from the
	DIE and set the length of the type.
	* gdbtypes.h (get_array_bounds): Move here from valprint.h.
	* gdbtypes.c (get_array_bounds): Move here from valprint.c and
	return 0 if the corresponding bounds of the type are undefined.
	* valprint.h (get_array_bounds): Move declaration to gdbtypes.h.
	* valprint.c (get_array_bounds): Move implementation to gdbtypes.c.
	(val_print_array_elements): Use get_array_bounds to compute the number
	of array elements instead of dividing the length of the array by the
	length of the element types.
	* valarith.c (vector_binop): Likewise.
	* valops.c (value_cast): Likewise.
	* c-valprint.c (c_val_print): Likewise.
	* c-typeprint.c (c_type_print_varspec_suffix): Likewise.


testsuite/ChangeLog:

2010-10-19  Ken Werner  <ken.werner@de.ibm.com>

	* gdb.base/gnu_vector.exp: Adjust expect messages.

 
Index: gdb/c-valprint.c
===================================================================
RCS file: /cvs/src/src/gdb/c-valprint.c,v
retrieving revision 1.74
diff -p -u -r1.74 c-valprint.c
--- gdb/c-valprint.c	15 Oct 2010 18:54:12 -0000	1.74
+++ gdb/c-valprint.c	19 Oct 2010 11:00:18 -0000
@@ -171,8 +171,13 @@ c_val_print (struct type *type, const gd
       elttype = check_typedef (unresolved_elttype);
       if (TYPE_LENGTH (type) > 0 && TYPE_LENGTH (unresolved_elttype) > 0)
 	{
+          LONGEST low_bound, high_bound;
+          
+          if (!get_array_bounds(type, &low_bound, &high_bound))
+            error (_("Could not determine the array high bound"));
+          
 	  eltlen = TYPE_LENGTH (elttype);
-	  len = TYPE_LENGTH (type) / eltlen;
+	  len = high_bound - low_bound + 1;
 	  if (options->prettyprint_arrays)
 	    {
 	      print_spaces_filtered (2 + 2 * recurse, stream);
Index: gdb/dwarf2read.c
===================================================================
RCS file: /cvs/src/src/gdb/dwarf2read.c,v
retrieving revision 1.472
diff -p -u -r1.472 dwarf2read.c
--- gdb/dwarf2read.c	17 Oct 2010 18:49:46 -0000	1.472
+++ gdb/dwarf2read.c	19 Oct 2010 11:00:18 -0000
@@ -7194,6 +7194,19 @@ read_array_type (struct die_info *die, s
   if (attr)
     make_vector_type (type);
 
+  /* The DIE may have DW_AT_byte_size set.  For example an OpenCL
+     implementation may choose to implement triple vectors using this
+     attribute.  */
+  attr = dwarf2_attr (die, DW_AT_byte_size, cu);
+  if (attr)
+    {
+      if (DW_UNSND (attr) >= TYPE_LENGTH (type))
+	TYPE_LENGTH (type) = DW_UNSND (attr);
+      else
+	complaint (&symfile_complaints, _("\
+DW_AT_byte_size for array type smaller than the total size of elements"));
+    }
+  
   name = dwarf2_name (die, cu);
   if (name)
     TYPE_NAME (type) = name;
Index: gdb/gdbtypes.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbtypes.c,v
retrieving revision 1.203
diff -p -u -r1.203 gdbtypes.c
--- gdb/gdbtypes.c	15 Oct 2010 17:48:47 -0000	1.203
+++ gdb/gdbtypes.c	19 Oct 2010 11:00:19 -0000
@@ -802,6 +802,50 @@ get_discrete_bounds (struct type *type, 
     }
 }
 
+/* Assuming TYPE is a simple, non-empty array type, compute its upper
+   and lower bound.  Save the low bound into LOW_BOUND if not NULL.
+   Save the high bound into HIGH_BOUND if not NULL.
+
+   Return 1 if the operation was successful. Return zero otherwise,
+   in which case the values of LOW_BOUND and HIGH_BOUNDS are unmodified.
+  
+   We now simply use get_discrete_bounds call to get the values
+   of the low and high bounds. 
+   get_discrete_bounds can return three values:
+   1, meaning that index is a range,
+   0, meaning that index is a discrete type,
+   or -1 for failure.  */
+
+int
+get_array_bounds (struct type *type, LONGEST *low_bound, LONGEST *high_bound)
+{
+  struct type *index = TYPE_INDEX_TYPE (type);
+  LONGEST low = 0;
+  LONGEST high = 0;
+  int res;
+                                
+  if (index == NULL)
+    return 0;
+
+  res = get_discrete_bounds (index, &low, &high);
+  if (res == -1)
+    return 0;
+
+  /* Check if the array bounds are undefined.  */
+  if (res == 1
+      && ((low_bound && TYPE_ARRAY_LOWER_BOUND_IS_UNDEFINED (type))
+	  || (high_bound && TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (type))))
+    return 0;
+  
+  if (low_bound)
+    *low_bound = low;
+
+  if (high_bound)
+    *high_bound = high;
+
+  return 1;
+}
+
 /* Create an array type using either a blank type supplied in
    RESULT_TYPE, or creating a new type, inheriting the objfile from
    RANGE_TYPE.
Index: gdb/gdbtypes.h
===================================================================
RCS file: /cvs/src/src/gdb/gdbtypes.h,v
retrieving revision 1.137
diff -p -u -r1.137 gdbtypes.h
--- gdb/gdbtypes.h	15 Oct 2010 17:48:47 -0000	1.137
+++ gdb/gdbtypes.h	19 Oct 2010 11:00:19 -0000
@@ -1383,6 +1383,9 @@ extern int get_vptr_fieldno (struct type
 
 extern int get_discrete_bounds (struct type *, LONGEST *, LONGEST *);
 
+extern int get_array_bounds (struct type *type, LONGEST *low_bound,
+			     LONGEST *high_bound);
+
 extern int class_types_same_p (const struct type *, const struct type *);
 
 extern int is_ancestor (struct type *, struct type *);
Index: gdb/valarith.c
===================================================================
RCS file: /cvs/src/src/gdb/valarith.c,v
retrieving revision 1.87
diff -p -u -r1.87 valarith.c
--- gdb/valarith.c	8 Oct 2010 16:50:53 -0000	1.87
+++ gdb/valarith.c	19 Oct 2010 11:00:19 -0000
@@ -1388,7 +1388,8 @@ vector_binop (struct value *val1, struct
 {
   struct value *val, *tmp, *mark;
   struct type *type1, *type2, *eltype1, *eltype2, *result_type;
-  int t1_is_vec, t2_is_vec, elsize, n, i;
+  int t1_is_vec, t2_is_vec, elsize, i;
+  LONGEST low_bound1, high_bound1, low_bound2, high_bound2;
 
   type1 = check_typedef (value_type (val1));
   type2 = check_typedef (value_type (val2));
@@ -1401,23 +1402,23 @@ vector_binop (struct value *val1, struct
   if (!t1_is_vec || !t2_is_vec)
     error (_("Vector operations are only supported among vectors"));
 
+  if (!get_array_bounds (type1, &low_bound1, &high_bound1)
+      || !get_array_bounds (type2, &low_bound2, &high_bound2))
+    error (_("Could not determine the vector bounds"));
+  
   eltype1 = check_typedef (TYPE_TARGET_TYPE (type1));
   eltype2 = check_typedef (TYPE_TARGET_TYPE (type2));
+  elsize = TYPE_LENGTH (eltype1);  
 
   if (TYPE_CODE (eltype1) != TYPE_CODE (eltype2)
-      || TYPE_LENGTH (eltype1) != TYPE_LENGTH (eltype2)
-      || TYPE_UNSIGNED (eltype1) != TYPE_UNSIGNED (eltype2))
+      || elsize != TYPE_LENGTH (eltype2)
+      || TYPE_UNSIGNED (eltype1) != TYPE_UNSIGNED (eltype2)
+      || low_bound1 != low_bound2 || high_bound1 != high_bound2)
     error (_("Cannot perform operation on vectors with different types"));
 
-  elsize = TYPE_LENGTH (eltype1);
-  n = TYPE_LENGTH (type1) / elsize;
-
-  if (n != TYPE_LENGTH (type2) / TYPE_LENGTH (eltype2))
-    error (_("Cannot perform operation on vectors with different sizes"));
-
   val = allocate_value (type1);
   mark = value_mark ();
-  for (i = 0; i < n; i++)
+  for (i = 0; i < high_bound1 - low_bound1 + 1; i++)
     {
       tmp = value_binop (value_subscript (val1, i),
 			 value_subscript (val2, i), op);
Index: gdb/valops.c
===================================================================
RCS file: /cvs/src/src/gdb/valops.c,v
retrieving revision 1.252
diff -p -u -r1.252 valops.c
--- gdb/valops.c	8 Oct 2010 16:50:53 -0000	1.252
+++ gdb/valops.c	19 Oct 2010 11:00:19 -0000
@@ -543,14 +543,17 @@ value_cast (struct type *type, struct va
       /* Widen the scalar to a vector.  */
       struct type *eltype;
       struct value *val;
-      int i, n;
+      LONGEST low_bound, high_bound;      
+      int i;
 
+      if (!get_array_bounds (type, &low_bound, &high_bound))
+	error (_("Could not determine the vector bounds"));
+      
       eltype = check_typedef (TYPE_TARGET_TYPE (type));
       arg2 = value_cast (eltype, arg2);
       val = allocate_value (type);
-      n = TYPE_LENGTH (type) / TYPE_LENGTH (eltype);
 
-      for (i = 0; i < n; i++)
+      for (i = 0; i < high_bound - low_bound + 1; i++)
 	{
 	  /* Duplicate the contents of arg2 into the destination vector.  */
 	  memcpy (value_contents_writeable (val) + (i * TYPE_LENGTH (eltype)),
Index: gdb/valprint.c
===================================================================
RCS file: /cvs/src/src/gdb/valprint.c,v
retrieving revision 1.97
diff -p -u -r1.97 valprint.c
--- gdb/valprint.c	18 Oct 2010 19:14:02 -0000	1.97
+++ gdb/valprint.c	19 Oct 2010 11:00:19 -0000
@@ -1067,44 +1067,6 @@ print_char_chars (struct ui_file *stream
     }
 }
 
-/* Assuming TYPE is a simple, non-empty array type, compute its upper
-   and lower bound.  Save the low bound into LOW_BOUND if not NULL.
-   Save the high bound into HIGH_BOUND if not NULL.
-
-   Return 1 if the operation was successful. Return zero otherwise,
-   in which case the values of LOW_BOUND and HIGH_BOUNDS are unmodified.
-  
-   We now simply use get_discrete_bounds call to get the values
-   of the low and high bounds. 
-   get_discrete_bounds can return three values:
-   1, meaning that index is a range,
-   0, meaning that index is a discrete type,
-   or -1 for failure.  */
-
-int
-get_array_bounds (struct type *type, LONGEST *low_bound, LONGEST *high_bound)
-{
-  struct type *index = TYPE_INDEX_TYPE (type);
-  LONGEST low = 0;
-  LONGEST high = 0;
-  int res;
-                                
-  if (index == NULL)
-    return 0;
-
-  res = get_discrete_bounds (index, &low, &high);
-  if (res == -1)
-    return 0;
-
-  if (low_bound)
-    *low_bound = low;
-
-  if (high_bound)
-    *high_bound = high;
-
-  return 1;
-}
-
 /* Print on STREAM using the given OPTIONS the index for the element
    at INDEX of an array whose index type is INDEX_TYPE.  */
     
@@ -1149,38 +1111,19 @@ val_print_array_elements (struct type *t
   unsigned int rep1;
   /* Number of repetitions we have detected so far.  */
   unsigned int reps;
-  LONGEST low_bound_index = 0;
+  LONGEST low_bound, high_bound;
 
   elttype = TYPE_TARGET_TYPE (type);
   eltlen = TYPE_LENGTH (check_typedef (elttype));
   index_type = TYPE_INDEX_TYPE (type);
 
-  /* Compute the number of elements in the array.  On most arrays,
-     the size of its elements is not zero, and so the number of elements
-     is simply the size of the array divided by the size of the elements.
-     But for arrays of elements whose size is zero, we need to look at
-     the bounds.  */
-  if (eltlen != 0)
-    len = TYPE_LENGTH (type) / eltlen;
+  if (get_array_bounds (type, &low_bound, &high_bound))
+    len = high_bound - low_bound + 1;
   else
     {
-      LONGEST low, hi;
-
-      if (get_array_bounds (type, &low, &hi))
-        len = hi - low + 1;
-      else
-        {
-          warning (_("unable to get bounds of array, assuming null array"));
-          len = 0;
-        }
-    }
-
-  /* Get the array low bound.  This only makes sense if the array
-     has one or more element in it.  */
-  if (len > 0 && !get_array_bounds (type, &low_bound_index, NULL))
-    {
-      warning (_("unable to get low bound of array, using zero as default"));
-      low_bound_index = 0;
+      warning (_("unable to get bounds of array, assuming null array"));
+      low_bound = 0;
+      len = 0;
     }
 
   annotate_array_section_begin (i, elttype);
@@ -1200,7 +1143,7 @@ val_print_array_elements (struct type *t
 	    }
 	}
       wrap_here (n_spaces (2 + 2 * recurse));
-      maybe_print_array_index (index_type, i + low_bound_index,
+      maybe_print_array_index (index_type, i + low_bound,
                                stream, options);
 
       rep1 = i + 1;
Index: gdb/valprint.h
===================================================================
RCS file: /cvs/src/src/gdb/valprint.h,v
retrieving revision 1.27
diff -p -u -r1.27 valprint.h
--- gdb/valprint.h	11 Jun 2010 15:36:05 -0000	1.27
+++ gdb/valprint.h	19 Oct 2010 11:00:19 -0000
@@ -109,9 +109,6 @@ extern void get_raw_print_options (struc
 extern void get_formatted_print_options (struct value_print_options *opts,
 					 char format);
 
-extern int get_array_bounds (struct type *type, LONGEST *low_bound,
-			     LONGEST *high_bound);
-
 extern void maybe_print_array_index (struct type *index_type, LONGEST index,
                                      struct ui_file *stream,
 				     const struct value_print_options *options);
Index: gdb/testsuite/gdb.base/gnu_vector.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.base/gnu_vector.exp,v
retrieving revision 1.3
diff -p -u -r1.3 gnu_vector.exp
--- gdb/testsuite/gdb.base/gnu_vector.exp	8 Oct 2010 16:50:55 -0000	1.3
+++ gdb/testsuite/gdb.base/gnu_vector.exp	19 Oct 2010 11:00:19 -0000
@@ -119,8 +119,8 @@ gdb_test "print f4a + d2" "Cannot perfor
 gdb_test "print d2 + f4a" "Cannot perform operation on vectors with different types"
 gdb_test "print ui4 + i4a" "Cannot perform operation on vectors with different types"
 gdb_test "print i4a + ui4" "Cannot perform operation on vectors with different types"
-gdb_test "print i4a + i2" "Cannot perform operation on vectors with different sizes"
-gdb_test "print i2 + i4a" "Cannot perform operation on vectors with different sizes"
-gdb_test "print f4a + f2" "Cannot perform operation on vectors with different sizes"
-gdb_test "print f2 + f4a" "Cannot perform operation on vectors with different sizes"
+gdb_test "print i4a + i2" "Cannot perform operation on vectors with different types"
+gdb_test "print i2 + i4a" "Cannot perform operation on vectors with different types"
+gdb_test "print f4a + f2" "Cannot perform operation on vectors with different types"
+gdb_test "print f2 + f4a" "Cannot perform operation on vectors with different types"
 

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

* Re: [patch] DW_AT_byte_size for array type entries
  2010-10-19 11:24 [patch] DW_AT_byte_size for array type entries Ken Werner
@ 2010-10-19 18:16 ` Ken Werner
  2010-11-02  8:23   ` Ken Werner
  2010-11-02 22:45   ` Tom Tromey
  0 siblings, 2 replies; 20+ messages in thread
From: Ken Werner @ 2010-10-19 18:16 UTC (permalink / raw)
  To: gdb-patches

[-- Attachment #1: Type: Text/Plain, Size: 1322 bytes --]

On Tuesday, October 19, 2010 1:23:57 pm Ken Werner wrote:
> Hi,
> 
> Section 5.4 of the DWARF standard allows to specify extra padding bytes for
> array type entries by using the DW_AT_byte_size attribute. This is used for
> example to specify the types for OpenCL 3-component vectors whose size and
> alignment are those of 4-component vectors. Currently the GDB does not
> understand this mechanism and the attached patch attempts to fix this. It
> extends the DWARF reader (dwarf2read.c:read_array_type) to respect the
> DW_AT_byte_size attribute and set the length of the array accordingly. This
> breaks the code that assumes that the number of elements of an array is
> simply the length of the array type divided by the length of the element
> type. Therefore the patch queries the number of array elements using the
> get_array_bounds function that has been enhanced to only return the bounds
> if they are defined (TYPE_ARRAY_[LOWER|UPPER]_BOUND_IS_UNDEFINED). In
> order to prevent the inclusion of the valprint.h header the
> get_array_bounds function has been moved from valprint.[c|h] to
> gdbtypes.[c|h].
> Tested on i686-*-linux-gnu with no regressions.
> 
> Regards
> Ken Werner

Hm, that patch lacks the chunk that changes the c_type_print_varspec_suffix 
function. Here is the full version.

Regards
Ken

[-- Attachment #2: DW_AT_byte_size.patch --]
[-- Type: text/x-patch, Size: 15121 bytes --]

ChangeLog:

2010-10-19  Ken Werner  <ken.werner@de.ibm.com>

	* dwarf2read.c (read_array_type): Read the DW_AT_byte_size from the
	DIE and set the length of the type.
	* gdbtypes.h (get_array_bounds): Move here from valprint.h.
	* gdbtypes.c (get_array_bounds): Move here from valprint.c and
	return 0 if the corresponding bounds of the type are undefined.
	* valprint.h (get_array_bounds): Move declaration to gdbtypes.h.
	* valprint.c (get_array_bounds): Move implementation to gdbtypes.c.
	(val_print_array_elements): Use get_array_bounds to compute the number
	of array elements instead of dividing the length of the array by the
	length of the element types.
	* valarith.c (vector_binop): Likewise.
	* valops.c (value_cast): Likewise.
	* c-valprint.c (c_val_print): Likewise.
	* c-typeprint.c (c_type_print_varspec_suffix): Likewise.


testsuite/ChangeLog:

2010-10-19  Ken Werner  <ken.werner@de.ibm.com>

	* gdb.base/gnu_vector.exp: Adjust expect messages.

 
Index: gdb/c-valprint.c
===================================================================
RCS file: /cvs/src/src/gdb/c-valprint.c,v
retrieving revision 1.74
diff -p -u -r1.74 c-valprint.c
--- gdb/c-valprint.c	15 Oct 2010 18:54:12 -0000	1.74
+++ gdb/c-valprint.c	19 Oct 2010 12:15:30 -0000
@@ -171,8 +171,13 @@ c_val_print (struct type *type, const gd
       elttype = check_typedef (unresolved_elttype);
       if (TYPE_LENGTH (type) > 0 && TYPE_LENGTH (unresolved_elttype) > 0)
 	{
+          LONGEST low_bound, high_bound;
+
+          if (!get_array_bounds(type, &low_bound, &high_bound))
+            error (_("Could not determine the array high bound"));
+
 	  eltlen = TYPE_LENGTH (elttype);
-	  len = TYPE_LENGTH (type) / eltlen;
+	  len = high_bound - low_bound + 1;
 	  if (options->prettyprint_arrays)
 	    {
 	      print_spaces_filtered (2 + 2 * recurse, stream);
Index: gdb/dwarf2read.c
===================================================================
RCS file: /cvs/src/src/gdb/dwarf2read.c,v
retrieving revision 1.472
diff -p -u -r1.472 dwarf2read.c
--- gdb/dwarf2read.c	17 Oct 2010 18:49:46 -0000	1.472
+++ gdb/dwarf2read.c	19 Oct 2010 12:15:31 -0000
@@ -7194,6 +7194,19 @@ read_array_type (struct die_info *die, s
   if (attr)
     make_vector_type (type);
 
+  /* The DIE may have DW_AT_byte_size set.  For example an OpenCL
+     implementation may choose to implement triple vectors using this
+     attribute.  */
+  attr = dwarf2_attr (die, DW_AT_byte_size, cu);
+  if (attr)
+    {
+      if (DW_UNSND (attr) >= TYPE_LENGTH (type))
+	TYPE_LENGTH (type) = DW_UNSND (attr);
+      else
+	complaint (&symfile_complaints, _("\
+DW_AT_byte_size for array type smaller than the total size of elements"));
+    }
+
   name = dwarf2_name (die, cu);
   if (name)
     TYPE_NAME (type) = name;
Index: gdb/gdbtypes.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbtypes.c,v
retrieving revision 1.203
diff -p -u -r1.203 gdbtypes.c
--- gdb/gdbtypes.c	15 Oct 2010 17:48:47 -0000	1.203
+++ gdb/gdbtypes.c	19 Oct 2010 12:15:31 -0000
@@ -802,6 +802,50 @@ get_discrete_bounds (struct type *type, 
     }
 }
 
+/* Assuming TYPE is a simple, non-empty array type, compute its upper
+   and lower bound.  Save the low bound into LOW_BOUND if not NULL.
+   Save the high bound into HIGH_BOUND if not NULL.
+
+   Return 1 if the operation was successful. Return zero otherwise,
+   in which case the values of LOW_BOUND and HIGH_BOUNDS are unmodified.
+
+   We now simply use get_discrete_bounds call to get the values
+   of the low and high bounds.
+   get_discrete_bounds can return three values:
+   1, meaning that index is a range,
+   0, meaning that index is a discrete type,
+   or -1 for failure.  */
+
+int
+get_array_bounds (struct type *type, LONGEST *low_bound, LONGEST *high_bound)
+{
+  struct type *index = TYPE_INDEX_TYPE (type);
+  LONGEST low = 0;
+  LONGEST high = 0;
+  int res;
+
+  if (index == NULL)
+    return 0;
+
+  res = get_discrete_bounds (index, &low, &high);
+  if (res == -1)
+    return 0;
+
+  /* Check if the array bounds are undefined.  */
+  if (res == 1
+      && ((low_bound && TYPE_ARRAY_LOWER_BOUND_IS_UNDEFINED (type))
+	  || (high_bound && TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (type))))
+    return 0;
+
+  if (low_bound)
+    *low_bound = low;
+
+  if (high_bound)
+    *high_bound = high;
+
+  return 1;
+}
+
 /* Create an array type using either a blank type supplied in
    RESULT_TYPE, or creating a new type, inheriting the objfile from
    RANGE_TYPE.
Index: gdb/gdbtypes.h
===================================================================
RCS file: /cvs/src/src/gdb/gdbtypes.h,v
retrieving revision 1.137
diff -p -u -r1.137 gdbtypes.h
--- gdb/gdbtypes.h	15 Oct 2010 17:48:47 -0000	1.137
+++ gdb/gdbtypes.h	19 Oct 2010 12:15:31 -0000
@@ -1383,6 +1383,9 @@ extern int get_vptr_fieldno (struct type
 
 extern int get_discrete_bounds (struct type *, LONGEST *, LONGEST *);
 
+extern int get_array_bounds (struct type *type, LONGEST *low_bound,
+			     LONGEST *high_bound);
+
 extern int class_types_same_p (const struct type *, const struct type *);
 
 extern int is_ancestor (struct type *, struct type *);
Index: gdb/valarith.c
===================================================================
RCS file: /cvs/src/src/gdb/valarith.c,v
retrieving revision 1.87
diff -p -u -r1.87 valarith.c
--- gdb/valarith.c	8 Oct 2010 16:50:53 -0000	1.87
+++ gdb/valarith.c	19 Oct 2010 12:15:31 -0000
@@ -1388,7 +1388,8 @@ vector_binop (struct value *val1, struct
 {
   struct value *val, *tmp, *mark;
   struct type *type1, *type2, *eltype1, *eltype2, *result_type;
-  int t1_is_vec, t2_is_vec, elsize, n, i;
+  int t1_is_vec, t2_is_vec, elsize, i;
+  LONGEST low_bound1, high_bound1, low_bound2, high_bound2;
 
   type1 = check_typedef (value_type (val1));
   type2 = check_typedef (value_type (val2));
@@ -1401,23 +1402,23 @@ vector_binop (struct value *val1, struct
   if (!t1_is_vec || !t2_is_vec)
     error (_("Vector operations are only supported among vectors"));
 
+  if (!get_array_bounds (type1, &low_bound1, &high_bound1)
+      || !get_array_bounds (type2, &low_bound2, &high_bound2))
+    error (_("Could not determine the vector bounds"));
+
   eltype1 = check_typedef (TYPE_TARGET_TYPE (type1));
   eltype2 = check_typedef (TYPE_TARGET_TYPE (type2));
+  elsize = TYPE_LENGTH (eltype1);
 
   if (TYPE_CODE (eltype1) != TYPE_CODE (eltype2)
-      || TYPE_LENGTH (eltype1) != TYPE_LENGTH (eltype2)
-      || TYPE_UNSIGNED (eltype1) != TYPE_UNSIGNED (eltype2))
+      || elsize != TYPE_LENGTH (eltype2)
+      || TYPE_UNSIGNED (eltype1) != TYPE_UNSIGNED (eltype2)
+      || low_bound1 != low_bound2 || high_bound1 != high_bound2)
     error (_("Cannot perform operation on vectors with different types"));
 
-  elsize = TYPE_LENGTH (eltype1);
-  n = TYPE_LENGTH (type1) / elsize;
-
-  if (n != TYPE_LENGTH (type2) / TYPE_LENGTH (eltype2))
-    error (_("Cannot perform operation on vectors with different sizes"));
-
   val = allocate_value (type1);
   mark = value_mark ();
-  for (i = 0; i < n; i++)
+  for (i = 0; i < high_bound1 - low_bound1 + 1; i++)
     {
       tmp = value_binop (value_subscript (val1, i),
 			 value_subscript (val2, i), op);
Index: gdb/valops.c
===================================================================
RCS file: /cvs/src/src/gdb/valops.c,v
retrieving revision 1.252
diff -p -u -r1.252 valops.c
--- gdb/valops.c	8 Oct 2010 16:50:53 -0000	1.252
+++ gdb/valops.c	19 Oct 2010 12:15:32 -0000
@@ -543,14 +543,17 @@ value_cast (struct type *type, struct va
       /* Widen the scalar to a vector.  */
       struct type *eltype;
       struct value *val;
-      int i, n;
+      LONGEST low_bound, high_bound;
+      int i;
+
+      if (!get_array_bounds (type, &low_bound, &high_bound))
+	error (_("Could not determine the vector bounds"));
 
       eltype = check_typedef (TYPE_TARGET_TYPE (type));
       arg2 = value_cast (eltype, arg2);
       val = allocate_value (type);
-      n = TYPE_LENGTH (type) / TYPE_LENGTH (eltype);
 
-      for (i = 0; i < n; i++)
+      for (i = 0; i < high_bound - low_bound + 1; i++)
 	{
 	  /* Duplicate the contents of arg2 into the destination vector.  */
 	  memcpy (value_contents_writeable (val) + (i * TYPE_LENGTH (eltype)),
Index: gdb/valprint.c
===================================================================
RCS file: /cvs/src/src/gdb/valprint.c,v
retrieving revision 1.97
diff -p -u -r1.97 valprint.c
--- gdb/valprint.c	18 Oct 2010 19:14:02 -0000	1.97
+++ gdb/valprint.c	19 Oct 2010 12:15:32 -0000
@@ -1067,44 +1067,6 @@ print_char_chars (struct ui_file *stream
     }
 }
 
-/* Assuming TYPE is a simple, non-empty array type, compute its upper
-   and lower bound.  Save the low bound into LOW_BOUND if not NULL.
-   Save the high bound into HIGH_BOUND if not NULL.
-
-   Return 1 if the operation was successful. Return zero otherwise,
-   in which case the values of LOW_BOUND and HIGH_BOUNDS are unmodified.
-  
-   We now simply use get_discrete_bounds call to get the values
-   of the low and high bounds. 
-   get_discrete_bounds can return three values:
-   1, meaning that index is a range,
-   0, meaning that index is a discrete type,
-   or -1 for failure.  */
-
-int
-get_array_bounds (struct type *type, LONGEST *low_bound, LONGEST *high_bound)
-{
-  struct type *index = TYPE_INDEX_TYPE (type);
-  LONGEST low = 0;
-  LONGEST high = 0;
-  int res;
-                                
-  if (index == NULL)
-    return 0;
-
-  res = get_discrete_bounds (index, &low, &high);
-  if (res == -1)
-    return 0;
-
-  if (low_bound)
-    *low_bound = low;
-
-  if (high_bound)
-    *high_bound = high;
-
-  return 1;
-}
-
 /* Print on STREAM using the given OPTIONS the index for the element
    at INDEX of an array whose index type is INDEX_TYPE.  */
     
@@ -1149,38 +1111,19 @@ val_print_array_elements (struct type *t
   unsigned int rep1;
   /* Number of repetitions we have detected so far.  */
   unsigned int reps;
-  LONGEST low_bound_index = 0;
+  LONGEST low_bound, high_bound;
 
   elttype = TYPE_TARGET_TYPE (type);
   eltlen = TYPE_LENGTH (check_typedef (elttype));
   index_type = TYPE_INDEX_TYPE (type);
 
-  /* Compute the number of elements in the array.  On most arrays,
-     the size of its elements is not zero, and so the number of elements
-     is simply the size of the array divided by the size of the elements.
-     But for arrays of elements whose size is zero, we need to look at
-     the bounds.  */
-  if (eltlen != 0)
-    len = TYPE_LENGTH (type) / eltlen;
+  if (get_array_bounds (type, &low_bound, &high_bound))
+    len = high_bound - low_bound + 1;
   else
     {
-      LONGEST low, hi;
-
-      if (get_array_bounds (type, &low, &hi))
-        len = hi - low + 1;
-      else
-        {
-          warning (_("unable to get bounds of array, assuming null array"));
-          len = 0;
-        }
-    }
-
-  /* Get the array low bound.  This only makes sense if the array
-     has one or more element in it.  */
-  if (len > 0 && !get_array_bounds (type, &low_bound_index, NULL))
-    {
-      warning (_("unable to get low bound of array, using zero as default"));
-      low_bound_index = 0;
+      warning (_("unable to get bounds of array, assuming null array"));
+      low_bound = 0;
+      len = 0;
     }
 
   annotate_array_section_begin (i, elttype);
@@ -1200,7 +1143,7 @@ val_print_array_elements (struct type *t
 	    }
 	}
       wrap_here (n_spaces (2 + 2 * recurse));
-      maybe_print_array_index (index_type, i + low_bound_index,
+      maybe_print_array_index (index_type, i + low_bound,
                                stream, options);
 
       rep1 = i + 1;
Index: gdb/valprint.h
===================================================================
RCS file: /cvs/src/src/gdb/valprint.h,v
retrieving revision 1.27
diff -p -u -r1.27 valprint.h
--- gdb/valprint.h	11 Jun 2010 15:36:05 -0000	1.27
+++ gdb/valprint.h	19 Oct 2010 12:15:32 -0000
@@ -109,9 +109,6 @@ extern void get_raw_print_options (struc
 extern void get_formatted_print_options (struct value_print_options *opts,
 					 char format);
 
-extern int get_array_bounds (struct type *type, LONGEST *low_bound,
-			     LONGEST *high_bound);
-
 extern void maybe_print_array_index (struct type *index_type, LONGEST index,
                                      struct ui_file *stream,
 				     const struct value_print_options *options);
Index: gdb/testsuite/gdb.base/gnu_vector.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.base/gnu_vector.exp,v
retrieving revision 1.3
diff -p -u -r1.3 gnu_vector.exp
--- gdb/testsuite/gdb.base/gnu_vector.exp	8 Oct 2010 16:50:55 -0000	1.3
+++ gdb/testsuite/gdb.base/gnu_vector.exp	19 Oct 2010 12:15:32 -0000
@@ -119,8 +119,8 @@ gdb_test "print f4a + d2" "Cannot perfor
 gdb_test "print d2 + f4a" "Cannot perform operation on vectors with different types"
 gdb_test "print ui4 + i4a" "Cannot perform operation on vectors with different types"
 gdb_test "print i4a + ui4" "Cannot perform operation on vectors with different types"
-gdb_test "print i4a + i2" "Cannot perform operation on vectors with different sizes"
-gdb_test "print i2 + i4a" "Cannot perform operation on vectors with different sizes"
-gdb_test "print f4a + f2" "Cannot perform operation on vectors with different sizes"
-gdb_test "print f2 + f4a" "Cannot perform operation on vectors with different sizes"
+gdb_test "print i4a + i2" "Cannot perform operation on vectors with different types"
+gdb_test "print i2 + i4a" "Cannot perform operation on vectors with different types"
+gdb_test "print f4a + f2" "Cannot perform operation on vectors with different types"
+gdb_test "print f2 + f4a" "Cannot perform operation on vectors with different types"
 
Index: gdb/c-typeprint.c
===================================================================
RCS file: /cvs/src/src/gdb/c-typeprint.c,v
retrieving revision 1.63
diff -p -u -r1.63 c-typeprint.c
--- gdb/c-typeprint.c	19 Oct 2010 04:22:20 -0000	1.63
+++ gdb/c-typeprint.c	19 Oct 2010 17:52:38 -0000
@@ -572,19 +572,20 @@ c_type_print_varspec_suffix (struct type
   switch (TYPE_CODE (type))
     {
     case TYPE_CODE_ARRAY:
-      if (passed_a_ptr)
-	fprintf_filtered (stream, ")");
+      {
+	LONGEST low_bound, high_bound;
 
-      fprintf_filtered (stream, "[");
-      if (TYPE_LENGTH (TYPE_TARGET_TYPE (type)) > 0
-	&& !TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (type))
-	fprintf_filtered (stream, "%d",
-			  (TYPE_LENGTH (type)
-			   / TYPE_LENGTH (TYPE_TARGET_TYPE (type))));
-      fprintf_filtered (stream, "]");
+	if (passed_a_ptr)
+	  fprintf_filtered (stream, ")");
 
-      c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, show,
-				   0, 0);
+	fprintf_filtered (stream, "[");
+	if (get_array_bounds (type, &low_bound, &high_bound))
+	  fprintf_filtered (stream, "%d", (int) (high_bound - low_bound + 1));
+	fprintf_filtered (stream, "]");
+
+	c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, show,
+				     0, 0);
+      }
       break;
 
     case TYPE_CODE_MEMBERPTR:

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

* Re: [patch] DW_AT_byte_size for array type entries
  2010-10-19 18:16 ` Ken Werner
@ 2010-11-02  8:23   ` Ken Werner
  2010-11-02 22:45   ` Tom Tromey
  1 sibling, 0 replies; 20+ messages in thread
From: Ken Werner @ 2010-11-02  8:23 UTC (permalink / raw)
  To: gdb-patches

On Tuesday, October 19, 2010 8:16:05 pm Ken Werner wrote:
> On Tuesday, October 19, 2010 1:23:57 pm Ken Werner wrote:
> > Hi,
> > 
> > Section 5.4 of the DWARF standard allows to specify extra padding bytes
> > for array type entries by using the DW_AT_byte_size attribute. This is
> > used for example to specify the types for OpenCL 3-component vectors
> > whose size and alignment are those of 4-component vectors. Currently the
> > GDB does not understand this mechanism and the attached patch attempts
> > to fix this. It extends the DWARF reader (dwarf2read.c:read_array_type)
> > to respect the DW_AT_byte_size attribute and set the length of the array
> > accordingly. This breaks the code that assumes that the number of
> > elements of an array is simply the length of the array type divided by
> > the length of the element type. Therefore the patch queries the number
> > of array elements using the get_array_bounds function that has been
> > enhanced to only return the bounds if they are defined
> > (TYPE_ARRAY_[LOWER|UPPER]_BOUND_IS_UNDEFINED). In order to prevent the
> > inclusion of the valprint.h header the
> > get_array_bounds function has been moved from valprint.[c|h] to
> > gdbtypes.[c|h].
> > Tested on i686-*-linux-gnu with no regressions.
> 
> Hm, that patch lacks the chunk that changes the c_type_print_varspec_suffix
> function. Here is the full version.

Any objections/comments on that patch?

Thanks
Ken

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

* Re: [patch] DW_AT_byte_size for array type entries
  2010-10-19 18:16 ` Ken Werner
  2010-11-02  8:23   ` Ken Werner
@ 2010-11-02 22:45   ` Tom Tromey
  2010-11-03 14:23     ` Ken Werner
  1 sibling, 1 reply; 20+ messages in thread
From: Tom Tromey @ 2010-11-02 22:45 UTC (permalink / raw)
  To: Ken Werner; +Cc: gdb-patches

>>>>> "Ken" == Ken Werner <ken@linux.vnet.ibm.com> writes:

Ken> Index: gdb/c-valprint.c
Ken> ===================================================================
Ken> RCS file: /cvs/src/src/gdb/c-valprint.c,v
Ken> retrieving revision 1.74
Ken> diff -p -u -r1.74 c-valprint.c
Ken> --- gdb/c-valprint.c	15 Oct 2010 18:54:12 -0000	1.74
Ken> +++ gdb/c-valprint.c	19 Oct 2010 12:15:30 -0000
Ken> @@ -171,8 +171,13 @@ c_val_print (struct type *type, const gd
Ken>        elttype = check_typedef (unresolved_elttype);
Ken>        if (TYPE_LENGTH (type) > 0 && TYPE_LENGTH (unresolved_elttype) > 0)
Ken>  	{
Ken> +          LONGEST low_bound, high_bound;
Ken> +
Ken> +          if (!get_array_bounds(type, &low_bound, &high_bound))

Missing space before open paren.

Ken> +            error (_("Could not determine the array high bound"));
Ken> +
Ken>  	  eltlen = TYPE_LENGTH (elttype);
Ken> -	  len = TYPE_LENGTH (type) / eltlen;
Ken> +	  len = high_bound - low_bound + 1;

I guess it is ok to use 'eltlen' elsewhere in the function because it is
only the array's overall size which is "weird" -- the element size is
still correct.  (Since we don't implement the DWARF stride stuff...)


The patch is ok with the above nit fixed.

I wonder whether f-valprint.c also needs an update.

Tom

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

* Re: [patch] DW_AT_byte_size for array type entries
  2010-11-02 22:45   ` Tom Tromey
@ 2010-11-03 14:23     ` Ken Werner
  2010-11-03 19:09       ` Regression on gdb.ada/null_array.exp [Re: [patch] DW_AT_byte_size for array type entries] Jan Kratochvil
  2010-12-13 20:03       ` [patch] DW_AT_byte_size for array type entries Ken Werner
  0 siblings, 2 replies; 20+ messages in thread
From: Ken Werner @ 2010-11-03 14:23 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches

[-- Attachment #1: Type: Text/Plain, Size: 1666 bytes --]

On Tuesday, November 02, 2010 11:31:03 pm Tom Tromey wrote:
> >>>>> "Ken" == Ken Werner <ken@linux.vnet.ibm.com> writes:
> Ken> Index: gdb/c-valprint.c
> Ken> ===================================================================
> Ken> RCS file: /cvs/src/src/gdb/c-valprint.c,v
> Ken> retrieving revision 1.74
> Ken> diff -p -u -r1.74 c-valprint.c
> Ken> --- gdb/c-valprint.c	15 Oct 2010 18:54:12 -0000	1.74
> Ken> +++ gdb/c-valprint.c	19 Oct 2010 12:15:30 -0000
> Ken> @@ -171,8 +171,13 @@ c_val_print (struct type *type, const gd
> Ken>        elttype = check_typedef (unresolved_elttype);
> Ken>        if (TYPE_LENGTH (type) > 0 && TYPE_LENGTH (unresolved_elttype)
> > 0) Ken>  	{
> Ken> +          LONGEST low_bound, high_bound;
> Ken> +
> Ken> +          if (!get_array_bounds(type, &low_bound, &high_bound))
> 
> Missing space before open paren.

Fixed.

> Ken> +            error (_("Could not determine the array high bound"));
> Ken> +
> Ken>  	  eltlen = TYPE_LENGTH (elttype);
> Ken> -	  len = TYPE_LENGTH (type) / eltlen;
> Ken> +	  len = high_bound - low_bound + 1;
> 
> I guess it is ok to use 'eltlen' elsewhere in the function because it is
> only the array's overall size which is "weird" -- the element size is
> still correct.  (Since we don't implement the DWARF stride stuff...)

Yes, that is also my understanding.

> The patch is ok with the above nit fixed.

Thanks. I've checked in the version below:
http://sourceware.org/ml/gdb-cvs/2010-11/msg00014.html

> I wonder whether f-valprint.c also needs an update.

The f77_create_arrayprint_offset_tbl function seems to setup the 
f77_array_offset_tbl with the appropriate lengths.

Regards
Ken

[-- Attachment #2: DW_AT_byte_size.patch --]
[-- Type: text/x-patch, Size: 14318 bytes --]

ChangeLog:

2010-11-03  Ken Werner  <ken.werner@de.ibm.com>

	* dwarf2read.c (read_array_type): Read the DW_AT_byte_size from the
	DIE and set the length of the type.
	* gdbtypes.h (get_array_bounds): Move here from valprint.h.
	* gdbtypes.c (get_array_bounds): Move here from valprint.c and
	return 0 if the corresponding bounds of the type are undefined.
	* valprint.h (get_array_bounds): Move declaration to gdbtypes.h.
	* valprint.c (get_array_bounds): Move implementation to gdbtypes.c.
	(val_print_array_elements): Use get_array_bounds to compute the number
	of array elements instead of dividing the length of the array by the
	length of the element types.
	* valarith.c (vector_binop): Likewise.
	* valops.c (value_cast): Likewise.
	* c-valprint.c (c_val_print): Likewise.
	* c-typeprint.c (c_type_print_varspec_suffix): Likewise.


testsuite/ChangeLog:

2010-11-03  Ken Werner  <ken.werner@de.ibm.com>

	* gdb.base/gnu_vector.exp: Adjust expect messages.

 
Index: gdb/c-valprint.c
===================================================================
--- gdb/c-valprint.c.orig	2010-11-03 14:38:39.000000000 +0100
+++ gdb/c-valprint.c	2010-11-03 15:09:59.000000000 +0100
@@ -171,8 +171,13 @@ c_val_print (struct type *type, const gd
       elttype = check_typedef (unresolved_elttype);
       if (TYPE_LENGTH (type) > 0 && TYPE_LENGTH (unresolved_elttype) > 0)
 	{
+          LONGEST low_bound, high_bound;
+
+          if (!get_array_bounds (type, &low_bound, &high_bound))
+            error (_("Could not determine the array high bound"));
+
 	  eltlen = TYPE_LENGTH (elttype);
-	  len = TYPE_LENGTH (type) / eltlen;
+	  len = high_bound - low_bound + 1;
 	  if (options->prettyprint_arrays)
 	    {
 	      print_spaces_filtered (2 + 2 * recurse, stream);
Index: gdb/dwarf2read.c
===================================================================
--- gdb/dwarf2read.c.orig	2010-11-03 14:38:39.000000000 +0100
+++ gdb/dwarf2read.c	2010-11-03 15:09:59.000000000 +0100
@@ -7194,6 +7194,19 @@ read_array_type (struct die_info *die, s
   if (attr)
     make_vector_type (type);
 
+  /* The DIE may have DW_AT_byte_size set.  For example an OpenCL
+     implementation may choose to implement triple vectors using this
+     attribute.  */
+  attr = dwarf2_attr (die, DW_AT_byte_size, cu);
+  if (attr)
+    {
+      if (DW_UNSND (attr) >= TYPE_LENGTH (type))
+	TYPE_LENGTH (type) = DW_UNSND (attr);
+      else
+	complaint (&symfile_complaints, _("\
+DW_AT_byte_size for array type smaller than the total size of elements"));
+    }
+
   name = dwarf2_name (die, cu);
   if (name)
     TYPE_NAME (type) = name;
Index: gdb/gdbtypes.c
===================================================================
--- gdb/gdbtypes.c.orig	2010-11-03 14:38:39.000000000 +0100
+++ gdb/gdbtypes.c	2010-11-03 15:09:59.000000000 +0100
@@ -802,6 +802,50 @@ get_discrete_bounds (struct type *type,
     }
 }
 
+/* Assuming TYPE is a simple, non-empty array type, compute its upper
+   and lower bound.  Save the low bound into LOW_BOUND if not NULL.
+   Save the high bound into HIGH_BOUND if not NULL.
+
+   Return 1 if the operation was successful. Return zero otherwise,
+   in which case the values of LOW_BOUND and HIGH_BOUNDS are unmodified.
+
+   We now simply use get_discrete_bounds call to get the values
+   of the low and high bounds.
+   get_discrete_bounds can return three values:
+   1, meaning that index is a range,
+   0, meaning that index is a discrete type,
+   or -1 for failure.  */
+
+int
+get_array_bounds (struct type *type, LONGEST *low_bound, LONGEST *high_bound)
+{
+  struct type *index = TYPE_INDEX_TYPE (type);
+  LONGEST low = 0;
+  LONGEST high = 0;
+  int res;
+
+  if (index == NULL)
+    return 0;
+
+  res = get_discrete_bounds (index, &low, &high);
+  if (res == -1)
+    return 0;
+
+  /* Check if the array bounds are undefined.  */
+  if (res == 1
+      && ((low_bound && TYPE_ARRAY_LOWER_BOUND_IS_UNDEFINED (type))
+	  || (high_bound && TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (type))))
+    return 0;
+
+  if (low_bound)
+    *low_bound = low;
+
+  if (high_bound)
+    *high_bound = high;
+
+  return 1;
+}
+
 /* Create an array type using either a blank type supplied in
    RESULT_TYPE, or creating a new type, inheriting the objfile from
    RANGE_TYPE.
Index: gdb/gdbtypes.h
===================================================================
--- gdb/gdbtypes.h.orig	2010-11-03 14:38:39.000000000 +0100
+++ gdb/gdbtypes.h	2010-11-03 15:09:59.000000000 +0100
@@ -1383,6 +1383,9 @@ extern int get_vptr_fieldno (struct type
 
 extern int get_discrete_bounds (struct type *, LONGEST *, LONGEST *);
 
+extern int get_array_bounds (struct type *type, LONGEST *low_bound,
+			     LONGEST *high_bound);
+
 extern int class_types_same_p (const struct type *, const struct type *);
 
 extern int is_ancestor (struct type *, struct type *);
Index: gdb/valarith.c
===================================================================
--- gdb/valarith.c.orig	2010-11-03 15:09:24.000000000 +0100
+++ gdb/valarith.c	2010-11-03 15:09:59.000000000 +0100
@@ -1394,7 +1394,8 @@ vector_binop (struct value *val1, struct
 {
   struct value *val, *tmp, *mark;
   struct type *type1, *type2, *eltype1, *eltype2, *result_type;
-  int t1_is_vec, t2_is_vec, elsize, n, i;
+  int t1_is_vec, t2_is_vec, elsize, i;
+  LONGEST low_bound1, high_bound1, low_bound2, high_bound2;
 
   type1 = check_typedef (value_type (val1));
   type2 = check_typedef (value_type (val2));
@@ -1407,23 +1408,23 @@ vector_binop (struct value *val1, struct
   if (!t1_is_vec || !t2_is_vec)
     error (_("Vector operations are only supported among vectors"));
 
+  if (!get_array_bounds (type1, &low_bound1, &high_bound1)
+      || !get_array_bounds (type2, &low_bound2, &high_bound2))
+    error (_("Could not determine the vector bounds"));
+
   eltype1 = check_typedef (TYPE_TARGET_TYPE (type1));
   eltype2 = check_typedef (TYPE_TARGET_TYPE (type2));
+  elsize = TYPE_LENGTH (eltype1);
 
   if (TYPE_CODE (eltype1) != TYPE_CODE (eltype2)
-      || TYPE_LENGTH (eltype1) != TYPE_LENGTH (eltype2)
-      || TYPE_UNSIGNED (eltype1) != TYPE_UNSIGNED (eltype2))
+      || elsize != TYPE_LENGTH (eltype2)
+      || TYPE_UNSIGNED (eltype1) != TYPE_UNSIGNED (eltype2)
+      || low_bound1 != low_bound2 || high_bound1 != high_bound2)
     error (_("Cannot perform operation on vectors with different types"));
 
-  elsize = TYPE_LENGTH (eltype1);
-  n = TYPE_LENGTH (type1) / elsize;
-
-  if (n != TYPE_LENGTH (type2) / TYPE_LENGTH (eltype2))
-    error (_("Cannot perform operation on vectors with different sizes"));
-
   val = allocate_value (type1);
   mark = value_mark ();
-  for (i = 0; i < n; i++)
+  for (i = 0; i < high_bound1 - low_bound1 + 1; i++)
     {
       tmp = value_binop (value_subscript (val1, i),
 			 value_subscript (val2, i), op);
Index: gdb/valops.c
===================================================================
--- gdb/valops.c.orig	2010-11-03 15:09:24.000000000 +0100
+++ gdb/valops.c	2010-11-03 15:09:59.000000000 +0100
@@ -544,14 +544,17 @@ value_cast (struct type *type, struct va
       /* Widen the scalar to a vector.  */
       struct type *eltype;
       struct value *val;
-      int i, n;
+      LONGEST low_bound, high_bound;
+      int i;
+
+      if (!get_array_bounds (type, &low_bound, &high_bound))
+	error (_("Could not determine the vector bounds"));
 
       eltype = check_typedef (TYPE_TARGET_TYPE (type));
       arg2 = value_cast (eltype, arg2);
       val = allocate_value (type);
-      n = TYPE_LENGTH (type) / TYPE_LENGTH (eltype);
 
-      for (i = 0; i < n; i++)
+      for (i = 0; i < high_bound - low_bound + 1; i++)
 	{
 	  /* Duplicate the contents of arg2 into the destination vector.  */
 	  memcpy (value_contents_writeable (val) + (i * TYPE_LENGTH (eltype)),
Index: gdb/valprint.c
===================================================================
--- gdb/valprint.c.orig	2010-11-03 14:38:39.000000000 +0100
+++ gdb/valprint.c	2010-11-03 15:09:59.000000000 +0100
@@ -1067,44 +1067,6 @@ print_char_chars (struct ui_file *stream
     }
 }
 
-/* Assuming TYPE is a simple, non-empty array type, compute its upper
-   and lower bound.  Save the low bound into LOW_BOUND if not NULL.
-   Save the high bound into HIGH_BOUND if not NULL.
-
-   Return 1 if the operation was successful. Return zero otherwise,
-   in which case the values of LOW_BOUND and HIGH_BOUNDS are unmodified.
-  
-   We now simply use get_discrete_bounds call to get the values
-   of the low and high bounds. 
-   get_discrete_bounds can return three values:
-   1, meaning that index is a range,
-   0, meaning that index is a discrete type,
-   or -1 for failure.  */
-
-int
-get_array_bounds (struct type *type, LONGEST *low_bound, LONGEST *high_bound)
-{
-  struct type *index = TYPE_INDEX_TYPE (type);
-  LONGEST low = 0;
-  LONGEST high = 0;
-  int res;
-                                
-  if (index == NULL)
-    return 0;
-
-  res = get_discrete_bounds (index, &low, &high);
-  if (res == -1)
-    return 0;
-
-  if (low_bound)
-    *low_bound = low;
-
-  if (high_bound)
-    *high_bound = high;
-
-  return 1;
-}
-
 /* Print on STREAM using the given OPTIONS the index for the element
    at INDEX of an array whose index type is INDEX_TYPE.  */
     
@@ -1149,38 +1111,19 @@ val_print_array_elements (struct type *t
   unsigned int rep1;
   /* Number of repetitions we have detected so far.  */
   unsigned int reps;
-  LONGEST low_bound_index = 0;
+  LONGEST low_bound, high_bound;
 
   elttype = TYPE_TARGET_TYPE (type);
   eltlen = TYPE_LENGTH (check_typedef (elttype));
   index_type = TYPE_INDEX_TYPE (type);
 
-  /* Compute the number of elements in the array.  On most arrays,
-     the size of its elements is not zero, and so the number of elements
-     is simply the size of the array divided by the size of the elements.
-     But for arrays of elements whose size is zero, we need to look at
-     the bounds.  */
-  if (eltlen != 0)
-    len = TYPE_LENGTH (type) / eltlen;
+  if (get_array_bounds (type, &low_bound, &high_bound))
+    len = high_bound - low_bound + 1;
   else
     {
-      LONGEST low, hi;
-
-      if (get_array_bounds (type, &low, &hi))
-        len = hi - low + 1;
-      else
-        {
-          warning (_("unable to get bounds of array, assuming null array"));
-          len = 0;
-        }
-    }
-
-  /* Get the array low bound.  This only makes sense if the array
-     has one or more element in it.  */
-  if (len > 0 && !get_array_bounds (type, &low_bound_index, NULL))
-    {
-      warning (_("unable to get low bound of array, using zero as default"));
-      low_bound_index = 0;
+      warning (_("unable to get bounds of array, assuming null array"));
+      low_bound = 0;
+      len = 0;
     }
 
   annotate_array_section_begin (i, elttype);
@@ -1200,7 +1143,7 @@ val_print_array_elements (struct type *t
 	    }
 	}
       wrap_here (n_spaces (2 + 2 * recurse));
-      maybe_print_array_index (index_type, i + low_bound_index,
+      maybe_print_array_index (index_type, i + low_bound,
                                stream, options);
 
       rep1 = i + 1;
Index: gdb/valprint.h
===================================================================
--- gdb/valprint.h.orig	2010-11-03 14:38:39.000000000 +0100
+++ gdb/valprint.h	2010-11-03 15:09:59.000000000 +0100
@@ -109,9 +109,6 @@ extern void get_raw_print_options (struc
 extern void get_formatted_print_options (struct value_print_options *opts,
 					 char format);
 
-extern int get_array_bounds (struct type *type, LONGEST *low_bound,
-			     LONGEST *high_bound);
-
 extern void maybe_print_array_index (struct type *index_type, LONGEST index,
                                      struct ui_file *stream,
 				     const struct value_print_options *options);
Index: gdb/testsuite/gdb.base/gnu_vector.exp
===================================================================
--- gdb/testsuite/gdb.base/gnu_vector.exp.orig	2010-11-03 15:09:24.000000000 +0100
+++ gdb/testsuite/gdb.base/gnu_vector.exp	2010-11-03 15:09:59.000000000 +0100
@@ -129,8 +129,8 @@ gdb_test "print f4a + d2" "Cannot perfor
 gdb_test "print d2 + f4a" "Cannot perform operation on vectors with different types"
 gdb_test "print ui4 + i4a" "Cannot perform operation on vectors with different types"
 gdb_test "print i4a + ui4" "Cannot perform operation on vectors with different types"
-gdb_test "print i4a + i2" "Cannot perform operation on vectors with different sizes"
-gdb_test "print i2 + i4a" "Cannot perform operation on vectors with different sizes"
-gdb_test "print f4a + f2" "Cannot perform operation on vectors with different sizes"
-gdb_test "print f2 + f4a" "Cannot perform operation on vectors with different sizes"
+gdb_test "print i4a + i2" "Cannot perform operation on vectors with different types"
+gdb_test "print i2 + i4a" "Cannot perform operation on vectors with different types"
+gdb_test "print f4a + f2" "Cannot perform operation on vectors with different types"
+gdb_test "print f2 + f4a" "Cannot perform operation on vectors with different types"
 
Index: gdb/c-typeprint.c
===================================================================
--- gdb/c-typeprint.c.orig	2010-11-03 14:38:39.000000000 +0100
+++ gdb/c-typeprint.c	2010-11-03 15:09:59.000000000 +0100
@@ -572,19 +572,20 @@ c_type_print_varspec_suffix (struct type
   switch (TYPE_CODE (type))
     {
     case TYPE_CODE_ARRAY:
-      if (passed_a_ptr)
-	fprintf_filtered (stream, ")");
+      {
+	LONGEST low_bound, high_bound;
 
-      fprintf_filtered (stream, "[");
-      if (TYPE_LENGTH (TYPE_TARGET_TYPE (type)) > 0
-	&& !TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (type))
-	fprintf_filtered (stream, "%d",
-			  (TYPE_LENGTH (type)
-			   / TYPE_LENGTH (TYPE_TARGET_TYPE (type))));
-      fprintf_filtered (stream, "]");
+	if (passed_a_ptr)
+	  fprintf_filtered (stream, ")");
 
-      c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, show,
-				   0, 0);
+	fprintf_filtered (stream, "[");
+	if (get_array_bounds (type, &low_bound, &high_bound))
+	  fprintf_filtered (stream, "%d", (int) (high_bound - low_bound + 1));
+	fprintf_filtered (stream, "]");
+
+	c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, show,
+				     0, 0);
+      }
       break;
 
     case TYPE_CODE_MEMBERPTR:

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

* Regression on gdb.ada/null_array.exp  [Re: [patch] DW_AT_byte_size for array type entries]
  2010-11-03 14:23     ` Ken Werner
@ 2010-11-03 19:09       ` Jan Kratochvil
  2010-11-03 21:16         ` Joel Brobecker
  2010-11-03 23:24         ` Regression on gdb.ada/null_array.exp [Re: [patch] DW_AT_byte_size for array type entries] Joel Brobecker
  2010-12-13 20:03       ` [patch] DW_AT_byte_size for array type entries Ken Werner
  1 sibling, 2 replies; 20+ messages in thread
From: Jan Kratochvil @ 2010-11-03 19:09 UTC (permalink / raw)
  To: Ken Werner; +Cc: Tom Tromey, gdb-patches

On Wed, 03 Nov 2010 04:22:50 -1000, Ken Werner wrote:
> Thanks. I've checked in the version below:
> http://sourceware.org/ml/gdb-cvs/2010-11/msg00014.html

This patch has a regression, for:
	gcc (GCC) 4.4.6 20101103 (prerelease)

The regression does not happen with:
	gcc (GCC) 4.6.0 20101103 (experimental)
	gcc (GCC) 4.5.2 20101103 (prerelease)

 (gdb) print my_table
-$1 = ()
-(gdb) PASS: gdb.ada/null_array.exp: print my_table
+$1 = (warning: unable to get bounds of array, assuming null array
+)
+(gdb) FAIL: gdb.ada/null_array.exp: print my_table


I cannot say more as I cannot read the GNAT debug info.


Regards,
Jan

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

* Re: Regression on gdb.ada/null_array.exp  [Re: [patch] DW_AT_byte_size for array type entries]
  2010-11-03 19:09       ` Regression on gdb.ada/null_array.exp [Re: [patch] DW_AT_byte_size for array type entries] Jan Kratochvil
@ 2010-11-03 21:16         ` Joel Brobecker
  2010-11-03 23:22           ` [commit/Ada] fix warning when printing empty array Joel Brobecker
  2010-11-03 23:24         ` Regression on gdb.ada/null_array.exp [Re: [patch] DW_AT_byte_size for array type entries] Joel Brobecker
  1 sibling, 1 reply; 20+ messages in thread
From: Joel Brobecker @ 2010-11-03 21:16 UTC (permalink / raw)
  To: Jan Kratochvil; +Cc: Ken Werner, Tom Tromey, gdb-patches

>  (gdb) print my_table
> -$1 = ()
> -(gdb) PASS: gdb.ada/null_array.exp: print my_table
> +$1 = (warning: unable to get bounds of array, assuming null array
> +)
> +(gdb) FAIL: gdb.ada/null_array.exp: print my_table

I see slightly different symptoms, but I also see a regression caused
by this change.  I'll take a look.

-- 
Joel

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

* [commit/Ada] fix warning when printing empty array
  2010-11-03 21:16         ` Joel Brobecker
@ 2010-11-03 23:22           ` Joel Brobecker
  0 siblings, 0 replies; 20+ messages in thread
From: Joel Brobecker @ 2010-11-03 23:22 UTC (permalink / raw)
  To: gdb-patches; +Cc: Joel Brobecker

This patch should fix the following regression:

     (gdb) print my_table
    -$1 = ()
    -(gdb) PASS: gdb.ada/null_array.exp: print my_table
    +$1 = (warning: unable to get bounds of array, assuming null array
    +)
    +(gdb) FAIL: gdb.ada/null_array.exp: print my_table

The problem was introduced by a change in val_print_array_elements
which removed a check for the case where the array's high bound
is smaller than the array's low bound (empty array).

This change restores the check and forces the len to zero in that case.
Looking at the patch that caused the regression, I suspect that we may
have other parts that might have been broken (non-zero array low bound?).

gdb/ChangeLog:

        * valprint.c (val_print_array_elements): Put back handling of
        empty arrays.

Tested on x86_64-linux. Checked in.

---
 gdb/ChangeLog  |    5 +++++
 gdb/valprint.c |   12 +++++++++++-
 2 files changed, 16 insertions(+), 1 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 719582b..221868b 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,8 @@
+2010-11-03  Joel Brobecker  <brobecker@adacore.com>
+
+	* valprint.c (val_print_array_elements): Put back handling of
+	empty arrays.
+
 2010-11-03  Ken Werner  <ken.werner@de.ibm.com>
 
 	* dwarf2read.c (read_array_type): Read the DW_AT_byte_size from the
diff --git a/gdb/valprint.c b/gdb/valprint.c
index dba528b..ddb16e4 100644
--- a/gdb/valprint.c
+++ b/gdb/valprint.c
@@ -1118,7 +1118,17 @@ val_print_array_elements (struct type *type, const gdb_byte *valaddr,
   index_type = TYPE_INDEX_TYPE (type);
 
   if (get_array_bounds (type, &low_bound, &high_bound))
-    len = high_bound - low_bound + 1;
+    {
+      /* The array length should normally be HIGH_BOUND - LOW_BOUND + 1.
+         But we have to be a little extra careful, because some languages
+	 such as Ada allow LOW_BOUND to be greater than HIGH_BOUND for
+	 empty arrays.  In that situation, the array length is just zero,
+	 not negative!  */
+      if (low_bound > high_bound)
+	len = 0;
+      else
+	len = high_bound - low_bound + 1;
+    }
   else
     {
       warning (_("unable to get bounds of array, assuming null array"));
-- 
1.7.1

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

* Re: Regression on gdb.ada/null_array.exp  [Re: [patch] DW_AT_byte_size for array type entries]
  2010-11-03 19:09       ` Regression on gdb.ada/null_array.exp [Re: [patch] DW_AT_byte_size for array type entries] Jan Kratochvil
  2010-11-03 21:16         ` Joel Brobecker
@ 2010-11-03 23:24         ` Joel Brobecker
  2010-11-04  0:31           ` Jan Kratochvil
  1 sibling, 1 reply; 20+ messages in thread
From: Joel Brobecker @ 2010-11-03 23:24 UTC (permalink / raw)
  To: Jan Kratochvil; +Cc: Ken Werner, Tom Tromey, gdb-patches

>  (gdb) print my_table
> -$1 = ()
> -(gdb) PASS: gdb.ada/null_array.exp: print my_table
> +$1 = (warning: unable to get bounds of array, assuming null array
> +)
> +(gdb) FAIL: gdb.ada/null_array.exp: print my_table

Can you double-check that the regression is gone for you as well?
I should have fixed the problem, but the symptoms were slightly
different...

Thanks,
-- 
Joel

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

* Re: Regression on gdb.ada/null_array.exp  [Re: [patch] DW_AT_byte_size for array type entries]
  2010-11-03 23:24         ` Regression on gdb.ada/null_array.exp [Re: [patch] DW_AT_byte_size for array type entries] Joel Brobecker
@ 2010-11-04  0:31           ` Jan Kratochvil
  2010-11-04  1:57             ` Joel Brobecker
  0 siblings, 1 reply; 20+ messages in thread
From: Jan Kratochvil @ 2010-11-04  0:31 UTC (permalink / raw)
  To: Joel Brobecker; +Cc: Ken Werner, Tom Tromey, gdb-patches

On Wed, 03 Nov 2010 13:24:01 -1000, Joel Brobecker wrote:
> >  (gdb) print my_table
> > -$1 = ()
> > -(gdb) PASS: gdb.ada/null_array.exp: print my_table
> > +$1 = (warning: unable to get bounds of array, assuming null array
> > +)
> > +(gdb) FAIL: gdb.ada/null_array.exp: print my_table
> 
> Can you double-check that the regression is gone for you as well?
> I should have fixed the problem, but the symptoms were slightly
> different...

The regression is still there, at least on
2c7c9e97e654779550ce5f1da513368e53852996 (which matches the current CVS HEAD).


Thanks,
Jan

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

* Re: Regression on gdb.ada/null_array.exp  [Re: [patch] DW_AT_byte_size for array type entries]
  2010-11-04  0:31           ` Jan Kratochvil
@ 2010-11-04  1:57             ` Joel Brobecker
  2010-11-04  3:26               ` Jan Kratochvil
  0 siblings, 1 reply; 20+ messages in thread
From: Joel Brobecker @ 2010-11-04  1:57 UTC (permalink / raw)
  To: Jan Kratochvil; +Cc: Ken Werner, Tom Tromey, gdb-patches

> The regression is still there, at least on
> 2c7c9e97e654779550ce5f1da513368e53852996 (which matches the current CVS HEAD).

:-(

Can you do the following and send me the whole directory?

  % cd testsuite/gdb.ada/null_array
  % gnatmake -g foo -cargs -save-temps -dA

(please do that in the source rather than the object directory, that
way, we don't have to deal with -I options and project files, etc).

Thanks,
-- 
Joel

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

* Re: Regression on gdb.ada/null_array.exp  [Re: [patch] DW_AT_byte_size for array type entries]
  2010-11-04  1:57             ` Joel Brobecker
@ 2010-11-04  3:26               ` Jan Kratochvil
  2010-11-04 18:01                 ` Joel Brobecker
  0 siblings, 1 reply; 20+ messages in thread
From: Jan Kratochvil @ 2010-11-04  3:26 UTC (permalink / raw)
  To: Joel Brobecker; +Cc: Ken Werner, Tom Tromey, gdb-patches

On Thu, 04 Nov 2010 02:57:14 +0100, Joel Brobecker wrote:
> Can you do the following and send me the whole directory?
> 
>   % cd testsuite/gdb.ada/null_array
>   % gnatmake -g foo -cargs -save-temps -dA

http://people.redhat.com/jkratoch/null_array.tar.gz

BTW local FSF GCC 4.4.x rebuild should also make it IMO reproducible.


Thanks,
Jan

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

* Re: Regression on gdb.ada/null_array.exp  [Re: [patch] DW_AT_byte_size for array type entries]
  2010-11-04  3:26               ` Jan Kratochvil
@ 2010-11-04 18:01                 ` Joel Brobecker
  2010-11-04 18:10                   ` Jan Kratochvil
  0 siblings, 1 reply; 20+ messages in thread
From: Joel Brobecker @ 2010-11-04 18:01 UTC (permalink / raw)
  To: Jan Kratochvil; +Cc: Ken Werner, Tom Tromey, gdb-patches

> On Thu, 04 Nov 2010 02:57:14 +0100, Joel Brobecker wrote:
> > Can you do the following and send me the whole directory?
> > 
> >   % cd testsuite/gdb.ada/null_array
> >   % gnatmake -g foo -cargs -save-temps -dA
> 
> http://people.redhat.com/jkratoch/null_array.tar.gz

Thanks. Finally had a chance to look at this. The debugging information
appears to be incorrect (missing ___XA type to determine the array
bounds). Before Ken's change, we were passing this test by pure chance,
because we did:

   number-of-elements = array-type-len / element-len
   (where array-type-len is 0)
   if (len > 0 and get_array_bounds (...))

So we were computing the bounds only with non-zero arrays.  Now, we
determine the array length purely from the bounds:

   if (get_array_bounds (...))

I don't think we can restore the original (lucky) behavior without
breaking the intent of Ken's patch.

> BTW local FSF GCC 4.4.x rebuild should also make it IMO reproducible.

Do the most recent compilers trigger the regresions as well?

-- 
Joel

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

* Re: Regression on gdb.ada/null_array.exp  [Re: [patch] DW_AT_byte_size for array type entries]
  2010-11-04 18:01                 ` Joel Brobecker
@ 2010-11-04 18:10                   ` Jan Kratochvil
  2010-11-04 18:23                     ` Joel Brobecker
  0 siblings, 1 reply; 20+ messages in thread
From: Jan Kratochvil @ 2010-11-04 18:10 UTC (permalink / raw)
  To: Joel Brobecker; +Cc: Ken Werner, Tom Tromey, gdb-patches

On Thu, 04 Nov 2010 19:00:47 +0100, Joel Brobecker wrote:
> I don't think we can restore the original (lucky) behavior without
> breaking the intent of Ken's patch.

OK, so could you XFAIL it? <=gcc-4.4 or the missing ___XA type are both fine
IMO.  I will do it otherwise.


> > BTW local FSF GCC 4.4.x rebuild should also make it IMO reproducible.
> 
> Do the most recent compilers trigger the regresions as well?

No.

On Wed, 03 Nov 2010 20:09:35 +0100, Jan Kratochvil wrote:
# This patch has a regression, for:
#       gcc (GCC) 4.4.6 20101103 (prerelease)
# 
# The regression does not happen with:
#       gcc (GCC) 4.6.0 20101103 (experimental)
#       gcc (GCC) 4.5.2 20101103 (prerelease)


Thanks,
Jan

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

* Re: Regression on gdb.ada/null_array.exp  [Re: [patch] DW_AT_byte_size for array type entries]
  2010-11-04 18:10                   ` Jan Kratochvil
@ 2010-11-04 18:23                     ` Joel Brobecker
  2010-11-04 18:54                       ` Jan Kratochvil
  0 siblings, 1 reply; 20+ messages in thread
From: Joel Brobecker @ 2010-11-04 18:23 UTC (permalink / raw)
  To: Jan Kratochvil; +Cc: Ken Werner, Tom Tromey, gdb-patches

> > I don't think we can restore the original (lucky) behavior without
> > breaking the intent of Ken's patch.
> 
> OK, so could you XFAIL it? <=gcc-4.4 or the missing ___XA type are both fine
> IMO.  I will do it otherwise.

I would do it, normally, but I think it's easier if you do it, because
I would not be able to test the XFAIL case.

> > > BTW local FSF GCC 4.4.x rebuild should also make it IMO reproducible.
> > 
> > Do the most recent compilers trigger the regresions as well?
> 
> No.

That's good news. Things will get even better as soon as the
descriptive-type patch gets in GCC.

-- 
Joel

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

* Re: Regression on gdb.ada/null_array.exp  [Re: [patch] DW_AT_byte_size for array type entries]
  2010-11-04 18:23                     ` Joel Brobecker
@ 2010-11-04 18:54                       ` Jan Kratochvil
  2010-11-04 22:11                         ` Joel Brobecker
  0 siblings, 1 reply; 20+ messages in thread
From: Jan Kratochvil @ 2010-11-04 18:54 UTC (permalink / raw)
  To: Joel Brobecker; +Cc: Ken Werner, Tom Tromey, gdb-patches

On Thu, 04 Nov 2010 19:23:46 +0100, Joel Brobecker wrote:
> > OK, so could you XFAIL it? <=gcc-4.4 or the missing ___XA type are both fine
> > IMO.  I will do it otherwise.
> 
> I would do it, normally, but I think it's easier if you do it, because
> I would not be able to test the XFAIL case.

Checked-in.

BTW I did not find any difference in the ___XA DIEs so I used the <=4.4 check.



Thanks,
Jan


http://sourceware.org/ml/gdb-cvs/2010-11/msg00021.html

--- src/gdb/testsuite/ChangeLog	2010/11/03 14:21:58	1.2496
+++ src/gdb/testsuite/ChangeLog	2010/11/04 18:52:11	1.2497
@@ -1,3 +1,9 @@
+2010-11-04  Jan Kratochvil  <jan.kratochvil@redhat.com>
+	    Joel Brobecker  <brobecker@adacore.com>
+
+	* gdb.ada/null_array.exp (print my_table): Call get_compiler_info and
+	check test_compiler_info.
+
 2010-11-03  Ken Werner  <ken.werner@de.ibm.com>
 
 	* gdb.base/gnu_vector.exp: Adjust expect messages.
--- src/gdb/testsuite/gdb.ada/null_array.exp	2010/01/01 07:31:51	1.5
+++ src/gdb/testsuite/gdb.ada/null_array.exp	2010/11/04 18:52:11	1.6
@@ -37,6 +37,15 @@
 set bp_location [gdb_get_line_number "START" ${testdir}/foo.adb]
 runto "foo.adb:$bp_location"
 
+if [get_compiler_info ${binfile}] {
+    return -1;
+}
+
+if {[test_compiler_info {gcc-[0-3]-*}]
+    || [test_compiler_info {gcc-4-[0-4]-*}]} {
+    # Ada array bounds are missing in older GCCs.
+    setup_xfail *-*-* 
+}
 gdb_test "print my_table" \
          "= \\(\\)" \
          "print my_table"

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

* Re: Regression on gdb.ada/null_array.exp  [Re: [patch] DW_AT_byte_size for array type entries]
  2010-11-04 18:54                       ` Jan Kratochvil
@ 2010-11-04 22:11                         ` Joel Brobecker
  0 siblings, 0 replies; 20+ messages in thread
From: Joel Brobecker @ 2010-11-04 22:11 UTC (permalink / raw)
  To: Jan Kratochvil; +Cc: Ken Werner, Tom Tromey, gdb-patches

> Checked-in.
> 
> BTW I did not find any difference in the ___XA DIEs so I used the <=4.4 check.

Thanks!

-- 
Joel

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

* Re: [patch] DW_AT_byte_size for array type entries
  2010-11-03 14:23     ` Ken Werner
  2010-11-03 19:09       ` Regression on gdb.ada/null_array.exp [Re: [patch] DW_AT_byte_size for array type entries] Jan Kratochvil
@ 2010-12-13 20:03       ` Ken Werner
  2010-12-14  5:42         ` Joel Brobecker
  1 sibling, 1 reply; 20+ messages in thread
From: Ken Werner @ 2010-12-13 20:03 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

[-- Attachment #1: Type: Text/Plain, Size: 1999 bytes --]

On Wednesday, November 03, 2010 3:22:50 pm Ken Werner wrote:
> On Tuesday, November 02, 2010 11:31:03 pm Tom Tromey wrote:
> > >>>>> "Ken" == Ken Werner <ken@linux.vnet.ibm.com> writes:
> > Ken> Index: gdb/c-valprint.c
> > Ken> ===================================================================
> > Ken> RCS file: /cvs/src/src/gdb/c-valprint.c,v
> > Ken> retrieving revision 1.74
> > Ken> diff -p -u -r1.74 c-valprint.c
> > Ken> --- gdb/c-valprint.c	15 Oct 2010 18:54:12 -0000	1.74
> > Ken> +++ gdb/c-valprint.c	19 Oct 2010 12:15:30 -0000
> > Ken> @@ -171,8 +171,13 @@ c_val_print (struct type *type, const gd
> > Ken>        elttype = check_typedef (unresolved_elttype);
> > Ken>        if (TYPE_LENGTH (type) > 0 && TYPE_LENGTH
> > (unresolved_elttype)
> > 
> > > 0) Ken>  	{
> > 
> > Ken> +          LONGEST low_bound, high_bound;
> > Ken> +
> > Ken> +          if (!get_array_bounds(type, &low_bound, &high_bound))
> > 
> > Missing space before open paren.
> 
> Fixed.
> 
> > Ken> +            error (_("Could not determine the array high bound"));
> > Ken> +
> > Ken>  	  eltlen = TYPE_LENGTH (elttype);
> > Ken> -	  len = TYPE_LENGTH (type) / eltlen;
> > Ken> +	  len = high_bound - low_bound + 1;
> > 
> > I guess it is ok to use 'eltlen' elsewhere in the function because it is
> > only the array's overall size which is "weird" -- the element size is
> > still correct.  (Since we don't implement the DWARF stride stuff...)
> 
> Yes, that is also my understanding.
> 
> > The patch is ok with the above nit fixed.
> 
> Thanks. I've checked in the version below:
> http://sourceware.org/ml/gdb-cvs/2010-11/msg00014.html

Hi,

The attached patch changes the value_one(), value_complement() and value_neg() 
functions to use get_array_bounds to compute the number of array elements 
instead of dividing the length of the array by the length of the element 
types. It seems that I overlooked these in the first place.

Tested on i686-*-linux-gnu with no regressions.
Ok to apply?

Regards
Ken

[-- Attachment #2: arraybounds.patch --]
[-- Type: text/x-patch, Size: 2724 bytes --]

2010-12-13  Ken Werner  <ken.werner@de.ibm.com>

	* valops.c (value_one): Use get_array_bounds to compute the number
	of array elements instead of dividing the length of the array by the
	length of the element types.
	* valarith.c (value_complement, value_neg): Likewise.

 
Index: gdb/valarith.c
===================================================================
RCS file: /cvs/src/src/gdb/valarith.c,v
retrieving revision 1.91
diff -u -r1.91 valarith.c
--- gdb/valarith.c	29 Nov 2010 21:18:16 -0000	1.91
+++ gdb/valarith.c	13 Dec 2010 19:43:52 -0000
@@ -1766,9 +1766,13 @@
     {
       struct value *tmp, *val = allocate_value (type);
       struct type *eltype = check_typedef (TYPE_TARGET_TYPE (type));
-      int i, n = TYPE_LENGTH (type) / TYPE_LENGTH (eltype);
+      int i;
+      LONGEST low_bound, high_bound;
 
-      for (i = 0; i < n; i++)
+      if (!get_array_bounds (type, &low_bound, &high_bound))
+	error (_("Could not determine the vector bounds"));
+
+      for (i = 0; i < high_bound - low_bound + 1; i++)
 	{
 	  tmp = value_neg (value_subscript (arg1, i));
 	  memcpy (value_contents_writeable (val) + i * TYPE_LENGTH (eltype),
@@ -1798,10 +1802,14 @@
     {
       struct value *tmp;
       struct type *eltype = check_typedef (TYPE_TARGET_TYPE (type));
-      int i, n = TYPE_LENGTH (type) / TYPE_LENGTH (eltype);
+      int i;
+      LONGEST low_bound, high_bound;
+
+      if (!get_array_bounds (type, &low_bound, &high_bound))
+	error (_("Could not determine the vector bounds"));
 
       val = allocate_value (type);
-      for (i = 0; i < n; i++)
+      for (i = 0; i < high_bound - low_bound + 1; i++)
         {
           tmp = value_complement (value_subscript (arg1, i));
           memcpy (value_contents_writeable (val) + i * TYPE_LENGTH (eltype),
Index: gdb/valops.c
===================================================================
RCS file: /cvs/src/src/gdb/valops.c,v
retrieving revision 1.259
diff -u -r1.259 valops.c
--- gdb/valops.c	1 Dec 2010 16:49:41 -0000	1.259
+++ gdb/valops.c	13 Dec 2010 19:43:52 -0000
@@ -877,11 +877,15 @@
   else if (TYPE_CODE (type1) == TYPE_CODE_ARRAY && TYPE_VECTOR (type1))
     {
       struct type *eltype = check_typedef (TYPE_TARGET_TYPE (type1));
-      int i, n = TYPE_LENGTH (type1) / TYPE_LENGTH (eltype);
+      int i;
+      LONGEST low_bound, high_bound;
       struct value *tmp;
 
+      if (!get_array_bounds (type1, &low_bound, &high_bound))
+	error (_("Could not determine the vector bounds"));
+
       val = allocate_value (type);
-      for (i = 0; i < n; i++)
+      for (i = 0; i < high_bound - low_bound + 1; i++)
 	{
 	  tmp = value_one (eltype, lv);
 	  memcpy (value_contents_writeable (val) + i * TYPE_LENGTH (eltype),

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

* Re: [patch] DW_AT_byte_size for array type entries
  2010-12-13 20:03       ` [patch] DW_AT_byte_size for array type entries Ken Werner
@ 2010-12-14  5:42         ` Joel Brobecker
  2010-12-14 10:27           ` Ken Werner
  0 siblings, 1 reply; 20+ messages in thread
From: Joel Brobecker @ 2010-12-14  5:42 UTC (permalink / raw)
  To: Ken Werner; +Cc: gdb-patches, Tom Tromey

> 2010-12-13  Ken Werner  <ken.werner@de.ibm.com>
> 
> 	* valops.c (value_one): Use get_array_bounds to compute the number
> 	of array elements instead of dividing the length of the array by the
> 	length of the element types.
> 	* valarith.c (value_complement, value_neg): Likewise.

This is OK.

As a followup patch, how about defining a new function `get_array_length'
next to get_array_bounds? That way, you  can factorize of this code that
keeps being repeated...

-- 
Joel

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

* Re: [patch] DW_AT_byte_size for array type entries
  2010-12-14  5:42         ` Joel Brobecker
@ 2010-12-14 10:27           ` Ken Werner
  0 siblings, 0 replies; 20+ messages in thread
From: Ken Werner @ 2010-12-14 10:27 UTC (permalink / raw)
  To: Joel Brobecker; +Cc: Tom Tromey, gdb-patches

On Tuesday, December 14, 2010 6:41:50 am Joel Brobecker wrote:
> > 2010-12-13  Ken Werner  <ken.werner@de.ibm.com>
> > 
> > 	* valops.c (value_one): Use get_array_bounds to compute the number
> > 	of array elements instead of dividing the length of the array by the
> > 	length of the element types.
> > 	* valarith.c (value_complement, value_neg): Likewise.
> 
> This is OK.

Patch committed:
http://sourceware.org/ml/gdb-cvs/2010-12/msg00063.html

> As a followup patch, how about defining a new function `get_array_length'
> next to get_array_bounds? That way, you  can factorize of this code that
> keeps being repeated...

Ok.

Regards
Ken

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

end of thread, other threads:[~2010-12-14 10:27 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-10-19 11:24 [patch] DW_AT_byte_size for array type entries Ken Werner
2010-10-19 18:16 ` Ken Werner
2010-11-02  8:23   ` Ken Werner
2010-11-02 22:45   ` Tom Tromey
2010-11-03 14:23     ` Ken Werner
2010-11-03 19:09       ` Regression on gdb.ada/null_array.exp [Re: [patch] DW_AT_byte_size for array type entries] Jan Kratochvil
2010-11-03 21:16         ` Joel Brobecker
2010-11-03 23:22           ` [commit/Ada] fix warning when printing empty array Joel Brobecker
2010-11-03 23:24         ` Regression on gdb.ada/null_array.exp [Re: [patch] DW_AT_byte_size for array type entries] Joel Brobecker
2010-11-04  0:31           ` Jan Kratochvil
2010-11-04  1:57             ` Joel Brobecker
2010-11-04  3:26               ` Jan Kratochvil
2010-11-04 18:01                 ` Joel Brobecker
2010-11-04 18:10                   ` Jan Kratochvil
2010-11-04 18:23                     ` Joel Brobecker
2010-11-04 18:54                       ` Jan Kratochvil
2010-11-04 22:11                         ` Joel Brobecker
2010-12-13 20:03       ` [patch] DW_AT_byte_size for array type entries Ken Werner
2010-12-14  5:42         ` Joel Brobecker
2010-12-14 10:27           ` Ken Werner

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