This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[RFA] get_array_bounds function: change low and high parameter type to LONGEST *


  get_discrete_bounds uses `LONGEST *' type 
for its parameters, this patch just extends 
this to get_array_bounds function.

  It also simplifies the get_array_bounds
as most of the code was redundant with get_discrete_bounds.
  The other changes are just to adapt to new parameter types.

  I thought about changing the type of the last parameter `i'
of val_print_array_elements, but this function is only code
with I either equal to zero or one, so this change seemed useless to me.

  Tested on gcc16 machine, no regression spotted.

  Is this OK?
	


Pierre Muller
Pascal language support maintainer for GDB

 

2010-06-02  Pierre Muller  <muller@ics.u-strasbg.fr>

	* valprint.h (get_array_bounds): Change low and high parameter types
	to LONGEST *.
	* valprint.c (get_array_bounds): Use get_discrete_bounds call to 
	compute bounds.
	(val_print_array_elements): Adapt to change above.
	* ada-valprint.c (print_optional_low_bound): Adapt to change above.
	* p-valprint.c (pascal_val_print): Likewise.

Index: src/gdb/valprint.h
===================================================================
RCS file: /cvs/src/src/gdb/valprint.h,v
retrieving revision 1.25
diff -u -p -r1.25 valprint.h
--- src/gdb/valprint.h	1 Jan 2010 07:31:43 -0000	1.25
+++ src/gdb/valprint.h	2 Jun 2010 07:05:06 -0000
@@ -109,8 +109,8 @@ 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, long *low_bound,
-			     long *high_bound);
+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,
Index: src/gdb/valprint.c
===================================================================
RCS file: /cvs/src/src/gdb/valprint.c,v
retrieving revision 1.93
diff -u -p -r1.93 valprint.c
--- src/gdb/valprint.c	17 May 2010 18:48:52 -0000	1.93
+++ src/gdb/valprint.c	2 Jun 2010 07:05:05 -0000
@@ -1034,44 +1034,27 @@ print_char_chars (struct ui_file *stream
 
    Return 1 if the operation was successful. Return zero otherwise,
    in which case the values of LOW_BOUND and HIGH_BOUNDS are unmodified.
-   
-   Computing the array upper and lower bounds is pretty easy, but this
-   function does some additional verifications before returning them.
-   If something incorrect is detected, it is better to return a status
-   rather than throwing an error, making it easier for the caller to
-   implement an error-recovery plan.  For instance, it may decide to
-   warn the user that the bounds were not found and then use some
-   default values instead.  */
+  
+   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, long *low_bound, long *high_bound)
+get_array_bounds (struct type *type, LONGEST *low_bound, LONGEST
*high_bound)
 {
   struct type *index = TYPE_INDEX_TYPE (type);
-  long low = 0;
-  long high = 0;
-                                  
+  LONGEST low = 0;
+  LONGEST high = 0;
+  int res;
+                                
   if (index == NULL)
     return 0;
 
-  if (TYPE_CODE (index) == TYPE_CODE_RANGE)
-    {
-      low = TYPE_LOW_BOUND (index);
-      high = TYPE_HIGH_BOUND (index);
-    }
-  else if (TYPE_CODE (index) == TYPE_CODE_ENUM)
-    {
-      const int n_enums = TYPE_NFIELDS (index);
-
-      low = TYPE_FIELD_BITPOS (index, 0);
-      high = TYPE_FIELD_BITPOS (index, n_enums - 1);
-    }
-  else
-    return 0;
-
-  /* Abort if the lower bound is greater than the higher bound, except
-     when low = high + 1.  This is a very common idiom used in Ada when
-     defining empty ranges (for instance "range 1 .. 0").  */
-  if (low > high + 1)
+  res = get_discrete_bounds (index, &low, &high);
+  if (res == -1)
     return 0;
 
   if (low_bound)
@@ -1126,7 +1109,7 @@ val_print_array_elements (struct type *t
   unsigned int rep1;
   /* Number of repetitions we have detected so far.  */
   unsigned int reps;
-  long low_bound_index = 0;
+  LONGEST low_bound_index = 0;
 
   elttype = TYPE_TARGET_TYPE (type);
   eltlen = TYPE_LENGTH (check_typedef (elttype));
@@ -1141,7 +1124,7 @@ val_print_array_elements (struct type *t
     len = TYPE_LENGTH (type) / eltlen;
   else
     {
-      long low, hi;
+      LONGEST low, hi;
 
       if (get_array_bounds (type, &low, &hi))
         len = hi - low + 1;
Index: src/gdb/ada-valprint.c
===================================================================
RCS file: /cvs/src/src/gdb/ada-valprint.c,v
retrieving revision 1.64
diff -u -p -r1.64 ada-valprint.c
--- src/gdb/ada-valprint.c	18 May 2010 19:23:37 -0000	1.64
+++ src/gdb/ada-valprint.c	2 Jun 2010 07:05:04 -0000
@@ -85,8 +85,8 @@ print_optional_low_bound (struct ui_file
 			  const struct value_print_options *options)
 {
   struct type *index_type;
-  long low_bound;
-  long high_bound;
+  LONGEST low_bound;
+  LONGEST high_bound;
 
   if (options->print_array_indexes)
     return 0;
@@ -131,7 +131,7 @@ print_optional_low_bound (struct ui_file
       break;
     }
 
-  ada_print_scalar (index_type, (LONGEST) low_bound, stream);
+  ada_print_scalar (index_type, low_bound, stream);
   fprintf_filtered (stream, " => ");
   return 1;
 }
Index: src/gdb/p-valprint.c
===================================================================
RCS file: /cvs/src/src/gdb/p-valprint.c,v
retrieving revision 1.73
diff -u -p -r1.73 p-valprint.c
--- src/gdb/p-valprint.c	20 May 2010 07:41:40 -0000	1.73
+++ src/gdb/p-valprint.c	2 Jun 2010 07:05:05 -0000
@@ -60,7 +60,7 @@ pascal_val_print (struct type *type, con
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   unsigned int i = 0;	/* Number of characters printed */
   unsigned len;
-  long low_bound, high_bound;
+  LONGEST low_bound, high_bound;
   struct type *elttype;
   unsigned eltlen;
   int length_pos, length_size, string_pos;


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]