]> git.pld-linux.org Git - packages/gdb.git/blame - gdb-vla-intel-fortran-strides.patch
- up to 8.2.1; disable guile for now (guile 2.2 is not supported)
[packages/gdb.git] / gdb-vla-intel-fortran-strides.patch
CommitLineData
4b0e5c1b
AM
1From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
2From: Fedora GDB patches <invalid@email.com>
3Date: Fri, 27 Oct 2017 21:07:50 +0200
4Subject: gdb-vla-intel-fortran-strides.patch
5
4b0e5c1b
AM
6;; VLA (Fortran dynamic arrays) from Intel + archer-jankratochvil-vla tests.
7;;=push
8
140f8057
JR
9git diff --stat -p gdb/master...gdb/users/bheckel/fortran-strides
10dbfd7140bf4c0500d1f5d192be781f83f78f7922
11
12 gdb/dwarf2loc.c | 46 ++-
13 gdb/dwarf2loc.h | 6 +
14 gdb/dwarf2read.c | 13 +-
15 gdb/eval.c | 391 +++++++++++++++++++++-----
16 gdb/expprint.c | 20 +-
17 gdb/expression.h | 18 +-
18 gdb/f-exp.y | 42 ++-
19 gdb/f-valprint.c | 8 +-
20 gdb/gdbtypes.c | 34 ++-
21 gdb/gdbtypes.h | 18 +-
22 gdb/parse.c | 24 +-
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 +++++++++++--
34 gdb/value.h | 2 +
35 23 files changed, 1242 insertions(+), 183 deletions(-)
36
4b0e5c1b 37diff --git a/gdb/dwarf2loc.c b/gdb/dwarf2loc.c
4b0e5c1b
AM
38--- a/gdb/dwarf2loc.c
39+++ b/gdb/dwarf2loc.c
ed003b1c 40@@ -2600,11 +2600,14 @@ dwarf2_locexpr_baton_eval (const struct dwarf2_locexpr_baton *dlbaton,
140f8057
JR
41 /* See dwarf2loc.h. */
42
43 int
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,
48- CORE_ADDR *value)
49+ CORE_ADDR *value,
50+ int is_signed)
51 {
52+ int rc = 0;
53+
54 if (prop == NULL)
55 return 0;
56
ed003b1c 57@@ -2628,7 +2631,7 @@ dwarf2_evaluate_property (const struct dynamic_prop *prop,
140f8057
JR
58
59 *value = value_as_address (val);
60 }
61- return 1;
62+ rc = 1;
63 }
64 }
65 break;
ed003b1c 66@@ -2650,7 +2653,7 @@ dwarf2_evaluate_property (const struct dynamic_prop *prop,
140f8057
JR
67 if (!value_optimized_out (val))
68 {
69 *value = value_as_address (val);
70- return 1;
71+ rc = 1;
72 }
73 }
74 }
ed003b1c 75@@ -2658,8 +2661,8 @@ dwarf2_evaluate_property (const struct dynamic_prop *prop,
140f8057
JR
76
77 case PROP_CONST:
78 *value = prop->data.const_val;
79- return 1;
80-
81+ rc = 1;
82+ break;
83 case PROP_ADDR_OFFSET:
84 {
85 struct dwarf2_property_baton *baton
ed003b1c 86@@ -2680,11 +2683,38 @@ dwarf2_evaluate_property (const struct dynamic_prop *prop,
140f8057
JR
87 val = value_at (baton->offset_info.type,
88 pinfo->addr + baton->offset_info.offset);
89 *value = value_as_address (val);
90- return 1;
91+ rc = 1;
92 }
93+ break;
4b0e5c1b
AM
94 }
95
96- return 0;
140f8057
JR
97+ if (rc == 1 && is_signed == 1)
98+ {
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));
105+
106+ /* Check if signed bit is set and sign-extend values. */
107+ if (*value & (neg_mask))
108+ *value |= (neg_mask );
4b0e5c1b 109+ }
140f8057
JR
110+ return rc;
111+}
4b0e5c1b 112+
140f8057
JR
113+int
114+dwarf2_evaluate_property (const struct dynamic_prop *prop,
115+ struct frame_info *frame,
116+ struct property_addr_info *addr_stack,
117+ CORE_ADDR *value)
118+{
119+ return dwarf2_evaluate_property_signed (prop,
120+ frame,
121+ addr_stack,
122+ value,
123+ 0);
124 }
125
126 /* See dwarf2loc.h. */
4b0e5c1b 127diff --git a/gdb/dwarf2loc.h b/gdb/dwarf2loc.h
4b0e5c1b
AM
128--- a/gdb/dwarf2loc.h
129+++ b/gdb/dwarf2loc.h
130@@ -143,6 +143,12 @@ int dwarf2_evaluate_property (const struct dynamic_prop *prop,
140f8057
JR
131 struct property_addr_info *addr_stack,
132 CORE_ADDR *value);
133
134+int dwarf2_evaluate_property_signed (const struct dynamic_prop *prop,
135+ struct frame_info *frame,
136+ struct property_addr_info *addr_stack,
137+ CORE_ADDR *value,
138+ int is_signed);
139+
140 /* A helper for the compiler interface that compiles a single dynamic
141 property to C code.
142
4b0e5c1b 143diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
4b0e5c1b
AM
144--- a/gdb/dwarf2read.c
145+++ b/gdb/dwarf2read.c
ed003b1c 146@@ -17566,7 +17566,7 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
140f8057
JR
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;
154 const char *name;
ed003b1c 155@@ -17586,7 +17586,9 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
140f8057
JR
156
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;
162
163 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
164 omitting DW_AT_lower_bound. */
ed003b1c 165@@ -17619,6 +17621,14 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
140f8057
JR
166 break;
167 }
168
169+ attr = dwarf2_attr (die, DW_AT_byte_stride, cu);
170+ if (attr)
171+ if (!attr_to_dynamic_prop (attr, die, cu, &stride))
ed003b1c
AM
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));
140f8057
JR
176+
177 attr = dwarf2_attr (die, DW_AT_lower_bound, cu);
178 if (attr)
179 attr_to_dynamic_prop (attr, die, cu, &low);
ed003b1c 180@@ -17696,7 +17706,7 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
140f8057
JR
181 && !TYPE_UNSIGNED (base_type) && (high.data.const_val & negative_mask))
182 high.data.const_val |= negative_mask;
183
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);
186
187 if (high_bound_is_count)
188 TYPE_RANGE_DATA (range_type)->flag_upper_bound_is_count = 1;
4b0e5c1b 189diff --git a/gdb/eval.c b/gdb/eval.c
4b0e5c1b
AM
190--- a/gdb/eval.c
191+++ b/gdb/eval.c
ed003b1c 192@@ -377,29 +377,325 @@ init_array_element (struct value *array, struct value *element,
140f8057
JR
193 return index;
194 }
195
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. */
202+
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)
208 {
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);
215-
216- *pos += 3;
4b0e5c1b
AM
217-
218- if (range_type == LOW_BOUND_DEFAULT || range_type == BOTH_BOUND_DEFAULT)
219- low_bound = TYPE_LOW_BOUND (range);
220- else
221- low_bound = value_as_long (evaluate_subexp (NULL_TYPE, exp, pos, noside));
140f8057
JR
222+ struct value *new_array = array;
223+ struct type *array_type = check_typedef (value_type (new_array));
224+ struct type *elt_type;
225+
226+ typedef struct subscript_range
227+ {
228+ enum range_type f90_range_type;
229+ LONGEST low, high, stride;
230+ } subscript_range;
231+
232+ typedef enum subscript_kind
233+ {
234+ SUBSCRIPT_RANGE, /* e.g. "(lowbound:highbound)" */
235+ SUBSCRIPT_INDEX /* e.g. "(literal)" */
236+ } kind;
237+
238+ /* Local struct to hold user data for Fortran subarray dimensions. */
239+ struct subscript_store
240+ {
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;
244+
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
251+ {
252+ subscript_range range;
253+ LONGEST number;
254+ } U;
255+ } *subscript_array;
256+
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
259+ dimension. */
260+ if (nargs != calc_f77_array_dims (value_type (new_array)))
261+ error (_("Wrong number of subscripts"));
262+
263+ subscript_array = (struct subscript_store*) alloca (sizeof (*subscript_array) * nargs);
264+
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++)
273+ {
274+ struct subscript_store *index = &subscript_array[i];
275
4b0e5c1b
AM
276- if (range_type == HIGH_BOUND_DEFAULT || range_type == BOTH_BOUND_DEFAULT)
277- high_bound = TYPE_HIGH_BOUND (range);
140f8057 278- else
4b0e5c1b 279- high_bound = value_as_long (evaluate_subexp (NULL_TYPE, exp, pos, noside));
140f8057
JR
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)
283+ {
284+ int pc = (*pos) + 1;
285+ subscript_range *range;
4b0e5c1b 286+
140f8057
JR
287+ index->kind = SUBSCRIPT_RANGE;
288+ range = &index->U.range;
289+
290+ *pos += 3;
291+ range->f90_range_type = (enum range_type) exp->elts[pc].longconst;
292+
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
295+ upper bound. */
296+ if ((range->f90_range_type & SUBARRAY_LOW_BOUND)
297+ == SUBARRAY_LOW_BOUND)
298+ range->low = value_as_long (evaluate_subexp (NULL_TYPE, exp,
299+ pos, noside));
300+ if ((range->f90_range_type & SUBARRAY_HIGH_BOUND)
301+ == SUBARRAY_HIGH_BOUND)
302+ range->high = value_as_long (evaluate_subexp (NULL_TYPE, exp,
303+ pos, noside));
304+
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,
308+ pos, noside));
309+
310+ /* Assign the default stride value '1'. */
311+ else
312+ range->stride = 1;
313+
314+ /* Check the provided stride value is illegal, aka '0'. */
315+ if (range->stride == 0)
316+ error (_("Stride must not be 0"));
317+ }
318+ /* User input is an index. E.g.: "p arry(5)". */
319+ else
320+ {
321+ struct value *val;
322+
323+ index->kind = SUBSCRIPT_INDEX;
324+
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);
329+ }
330+
331+ }
332+
333+ /* Traverse the array from right to left and set the high and low bounds
334+ for later use. */
335+ for (i = nargs - 1; i >= 0; i--)
336+ {
337+ struct subscript_store *index = &subscript_array[i];
338+ struct type *index_type = TYPE_INDEX_TYPE (array_type);
339+
340+ switch (index->kind)
341+ {
342+ case SUBSCRIPT_RANGE:
343+ {
344+
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;
350+
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);
355+
356+ if ((range->f90_range_type & SUBARRAY_HIGH_BOUND) == 0)
357+ range->high = TYPE_HIGH_BOUND (index_type);
358+
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)"));
366+
367+ /* For a negative stride the lower boundary must be larger than the
368+ upper boundary.
369+ For a positive stride the lower boundary must be smaller than the
370+ upper boundary. */
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"));
374+
375+ }
376+ break;
377+
378+ case SUBSCRIPT_INDEX:
379+ break;
4b0e5c1b 380+
140f8057
JR
381+ }
382+
383+ array_type = TYPE_TARGET_TYPE (array_type);
384+ }
385+
386+ /* Reset ARRAY_TYPE before slicing.*/
387+ array_type = check_typedef (value_type (new_array));
388+
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--)
394+ {
395+ struct subscript_store *index = &subscript_array[i];
396+ struct type *index_type = TYPE_INDEX_TYPE (array_type);
397+
398+ switch (index->kind)
399+ {
400+ case SUBSCRIPT_RANGE:
401+ {
402+
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;
408+
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. */
413+ dim_count++;
414+
415+ new_array
416+ = value_slice_1 (new_array, range->low,
417+ range->high - range->low + 1,
418+ range->stride, dim_count);
419+ }
420+ break;
421+
422+ case SUBSCRIPT_INDEX:
423+ {
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)
431+ new_array
432+ = value_subscripted_rvalue (new_array, index->U.number,
433+ f77_get_lowerbound (value_type
434+ (new_array)));
435+ else
436+ {
437+ dim_count++;
438+
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)"));
447+
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)"));
451+
452+ new_array = value_slice_1 (new_array,
453+ index->U.number,
454+ 1, /* COUNT is '1' element */
455+ 1, /* STRIDE set to '1' */
456+ dim_count);
457+ }
458+
459+ }
460+ break;
461+ }
462+ array_type = TYPE_TARGET_TYPE (array_type);
463+ }
464+
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
468+ correctly.
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.
471+ E.g.:
472+ "p ary(3, 7, 2:15)" in Fortran has only 1 dimension, but we calculated 3
473+ ranges.
474+ "p ary(3, 7:12, 4)" in Fortran has only 1 dimension, but we calculated 2
475+ ranges.
476+ "p ary(2:4, 5, 7)" in Fortran has only 1 dimension, and we calculated 1
477+ range. */
478+ if (dim_count > 1)
479+ {
480+ struct value *v = NULL;
481+
482+ elt_type = TYPE_TARGET_TYPE (value_type (new_array));
483+
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++)
492+ {
493+ struct subscript_store *index = &subscript_array[i];
494+
495+ if (index->kind == SUBSCRIPT_RANGE)
496+ {
497+ struct type *range_type, *interim_array_type;
498+
499+ int new_length;
4b0e5c1b
AM
500
501- return value_slice (array, low_bound, high_bound - low_bound + 1);
140f8057
JR
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;
506+
507+ new_length /= index->U.range.stride;
508+
509+ range_type
510+ = create_static_range_type (NULL,
511+ elt_type,
512+ index->U.range.low,
513+ index->U.range.low + new_length);
514+
515+ interim_array_type = create_array_type (NULL,
516+ elt_type,
517+ range_type);
518+
519+ TYPE_CODE (interim_array_type)
520+ = TYPE_CODE (value_type (new_array));
521+
522+ v = allocate_value (interim_array_type);
523+
524+ elt_type = value_type (v);
525+ }
526+
527+ }
528+ value_contents_copy (v, 0, new_array, 0, TYPE_LENGTH (elt_type));
529+ return v;
530+ }
531+
532+ return new_array;
533 }
534
535
ed003b1c 536@@ -1926,19 +2222,8 @@ evaluate_subexp_standard (struct type *expect_type,
140f8057
JR
537 switch (code)
538 {
539 case TYPE_CODE_ARRAY:
540- if (exp->elts[*pos].opcode == OP_RANGE)
541- return value_f90_subarray (arg1, exp, pos, noside);
542- else
543- goto multi_f77_subscript;
544-
545 case TYPE_CODE_STRING:
546- if (exp->elts[*pos].opcode == OP_RANGE)
547- return value_f90_subarray (arg1, exp, pos, noside);
548- else
549- {
550- arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
551- return value_subscript (arg1, value_as_long (arg2));
552- }
553+ return value_f90_subarray (arg1, exp, pos, nargs, noside);
554
555 case TYPE_CODE_PTR:
556 case TYPE_CODE_FUNC:
ed003b1c 557@@ -2334,49 +2619,6 @@ evaluate_subexp_standard (struct type *expect_type,
140f8057
JR
558 }
559 return (arg1);
560
561- multi_f77_subscript:
562- {
563- LONGEST subscript_array[MAX_FORTRAN_DIMS];
564- int ndimensions = 1, i;
565- struct value *array = arg1;
566-
567- if (nargs > MAX_FORTRAN_DIMS)
568- error (_("Too many subscripts for F77 (%d Max)"), MAX_FORTRAN_DIMS);
569-
570- ndimensions = calc_f77_array_dims (type);
571-
572- if (nargs != ndimensions)
573- error (_("Wrong number of subscripts"));
574-
575- gdb_assert (nargs > 0);
576-
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. */
579-
580- /* Take array indices left to right. */
581- for (i = 0; i < nargs; i++)
582- {
583- /* Evaluate each subscript; it must be a legal integer in F77. */
584- arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
585-
586- /* Fill in the subscript array. */
587-
588- subscript_array[i] = value_as_long (arg2);
589- }
590-
591- /* Internal type of array is arranged right to left. */
592- for (i = nargs; i > 0; i--)
593- {
594- struct type *array_type = check_typedef (value_type (array));
595- LONGEST index = subscript_array[i - 1];
596-
597- array = value_subscripted_rvalue (array, index,
598- f77_get_lowerbound (array_type));
599- }
600-
601- return array;
602- }
603-
604 case BINOP_LOGICAL_AND:
605 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
606 if (noside == EVAL_SKIP)
ed003b1c 607@@ -3293,6 +3535,9 @@ calc_f77_array_dims (struct type *array_type)
140f8057
JR
608 int ndimen = 1;
609 struct type *tmp_type;
610
611+ if (TYPE_CODE (array_type) == TYPE_CODE_STRING)
612+ return 1;
613+
614 if ((TYPE_CODE (array_type) != TYPE_CODE_ARRAY))
615 error (_("Can't get dimensions for a non-array type"));
616
4b0e5c1b 617diff --git a/gdb/expprint.c b/gdb/expprint.c
4b0e5c1b
AM
618--- a/gdb/expprint.c
619+++ b/gdb/expprint.c
ed003b1c
AM
620@@ -578,17 +578,14 @@ print_subexp_standard (struct expression *exp, int *pos,
621 longest_to_int (exp->elts[pc + 1].longconst);
140f8057
JR
622 *pos += 2;
623
ed003b1c
AM
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);
140f8057
JR
629 fputs_filtered ("RANGE(", stream);
630- if (range_type == HIGH_BOUND_DEFAULT
ed003b1c
AM
631- || range_type == NONE_BOUND_DEFAULT
632- || range_type == NONE_BOUND_DEFAULT_EXCLUSIVE)
140f8057
JR
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);
641 return;
ed003b1c 642@@ -1098,22 +1095,24 @@ dump_subexp_body_standard (struct expression *exp,
140f8057
JR
643
644 switch (range_type)
645 {
646- case BOTH_BOUND_DEFAULT:
647+ case SUBARRAY_NONE_BOUND:
648 fputs_filtered ("Range '..'", stream);
649 break;
650- case LOW_BOUND_DEFAULT:
651+ case SUBARRAY_HIGH_BOUND:
652 fputs_filtered ("Range '..EXP'", stream);
653 break;
ed003b1c
AM
654- case LOW_BOUND_DEFAULT_EXCLUSIVE:
655- fputs_filtered ("ExclusiveRange '..EXP'", stream);
656- break;
140f8057
JR
657- case HIGH_BOUND_DEFAULT:
658+ case SUBARRAY_LOW_BOUND:
659 fputs_filtered ("Range 'EXP..'", stream);
660 break;
661- case NONE_BOUND_DEFAULT:
ed003b1c
AM
662+ case (SUBARRAY_LOW_BOUND
663+ | SUBARRAY_HIGH_BOUND
664+ | SUBARRAY_HIGH_BOUND_EXCLUSIVE):
665+ fputs_filtered ("ExclusiveRange '..EXP'", stream);
666+ break;
140f8057
JR
667+ case (SUBARRAY_LOW_BOUND | SUBARRAY_HIGH_BOUND):
668 fputs_filtered ("Range 'EXP..EXP'", stream);
669 break;
ed003b1c
AM
670- case NONE_BOUND_DEFAULT_EXCLUSIVE:
671+ case (SUBARRAY_HIGH_BOUND | SUBARRAY_HIGH_BOUND_EXCLUSIVE):
672 fputs_filtered ("ExclusiveRange 'EXP..EXP'", stream);
673 break;
140f8057 674 default:
ed003b1c 675@@ -1121,11 +1120,9 @@ dump_subexp_body_standard (struct expression *exp,
140f8057
JR
676 break;
677 }
678
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);
687 }
688 break;
4b0e5c1b 689diff --git a/gdb/expression.h b/gdb/expression.h
4b0e5c1b
AM
690--- a/gdb/expression.h
691+++ b/gdb/expression.h
ed003b1c 692@@ -148,28 +148,27 @@ extern void dump_raw_expression (struct expression *,
140f8057
JR
693 struct ui_file *, const char *);
694 extern void dump_prefix_expression (struct expression *, struct ui_file *);
695
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
ed003b1c
AM
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. */
706
140f8057 707 enum range_type
ed003b1c
AM
708-{
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. */
713- LOW_BOUND_DEFAULT,
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,
723-};
724+ {
140f8057
JR
725+ SUBARRAY_NONE_BOUND = 0x0, /* "( : )" */
726+ SUBARRAY_LOW_BOUND = 0x1, /* "(low:)" */
727+ SUBARRAY_HIGH_BOUND = 0x2, /* "(:high)" */
ed003b1c
AM
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),
738+ };
140f8057
JR
739
740 #endif /* !defined (EXPRESSION_H) */
4b0e5c1b 741diff --git a/gdb/f-exp.y b/gdb/f-exp.y
4b0e5c1b
AM
742--- a/gdb/f-exp.y
743+++ b/gdb/f-exp.y
744@@ -257,31 +257,63 @@ arglist : subrange
140f8057
JR
745
746 arglist : arglist ',' exp %prec ABOVE_COMMA
747 { arglist_len++; }
748+ | arglist ',' subrange %prec ABOVE_COMMA
749+ { arglist_len++; }
750 ;
751
752 /* There are four sorts of subrange types in F90. */
753
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); }
761 ;
762
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); }
768 ;
769
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); }
775 ;
776
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); }
782+ ;
783+
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); }
791+ ;
792+
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); }
798+ ;
799+
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); }
805+ ;
806+
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); }
811 ;
812
4b0e5c1b 813diff --git a/gdb/f-valprint.c b/gdb/f-valprint.c
4b0e5c1b
AM
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,
140f8057
JR
817
818 if (nss != ndimensions)
819 {
820- size_t dim_size = TYPE_LENGTH (TYPE_TARGET_TYPE (type));
821+ size_t dim_size;
822 size_t offs = 0;
823+ LONGEST byte_stride = abs (TYPE_BYTE_STRIDE (range_type));
824+
825+ if (byte_stride)
826+ dim_size = byte_stride;
827+ else
828+ dim_size = TYPE_LENGTH (TYPE_TARGET_TYPE (type));
829
830 for (i = lowerbound;
831 (i < upperbound + 1 && (*elts) < options->print_max);
4b0e5c1b 832diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
4b0e5c1b
AM
833--- a/gdb/gdbtypes.c
834+++ b/gdb/gdbtypes.c
835@@ -902,7 +902,8 @@ operator== (const range_bounds &l, const range_bounds &r)
140f8057
JR
836 struct type *
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)
842 {
843 if (result_type == NULL)
844 result_type = alloc_type_copy (index_type);
4b0e5c1b 845@@ -917,6 +918,7 @@ create_range_type (struct type *result_type, struct type *index_type,
140f8057
JR
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;
850
851 if (low_bound->kind == PROP_CONST && low_bound->data.const_val >= 0)
852 TYPE_UNSIGNED (result_type) = 1;
4b0e5c1b 853@@ -945,7 +947,7 @@ struct type *
140f8057
JR
854 create_static_range_type (struct type *result_type, struct type *index_type,
855 LONGEST low_bound, LONGEST high_bound)
856 {
857- struct dynamic_prop low, high;
858+ struct dynamic_prop low, high, stride;
859
860 low.kind = PROP_CONST;
861 low.data.const_val = low_bound;
4b0e5c1b 862@@ -953,7 +955,11 @@ create_static_range_type (struct type *result_type, struct type *index_type,
140f8057
JR
863 high.kind = PROP_CONST;
864 high.data.const_val = high_bound;
865
866- result_type = create_range_type (result_type, index_type, &low, &high);
867+ stride.kind = PROP_CONST;
868+ stride.data.const_val = 0;
869+
870+ result_type = create_range_type (result_type, index_type,
871+ &low, &high, &stride);
872
873 return result_type;
874 }
4b0e5c1b 875@@ -1171,16 +1177,20 @@ create_array_type_with_stride (struct type *result_type,
140f8057
JR
876 && (!type_not_associated (result_type)
877 && !type_not_allocated (result_type)))
878 {
879- LONGEST low_bound, high_bound;
880+ LONGEST low_bound, high_bound, byte_stride;
881
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));
886+
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;
ed003b1c 897@@ -1981,12 +1991,12 @@ resolve_dynamic_range (struct type *dyn_range_type,
140f8057
JR
898 CORE_ADDR value;
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;
903
904 gdb_assert (TYPE_CODE (dyn_range_type) == TYPE_CODE_RANGE);
905
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))
909 {
910 low_bound.kind = PROP_CONST;
911 low_bound.data.const_val = value;
ed003b1c 912@@ -1998,7 +2008,7 @@ resolve_dynamic_range (struct type *dyn_range_type,
140f8057
JR
913 }
914
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))
918 {
919 high_bound.kind = PROP_CONST;
920 high_bound.data.const_val = value;
ed003b1c 921@@ -2013,12 +2023,20 @@ resolve_dynamic_range (struct type *dyn_range_type,
140f8057
JR
922 high_bound.data.const_val = 0;
923 }
924
925+ prop = &TYPE_RANGE_DATA (dyn_range_type)->stride;
926+ if (dwarf2_evaluate_property_signed (prop, NULL, addr_stack, &value, 1))
927+ {
928+ stride.kind = PROP_CONST;
929+ stride.data.const_val = value;
930+ }
931+
932 static_target_type
933 = resolve_dynamic_type_internal (TYPE_TARGET_TYPE (dyn_range_type),
934 addr_stack, 0);
935 static_range_type = create_range_type (copy_type (dyn_range_type),
936 static_target_type,
937- &low_bound, &high_bound);
938+ &low_bound, &high_bound, &stride);
939+
940 TYPE_RANGE_DATA (static_range_type)->flag_bound_evaluated = 1;
941 return static_range_type;
942 }
4b0e5c1b 943diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
4b0e5c1b
AM
944--- a/gdb/gdbtypes.h
945+++ b/gdb/gdbtypes.h
ed003b1c 946@@ -612,6 +612,10 @@ struct range_bounds
140f8057
JR
947
948 struct dynamic_prop high;
949
950+ /* * Stride of range. */
951+
952+ struct dynamic_prop stride;
953+
954 /* True if HIGH range bound contains the number of elements in the
955 subrange. This affects how the final hight bound is computed. */
956
ed003b1c 957@@ -776,7 +780,6 @@ struct main_type
140f8057
JR
958 /* * Union member used for range types. */
959
960 struct range_bounds *bounds;
961-
962 } flds_bnds;
963
964 /* * Slot to point to additional language-specific fields of this
ed003b1c 965@@ -1329,6 +1332,15 @@ extern bool set_type_align (struct type *, ULONGEST);
140f8057
JR
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
977+
978
979 /* Property accessors for the type data location. */
980 #define TYPE_DATA_LOCATION(thistype) \
ed003b1c 981@@ -1363,6 +1375,9 @@ extern bool set_type_align (struct type *, ULONGEST);
140f8057
JR
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)
987+
988
989 #define TYPE_ARRAY_UPPER_BOUND_VALUE(arraytype) \
990 (TYPE_HIGH_BOUND(TYPE_INDEX_TYPE((arraytype))))
ed003b1c 991@@ -1892,6 +1907,7 @@ extern struct type *create_array_type_with_stride
4b0e5c1b 992 struct dynamic_prop *, unsigned int);
140f8057
JR
993
994 extern struct type *create_range_type (struct type *, struct type *,
140f8057 995+ const struct dynamic_prop *,
4b0e5c1b 996 const struct dynamic_prop *,
140f8057
JR
997 const struct dynamic_prop *);
998
4b0e5c1b 999diff --git a/gdb/parse.c b/gdb/parse.c
4b0e5c1b
AM
1000--- a/gdb/parse.c
1001+++ b/gdb/parse.c
ed003b1c 1002@@ -989,24 +989,20 @@ operator_length_standard (const struct expression *expr, int endpos,
140f8057
JR
1003
1004 case OP_RANGE:
1005 oplen = 3;
1006+ args = 0;
1007 range_type = (enum range_type)
1008 longest_to_int (expr->elts[endpos - 2].longconst);
1009
1010- switch (range_type)
1011- {
1012- case LOW_BOUND_DEFAULT:
ed003b1c 1013- case LOW_BOUND_DEFAULT_EXCLUSIVE:
140f8057
JR
1014- case HIGH_BOUND_DEFAULT:
1015- args = 1;
1016- break;
1017- case BOTH_BOUND_DEFAULT:
1018- args = 0;
1019- break;
1020- case NONE_BOUND_DEFAULT:
ed003b1c 1021- case NONE_BOUND_DEFAULT_EXCLUSIVE:
140f8057
JR
1022- args = 2;
1023- break;
1024- }
1025+ /* Increment the argument counter for each argument
1026+ provided by the user. */
1027+ if ((range_type & SUBARRAY_LOW_BOUND) == SUBARRAY_LOW_BOUND)
1028+ args++;
1029+
1030+ if ((range_type & SUBARRAY_HIGH_BOUND) == SUBARRAY_HIGH_BOUND)
1031+ args++;
1032+
1033+ if ((range_type & SUBARRAY_STRIDE) == SUBARRAY_STRIDE)
1034+ args++;
1035
1036 break;
1037
4b0e5c1b 1038diff --git a/gdb/rust-exp.y b/gdb/rust-exp.y
4b0e5c1b
AM
1039--- a/gdb/rust-exp.y
1040+++ b/gdb/rust-exp.y
ed003b1c 1041@@ -2478,24 +2478,28 @@ convert_ast_to_expression (struct parser_state *state,
140f8057
JR
1042
1043 case OP_RANGE:
1044 {
1045- enum range_type kind = BOTH_BOUND_DEFAULT;
1046+ enum range_type kind = SUBARRAY_NONE_BOUND;
1047
1048 if (operation->left.op != NULL)
1049 {
1050 convert_ast_to_expression (state, operation->left.op, top);
1051- kind = HIGH_BOUND_DEFAULT;
1052+ kind = SUBARRAY_LOW_BOUND;
1053 }
1054 if (operation->right.op != NULL)
1055 {
1056 convert_ast_to_expression (state, operation->right.op, top);
1057- if (kind == BOTH_BOUND_DEFAULT)
ed003b1c
AM
1058- kind = (operation->inclusive
1059- ? LOW_BOUND_DEFAULT : LOW_BOUND_DEFAULT_EXCLUSIVE);
1060+ if (kind == SUBARRAY_NONE_BOUND)
1061+ {
1062+ kind = (range_type) SUBARRAY_HIGH_BOUND;
1063+ if (!operation->inclusive)
1064+ kind = (range_type) (kind | SUBARRAY_HIGH_BOUND_EXCLUSIVE);
1065+ }
1066 else
1067 {
140f8057 1068- gdb_assert (kind == HIGH_BOUND_DEFAULT);
ed003b1c
AM
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);
1075 }
140f8057 1076 }
ed003b1c 1077 else
4b0e5c1b 1078diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
4b0e5c1b
AM
1079--- a/gdb/rust-lang.c
1080+++ b/gdb/rust-lang.c
ed003b1c 1081@@ -1149,13 +1149,11 @@ rust_range (struct expression *exp, int *pos, enum noside noside)
140f8057
JR
1082 kind = (enum range_type) longest_to_int (exp->elts[*pos + 1].longconst);
1083 *pos += 3;
1084
ed003b1c
AM
1085- if (kind == HIGH_BOUND_DEFAULT || kind == NONE_BOUND_DEFAULT
1086- || kind == NONE_BOUND_DEFAULT_EXCLUSIVE)
140f8057
JR
1087+ if ((kind & SUBARRAY_LOW_BOUND) == SUBARRAY_LOW_BOUND)
1088 low = evaluate_subexp (NULL_TYPE, exp, pos, noside);
ed003b1c
AM
1089- if (kind == LOW_BOUND_DEFAULT || kind == LOW_BOUND_DEFAULT_EXCLUSIVE
1090- || kind == NONE_BOUND_DEFAULT || kind == NONE_BOUND_DEFAULT_EXCLUSIVE)
140f8057
JR
1091+ if ((kind & SUBARRAY_HIGH_BOUND) == SUBARRAY_HIGH_BOUND)
1092 high = evaluate_subexp (NULL_TYPE, exp, pos, noside);
ed003b1c
AM
1093- bool inclusive = (kind == NONE_BOUND_DEFAULT || kind == LOW_BOUND_DEFAULT);
1094+ bool inclusive = (!((kind & SUBARRAY_HIGH_BOUND_EXCLUSIVE) == SUBARRAY_HIGH_BOUND_EXCLUSIVE));
140f8057
JR
1095
1096 if (noside == EVAL_SKIP)
ed003b1c
AM
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,
140f8057
JR
1099
1100 *low = 0;
1101 *high = 0;
1102- *kind = BOTH_BOUND_DEFAULT;
1103+ *kind = SUBARRAY_NONE_BOUND;
1104
1105 if (TYPE_NFIELDS (type) == 0)
1106 return;
ed003b1c 1107@@ -1252,15 +1250,14 @@ rust_compute_range (struct type *type, struct value *range,
140f8057
JR
1108 i = 0;
1109 if (strcmp (TYPE_FIELD_NAME (type, 0), "start") == 0)
1110 {
1111- *kind = HIGH_BOUND_DEFAULT;
1112+ *kind = SUBARRAY_LOW_BOUND;
1113 *low = value_as_long (value_field (range, 0));
1114 ++i;
1115 }
1116 if (TYPE_NFIELDS (type) > i
1117 && strcmp (TYPE_FIELD_NAME (type, i), "end") == 0)
1118 {
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));
ed003b1c
AM
1123
1124 if (rust_inclusive_range_type_p (type))
1125@@ -1278,7 +1275,7 @@ rust_subscript (struct expression *exp, int *pos, enum noside noside,
140f8057
JR
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;
1131 LONGEST high = 0;
1132 int want_slice = 0;
1133
ed003b1c 1134@@ -1376,7 +1373,7 @@ rust_subscript (struct expression *exp, int *pos, enum noside noside,
140f8057
JR
1135 error (_("Cannot subscript non-array type"));
1136
1137 if (want_slice
1138- && (kind == BOTH_BOUND_DEFAULT || kind == LOW_BOUND_DEFAULT))
1139+ && ((kind & SUBARRAY_LOW_BOUND) != SUBARRAY_LOW_BOUND))
1140 low = low_bound;
1141 if (low < 0)
1142 error (_("Index less than zero"));
ed003b1c 1143@@ -1394,7 +1391,7 @@ rust_subscript (struct expression *exp, int *pos, enum noside noside,
140f8057
JR
1144 CORE_ADDR addr;
1145 struct value *addrval, *tem;
1146
1147- if (kind == BOTH_BOUND_DEFAULT || kind == HIGH_BOUND_DEFAULT)
1148+ if ((kind & SUBARRAY_HIGH_BOUND) != SUBARRAY_HIGH_BOUND)
1149 high = high_bound;
1150 if (high < 0)
1151 error (_("High index less than zero"));
4b0e5c1b
AM
1152diff --git a/gdb/testsuite/gdb.fortran/static-arrays.exp b/gdb/testsuite/gdb.fortran/static-arrays.exp
1153new file mode 100644
4b0e5c1b
AM
1154--- /dev/null
1155+++ b/gdb/testsuite/gdb.fortran/static-arrays.exp
140f8057
JR
1156@@ -0,0 +1,421 @@
1157+# Copyright 2015 Free Software Foundation, Inc.
1158+#
1159+# Contributed by Intel Corp. <christoph.t.weinmann@intel.com>
1160+#
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.
1165+#
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.
1170+#
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/>.
1173+
1174+standard_testfile static-arrays.f90
1175+
1176+if { [prepare_for_testing $testfile.exp $testfile $srcfile {debug f90}] } {
1177+ return -1
1178+}
1179+
1180+if ![runto MAIN__] then {
1181+ perror "couldn't run to breakpoint MAIN__"
1182+ continue
1183+}
1184+
1185+gdb_breakpoint [gdb_get_line_number "BP1"]
1186+gdb_continue_to_breakpoint "BP1" ".*BP1.*"
1187+
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\\)" \
1190+ "print ar1."
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\\).*" \
1194+ "print ar1\(8:\)"
1195+gdb_test "print ar1\(:3\)" "\\$\[0-9\]+ = \\(1, 2, 3\\).*" \
1196+ "print ar1\(:3\)"
1197+gdb_test "print ar1\(:\)" "\\$\[0-9\]+ = \\(1, 2, 3, 4, 5, 6, 7, 8, 9\\)" \
1198+ "print ar1\(:\)"
1199+
1200+# Check assignment
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"
1212+
1213+# Test for subarrays of one dimensional arrays with literals
1214+ gdb_test "print ar1\(3\)" "\\$\[0-9\]+ = 3" \
1215+ "print ar1\(3\)"
1216+
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\)"
1227+
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\)"
1237+
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\)"
1247+
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\)"
1258+
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\)"
1271+
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\)"
1285+
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\)"
1298+
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\)"
1311+
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\)"
1324+
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\)"
1337+
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\)"
1350+
1351+
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\)"
1364+
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\)"
1374+
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\)"
1387+
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\)"
1401+
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\)"
1414+
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\)"
1427+
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\)"
1440+
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\)"
1453+
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\)"
1466+
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\)"
1479+
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\)"
1489+
1490+# Stride > 1
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\\)\
1506+ \\)" \
1507+ "print ar3\(2:6:2,5,4:7:3\)"
1508+
1509+# Stride < 0
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\\)\
1515+ \\)" \
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\\)\
1526+ \\)" \
1527+ "print ar3\(2:6:2,5,7:4:-3\)"
1528+
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)"
1536+
1537+gdb_test "p ar4\(7,-6:2:3,-7\)" \
1538+ "\\$\[0-9\]+ = \\(729, 759, 789\\)" \
1539+ "print ar4(7,-6:2:3,-7)"
1540+
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\\) \\)\
1548+ \\)" \
1549+ "print ar4(9:2:-2, -6:2:3, -6:-15:-3)"
1550+
1551+gdb_test "p ar4\(:,:,:\)" \
1552+ "\\$\[0-9\]+ = \\(\\( \\( 111, 211, 311, 411, 511, 611, 711,\
1553+ 811, .*" \
1554+ "print ar4(:,:,:)"
1555+
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" \
1576+ "Invalid cast." \
1577+ "Assignment of value to subarray"
4b0e5c1b
AM
1578diff --git a/gdb/testsuite/gdb.fortran/static-arrays.f90 b/gdb/testsuite/gdb.fortran/static-arrays.f90
1579new file mode 100644
4b0e5c1b
AM
1580--- /dev/null
1581+++ b/gdb/testsuite/gdb.fortran/static-arrays.f90
140f8057
JR
1582@@ -0,0 +1,55 @@
1583+! Copyright 2015 Free Software Foundation, Inc.
1584+!
1585+! Contributed by Intel Corp. <christoph.t.weinmann@intel.com>
1586+!
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.
1591+!
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.
1596+!
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/>.
1599+
1600+subroutine sub
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
1605+ integer :: i,j,k
1606+
1607+ ar1 = 1
1608+ ar2 = 1
1609+ ar3 = 1
1610+ ar4 = 4
1611+
1612+ ! Resulting array ar3 looks like ((( 111, 112, 113, 114,...)))
1613+ do i = 1, 9, 1
1614+ ar1(i) = i
1615+ do j = 1, 9, 1
1616+ ar2(i,j) = i*10 + j
1617+ do k = 1, 9, 1
1618+ ar3(i,j,k) = i*100 + j*10 + k
1619+ end do
1620+ end do
1621+ end do
1622+
1623+ do i = 1, 10, 1
1624+ do j = -7, 3, 1
1625+ do k = -15, -5, 1
1626+ ar4(i,j,k) = i*100 + (j+8)*10 + (k+16)
1627+ end do
1628+ end do
1629+ end do
1630+
1631+ ar1(1) = 11 !BP1
1632+ return
1633+end
1634+
1635+program testprog
1636+ call sub
1637+end
4b0e5c1b 1638diff --git a/gdb/testsuite/gdb.fortran/vla-ptype.exp b/gdb/testsuite/gdb.fortran/vla-ptype.exp
4b0e5c1b
AM
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"
140f8057
JR
1642 gdb_test "ptype vla2(5, 45, 20)" \
1643 "no such vector element \\\(vector not allocated\\\)" \
1644 "ptype vla2(5, 45, 20) not allocated"
1645+
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"
4b0e5c1b 1649diff --git a/gdb/testsuite/gdb.fortran/vla-sizeof.exp b/gdb/testsuite/gdb.fortran/vla-sizeof.exp
4b0e5c1b
AM
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"
140f8057
JR
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"
1656+
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"
4b0e5c1b
AM
1660diff --git a/gdb/testsuite/gdb.fortran/vla-stride.exp b/gdb/testsuite/gdb.fortran/vla-stride.exp
1661new file mode 100644
4b0e5c1b
AM
1662--- /dev/null
1663+++ b/gdb/testsuite/gdb.fortran/vla-stride.exp
140f8057
JR
1664@@ -0,0 +1,44 @@
1665+# Copyright 2016 Free Software Foundation, Inc.
1666+
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.
1671+#
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.
1676+#
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/>.
1679+
1680+standard_testfile ".f90"
1681+
1682+if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile} \
1683+ {debug f90 quiet}] } {
1684+ return -1
1685+}
1686+
1687+if ![runto MAIN__] then {
1688+ perror "couldn't run to breakpoint MAIN__"
1689+ continue
1690+}
1691+
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"
1698+
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"
1704+
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"
4b0e5c1b
AM
1709diff --git a/gdb/testsuite/gdb.fortran/vla-stride.f90 b/gdb/testsuite/gdb.fortran/vla-stride.f90
1710new file mode 100644
4b0e5c1b
AM
1711--- /dev/null
1712+++ b/gdb/testsuite/gdb.fortran/vla-stride.f90
140f8057
JR
1713@@ -0,0 +1,29 @@
1714+! Copyright 2016 Free Software Foundation, Inc.
1715+!
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.
1720+!
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.
1725+!
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/>.
1728+
1729+program vla_stride
1730+ integer, target, allocatable :: vla (:)
1731+ integer, pointer :: pvla (:)
1732+
1733+ allocate(vla(10))
1734+ vla = (/ (I, I = 1,10) /)
1735+
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
1740+
1741+ pvla => null() ! single-element
1742+end program vla_stride
4b0e5c1b 1743diff --git a/gdb/testsuite/gdb.fortran/vla.f90 b/gdb/testsuite/gdb.fortran/vla.f90
4b0e5c1b
AM
1744--- a/gdb/testsuite/gdb.fortran/vla.f90
1745+++ b/gdb/testsuite/gdb.fortran/vla.f90
1746@@ -54,4 +54,14 @@ program vla
140f8057
JR
1747
1748 allocate (vla3 (2,2)) ! vla2-deallocated
1749 vla3(:,:) = 13
1750+
1751+ allocate (vla1 (-2:1, -5:4, -3:-1))
1752+ l = allocated(vla1)
1753+
1754+ vla1(:, :, :) = 1
1755+ vla1(-2, -3, -1) = -231
1756+
1757+ deallocate (vla1) ! vla1-neg-bounds
1758+ l = allocated(vla1)
1759+
1760 end program vla
4b0e5c1b 1761diff --git a/gdb/valarith.c b/gdb/valarith.c
4b0e5c1b
AM
1762--- a/gdb/valarith.c
1763+++ b/gdb/valarith.c
ed003b1c 1764@@ -187,10 +187,16 @@ value_subscripted_rvalue (struct value *array, LONGEST index, int lowerbound)
140f8057
JR
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));
1771+
1772+ if (elt_stride != 0)
1773+ elt_offs *= elt_stride;
1774+ else
1775+ elt_offs *= elt_size;
1776
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)))
1780 {
1781 if (type_not_associated (array_type))
1782 error (_("no such vector element (vector not associated)"));
4b0e5c1b 1783diff --git a/gdb/valops.c b/gdb/valops.c
4b0e5c1b
AM
1784--- a/gdb/valops.c
1785+++ b/gdb/valops.c
ed003b1c 1786@@ -3808,56 +3808,195 @@ value_of_this_silent (const struct language_defn *lang)
4b0e5c1b 1787
140f8057
JR
1788 struct value *
1789 value_slice (struct value *array, int lowbound, int length)
4b0e5c1b 1790+{
140f8057
JR
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
1796+ exactly once. */
1797+ return value_slice_1 (array, lowbound, length, 1, 1);
1798+}
1799+
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. */
1811+
1812+struct value *
1813+value_slice_1 (struct value *array, int lowbound, int length,
1814+ int stride_length, int call_count)
4b0e5c1b 1815 {
140f8057
JR
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;
1824+ struct value *v;
1825+ int slice_range_size, i = 0, row_count = 1, elem_count = 1;
1826
1827- array_type = check_typedef (value_type (array));
1828+ /* Check for legacy code if we are actually dealing with an array or
1829+ string. */
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"));
1833
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"));
140f8057
JR
1837+ ary_low_bound = TYPE_LOW_BOUND (TYPE_INDEX_TYPE (array_type));
1838+ ary_high_bound = TYPE_HIGH_BOUND (TYPE_INDEX_TYPE (array_type));
1839+
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)
1843+ {
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));
1849+ }
1850+
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;
1857+ else
1858+ elem_count = ((length - 1) / stride_length) + 1;
1859+
1860+ elt_size = TYPE_LENGTH (elt_type);
1861+ elt_offs = lowbound - ary_low_bound;
4b0e5c1b
AM
1862
1863- if (lowbound < lowerbound || length < 0
1864- || lowbound + length - 1 > upperbound)
1865- error (_("slice out of range"));
140f8057
JR
1866+ elt_offs *= elt_size;
1867+
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"));
1874+
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)
1880+ {
1881+ range_type = TYPE_INDEX_TYPE (array_type);
1882+ slice_range_size = ary_low_bound + elem_count - 1;
1883+
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"));
1887+ }
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
1890+ accordingly. */
1891+ else
1892+ {
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);
1896+ }
1897
1898 /* FIXME-type-allocation: need a way to free this type when we are
1899- done with it. */
1900- slice_range_type = create_static_range_type ((struct type *) NULL,
1901- TYPE_TARGET_TYPE (range_type),
1902- lowbound,
1903- lowbound + length - 1);
1904+ done with it. */
1905
1906+ slice_range_type = create_static_range_type (NULL, TYPE_TARGET_TYPE (range_type),
1907+ ary_low_bound, slice_range_size);
1908 {
1909- struct type *element_type = TYPE_TARGET_TYPE (array_type);
1910- LONGEST offset
1911- = (lowbound - lowerbound) * TYPE_LENGTH (check_typedef (element_type));
140f8057
JR
1912+ struct type *element_type;
1913+
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)
1917+ {
1918+ element_type = TYPE_TARGET_TYPE (array_type);
1919+
1920+ slice_type = create_array_type (NULL, element_type, slice_range_type);
4b0e5c1b
AM
1921
1922- slice_type = create_array_type ((struct type *) NULL,
1923- element_type,
1924- slice_range_type);
1925- TYPE_CODE (slice_type) = TYPE_CODE (array_type);
140f8057 1926+ TYPE_CODE (slice_type) = TYPE_CODE (array_type);
4b0e5c1b
AM
1927
1928- if (VALUE_LVAL (array) == lval_memory && value_lazy (array))
1929- slice = allocate_value_lazy (slice_type);
140f8057
JR
1930+ if (VALUE_LVAL (array) == lval_memory && value_lazy (array))
1931+ v = allocate_value_lazy (slice_type);
1932+ else
1933+ {
1934+ v = allocate_value (slice_type);
1935+ value_contents_copy (v,
1936+ value_embedded_offset (v),
1937+ array,
1938+ value_embedded_offset (array) + elt_offs,
1939+ elt_size * longest_to_int (length));
1940+ }
4b0e5c1b 1941+
140f8057
JR
1942+ }
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. */
1946 else
1947 {
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));
1954+
1955+ if (call_count == 1)
1956+ {
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);
1960+ }
1961+ else
1962+ {
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));
1966+ }
1967+
1968+ slice_type = create_array_type (NULL, element_type, slice_range_type);
1969+
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);
1974+ else
1975+ TYPE_CODE (slice_type) = TYPE_CODE (TYPE_TARGET_TYPE (array_type));
1976+
1977+ v = allocate_value (slice_type);
1978+
1979+ /* Iterate through the rows of the outer array and set the new offset
1980+ for each row. */
1981+ for (i = 0; i < row_count; i++)
1982+ {
1983+ elt_offs = offs_store + i * src_row_length;
1984+
1985+ /* Iterate through the elements in each row to copy only those. */
1986+ for (j = 1; j <= elem_count; j++)
1987+ {
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;
1992+ }
1993+ }
1994 }
1995
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)
2000+ {
2001+ VALUE_REGNUM (v) = VALUE_REGNUM (array);
2002+ VALUE_NEXT_FRAME_ID (v) = VALUE_NEXT_FRAME_ID (array);
2003+ }
2004+ set_value_offset (v, value_offset (array) + elt_offs);
2005 }
2006
2007- return slice;
2008+ return v;
2009 }
2010
2011 /* Create a value for a FORTRAN complex number. Currently most of the
4b0e5c1b 2012diff --git a/gdb/value.h b/gdb/value.h
4b0e5c1b
AM
2013--- a/gdb/value.h
2014+++ b/gdb/value.h
ed003b1c 2015@@ -1139,6 +1139,8 @@ extern struct value *varying_to_slice (struct value *);
140f8057
JR
2016
2017 extern struct value *value_slice (struct value *, int, int);
2018
2019+extern struct value *value_slice_1 (struct value *, int, int, int, int);
2020+
2021 extern struct value *value_literal_complex (struct value *, struct value *,
2022 struct type *);
2023
This page took 2.266701 seconds and 4 git commands to generate.