aboutsummaryrefslogtreecommitdiff
path: root/gdb/valprint.c
diff options
context:
space:
mode:
authorPierre Muller <muller@sourceware.org>2010-06-03 06:50:49 +0000
committerPierre Muller <muller@sourceware.org>2010-06-03 06:50:49 +0000
commitdf1784511914208f03f111bc06e42ab3d75dcbd5 (patch)
tree1918a82ddd9b0bfd6a9b61c430f4f7e24a0060f2 /gdb/valprint.c
parent416a7ddd02bd7e6e95c2275008d82a469ca0de1e (diff)
downloadgdb-df1784511914208f03f111bc06e42ab3d75dcbd5.zip
gdb-df1784511914208f03f111bc06e42ab3d75dcbd5.tar.gz
gdb-df1784511914208f03f111bc06e42ab3d75dcbd5.tar.bz2
* 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.
Diffstat (limited to 'gdb/valprint.c')
-rw-r--r--gdb/valprint.c49
1 files changed, 16 insertions, 33 deletions
diff --git a/gdb/valprint.c b/gdb/valprint.c
index 517e607..2b06579 100644
--- a/gdb/valprint.c
+++ b/gdb/valprint.c
@@ -1034,44 +1034,27 @@ print_char_chars (struct ui_file *stream, struct type *type,
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 *type, const gdb_byte *valaddr,
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 *type, const gdb_byte *valaddr,
len = TYPE_LENGTH (type) / eltlen;
else
{
- long low, hi;
+ LONGEST low, hi;
if (get_array_bounds (type, &low, &hi))
len = hi - low + 1;