1 From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
2 From: Fedora GDB patches <invalid@email.com>
3 Date: Fri, 27 Oct 2017 21:07:50 +0200
4 Subject: gdb-vla-intel-fortran-strides.patch
6 ;; VLA (Fortran dynamic arrays) from Intel + archer-jankratochvil-vla tests.
9 git diff --stat -p gdb/master...gdb/users/bheckel/fortran-strides
10 dbfd7140bf4c0500d1f5d192be781f83f78f7922
12 gdb/dwarf2loc.c | 46 ++-
14 gdb/dwarf2read.c | 13 +-
15 gdb/eval.c | 391 +++++++++++++++++++++-----
16 gdb/expprint.c | 20 +-
17 gdb/expression.h | 18 +-
19 gdb/f-valprint.c | 8 +-
20 gdb/gdbtypes.c | 34 ++-
21 gdb/gdbtypes.h | 18 +-
23 gdb/rust-exp.y | 12 +-
24 gdb/rust-lang.c | 17 +-
25 gdb/testsuite/gdb.fortran/static-arrays.exp | 421 ++++++++++++++++++++++++++++
26 gdb/testsuite/gdb.fortran/static-arrays.f90 | 55 ++++
27 gdb/testsuite/gdb.fortran/vla-ptype.exp | 4 +
28 gdb/testsuite/gdb.fortran/vla-sizeof.exp | 4 +
29 gdb/testsuite/gdb.fortran/vla-stride.exp | 44 +++
30 gdb/testsuite/gdb.fortran/vla-stride.f90 | 29 ++
31 gdb/testsuite/gdb.fortran/vla.f90 | 10 +
32 gdb/valarith.c | 10 +-
33 gdb/valops.c | 197 +++++++++++--
35 23 files changed, 1242 insertions(+), 183 deletions(-)
37 diff --git a/gdb/dwarf2loc.c b/gdb/dwarf2loc.c
40 @@ -2600,11 +2600,14 @@ dwarf2_locexpr_baton_eval (const struct dwarf2_locexpr_baton *dlbaton,
41 /* See dwarf2loc.h. */
44 -dwarf2_evaluate_property (const struct dynamic_prop *prop,
45 +dwarf2_evaluate_property_signed (const struct dynamic_prop *prop,
46 struct frame_info *frame,
47 struct property_addr_info *addr_stack,
57 @@ -2628,7 +2631,7 @@ dwarf2_evaluate_property (const struct dynamic_prop *prop,
59 *value = value_as_address (val);
66 @@ -2650,7 +2653,7 @@ dwarf2_evaluate_property (const struct dynamic_prop *prop,
67 if (!value_optimized_out (val))
69 *value = value_as_address (val);
75 @@ -2658,8 +2661,8 @@ dwarf2_evaluate_property (const struct dynamic_prop *prop,
78 *value = prop->data.const_val;
83 case PROP_ADDR_OFFSET:
85 struct dwarf2_property_baton *baton
86 @@ -2680,11 +2683,38 @@ dwarf2_evaluate_property (const struct dynamic_prop *prop,
87 val = value_at (baton->offset_info.type,
88 pinfo->addr + baton->offset_info.offset);
89 *value = value_as_address (val);
97 + if (rc == 1 && is_signed == 1)
99 + /* If we have a valid return candidate and it's value is signed,
100 + we have to sign-extend the value because CORE_ADDR on 64bit machine has
101 + 8 bytes but address size of an 32bit application is 4 bytes. */
102 + struct gdbarch * gdbarch = target_gdbarch ();
103 + const int addr_bit = gdbarch_addr_bit (gdbarch);
104 + const CORE_ADDR neg_mask = ((~0) << (addr_bit - 1));
106 + /* Check if signed bit is set and sign-extend values. */
107 + if (*value & (neg_mask))
108 + *value |= (neg_mask );
114 +dwarf2_evaluate_property (const struct dynamic_prop *prop,
115 + struct frame_info *frame,
116 + struct property_addr_info *addr_stack,
119 + return dwarf2_evaluate_property_signed (prop,
126 /* See dwarf2loc.h. */
127 diff --git a/gdb/dwarf2loc.h b/gdb/dwarf2loc.h
128 --- a/gdb/dwarf2loc.h
129 +++ b/gdb/dwarf2loc.h
130 @@ -143,6 +143,12 @@ int dwarf2_evaluate_property (const struct dynamic_prop *prop,
131 struct property_addr_info *addr_stack,
134 +int dwarf2_evaluate_property_signed (const struct dynamic_prop *prop,
135 + struct frame_info *frame,
136 + struct property_addr_info *addr_stack,
140 /* A helper for the compiler interface that compiles a single dynamic
143 diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
144 --- a/gdb/dwarf2read.c
145 +++ b/gdb/dwarf2read.c
146 @@ -17566,7 +17566,7 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
147 struct type *base_type, *orig_base_type;
148 struct type *range_type;
149 struct attribute *attr;
150 - struct dynamic_prop low, high;
151 + struct dynamic_prop low, high, stride;
152 int low_default_is_valid;
153 int high_bound_is_count = 0;
155 @@ -17586,7 +17586,9 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
157 low.kind = PROP_CONST;
158 high.kind = PROP_CONST;
159 + stride.kind = PROP_CONST;
160 high.data.const_val = 0;
161 + stride.data.const_val = 0;
163 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
164 omitting DW_AT_lower_bound. */
165 @@ -17619,6 +17621,14 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
169 + attr = dwarf2_attr (die, DW_AT_byte_stride, cu);
171 + if (!attr_to_dynamic_prop (attr, die, cu, &stride))
172 + complaint (_("Missing DW_AT_byte_stride "
173 + "- DIE at 0x%s [in module %s]"),
174 + sect_offset_str (die->sect_off),
175 + objfile_name (cu->per_cu->dwarf2_per_objfile->objfile));
177 attr = dwarf2_attr (die, DW_AT_lower_bound, cu);
179 attr_to_dynamic_prop (attr, die, cu, &low);
180 @@ -17696,7 +17706,7 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
181 && !TYPE_UNSIGNED (base_type) && (high.data.const_val & negative_mask))
182 high.data.const_val |= negative_mask;
184 - range_type = create_range_type (NULL, orig_base_type, &low, &high);
185 + range_type = create_range_type (NULL, orig_base_type, &low, &high, &stride);
187 if (high_bound_is_count)
188 TYPE_RANGE_DATA (range_type)->flag_upper_bound_is_count = 1;
189 diff --git a/gdb/eval.c b/gdb/eval.c
192 @@ -377,29 +377,325 @@ init_array_element (struct value *array, struct value *element,
196 +/* Evaluates any operation on Fortran arrays or strings with at least
197 + one user provided parameter. Expects the input ARRAY to be either
198 + an array, or a string. Evaluates EXP by incrementing POS, and
199 + writes the content from the elt stack into a local struct. NARGS
200 + specifies number of literal or range arguments the user provided.
201 + NARGS must be the same number as ARRAY has dimensions. */
203 static struct value *
204 -value_f90_subarray (struct value *array,
205 - struct expression *exp, int *pos, enum noside noside)
206 +value_f90_subarray (struct value *array, struct expression *exp,
207 + int *pos, int nargs, enum noside noside)
209 - int pc = (*pos) + 1;
210 + int i, dim_count = 0;
211 LONGEST low_bound, high_bound;
212 - struct type *range = check_typedef (TYPE_INDEX_TYPE (value_type (array)));
213 - enum range_type range_type
214 - = (enum range_type) longest_to_int (exp->elts[pc].longconst);
218 - if (range_type == LOW_BOUND_DEFAULT || range_type == BOTH_BOUND_DEFAULT)
219 - low_bound = TYPE_LOW_BOUND (range);
221 - low_bound = value_as_long (evaluate_subexp (NULL_TYPE, exp, pos, noside));
222 + struct value *new_array = array;
223 + struct type *array_type = check_typedef (value_type (new_array));
224 + struct type *elt_type;
226 + typedef struct subscript_range
228 + enum range_type f90_range_type;
229 + LONGEST low, high, stride;
232 + typedef enum subscript_kind
234 + SUBSCRIPT_RANGE, /* e.g. "(lowbound:highbound)" */
235 + SUBSCRIPT_INDEX /* e.g. "(literal)" */
238 + /* Local struct to hold user data for Fortran subarray dimensions. */
239 + struct subscript_store
241 + /* For every dimension, we are either working on a range or an index
242 + expression, so we store this info separately for later. */
243 + enum subscript_kind kind;
245 + /* We also store either the lower and upper bound info, or the index
246 + number. Before evaluation of the input values, we do not know if we are
247 + actually working on a range of ranges, or an index in a range. So as a
248 + first step we store all input in a union. The array calculation itself
249 + deals with this later on. */
250 + union element_range
252 + subscript_range range;
255 + } *subscript_array;
257 + /* Check if the number of arguments provided by the user matches
258 + the number of dimension of the array. A string has only one
260 + if (nargs != calc_f77_array_dims (value_type (new_array)))
261 + error (_("Wrong number of subscripts"));
263 + subscript_array = (struct subscript_store*) alloca (sizeof (*subscript_array) * nargs);
265 + /* Parse the user input into the SUBSCRIPT_ARRAY to store it. We need
266 + to evaluate it first, as the input is from left-to-right. The
267 + array is stored from right-to-left. So we have to use the user
268 + input in reverse order. Later on, we need the input information to
269 + re-calculate the output array. For multi-dimensional arrays, we
270 + can be dealing with any possible combination of ranges and indices
271 + for every dimension. */
272 + for (i = 0; i < nargs; i++)
274 + struct subscript_store *index = &subscript_array[i];
276 - if (range_type == HIGH_BOUND_DEFAULT || range_type == BOTH_BOUND_DEFAULT)
277 - high_bound = TYPE_HIGH_BOUND (range);
279 - high_bound = value_as_long (evaluate_subexp (NULL_TYPE, exp, pos, noside));
280 + /* The user input is a range, with or without lower and upper bound.
281 + E.g.: "p arry(2:5)", "p arry( :5)", "p arry( : )", etc. */
282 + if (exp->elts[*pos].opcode == OP_RANGE)
284 + int pc = (*pos) + 1;
285 + subscript_range *range;
287 + index->kind = SUBSCRIPT_RANGE;
288 + range = &index->U.range;
291 + range->f90_range_type = (enum range_type) exp->elts[pc].longconst;
293 + /* If a lower bound was provided by the user, the bit has been
294 + set and we can assign the value from the elt stack. Same for
296 + if ((range->f90_range_type & SUBARRAY_LOW_BOUND)
297 + == SUBARRAY_LOW_BOUND)
298 + range->low = value_as_long (evaluate_subexp (NULL_TYPE, exp,
300 + if ((range->f90_range_type & SUBARRAY_HIGH_BOUND)
301 + == SUBARRAY_HIGH_BOUND)
302 + range->high = value_as_long (evaluate_subexp (NULL_TYPE, exp,
305 + /* Assign the user's stride value if provided. */
306 + if ((range->f90_range_type & SUBARRAY_STRIDE) == SUBARRAY_STRIDE)
307 + range->stride = value_as_long (evaluate_subexp (NULL_TYPE, exp,
310 + /* Assign the default stride value '1'. */
314 + /* Check the provided stride value is illegal, aka '0'. */
315 + if (range->stride == 0)
316 + error (_("Stride must not be 0"));
318 + /* User input is an index. E.g.: "p arry(5)". */
323 + index->kind = SUBSCRIPT_INDEX;
325 + /* Evaluate each subscript; it must be a legal integer in F77. This
326 + ensures the validity of the provided index. */
327 + val = evaluate_subexp_with_coercion (exp, pos, noside);
328 + index->U.number = value_as_long (val);
333 + /* Traverse the array from right to left and set the high and low bounds
335 + for (i = nargs - 1; i >= 0; i--)
337 + struct subscript_store *index = &subscript_array[i];
338 + struct type *index_type = TYPE_INDEX_TYPE (array_type);
340 + switch (index->kind)
342 + case SUBSCRIPT_RANGE:
345 + /* When we hit the first range specified by the user, we must
346 + treat any subsequent user entry as a range. We simply
347 + increment DIM_COUNT which tells us how many times we are
348 + calling VALUE_SLICE_1. */
349 + subscript_range *range = &index->U.range;
351 + /* If no lower bound was provided by the user, we take the
352 + default boundary. Same for the high bound. */
353 + if ((range->f90_range_type & SUBARRAY_LOW_BOUND) == 0)
354 + range->low = TYPE_LOW_BOUND (index_type);
356 + if ((range->f90_range_type & SUBARRAY_HIGH_BOUND) == 0)
357 + range->high = TYPE_HIGH_BOUND (index_type);
359 + /* Both user provided low and high bound have to be inside the
360 + array bounds. Throw an error if not. */
361 + if (range->low < TYPE_LOW_BOUND (index_type)
362 + || range->low > TYPE_HIGH_BOUND (index_type)
363 + || range->high < TYPE_LOW_BOUND (index_type)
364 + || range->high > TYPE_HIGH_BOUND (index_type))
365 + error (_("provided bound(s) outside array bound(s)"));
367 + /* For a negative stride the lower boundary must be larger than the
369 + For a positive stride the lower boundary must be smaller than the
371 + if ((range->stride < 0 && range->low < range->high)
372 + || (range->stride > 0 && range->low > range->high))
373 + error (_("Wrong value provided for stride and boundaries"));
378 + case SUBSCRIPT_INDEX:
383 + array_type = TYPE_TARGET_TYPE (array_type);
386 + /* Reset ARRAY_TYPE before slicing.*/
387 + array_type = check_typedef (value_type (new_array));
389 + /* Traverse the array from right to left and evaluate each corresponding
390 + user input. VALUE_SUBSCRIPT is called for every index, until a range
391 + expression is evaluated. After a range expression has been evaluated,
392 + every subsequent expression is also treated as a range. */
393 + for (i = nargs - 1; i >= 0; i--)
395 + struct subscript_store *index = &subscript_array[i];
396 + struct type *index_type = TYPE_INDEX_TYPE (array_type);
398 + switch (index->kind)
400 + case SUBSCRIPT_RANGE:
403 + /* When we hit the first range specified by the user, we must
404 + treat any subsequent user entry as a range. We simply
405 + increment DIM_COUNT which tells us how many times we are
406 + calling VALUE_SLICE_1. */
407 + subscript_range *range = &index->U.range;
409 + /* DIM_COUNT counts every user argument that is treated as a range.
410 + This is necessary for expressions like 'print array(7, 8:9).
411 + Here the first argument is a literal, but must be treated as a
412 + range argument to allow the correct output representation. */
416 + = value_slice_1 (new_array, range->low,
417 + range->high - range->low + 1,
418 + range->stride, dim_count);
422 + case SUBSCRIPT_INDEX:
424 + /* DIM_COUNT only stays '0' when no range argument was processed
425 + before, starting from the last dimension. This way we can
426 + reduce the number of dimensions from the result array.
427 + However, if a range has been processed before an index, we
428 + treat the index like a range with equal low- and high bounds
429 + to get the value offset right. */
430 + if (dim_count == 0)
432 + = value_subscripted_rvalue (new_array, index->U.number,
433 + f77_get_lowerbound (value_type
439 + /* We might end up here, because we have to treat the provided
440 + index like a range. But now VALUE_SUBSCRIPTED_RVALUE
441 + cannot do the range checks for us. So we have to make sure
442 + ourselves that the user provided index is inside the
443 + array bounds. Throw an error if not. */
444 + if (index->U.number < TYPE_LOW_BOUND (index_type)
445 + && index->U.number > TYPE_HIGH_BOUND (index_type))
446 + error (_("provided bound(s) outside array bound(s)"));
448 + if (index->U.number > TYPE_LOW_BOUND (index_type)
449 + && index->U.number > TYPE_HIGH_BOUND (index_type))
450 + error (_("provided bound(s) outside array bound(s)"));
452 + new_array = value_slice_1 (new_array,
454 + 1, /* COUNT is '1' element */
455 + 1, /* STRIDE set to '1' */
462 + array_type = TYPE_TARGET_TYPE (array_type);
465 + /* With DIM_COUNT > 1 we currently have a one dimensional array, but expect
466 + an array of arrays, depending on how many ranges have been provided by
467 + the user. So we need to rebuild the array dimensions for printing it
469 + Starting from right to left in the user input, after we hit the first
470 + range argument every subsequent argument is also treated as a range.
472 + "p ary(3, 7, 2:15)" in Fortran has only 1 dimension, but we calculated 3
474 + "p ary(3, 7:12, 4)" in Fortran has only 1 dimension, but we calculated 2
476 + "p ary(2:4, 5, 7)" in Fortran has only 1 dimension, and we calculated 1
480 + struct value *v = NULL;
482 + elt_type = TYPE_TARGET_TYPE (value_type (new_array));
484 + /* Every SUBSCRIPT_RANGE in the user input signifies an actual range in
485 + the output array. So we traverse the SUBSCRIPT_ARRAY again, looking
486 + for a range entry. When we find one, we use the range info to create
487 + an additional range_type to set the correct bounds and dimensions for
488 + the output array. In addition, we may have a stride value that is not
489 + '1', forcing us to adjust the number of elements in a range, according
490 + to the stride value. */
491 + for (i = 0; i < nargs; i++)
493 + struct subscript_store *index = &subscript_array[i];
495 + if (index->kind == SUBSCRIPT_RANGE)
497 + struct type *range_type, *interim_array_type;
501 - return value_slice (array, low_bound, high_bound - low_bound + 1);
502 + /* The length of a sub-dimension with all elements between the
503 + bounds plus the start element itself. It may be modified by
504 + a user provided stride value. */
505 + new_length = index->U.range.high - index->U.range.low;
507 + new_length /= index->U.range.stride;
510 + = create_static_range_type (NULL,
512 + index->U.range.low,
513 + index->U.range.low + new_length);
515 + interim_array_type = create_array_type (NULL,
519 + TYPE_CODE (interim_array_type)
520 + = TYPE_CODE (value_type (new_array));
522 + v = allocate_value (interim_array_type);
524 + elt_type = value_type (v);
528 + value_contents_copy (v, 0, new_array, 0, TYPE_LENGTH (elt_type));
536 @@ -1926,19 +2222,8 @@ evaluate_subexp_standard (struct type *expect_type,
539 case TYPE_CODE_ARRAY:
540 - if (exp->elts[*pos].opcode == OP_RANGE)
541 - return value_f90_subarray (arg1, exp, pos, noside);
543 - goto multi_f77_subscript;
545 case TYPE_CODE_STRING:
546 - if (exp->elts[*pos].opcode == OP_RANGE)
547 - return value_f90_subarray (arg1, exp, pos, noside);
550 - arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
551 - return value_subscript (arg1, value_as_long (arg2));
553 + return value_f90_subarray (arg1, exp, pos, nargs, noside);
557 @@ -2334,49 +2619,6 @@ evaluate_subexp_standard (struct type *expect_type,
561 - multi_f77_subscript:
563 - LONGEST subscript_array[MAX_FORTRAN_DIMS];
564 - int ndimensions = 1, i;
565 - struct value *array = arg1;
567 - if (nargs > MAX_FORTRAN_DIMS)
568 - error (_("Too many subscripts for F77 (%d Max)"), MAX_FORTRAN_DIMS);
570 - ndimensions = calc_f77_array_dims (type);
572 - if (nargs != ndimensions)
573 - error (_("Wrong number of subscripts"));
575 - gdb_assert (nargs > 0);
577 - /* Now that we know we have a legal array subscript expression
578 - let us actually find out where this element exists in the array. */
580 - /* Take array indices left to right. */
581 - for (i = 0; i < nargs; i++)
583 - /* Evaluate each subscript; it must be a legal integer in F77. */
584 - arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
586 - /* Fill in the subscript array. */
588 - subscript_array[i] = value_as_long (arg2);
591 - /* Internal type of array is arranged right to left. */
592 - for (i = nargs; i > 0; i--)
594 - struct type *array_type = check_typedef (value_type (array));
595 - LONGEST index = subscript_array[i - 1];
597 - array = value_subscripted_rvalue (array, index,
598 - f77_get_lowerbound (array_type));
604 case BINOP_LOGICAL_AND:
605 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
606 if (noside == EVAL_SKIP)
607 @@ -3293,6 +3535,9 @@ calc_f77_array_dims (struct type *array_type)
609 struct type *tmp_type;
611 + if (TYPE_CODE (array_type) == TYPE_CODE_STRING)
614 if ((TYPE_CODE (array_type) != TYPE_CODE_ARRAY))
615 error (_("Can't get dimensions for a non-array type"));
617 diff --git a/gdb/expprint.c b/gdb/expprint.c
620 @@ -578,17 +578,14 @@ print_subexp_standard (struct expression *exp, int *pos,
621 longest_to_int (exp->elts[pc + 1].longconst);
624 - if (range_type == NONE_BOUND_DEFAULT_EXCLUSIVE
625 - || range_type == LOW_BOUND_DEFAULT_EXCLUSIVE)
626 + if ((range_type & SUBARRAY_HIGH_BOUND_EXCLUSIVE)
627 + == SUBARRAY_HIGH_BOUND_EXCLUSIVE)
628 fputs_filtered ("EXCLUSIVE_", stream);
629 fputs_filtered ("RANGE(", stream);
630 - if (range_type == HIGH_BOUND_DEFAULT
631 - || range_type == NONE_BOUND_DEFAULT
632 - || range_type == NONE_BOUND_DEFAULT_EXCLUSIVE)
633 + if ((range_type & SUBARRAY_LOW_BOUND) == SUBARRAY_LOW_BOUND)
634 print_subexp (exp, pos, stream, PREC_ABOVE_COMMA);
635 fputs_filtered ("..", stream);
636 - if (range_type == LOW_BOUND_DEFAULT
637 - || range_type == NONE_BOUND_DEFAULT)
638 + if ((range_type & SUBARRAY_HIGH_BOUND) == SUBARRAY_HIGH_BOUND)
639 print_subexp (exp, pos, stream, PREC_ABOVE_COMMA);
640 fputs_filtered (")", stream);
642 @@ -1098,22 +1095,24 @@ dump_subexp_body_standard (struct expression *exp,
646 - case BOTH_BOUND_DEFAULT:
647 + case SUBARRAY_NONE_BOUND:
648 fputs_filtered ("Range '..'", stream);
650 - case LOW_BOUND_DEFAULT:
651 + case SUBARRAY_HIGH_BOUND:
652 fputs_filtered ("Range '..EXP'", stream);
654 - case LOW_BOUND_DEFAULT_EXCLUSIVE:
655 - fputs_filtered ("ExclusiveRange '..EXP'", stream);
657 - case HIGH_BOUND_DEFAULT:
658 + case SUBARRAY_LOW_BOUND:
659 fputs_filtered ("Range 'EXP..'", stream);
661 - case NONE_BOUND_DEFAULT:
662 + case (SUBARRAY_LOW_BOUND
663 + | SUBARRAY_HIGH_BOUND
664 + | SUBARRAY_HIGH_BOUND_EXCLUSIVE):
665 + fputs_filtered ("ExclusiveRange '..EXP'", stream);
667 + case (SUBARRAY_LOW_BOUND | SUBARRAY_HIGH_BOUND):
668 fputs_filtered ("Range 'EXP..EXP'", stream);
670 - case NONE_BOUND_DEFAULT_EXCLUSIVE:
671 + case (SUBARRAY_HIGH_BOUND | SUBARRAY_HIGH_BOUND_EXCLUSIVE):
672 fputs_filtered ("ExclusiveRange 'EXP..EXP'", stream);
675 @@ -1121,11 +1120,9 @@ dump_subexp_body_standard (struct expression *exp,
679 - if (range_type == HIGH_BOUND_DEFAULT
680 - || range_type == NONE_BOUND_DEFAULT)
681 + if ((range_type & SUBARRAY_LOW_BOUND) == SUBARRAY_LOW_BOUND)
682 elt = dump_subexp (exp, stream, elt);
683 - if (range_type == LOW_BOUND_DEFAULT
684 - || range_type == NONE_BOUND_DEFAULT)
685 + if ((range_type & SUBARRAY_HIGH_BOUND) == SUBARRAY_HIGH_BOUND)
686 elt = dump_subexp (exp, stream, elt);
689 diff --git a/gdb/expression.h b/gdb/expression.h
690 --- a/gdb/expression.h
691 +++ b/gdb/expression.h
692 @@ -148,28 +148,27 @@ extern void dump_raw_expression (struct expression *,
693 struct ui_file *, const char *);
694 extern void dump_prefix_expression (struct expression *, struct ui_file *);
696 -/* In an OP_RANGE expression, either bound could be empty, indicating
697 - that its value is by default that of the corresponding bound of the
698 - array or string. Also, the upper end of the range can be exclusive
699 - or inclusive. So we have six sorts of subrange. This enumeration
700 - type is to identify this. */
701 +/* In an OP_RANGE expression, either bound can be provided by the
702 + user, or not. In addition to this, the user can also specify a
703 + stride value to indicated only certain elements of the array.
704 + Also, the upper end of the range can be exclusive or inclusive.
705 + This enumeration type is to identify this. */
709 - /* Neither the low nor the high bound was given -- so this refers to
710 - the entire available range. */
711 - BOTH_BOUND_DEFAULT,
712 - /* The low bound was not given and the high bound is inclusive. */
714 - /* The high bound was not given and the low bound in inclusive. */
715 - HIGH_BOUND_DEFAULT,
716 - /* Both bounds were given and both are inclusive. */
717 - NONE_BOUND_DEFAULT,
718 - /* The low bound was not given and the high bound is exclusive. */
719 - NONE_BOUND_DEFAULT_EXCLUSIVE,
720 - /* Both bounds were given. The low bound is inclusive and the high
721 - bound is exclusive. */
722 - LOW_BOUND_DEFAULT_EXCLUSIVE,
725 + SUBARRAY_NONE_BOUND = 0x0, /* "( : )" */
726 + SUBARRAY_LOW_BOUND = 0x1, /* "(low:)" */
727 + SUBARRAY_HIGH_BOUND = 0x2, /* "(:high)" */
728 + SUBARRAY_STRIDE = 0x4, /* "(::stride)" */
729 + /* The low bound was not given and the high bound is exclusive.
730 + In this case we always use (SUBARRAY_HIGH_BOUND |
731 + SUBARRAY_HIGH_BOUND_EXCLUSIVE). */
732 + SUBARRAY_HIGH_BOUND_EXCLUSIVE = 0x8,
733 + /* Both bounds were given. The low bound is inclusive and the high
734 + bound is exclusive. In this case, we use (SUBARRAY_LOW_BOUND |
735 + SUBARRAY_HIGH_BOUND | SUBARRAY_HIGH_BOUND_EXCLUSIVE). */
736 + // SUBARRAY_LOW_BOUND_EXCLUSIVE = (SUBARRAY_LOW_BOUND
737 + // | SUBARRAY_HIGH_BOUND_EXCLUSIVE),
740 #endif /* !defined (EXPRESSION_H) */
741 diff --git a/gdb/f-exp.y b/gdb/f-exp.y
744 @@ -257,31 +257,63 @@ arglist : subrange
746 arglist : arglist ',' exp %prec ABOVE_COMMA
748 + | arglist ',' subrange %prec ABOVE_COMMA
752 /* There are four sorts of subrange types in F90. */
754 subrange: exp ':' exp %prec ABOVE_COMMA
755 - { write_exp_elt_opcode (pstate, OP_RANGE);
756 - write_exp_elt_longcst (pstate, NONE_BOUND_DEFAULT);
757 + { write_exp_elt_opcode (pstate, OP_RANGE);
758 + write_exp_elt_longcst (pstate,
759 + SUBARRAY_LOW_BOUND | SUBARRAY_HIGH_BOUND);
760 write_exp_elt_opcode (pstate, OP_RANGE); }
763 subrange: exp ':' %prec ABOVE_COMMA
764 { write_exp_elt_opcode (pstate, OP_RANGE);
765 - write_exp_elt_longcst (pstate, HIGH_BOUND_DEFAULT);
766 + write_exp_elt_longcst (pstate, SUBARRAY_LOW_BOUND);
767 write_exp_elt_opcode (pstate, OP_RANGE); }
770 subrange: ':' exp %prec ABOVE_COMMA
771 { write_exp_elt_opcode (pstate, OP_RANGE);
772 - write_exp_elt_longcst (pstate, LOW_BOUND_DEFAULT);
773 + write_exp_elt_longcst (pstate, SUBARRAY_HIGH_BOUND);
774 write_exp_elt_opcode (pstate, OP_RANGE); }
777 subrange: ':' %prec ABOVE_COMMA
778 { write_exp_elt_opcode (pstate, OP_RANGE);
779 - write_exp_elt_longcst (pstate, BOTH_BOUND_DEFAULT);
780 + write_exp_elt_longcst (pstate, SUBARRAY_NONE_BOUND);
781 + write_exp_elt_opcode (pstate, OP_RANGE); }
784 +/* Each subrange type can have a stride argument. */
785 +subrange: exp ':' exp ':' exp %prec ABOVE_COMMA
786 + { write_exp_elt_opcode (pstate, OP_RANGE);
787 + write_exp_elt_longcst (pstate, SUBARRAY_LOW_BOUND
788 + | SUBARRAY_HIGH_BOUND
789 + | SUBARRAY_STRIDE);
790 + write_exp_elt_opcode (pstate, OP_RANGE); }
793 +subrange: exp ':' ':' exp %prec ABOVE_COMMA
794 + { write_exp_elt_opcode (pstate, OP_RANGE);
795 + write_exp_elt_longcst (pstate, SUBARRAY_LOW_BOUND
796 + | SUBARRAY_STRIDE);
797 + write_exp_elt_opcode (pstate, OP_RANGE); }
800 +subrange: ':' exp ':' exp %prec ABOVE_COMMA
801 + { write_exp_elt_opcode (pstate, OP_RANGE);
802 + write_exp_elt_longcst (pstate, SUBARRAY_HIGH_BOUND
803 + | SUBARRAY_STRIDE);
804 + write_exp_elt_opcode (pstate, OP_RANGE); }
807 +subrange: ':' ':' exp %prec ABOVE_COMMA
808 + { write_exp_elt_opcode (pstate, OP_RANGE);
809 + write_exp_elt_longcst (pstate, SUBARRAY_STRIDE);
810 write_exp_elt_opcode (pstate, OP_RANGE); }
813 diff --git a/gdb/f-valprint.c b/gdb/f-valprint.c
814 --- a/gdb/f-valprint.c
815 +++ b/gdb/f-valprint.c
816 @@ -119,8 +119,14 @@ f77_print_array_1 (int nss, int ndimensions, struct type *type,
818 if (nss != ndimensions)
820 - size_t dim_size = TYPE_LENGTH (TYPE_TARGET_TYPE (type));
823 + LONGEST byte_stride = abs (TYPE_BYTE_STRIDE (range_type));
826 + dim_size = byte_stride;
828 + dim_size = TYPE_LENGTH (TYPE_TARGET_TYPE (type));
831 (i < upperbound + 1 && (*elts) < options->print_max);
832 diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
835 @@ -902,7 +902,8 @@ operator== (const range_bounds &l, const range_bounds &r)
837 create_range_type (struct type *result_type, struct type *index_type,
838 const struct dynamic_prop *low_bound,
839 - const struct dynamic_prop *high_bound)
840 + const struct dynamic_prop *high_bound,
841 + const struct dynamic_prop *stride)
843 if (result_type == NULL)
844 result_type = alloc_type_copy (index_type);
845 @@ -917,6 +918,7 @@ create_range_type (struct type *result_type, struct type *index_type,
846 TYPE_ZALLOC (result_type, sizeof (struct range_bounds));
847 TYPE_RANGE_DATA (result_type)->low = *low_bound;
848 TYPE_RANGE_DATA (result_type)->high = *high_bound;
849 + TYPE_RANGE_DATA (result_type)->stride = *stride;
851 if (low_bound->kind == PROP_CONST && low_bound->data.const_val >= 0)
852 TYPE_UNSIGNED (result_type) = 1;
853 @@ -945,7 +947,7 @@ struct type *
854 create_static_range_type (struct type *result_type, struct type *index_type,
855 LONGEST low_bound, LONGEST high_bound)
857 - struct dynamic_prop low, high;
858 + struct dynamic_prop low, high, stride;
860 low.kind = PROP_CONST;
861 low.data.const_val = low_bound;
862 @@ -953,7 +955,11 @@ create_static_range_type (struct type *result_type, struct type *index_type,
863 high.kind = PROP_CONST;
864 high.data.const_val = high_bound;
866 - result_type = create_range_type (result_type, index_type, &low, &high);
867 + stride.kind = PROP_CONST;
868 + stride.data.const_val = 0;
870 + result_type = create_range_type (result_type, index_type,
871 + &low, &high, &stride);
875 @@ -1171,16 +1177,20 @@ create_array_type_with_stride (struct type *result_type,
876 && (!type_not_associated (result_type)
877 && !type_not_allocated (result_type)))
879 - LONGEST low_bound, high_bound;
880 + LONGEST low_bound, high_bound, byte_stride;
882 if (get_discrete_bounds (range_type, &low_bound, &high_bound) < 0)
883 low_bound = high_bound = 0;
884 element_type = check_typedef (element_type);
885 + byte_stride = abs (TYPE_BYTE_STRIDE (range_type));
887 /* Be careful when setting the array length. Ada arrays can be
888 empty arrays with the high_bound being smaller than the low_bound.
889 In such cases, the array length should be zero. */
890 if (high_bound < low_bound)
891 TYPE_LENGTH (result_type) = 0;
892 + else if (byte_stride > 0)
893 + TYPE_LENGTH (result_type) = byte_stride * (high_bound - low_bound + 1);
894 else if (bit_stride > 0)
895 TYPE_LENGTH (result_type) =
896 (bit_stride * (high_bound - low_bound + 1) + 7) / 8;
897 @@ -1981,12 +1991,12 @@ resolve_dynamic_range (struct type *dyn_range_type,
899 struct type *static_range_type, *static_target_type;
900 const struct dynamic_prop *prop;
901 - struct dynamic_prop low_bound, high_bound;
902 + struct dynamic_prop low_bound, high_bound, stride;
904 gdb_assert (TYPE_CODE (dyn_range_type) == TYPE_CODE_RANGE);
906 prop = &TYPE_RANGE_DATA (dyn_range_type)->low;
907 - if (dwarf2_evaluate_property (prop, NULL, addr_stack, &value))
908 + if (dwarf2_evaluate_property_signed (prop, NULL, addr_stack, &value, 1))
910 low_bound.kind = PROP_CONST;
911 low_bound.data.const_val = value;
912 @@ -1998,7 +2008,7 @@ resolve_dynamic_range (struct type *dyn_range_type,
915 prop = &TYPE_RANGE_DATA (dyn_range_type)->high;
916 - if (dwarf2_evaluate_property (prop, NULL, addr_stack, &value))
917 + if (dwarf2_evaluate_property_signed (prop, NULL, addr_stack, &value, 1))
919 high_bound.kind = PROP_CONST;
920 high_bound.data.const_val = value;
921 @@ -2013,12 +2023,20 @@ resolve_dynamic_range (struct type *dyn_range_type,
922 high_bound.data.const_val = 0;
925 + prop = &TYPE_RANGE_DATA (dyn_range_type)->stride;
926 + if (dwarf2_evaluate_property_signed (prop, NULL, addr_stack, &value, 1))
928 + stride.kind = PROP_CONST;
929 + stride.data.const_val = value;
933 = resolve_dynamic_type_internal (TYPE_TARGET_TYPE (dyn_range_type),
935 static_range_type = create_range_type (copy_type (dyn_range_type),
937 - &low_bound, &high_bound);
938 + &low_bound, &high_bound, &stride);
940 TYPE_RANGE_DATA (static_range_type)->flag_bound_evaluated = 1;
941 return static_range_type;
943 diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
946 @@ -612,6 +612,10 @@ struct range_bounds
948 struct dynamic_prop high;
950 + /* * Stride of range. */
952 + struct dynamic_prop stride;
954 /* True if HIGH range bound contains the number of elements in the
955 subrange. This affects how the final hight bound is computed. */
957 @@ -776,7 +780,6 @@ struct main_type
958 /* * Union member used for range types. */
960 struct range_bounds *bounds;
964 /* * Slot to point to additional language-specific fields of this
965 @@ -1329,6 +1332,15 @@ extern bool set_type_align (struct type *, ULONGEST);
966 TYPE_RANGE_DATA(range_type)->high.kind
967 #define TYPE_LOW_BOUND_KIND(range_type) \
968 TYPE_RANGE_DATA(range_type)->low.kind
969 +#define TYPE_BYTE_STRIDE(range_type) \
970 + TYPE_RANGE_DATA(range_type)->stride.data.const_val
971 +#define TYPE_BYTE_STRIDE_BLOCK(range_type) \
972 + TYPE_RANGE_DATA(range_type)->stride.data.locexpr
973 +#define TYPE_BYTE_STRIDE_LOCLIST(range_type) \
974 + TYPE_RANGE_DATA(range_type)->stride.data.loclist
975 +#define TYPE_BYTE_STRIDE_KIND(range_type) \
976 + TYPE_RANGE_DATA(range_type)->stride.kind
979 /* Property accessors for the type data location. */
980 #define TYPE_DATA_LOCATION(thistype) \
981 @@ -1363,6 +1375,9 @@ extern bool set_type_align (struct type *, ULONGEST);
982 TYPE_HIGH_BOUND_UNDEFINED(TYPE_INDEX_TYPE(arraytype))
983 #define TYPE_ARRAY_LOWER_BOUND_IS_UNDEFINED(arraytype) \
984 TYPE_LOW_BOUND_UNDEFINED(TYPE_INDEX_TYPE(arraytype))
985 +#define TYPE_ARRAY_STRIDE_IS_UNDEFINED(arraytype) \
986 + (TYPE_BYTE_STRIDE(TYPE_INDEX_TYPE(arraytype)) == 0)
989 #define TYPE_ARRAY_UPPER_BOUND_VALUE(arraytype) \
990 (TYPE_HIGH_BOUND(TYPE_INDEX_TYPE((arraytype))))
991 @@ -1892,6 +1907,7 @@ extern struct type *create_array_type_with_stride
992 struct dynamic_prop *, unsigned int);
994 extern struct type *create_range_type (struct type *, struct type *,
995 + const struct dynamic_prop *,
996 const struct dynamic_prop *,
997 const struct dynamic_prop *);
999 diff --git a/gdb/parse.c b/gdb/parse.c
1002 @@ -989,24 +989,20 @@ operator_length_standard (const struct expression *expr, int endpos,
1007 range_type = (enum range_type)
1008 longest_to_int (expr->elts[endpos - 2].longconst);
1010 - switch (range_type)
1012 - case LOW_BOUND_DEFAULT:
1013 - case LOW_BOUND_DEFAULT_EXCLUSIVE:
1014 - case HIGH_BOUND_DEFAULT:
1017 - case BOTH_BOUND_DEFAULT:
1020 - case NONE_BOUND_DEFAULT:
1021 - case NONE_BOUND_DEFAULT_EXCLUSIVE:
1025 + /* Increment the argument counter for each argument
1026 + provided by the user. */
1027 + if ((range_type & SUBARRAY_LOW_BOUND) == SUBARRAY_LOW_BOUND)
1030 + if ((range_type & SUBARRAY_HIGH_BOUND) == SUBARRAY_HIGH_BOUND)
1033 + if ((range_type & SUBARRAY_STRIDE) == SUBARRAY_STRIDE)
1038 diff --git a/gdb/rust-exp.y b/gdb/rust-exp.y
1039 --- a/gdb/rust-exp.y
1040 +++ b/gdb/rust-exp.y
1041 @@ -2478,24 +2478,28 @@ convert_ast_to_expression (struct parser_state *state,
1045 - enum range_type kind = BOTH_BOUND_DEFAULT;
1046 + enum range_type kind = SUBARRAY_NONE_BOUND;
1048 if (operation->left.op != NULL)
1050 convert_ast_to_expression (state, operation->left.op, top);
1051 - kind = HIGH_BOUND_DEFAULT;
1052 + kind = SUBARRAY_LOW_BOUND;
1054 if (operation->right.op != NULL)
1056 convert_ast_to_expression (state, operation->right.op, top);
1057 - if (kind == BOTH_BOUND_DEFAULT)
1058 - kind = (operation->inclusive
1059 - ? LOW_BOUND_DEFAULT : LOW_BOUND_DEFAULT_EXCLUSIVE);
1060 + if (kind == SUBARRAY_NONE_BOUND)
1062 + kind = (range_type) SUBARRAY_HIGH_BOUND;
1063 + if (!operation->inclusive)
1064 + kind = (range_type) (kind | SUBARRAY_HIGH_BOUND_EXCLUSIVE);
1068 - gdb_assert (kind == HIGH_BOUND_DEFAULT);
1069 - kind = (operation->inclusive
1070 - ? NONE_BOUND_DEFAULT : NONE_BOUND_DEFAULT_EXCLUSIVE);
1071 + gdb_assert (kind == SUBARRAY_LOW_BOUND);
1072 + kind = (range_type) (kind | SUBARRAY_HIGH_BOUND);
1073 + if (!operation->inclusive)
1074 + kind = (range_type) (kind | SUBARRAY_HIGH_BOUND_EXCLUSIVE);
1078 diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
1079 --- a/gdb/rust-lang.c
1080 +++ b/gdb/rust-lang.c
1081 @@ -1149,13 +1149,11 @@ rust_range (struct expression *exp, int *pos, enum noside noside)
1082 kind = (enum range_type) longest_to_int (exp->elts[*pos + 1].longconst);
1085 - if (kind == HIGH_BOUND_DEFAULT || kind == NONE_BOUND_DEFAULT
1086 - || kind == NONE_BOUND_DEFAULT_EXCLUSIVE)
1087 + if ((kind & SUBARRAY_LOW_BOUND) == SUBARRAY_LOW_BOUND)
1088 low = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1089 - if (kind == LOW_BOUND_DEFAULT || kind == LOW_BOUND_DEFAULT_EXCLUSIVE
1090 - || kind == NONE_BOUND_DEFAULT || kind == NONE_BOUND_DEFAULT_EXCLUSIVE)
1091 + if ((kind & SUBARRAY_HIGH_BOUND) == SUBARRAY_HIGH_BOUND)
1092 high = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1093 - bool inclusive = (kind == NONE_BOUND_DEFAULT || kind == LOW_BOUND_DEFAULT);
1094 + bool inclusive = (!((kind & SUBARRAY_HIGH_BOUND_EXCLUSIVE) == SUBARRAY_HIGH_BOUND_EXCLUSIVE));
1096 if (noside == EVAL_SKIP)
1097 return value_from_longest (builtin_type (exp->gdbarch)->builtin_int, 1);
1098 @@ -1244,7 +1242,7 @@ rust_compute_range (struct type *type, struct value *range,
1102 - *kind = BOTH_BOUND_DEFAULT;
1103 + *kind = SUBARRAY_NONE_BOUND;
1105 if (TYPE_NFIELDS (type) == 0)
1107 @@ -1252,15 +1250,14 @@ rust_compute_range (struct type *type, struct value *range,
1109 if (strcmp (TYPE_FIELD_NAME (type, 0), "start") == 0)
1111 - *kind = HIGH_BOUND_DEFAULT;
1112 + *kind = SUBARRAY_LOW_BOUND;
1113 *low = value_as_long (value_field (range, 0));
1116 if (TYPE_NFIELDS (type) > i
1117 && strcmp (TYPE_FIELD_NAME (type, i), "end") == 0)
1119 - *kind = (*kind == BOTH_BOUND_DEFAULT
1120 - ? LOW_BOUND_DEFAULT : NONE_BOUND_DEFAULT);
1121 + *kind = (range_type) (*kind | SUBARRAY_HIGH_BOUND);
1122 *high = value_as_long (value_field (range, i));
1124 if (rust_inclusive_range_type_p (type))
1125 @@ -1278,7 +1275,7 @@ rust_subscript (struct expression *exp, int *pos, enum noside noside,
1126 struct type *rhstype;
1127 LONGEST low, high_bound;
1128 /* Initialized to appease the compiler. */
1129 - enum range_type kind = BOTH_BOUND_DEFAULT;
1130 + enum range_type kind = SUBARRAY_NONE_BOUND;
1134 @@ -1376,7 +1373,7 @@ rust_subscript (struct expression *exp, int *pos, enum noside noside,
1135 error (_("Cannot subscript non-array type"));
1138 - && (kind == BOTH_BOUND_DEFAULT || kind == LOW_BOUND_DEFAULT))
1139 + && ((kind & SUBARRAY_LOW_BOUND) != SUBARRAY_LOW_BOUND))
1142 error (_("Index less than zero"));
1143 @@ -1394,7 +1391,7 @@ rust_subscript (struct expression *exp, int *pos, enum noside noside,
1145 struct value *addrval, *tem;
1147 - if (kind == BOTH_BOUND_DEFAULT || kind == HIGH_BOUND_DEFAULT)
1148 + if ((kind & SUBARRAY_HIGH_BOUND) != SUBARRAY_HIGH_BOUND)
1151 error (_("High index less than zero"));
1152 diff --git a/gdb/testsuite/gdb.fortran/static-arrays.exp b/gdb/testsuite/gdb.fortran/static-arrays.exp
1153 new file mode 100644
1155 +++ b/gdb/testsuite/gdb.fortran/static-arrays.exp
1157 +# Copyright 2015 Free Software Foundation, Inc.
1159 +# Contributed by Intel Corp. <christoph.t.weinmann@intel.com>
1161 +# This program is free software; you can redistribute it and/or modify
1162 +# it under the terms of the GNU General Public License as published by
1163 +# the Free Software Foundation; either version 3 of the License, or
1164 +# (at your option) any later version.
1166 +# This program is distributed in the hope that it will be useful,
1167 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1168 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1169 +# GNU General Public License for more details.
1171 +# You should have received a copy of the GNU General Public License
1172 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1174 +standard_testfile static-arrays.f90
1176 +if { [prepare_for_testing $testfile.exp $testfile $srcfile {debug f90}] } {
1180 +if ![runto MAIN__] then {
1181 + perror "couldn't run to breakpoint MAIN__"
1185 +gdb_breakpoint [gdb_get_line_number "BP1"]
1186 +gdb_continue_to_breakpoint "BP1" ".*BP1.*"
1188 +# Tests subarrays of one dimensional arrays with subrange variations
1189 +gdb_test "print ar1" "\\$\[0-9\]+ = \\(1, 2, 3, 4, 5, 6, 7, 8, 9\\)" \
1191 +gdb_test "print ar1\(4:7\)" "\\$\[0-9\]+ = \\(4, 5, 6, 7\\)" \
1192 + "print ar1\(4:7\)"
1193 +gdb_test "print ar1\(8:\)" "\\$\[0-9\]+ = \\(8, 9\\).*" \
1195 +gdb_test "print ar1\(:3\)" "\\$\[0-9\]+ = \\(1, 2, 3\\).*" \
1197 +gdb_test "print ar1\(:\)" "\\$\[0-9\]+ = \\(1, 2, 3, 4, 5, 6, 7, 8, 9\\)" \
1201 +gdb_test_no_output "set \$my_ary = ar1\(3:8\)"
1202 +gdb_test "print \$my_ary" \
1203 + "\\$\[0-9\]+ = \\(3, 4, 5, 6, 7, 8\\)" \
1204 + "Assignment of subarray to variable"
1205 +gdb_test_no_output "set ar1\(5\) = 42"
1206 + gdb_test "print ar1\(3:8\)" \
1207 + "\\$\[0-9\]+ = \\(3, 4, 42, 6, 7, 8\\)" \
1208 + "print ar1\(3:8\) after assignment"
1209 +gdb_test "print \$my_ary" \
1210 + "\\$\[0-9\]+ = \\(3, 4, 5, 6, 7, 8\\)" \
1211 + "Assignment of subarray to variable after original array changed"
1213 +# Test for subarrays of one dimensional arrays with literals
1214 + gdb_test "print ar1\(3\)" "\\$\[0-9\]+ = 3" \
1217 +# Tests for subranges of 2 dimensional arrays with subrange variations
1218 +gdb_test "print ar2\(2:3, 3:4\)" \
1219 + "\\$\[0-9\]+ = \\(\\( 23, 33\\) \\( 24, 34\\) \\)" \
1220 + "print ar2\(2:3, 3:4\)."
1221 +gdb_test "print ar2\(8:9,8:\)" \
1222 + "\\$\[0-9\]+ = \\(\\( 88, 98\\) \\( 89, 99\\) \\)" \
1223 + "print ar2\(8:9,8:\)"
1224 +gdb_test "print ar2\(8:9,:2\)" \
1225 + "\\$\[0-9\]+ = \\(\\( 81, 91\\) \\( 82, 92\\) \\)" \
1226 + "print ar2\(8:9,:2\)"
1228 +gdb_test "print ar2\(8:,8:9\)" \
1229 + "\\$\[0-9\]+ = \\(\\( 88, 98\\) \\( 89, 99\\) \\)" \
1230 + "print ar2\(8:,8:9\)"
1231 +gdb_test "print ar2\(8:,8:\)" \
1232 + "\\$\[0-9\]+ = \\(\\( 88, 98\\) \\( 89, 99\\) \\)" \
1233 + "print ar2\(8:,8:\)"
1234 +gdb_test "print ar2\(8:,:2\)" \
1235 + "\\$\[0-9\]+ = \\(\\( 81, 91\\) \\( 82, 92\\) \\)" \
1236 + "print ar2\(8:,:2\)"
1238 +gdb_test "print ar2\(:2,2:3\)" \
1239 + "\\$\[0-9\]+ = \\(\\( 12, 22\\) \\( 13, 23\\) \\)" \
1240 + "print ar2\(:2,2:3\)"
1241 +gdb_test "print ar2\(:2,8:\)" \
1242 + "\\$\[0-9\]+ = \\(\\( 18, 28\\) \\( 19, 29\\) \\)" \
1243 + "print ar2\(:2,8:\)"
1244 +gdb_test "print ar2\(:2,:2\)" \
1245 + "\\$\[0-9\]+ = \\(\\( 11, 21\\) \\( 12, 22\\) \\)" \
1246 + "print ar2\(:2,:2\)"
1248 +# Test subranges of 2 dimensional arrays with literals and subrange variations
1249 +gdb_test "print ar2\(7, 3:6\)" \
1250 + "\\$\[0-9\]+ = \\(73, 74, 75, 76\\)" \
1251 + "print ar2\(7, 3:6\)"
1252 +gdb_test "print ar2\(7,8:\)" \
1253 + "\\$\[0-9\]+ = \\(78, 79\\)" \
1254 + "print ar2\(7,8:\)"
1255 +gdb_test "print ar2\(7,:2\)" \
1256 + "\\$\[0-9\]+ = \\(71, 72\\)" \
1257 + "print ar2\(7,:2\)"
1259 +gdb_test "print ar2\(7:8,4\)" \
1260 + "\\$\[0-9\]+ = \\(74, 84\\)" \
1261 + "print ar2(7:8,4\)"
1262 +gdb_test "print ar2\(8:,4\)" \
1263 + "\\$\[0-9\]+ = \\(84, 94\\)" \
1264 + "print ar2\(8:,4\)"
1265 +gdb_test "print ar2\(:2,4\)" \
1266 + "\\$\[0-9\]+ = \\(14, 24\\)" \
1267 + "print ar2\(:2,4\)"
1268 +gdb_test "print ar2\(3,4\)" \
1269 + "\\$\[0-9\]+ = 34" \
1270 + "print ar2\(3,4\)"
1272 +# Test subarrays of 3 dimensional arrays with literals and subrange variations
1273 +gdb_test "print ar3\(2:4,3:4,7:8\)" \
1274 + "\\$\[0-9\]+ = \\(\\( \\( 237, 337, 437\\) \\( 247, 347, 447\\)\
1275 + \\) \\( \\( 238, 338, 438\\) \\( 248, 348, 448\\) \\) \\)" \
1276 + "print ar3\(2:4,3:4,7:8\)"
1277 +gdb_test "print ar3\(2:3,4:5,8:\)" \
1278 + "\\$\[0-9\]+ = \\(\\( \\( 248, 348\\) \\( 258, 358\\) \\) \\(\
1279 + \\( 249, 349\\) \\( 259, 359\\) \\) \\)" \
1280 + "print ar3\(2:3,4:5,8:\)"
1281 +gdb_test "print ar3\(2:3,4:5,:2\)" \
1282 + "\\$\[0-9\]+ = \\(\\( \\( 241, 341\\) \\( 251, 351\\) \\) \\(\
1283 + \\( 242, 342\\) \\( 252, 352\\) \\) \\)" \
1284 + "print ar3\(2:3,4:5,:2\)"
1286 +gdb_test "print ar3\(2:3,8:,7:8\)" \
1287 + "\\$\[0-9\]+ = \\(\\( \\( 287, 387\\) \\( 297, 397\\) \\) \\(\
1288 + \\( 288, 388\\) \\( 298, 398\\) \\) \\)" \
1289 + "print ar3\(2:3,8:,7:8\)"
1290 +gdb_test "print ar3\(2:3,8:,8:\)" \
1291 + "\\$\[0-9\]+ = \\(\\( \\( 288, 388\\) \\( 298, 398\\) \\) \\(\
1292 + \\( 289, 389\\) \\( 299, 399\\) \\) \\)" \
1293 + "print ar3\(2:3,8:,8:\)"
1294 +gdb_test "print ar3\(2:3,8:,:2\)" \
1295 + "\\$\[0-9\]+ = \\(\\( \\( 281, 381\\) \\( 291, 391\\) \\) \\(\
1296 + \\( 282, 382\\) \\( 292, 392\\) \\) \\)" \
1297 + "print ar3\(2:3,8:,:2\)"
1299 +gdb_test "print ar3\(2:3,:2,7:8\)" \
1300 + "\\$\[0-9\]+ = \\(\\( \\( 217, 317\\) \\( 227, 327\\) \\) \\(\
1301 + \\( 218, 318\\) \\( 228, 328\\) \\) \\)" \
1302 + "print ar3\(2:3,:2,7:8\)"
1303 +gdb_test "print ar3\(2:3,:2,8:\)" \
1304 + "\\$\[0-9\]+ = \\(\\( \\( 218, 318\\) \\( 228, 328\\) \\) \\(\
1305 + \\( 219, 319\\) \\( 229, 329\\) \\) \\)" \
1306 + "print ar3\(2:3,:2,8:\)"
1307 +gdb_test "print ar3\(2:3,:2,:2\)" \
1308 + "\\$\[0-9\]+ = \\(\\( \\( 211, 311\\) \\( 221, 321\\) \\) \\(\
1309 + \\( 212, 312\\) \\( 222, 322\\) \\) \\)" \
1310 + "print ar3\(2:3,:2,:2\)"
1312 +gdb_test "print ar3\(8:,3:4,7:8\)" \
1313 + "\\$\[0-9\]+ = \\(\\( \\( 837, 937\\) \\( 847, 947\\) \\) \\(\
1314 + \\( 838, 938\\) \\( 848, 948\\) \\) \\)" \
1315 + "print ar3\(8:,3:4,7:8\)"
1316 +gdb_test "print ar3\(8:,4:5,8:\)" \
1317 + "\\$\[0-9\]+ = \\(\\( \\( 848, 948\\) \\( 858, 958\\) \\) \\(\
1318 + \\( 849, 949\\) \\( 859, 959\\) \\) \\)" \
1319 + "print ar3\(8:,4:5,8:\)"
1320 +gdb_test "print ar3\(8:,4:5,:2\)" \
1321 + "\\$\[0-9\]+ = \\(\\( \\( 841, 941\\) \\( 851, 951\\) \\) \\(\
1322 + \\( 842, 942\\) \\( 852, 952\\) \\) \\)" \
1323 + "print ar3\(8:,4:5,:2\)"
1325 +gdb_test "print ar3\(8:,8:,7:8\)" \
1326 + "\\$\[0-9\]+ = \\(\\( \\( 887, 987\\) \\( 897, 997\\) \\) \\(\
1327 + \\( 888, 988\\) \\( 898, 998\\) \\) \\)" \
1328 + "print ar3\(8:,8:,7:8\)"
1329 +gdb_test "print ar3\(8:,8:,8:\)" \
1330 + "\\$\[0-9\]+ = \\(\\( \\( 888, 988\\) \\( 898, 998\\) \\) \\(\
1331 + \\( 889, 989\\) \\( 899, 999\\) \\) \\)" \
1332 + "print ar3\(8:,8:,8:\)"
1333 +gdb_test "print ar3\(8:,8:,:2\)" \
1334 + "\\$\[0-9\]+ = \\(\\( \\( 881, 981\\) \\( 891, 991\\) \\) \\(\
1335 + \\( 882, 982\\) \\( 892, 992\\) \\) \\)" \
1336 + "print ar3\(8:,8:,:2\)"
1338 +gdb_test "print ar3\(8:,:2,7:8\)" \
1339 + "\\$\[0-9\]+ = \\(\\( \\( 817, 917\\) \\( 827, 927\\) \\) \\(\
1340 + \\( 818, 918\\) \\( 828, 928\\) \\) \\)" \
1341 + "print ar3\(8:,:2,7:8\)"
1342 +gdb_test "print ar3\(8:,:2,8:\)" \
1343 + "\\$\[0-9\]+ = \\(\\( \\( 818, 918\\) \\( 828, 928\\) \\) \\(\
1344 + \\( 819, 919\\) \\( 829, 929\\) \\) \\)" \
1345 + "print ar3\(8:,:2,8:\)"
1346 +gdb_test "print ar3\(8:,:2,:2\)" \
1347 + "\\$\[0-9\]+ = \\(\\( \\( 811, 911\\) \\( 821, 921\\) \\) \\(\
1348 + \\( 812, 912\\) \\( 822, 922\\) \\) \\)" \
1349 + "print ar3\(8:,:2,:2\)"
1352 +gdb_test "print ar3\(:2,3:4,7:8\)" \
1353 + "\\$\[0-9\]+ = \\(\\( \\( 137, 237\\) \\( 147, 247\\) \\) \\(\
1354 + \\( 138, 238\\) \\( 148, 248\\) \\) \\)" \
1355 + "print ar3 \(:2,3:4,7:8\)."
1356 +gdb_test "print ar3\(:2,3:4,8:\)" \
1357 + "\\$\[0-9\]+ = \\(\\( \\( 138, 238\\) \\( 148, 248\\) \\) \\(\
1358 + \\( 139, 239\\) \\( 149, 249\\) \\) \\)" \
1359 + "print ar3\(:2,3:4,8:\)"
1360 +gdb_test "print ar3\(:2,3:4,:2\)" \
1361 + "\\$\[0-9\]+ = \\(\\( \\( 131, 231\\) \\( 141, 241\\) \\) \\(\
1362 + \\( 132, 232\\) \\( 142, 242\\) \\) \\)" \
1363 + "print ar3\(:2,3:4,:2\)"
1365 +gdb_test "print ar3\(:2,8:,7:8\)" "\\$\[0-9\]+ = \\(\\( \\( 187, 287\\) \\(\
1366 + 197, 297\\) \\) \\( \\( 188, 288\\) \\( 198, 298\\) \\) \\)" \
1367 + "print ar3\(:2,8:,7:8\)"
1368 +gdb_test "print ar3\(:2,8:,8:\)" "\\$\[0-9\]+ = \\(\\( \\( 188, 288\\) \\( 198,\
1369 + 298\\) \\) \\( \\( 189, 289\\) \\( 199, 299\\) \\) \\)" \
1370 + "print ar3\(:2,8:,8:\)"
1371 +gdb_test "print ar3\(:2,8:,:2\)" "\\$\[0-9\]+ = \\(\\( \\( 181, 281\\) \\( 191,\
1372 + 291\\) \\) \\( \\( 182, 282\\) \\( 192, 292\\) \\) \\)" \
1373 + "print ar3\(:2,8:,:2\)"
1375 +gdb_test "print ar3\(:2,:2,7:8\)" \
1376 + "\\$\[0-9\]+ = \\(\\( \\( 117, 217\\) \\( 127, 227\\) \\) \\(\
1377 + \\( 118, 218\\) \\( 128, 228\\) \\) \\)" \
1378 + "print ar3\(:2,:2,7:8\)"
1379 +gdb_test "print ar3\(:2,:2,8:\)" \
1380 + "\\$\[0-9\]+ = \\(\\( \\( 118, 218\\) \\( 128, 228\\) \\) \\(\
1381 + \\( 119, 219\\) \\( 129, 229\\) \\) \\)" \
1382 + "print ar3\(:2,:2,8:\)"
1383 +gdb_test "print ar3\(:2,:2,:2\)" \
1384 + "\\$\[0-9\]+ = \\(\\( \\( 111, 211\\) \\( 121, 221\\) \\) \\(\
1385 + \\( 112, 212\\) \\( 122, 222\\) \\) \\)" \
1386 + "print ar3\(:2,:2,:2\)"
1388 +#Tests for subarrays of 3 dimensional arrays with literals and subranges
1389 +gdb_test "print ar3\(3,3:4,7:8\)" \
1390 + "\\$\[0-9\]+ = \\(\\( 337, 347\\) \\( 338, 348\\) \\)" \
1391 + "print ar3\(3,3:4,7:8\)"
1392 +gdb_test "print ar3\(3,4:5,8:\)" \
1393 + "\\$\[0-9\]+ = \\(\\( 348, 358\\) \\( 349, 359\\) \\)" \
1394 + "print ar3\(3,4:5,8:\)"
1395 +gdb_test "print ar3\(3,4:5,:2\)" \
1396 + "\\$\[0-9\]+ = \\(\\( 341, 351\\) \\( 342, 352\\) \\)" \
1397 + "print ar3\(3,4:5,:2\)"
1398 +gdb_test "print ar3\(3,4:5,3\)" \
1399 + "\\$\[0-9\]+ = \\(343, 353\\)" \
1400 + "print ar3\(3,4:5,3\)"
1402 +gdb_test "print ar3\(2,8:,7:8\)" \
1403 + "\\$\[0-9\]+ = \\(\\( 287, 297\\) \\( 288, 298\\) \\)" \
1404 + "print ar3\(2,8:,7:8\)"
1405 +gdb_test "print ar3\(2,8:,8:\)" \
1406 + "\\$\[0-9\]+ = \\(\\( 288, 298\\) \\( 289, 299\\) \\)" \
1407 + "print ar3\(2,8:,8:\)"
1408 +gdb_test "print ar3\(2,8:,:2\)"\
1409 + "\\$\[0-9\]+ = \\(\\( 281, 291\\) \\( 282, 292\\) \\)" \
1410 + "print ar3\(2,8:,:2\)"
1411 +gdb_test "print ar3\(2,8:,3\)" \
1412 + "\\$\[0-9\]+ = \\(283, 293\\)" \
1413 + "print ar3\(2,8:,3\)"
1415 +gdb_test "print ar3\(2,:2,7:8\)" \
1416 + "\\$\[0-9\]+ = \\(\\( 217, 227\\) \\( 218, 228\\) \\)" \
1417 + "print ar3\(2,:2,7:8\)"
1418 +gdb_test "print ar3\(2,:2,8:\)" \
1419 + "\\$\[0-9\]+ = \\(\\( 218, 228\\) \\( 219, 229\\) \\)" \
1420 + "print ar3\(2,:2,8:\)"
1421 +gdb_test "print ar3\(2,:2,:2\)" \
1422 + "\\$\[0-9\]+ = \\(\\( 211, 221\\) \\( 212, 222\\) \\)" \
1423 + "print ar3\(2,:2,:2\)"
1424 +gdb_test "print ar3\(2,:2,3\)" \
1425 + "\\$\[0-9\]+ = \\(213, 223\\)" \
1426 + "print ar3\(2,:2,3\)"
1428 +gdb_test "print ar3\(3,4,7:8\)" \
1429 + "\\$\[0-9\]+ = \\(347, 348\\)" \
1430 + "print ar3\(3,4,7:8\)"
1431 +gdb_test "print ar3\(3,4,8:\)" \
1432 + "\\$\[0-9\]+ = \\(348, 349\\)" \
1433 +i "print ar3\(3,4,8:\)"
1434 +gdb_test "print ar3\(3,4,:2\)" \
1435 + "\\$\[0-9\]+ = \\(341, 342\\)" \
1436 + "print ar3\(3,4,:2\)"
1437 +gdb_test "print ar3\(5,6,7\)" \
1438 + "\\$\[0-9\]+ = 567" \
1439 + "print ar3\(5,6,7\)"
1441 +gdb_test "print ar3\(3:4,6,7:8\)" \
1442 + "\\$\[0-9\]+ = \\(\\( 367, 467\\) \\( 368, 468\\) \\)" \
1443 + "print ar3\(3:4,6,7:8\)"
1444 +gdb_test "print ar3\(3:4,6,8:\)" \
1445 + "\\$\[0-9\]+ = \\(\\( 368, 468\\) \\( 369, 469\\) \\)" \
1446 + "print ar3\(3:4,6,8:\)"
1447 +gdb_test "print ar3\(3:4,6,:2\)" \
1448 + "\\$\[0-9\]+ = \\(\\( 361, 461\\) \\( 362, 462\\) \\)" \
1449 + "print ar3\(3:4,6,:2\)"
1450 +gdb_test "print ar3\(3:4,6,5\)" \
1451 + "\\$\[0-9\]+ = \\(365, 465\\)" \
1452 + "print ar3\(3:4,6,5\)"
1454 +gdb_test "print ar3\(8:,6,7:8\)" \
1455 + "\\$\[0-9\]+ = \\(\\( 867, 967\\) \\( 868, 968\\) \\)" \
1456 + "print ar3\(8:,6,7:8\)"
1457 +gdb_test "print ar3\(8:,6,8:\)" \
1458 + "\\$\[0-9\]+ = \\(\\( 868, 968\\) \\( 869, 969\\) \\)" \
1459 + "print ar3\(8:,6,8:\)"
1460 +gdb_test "print ar3\(8:,6,:2\)" \
1461 + "\\$\[0-9\]+ = \\(\\( 861, 961\\) \\( 862, 962\\) \\)" \
1462 + "print ar3\(8:,6,:2\)"
1463 +gdb_test "print ar3\(8:,6,5\)" \
1464 + "\\$\[0-9\]+ = \\(865, 965\\)" \
1465 + "print ar3\(8:,6,5\)"
1467 +gdb_test "print ar3\(:2,6,7:8\)" \
1468 + "\\$\[0-9\]+ = \\(\\( 167, 267\\) \\( 168, 268\\) \\)" \
1469 + "print ar3\(:2,6,7:8\)"
1470 +gdb_test "print ar3\(:2,6,8:\)" \
1471 + "\\$\[0-9\]+ = \\(\\( 168, 268\\) \\( 169, 269\\) \\)" \
1472 + "print ar3\(:2,6,8:\)"
1473 +gdb_test "print ar3\(:2,6,:2\)" \
1474 + "\\$\[0-9\]+ = \\(\\( 161, 261\\) \\( 162, 262\\) \\)" \
1475 + "print ar3\(:2,6,:2\)"
1476 +gdb_test "print ar3\(:2,6,5\)" \
1477 + "\\$\[0-9\]+ = \\(165, 265\\)" \
1478 + "print ar3\(:2,6,5\)"
1480 +gdb_test "print ar3\(3:4,5:6,4\)" \
1481 + "\\$\[0-9\]+ = \\(\\( 354, 454\\) \\( 364, 464\\) \\)" \
1482 + "print ar2\(3:4,5:6,4\)"
1483 +gdb_test "print ar3\(8:,5:6,4\)" \
1484 + "\\$\[0-9\]+ = \\(\\( 854, 954\\) \\( 864, 964\\) \\)" \
1485 + "print ar2\(8:,5:6,4\)"
1486 +gdb_test "print ar3\(:2,5:6,4\)" \
1487 + "\\$\[0-9\]+ = \\(\\( 154, 254\\) \\( 164, 264\\) \\)" \
1488 + "print ar2\(:2,5:6,4\)"
1491 +gdb_test "print ar1\(2:6:2\)" \
1492 + "\\$\[0-9\]+ = \\(2, 4, 6\\)" \
1493 + "print ar1\(2:6:2\)"
1494 +gdb_test "print ar2\(2:6:2,3:4\)" \
1495 + "\\$\[0-9\]+ = \\(\\( 23, 43, 63\\) \\( 24, 44, 64\\) \\)" \
1496 + "print ar2\(2:6:2,3:4\)"
1497 +gdb_test "print ar2\(2:6:2,3\)" \
1498 + "\\$\[0-9\]+ = \\(23, 43, 63\\)" \
1499 + "print ar2\(2:6:2,3\)"
1500 +gdb_test "print ar3\(2:6:2,3:5:2,4:7:3\)" \
1501 + "\\$\[0-9\]+ = \\(\\( \\( 234, 434, 634\\) \\( 254, 454, 654\\)\
1502 + \\) \\( \\( 237, 437, 637\\) \\( 257, 457, 657\\) \\) \\)" \
1503 + "print ar3\(2:6:2,3:5:2,4:7:3\)"
1504 +gdb_test "print ar3\(2:6:2,5,4:7:3\)" \
1505 + "\\$\[0-9\]+ = \\(\\( 254, 454, 654\\) \\( 257, 457, 657\\)\
1507 + "print ar3\(2:6:2,5,4:7:3\)"
1510 +gdb_test "print ar1\(8:2:-2\)" \
1511 + "\\$\[0-9\]+ = \\(8, 6, 4, 2\\)" \
1512 + "print ar1\(8:2:-2\)"
1513 +gdb_test "print ar2\(8:2:-2,3:4\)" \
1514 + "\\$\[0-9\]+ = \\(\\( 83, 63, 43, 23\\) \\( 84, 64, 44, 24\\)\
1516 + "print ar2\(8:2:-2,3:4\)"
1517 +gdb_test "print ar2\(2:6:2,3\)" \
1518 + "\\$\[0-9\]+ = \\(23, 43, 63\\)" \
1519 + "print ar2\(2:6:2,3\)"
1520 +gdb_test "print ar3\(2:3,7:3:-4,4:7:3\)" \
1521 + "\\$\[0-9\]+ = \\(\\( \\( 274, 374\\) \\( 234, 334\\) \\) \\(\
1522 + \\( 277, 377\\) \\( 237, 337\\) \\) \\)" \
1523 + "print ar3\(2:3,7:3:-4,4:7:3\)"
1524 +gdb_test "print ar3\(2:6:2,5,7:4:-3\)" \
1525 + "\\$\[0-9\]+ = \\(\\( 257, 457, 657\\) \\( 254, 454, 654\\)\
1527 + "print ar3\(2:6:2,5,7:4:-3\)"
1529 +# Tests with negative and mixed indices
1530 +gdb_test "p ar4\(2:4, -2:1, -15:-14\)" \
1531 + "\\$\[0-9\]+ = \\(\\( \\( 261, 361, 461\\) \\( 271, 371, 471\\)\
1532 + \\( 281, 381, 481\\) \\( 291, 391, 491\\) \\) \\( \\( 262,\
1533 + 362, 462\\) \\( 272, 372, 472\\) \\( 282, 382, 482\\) \\( 292,\
1534 + 392, 492\\) \\) \\)" \
1535 + "print ar4(2:4, -2:1, -15:-14)"
1537 +gdb_test "p ar4\(7,-6:2:3,-7\)" \
1538 + "\\$\[0-9\]+ = \\(729, 759, 789\\)" \
1539 + "print ar4(7,-6:2:3,-7)"
1541 +gdb_test "p ar4\(9:2:-2, -6:2:3, -6:-15:-3\)" \
1542 + "\\$\[0-9\]+ = \\(\\( \\( 930, 730, 530, 330\\) \\( 960, 760,\
1543 + 560, 360\\) \\( 990, 790, 590, 390\\) \\) \\( \\( 927, 727,\
1544 + 527, 327\\) \\( 957, 757, 557, 357\\) \\( 987, 787, 587,\
1545 + 387\\) \\) \\( \\( 924, 724, 524, 324\\) \\( 954, 754, 554,\
1546 + 354\\) \\( 984, 784, 584, 384\\) \\) \\( \\( 921, 721, 521,\
1547 + 321\\) \\( 951, 751, 551, 351\\) \\( 981, 781, 581, 381\\) \\)\
1549 + "print ar4(9:2:-2, -6:2:3, -6:-15:-3)"
1551 +gdb_test "p ar4\(:,:,:\)" \
1552 + "\\$\[0-9\]+ = \\(\\( \\( 111, 211, 311, 411, 511, 611, 711,\
1554 + "print ar4(:,:,:)"
1556 +# Provoke error messages for bad user input
1557 +gdb_test "print ar1\(0:4\)" \
1558 + "provided bound\\(s\\) outside array bound\\(s\\)" \
1559 + "print ar1\(0:4\)"
1560 +gdb_test "print ar1\(8:12\)" \
1561 + "provided bound\\(s\\) outside array bound\\(s\\)" \
1562 + "print ar1\(8:12\)"
1563 +gdb_test "print ar1\(8:2:\)" \
1564 + "A syntax error in expression, near `\\)'." \
1565 + "print ar1\(8:2:\)"
1566 +gdb_test "print ar1\(8:2:2\)" \
1567 + "Wrong value provided for stride and boundaries" \
1568 + "print ar1\(8:2:2\)"
1569 +gdb_test "print ar1\(2:8:-2\)" \
1570 + "Wrong value provided for stride and boundaries" \
1571 + "print ar1\(2:8:-2\)"
1572 +gdb_test "print ar1\(2:7:0\)" \
1573 + "Stride must not be 0" \
1574 + "print ar1\(2:7:0\)"
1575 +gdb_test "print ar1\(3:7\) = 42" \
1577 + "Assignment of value to subarray"
1578 diff --git a/gdb/testsuite/gdb.fortran/static-arrays.f90 b/gdb/testsuite/gdb.fortran/static-arrays.f90
1579 new file mode 100644
1581 +++ b/gdb/testsuite/gdb.fortran/static-arrays.f90
1583 +! Copyright 2015 Free Software Foundation, Inc.
1585 +! Contributed by Intel Corp. <christoph.t.weinmann@intel.com>
1587 +! This program is free software; you can redistribute it and/or modify
1588 +! it under the terms of the GNU General Public License as published by
1589 +! the Free Software Foundation; either version 3 of the License, or
1590 +! (at your option) any later version.
1592 +! This program is distributed in the hope that it will be useful,
1593 +! but WITHOUT ANY WARRANTY; without even the implied warranty of
1594 +! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1595 +! GNU General Public License for more details.
1597 +! You should have received a copy of the GNU General Public License
1598 +! along with this program. If not, see <http://www.gnu.org/licenses/>.
1601 + integer, dimension(9) :: ar1
1602 + integer, dimension(9,9) :: ar2
1603 + integer, dimension(9,9,9) :: ar3
1604 + integer, dimension(10,-7:3, -15:-5) :: ar4
1612 + ! Resulting array ar3 looks like ((( 111, 112, 113, 114,...)))
1616 + ar2(i,j) = i*10 + j
1618 + ar3(i,j,k) = i*100 + j*10 + k
1626 + ar4(i,j,k) = i*100 + (j+8)*10 + (k+16)
1638 diff --git a/gdb/testsuite/gdb.fortran/vla-ptype.exp b/gdb/testsuite/gdb.fortran/vla-ptype.exp
1639 --- a/gdb/testsuite/gdb.fortran/vla-ptype.exp
1640 +++ b/gdb/testsuite/gdb.fortran/vla-ptype.exp
1641 @@ -98,3 +98,7 @@ gdb_test "ptype vla2" "type = <not allocated>" "ptype vla2 not allocated"
1642 gdb_test "ptype vla2(5, 45, 20)" \
1643 "no such vector element \\\(vector not allocated\\\)" \
1644 "ptype vla2(5, 45, 20) not allocated"
1646 +gdb_breakpoint [gdb_get_line_number "vla1-neg-bounds"]
1647 +gdb_continue_to_breakpoint "vla1-neg-bounds"
1648 +gdb_test "ptype vla1" "type = $real \\(-2:1,-5:4,-3:-1\\)" "ptype vla1 negative bounds"
1649 diff --git a/gdb/testsuite/gdb.fortran/vla-sizeof.exp b/gdb/testsuite/gdb.fortran/vla-sizeof.exp
1650 --- a/gdb/testsuite/gdb.fortran/vla-sizeof.exp
1651 +++ b/gdb/testsuite/gdb.fortran/vla-sizeof.exp
1652 @@ -44,3 +44,7 @@ gdb_test "print sizeof(pvla)" " = 0" "print sizeof non-associated pvla"
1653 gdb_breakpoint [gdb_get_line_number "pvla-associated"]
1654 gdb_continue_to_breakpoint "pvla-associated"
1655 gdb_test "print sizeof(pvla)" " = 4000" "print sizeof associated pvla"
1657 +gdb_breakpoint [gdb_get_line_number "vla1-neg-bounds"]
1658 +gdb_continue_to_breakpoint "vla1-neg-bounds"
1659 +gdb_test "print sizeof(vla1)" " = 480" "print sizeof vla1 negative bounds"
1660 diff --git a/gdb/testsuite/gdb.fortran/vla-stride.exp b/gdb/testsuite/gdb.fortran/vla-stride.exp
1661 new file mode 100644
1663 +++ b/gdb/testsuite/gdb.fortran/vla-stride.exp
1665 +# Copyright 2016 Free Software Foundation, Inc.
1667 +# This program is free software; you can redistribute it and/or modify
1668 +# it under the terms of the GNU General Public License as published by
1669 +# the Free Software Foundation; either version 3 of the License, or
1670 +# (at your option) any later version.
1672 +# This program is distributed in the hope that it will be useful,
1673 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1674 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1675 +# GNU General Public License for more details.
1677 +# You should have received a copy of the GNU General Public License
1678 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1680 +standard_testfile ".f90"
1682 +if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile} \
1683 + {debug f90 quiet}] } {
1687 +if ![runto MAIN__] then {
1688 + perror "couldn't run to breakpoint MAIN__"
1692 +gdb_breakpoint [gdb_get_line_number "re-reverse-elements"]
1693 +gdb_continue_to_breakpoint "re-reverse-elements"
1694 +gdb_test "print pvla" " = \\\(1, 2, 3, 4, 5, 6, 7, 8, 9, 10\\\)" \
1695 + "print re-reverse-elements"
1696 +gdb_test "print pvla(1)" " = 1" "print first re-reverse-element"
1697 +gdb_test "print pvla(10)" " = 10" "print last re-reverse-element"
1699 +gdb_breakpoint [gdb_get_line_number "odd-elements"]
1700 +gdb_continue_to_breakpoint "odd-elements"
1701 +gdb_test "print pvla" " = \\\(1, 3, 5, 7, 9\\\)" "print odd-elements"
1702 +gdb_test "print pvla(1)" " = 1" "print first odd-element"
1703 +gdb_test "print pvla(5)" " = 9" "print last odd-element"
1705 +gdb_breakpoint [gdb_get_line_number "single-element"]
1706 +gdb_continue_to_breakpoint "single-element"
1707 +gdb_test "print pvla" " = \\\(5\\\)" "print single-element"
1708 +gdb_test "print pvla(1)" " = 5" "print one single-element"
1709 diff --git a/gdb/testsuite/gdb.fortran/vla-stride.f90 b/gdb/testsuite/gdb.fortran/vla-stride.f90
1710 new file mode 100644
1712 +++ b/gdb/testsuite/gdb.fortran/vla-stride.f90
1714 +! Copyright 2016 Free Software Foundation, Inc.
1716 +! This program is free software; you can redistribute it and/or modify
1717 +! it under the terms of the GNU General Public License as published by
1718 +! the Free Software Foundation; either version 3 of the License, or
1719 +! (at your option) any later version.
1721 +! This program is distributed in the hope that it will be useful,
1722 +! but WITHOUT ANY WARRANTY; without even the implied warranty of
1723 +! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1724 +! GNU General Public License for more details.
1726 +! You should have received a copy of the GNU General Public License
1727 +! along with this program. If not, see <http://www.gnu.org/licenses/>.
1730 + integer, target, allocatable :: vla (:)
1731 + integer, pointer :: pvla (:)
1734 + vla = (/ (I, I = 1,10) /)
1736 + pvla => vla(10:1:-1)
1737 + pvla => pvla(10:1:-1)
1738 + pvla => vla(1:10:2) ! re-reverse-elements
1739 + pvla => vla(5:4:-2) ! odd-elements
1741 + pvla => null() ! single-element
1742 +end program vla_stride
1743 diff --git a/gdb/testsuite/gdb.fortran/vla.f90 b/gdb/testsuite/gdb.fortran/vla.f90
1744 --- a/gdb/testsuite/gdb.fortran/vla.f90
1745 +++ b/gdb/testsuite/gdb.fortran/vla.f90
1746 @@ -54,4 +54,14 @@ program vla
1748 allocate (vla3 (2,2)) ! vla2-deallocated
1751 + allocate (vla1 (-2:1, -5:4, -3:-1))
1752 + l = allocated(vla1)
1755 + vla1(-2, -3, -1) = -231
1757 + deallocate (vla1) ! vla1-neg-bounds
1758 + l = allocated(vla1)
1761 diff --git a/gdb/valarith.c b/gdb/valarith.c
1762 --- a/gdb/valarith.c
1763 +++ b/gdb/valarith.c
1764 @@ -187,10 +187,16 @@ value_subscripted_rvalue (struct value *array, LONGEST index, int lowerbound)
1765 struct type *array_type = check_typedef (value_type (array));
1766 struct type *elt_type = check_typedef (TYPE_TARGET_TYPE (array_type));
1767 ULONGEST elt_size = type_length_units (elt_type);
1768 - ULONGEST elt_offs = elt_size * (index - lowerbound);
1769 + LONGEST elt_offs = index - lowerbound;
1770 + LONGEST elt_stride = TYPE_BYTE_STRIDE (TYPE_INDEX_TYPE (array_type));
1772 + if (elt_stride != 0)
1773 + elt_offs *= elt_stride;
1775 + elt_offs *= elt_size;
1777 if (index < lowerbound || (!TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (array_type)
1778 - && elt_offs >= type_length_units (array_type)))
1779 + && abs (elt_offs) >= type_length_units (array_type)))
1781 if (type_not_associated (array_type))
1782 error (_("no such vector element (vector not associated)"));
1783 diff --git a/gdb/valops.c b/gdb/valops.c
1786 @@ -3808,56 +3808,195 @@ value_of_this_silent (const struct language_defn *lang)
1789 value_slice (struct value *array, int lowbound, int length)
1791 + /* Pass unaltered arguments to VALUE_SLICE_1, plus a default stride
1792 + value of '1', which returns every element between LOWBOUND and
1793 + (LOWBOUND + LENGTH). We also provide a default CALL_COUNT of '1'
1794 + as we are only considering the highest dimension, or we are
1795 + working on a one dimensional array. So we call VALUE_SLICE_1
1797 + return value_slice_1 (array, lowbound, length, 1, 1);
1800 +/* VALUE_SLICE_1 is called for each array dimension to calculate the number
1801 + of elements as defined by the subscript expression.
1802 + CALL_COUNT is used to determine if we are calling the function once, e.g.
1803 + we are working on the current dimension of ARRAY, or if we are calling
1804 + the function repeatedly. In the later case we need to take elements
1805 + from the TARGET_TYPE of ARRAY.
1806 + With a CALL_COUNT greater than 1 we calculate the offsets for every element
1807 + that should be in the result array. Then we fetch the contents and then
1808 + copy them into the result array. The result array will have one dimension
1809 + less than the input array, so later on we need to recreate the indices and
1810 + ranges in the calling function. */
1813 +value_slice_1 (struct value *array, int lowbound, int length,
1814 + int stride_length, int call_count)
1816 struct type *slice_range_type, *slice_type, *range_type;
1817 - LONGEST lowerbound, upperbound;
1818 - struct value *slice;
1819 - struct type *array_type;
1820 + struct type *array_type = check_typedef (value_type (array));
1821 + struct type *elt_type = check_typedef (TYPE_TARGET_TYPE (array_type));
1822 + unsigned int elt_size, elt_offs;
1823 + LONGEST ary_high_bound, ary_low_bound;
1825 + int slice_range_size, i = 0, row_count = 1, elem_count = 1;
1827 - array_type = check_typedef (value_type (array));
1828 + /* Check for legacy code if we are actually dealing with an array or
1830 if (TYPE_CODE (array_type) != TYPE_CODE_ARRAY
1831 && TYPE_CODE (array_type) != TYPE_CODE_STRING)
1832 error (_("cannot take slice of non-array"));
1834 - range_type = TYPE_INDEX_TYPE (array_type);
1835 - if (get_discrete_bounds (range_type, &lowerbound, &upperbound) < 0)
1836 - error (_("slice from bad array or bitstring"));
1837 + ary_low_bound = TYPE_LOW_BOUND (TYPE_INDEX_TYPE (array_type));
1838 + ary_high_bound = TYPE_HIGH_BOUND (TYPE_INDEX_TYPE (array_type));
1840 + /* When we are working on a multi-dimensional array, we need to get the
1841 + attributes of the underlying type. */
1842 + if (call_count > 1)
1844 + ary_low_bound = TYPE_LOW_BOUND (TYPE_INDEX_TYPE (elt_type));
1845 + ary_high_bound = TYPE_HIGH_BOUND (TYPE_INDEX_TYPE (elt_type));
1846 + elt_type = check_typedef (TYPE_TARGET_TYPE (elt_type));
1847 + row_count = TYPE_LENGTH (array_type)
1848 + / TYPE_LENGTH (TYPE_TARGET_TYPE (array_type));
1851 + /* With a stride of '1', the number of elements per result row is equal to
1852 + the LENGTH of the subarray. With non-default stride values, we skip
1853 + elements, but have to add the start element to the total number of
1854 + elements per row. */
1855 + if (stride_length == 1)
1856 + elem_count = length;
1858 + elem_count = ((length - 1) / stride_length) + 1;
1860 + elt_size = TYPE_LENGTH (elt_type);
1861 + elt_offs = lowbound - ary_low_bound;
1863 - if (lowbound < lowerbound || length < 0
1864 - || lowbound + length - 1 > upperbound)
1865 - error (_("slice out of range"));
1866 + elt_offs *= elt_size;
1868 + /* Check for valid user input. In case of Fortran this was already done
1869 + in the calling function. */
1870 + if (call_count == 1
1871 + && (!TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (array_type)
1872 + && elt_offs >= TYPE_LENGTH (array_type)))
1873 + error (_("no such vector element"));
1875 + /* CALL_COUNT is 1 when we are dealing either with the highest dimension
1876 + of the array, or a one dimensional array. Set RANGE_TYPE accordingly.
1877 + In both cases we calculate how many rows/elements will be in the output
1878 + array by setting slice_range_size. */
1879 + if (call_count == 1)
1881 + range_type = TYPE_INDEX_TYPE (array_type);
1882 + slice_range_size = ary_low_bound + elem_count - 1;
1884 + /* Check if the array bounds are valid. */
1885 + if (get_discrete_bounds (range_type, &ary_low_bound, &ary_high_bound) < 0)
1886 + error (_("slice from bad array or bitstring"));
1888 + /* When CALL_COUNT is greater than 1, we are dealing with an array of arrays.
1889 + So we need to get the type below the current one and set the RANGE_TYPE
1893 + range_type = TYPE_INDEX_TYPE (TYPE_TARGET_TYPE (array_type));
1894 + slice_range_size = ary_low_bound + (row_count * elem_count) - 1;
1895 + ary_low_bound = TYPE_LOW_BOUND (range_type);
1898 /* FIXME-type-allocation: need a way to free this type when we are
1900 - slice_range_type = create_static_range_type ((struct type *) NULL,
1901 - TYPE_TARGET_TYPE (range_type),
1903 - lowbound + length - 1);
1906 + slice_range_type = create_static_range_type (NULL, TYPE_TARGET_TYPE (range_type),
1907 + ary_low_bound, slice_range_size);
1909 - struct type *element_type = TYPE_TARGET_TYPE (array_type);
1911 - = (lowbound - lowerbound) * TYPE_LENGTH (check_typedef (element_type));
1912 + struct type *element_type;
1914 + /* When both CALL_COUNT and STRIDE_LENGTH equal 1, we can use the legacy
1915 + code for subarrays. */
1916 + if (call_count == 1 && stride_length == 1)
1918 + element_type = TYPE_TARGET_TYPE (array_type);
1920 + slice_type = create_array_type (NULL, element_type, slice_range_type);
1922 - slice_type = create_array_type ((struct type *) NULL,
1924 - slice_range_type);
1925 - TYPE_CODE (slice_type) = TYPE_CODE (array_type);
1926 + TYPE_CODE (slice_type) = TYPE_CODE (array_type);
1928 - if (VALUE_LVAL (array) == lval_memory && value_lazy (array))
1929 - slice = allocate_value_lazy (slice_type);
1930 + if (VALUE_LVAL (array) == lval_memory && value_lazy (array))
1931 + v = allocate_value_lazy (slice_type);
1934 + v = allocate_value (slice_type);
1935 + value_contents_copy (v,
1936 + value_embedded_offset (v),
1938 + value_embedded_offset (array) + elt_offs,
1939 + elt_size * longest_to_int (length));
1943 + /* With a CALL_COUNT or STRIDE_LENGTH are greater than 1 we are working
1944 + on a range of ranges. So we copy the relevant elements into the
1945 + new array we return. */
1948 - slice = allocate_value (slice_type);
1949 - value_contents_copy (slice, 0, array, offset,
1950 - type_length_units (slice_type));
1951 + int j, offs_store = elt_offs;
1952 + LONGEST dst_offset = 0;
1953 + LONGEST src_row_length = TYPE_LENGTH (TYPE_TARGET_TYPE (array_type));
1955 + if (call_count == 1)
1957 + /* When CALL_COUNT is equal to 1 we are working on the current range
1958 + and use these elements directly. */
1959 + element_type = TYPE_TARGET_TYPE (array_type);
1963 + /* Working on an array of arrays, the type of the elements is the type
1964 + of the subarrays' type. */
1965 + element_type = TYPE_TARGET_TYPE (TYPE_TARGET_TYPE (array_type));
1968 + slice_type = create_array_type (NULL, element_type, slice_range_type);
1970 + /* If we have a one dimensional array, we copy its TYPE_CODE. For a
1971 + multi dimensional array we copy the embedded type's TYPE_CODE. */
1972 + if (call_count == 1)
1973 + TYPE_CODE (slice_type) = TYPE_CODE (array_type);
1975 + TYPE_CODE (slice_type) = TYPE_CODE (TYPE_TARGET_TYPE (array_type));
1977 + v = allocate_value (slice_type);
1979 + /* Iterate through the rows of the outer array and set the new offset
1981 + for (i = 0; i < row_count; i++)
1983 + elt_offs = offs_store + i * src_row_length;
1985 + /* Iterate through the elements in each row to copy only those. */
1986 + for (j = 1; j <= elem_count; j++)
1988 + /* Fetches the contents of ARRAY and copies them into V. */
1989 + value_contents_copy (v, dst_offset, array, elt_offs, elt_size);
1990 + elt_offs += elt_size * stride_length;
1991 + dst_offset += elt_size;
1996 - set_value_component_location (slice, array);
1997 - set_value_offset (slice, value_offset (array) + offset);
1998 + set_value_component_location (v, array);
1999 + if (VALUE_LVAL (v) == lval_register)
2001 + VALUE_REGNUM (v) = VALUE_REGNUM (array);
2002 + VALUE_NEXT_FRAME_ID (v) = VALUE_NEXT_FRAME_ID (array);
2004 + set_value_offset (v, value_offset (array) + elt_offs);
2011 /* Create a value for a FORTRAN complex number. Currently most of the
2012 diff --git a/gdb/value.h b/gdb/value.h
2015 @@ -1139,6 +1139,8 @@ extern struct value *varying_to_slice (struct value *);
2017 extern struct value *value_slice (struct value *, int, int);
2019 +extern struct value *value_slice_1 (struct value *, int, int, int, int);
2021 extern struct value *value_literal_complex (struct value *, struct value *,