15796c8dcSSimon Schubert /* Support for printing Modula 2 values for GDB, the GNU debugger.
25796c8dcSSimon Schubert
3*ef5ccd6cSJohn Marino Copyright (C) 1986-2013 Free Software Foundation, Inc.
45796c8dcSSimon Schubert
55796c8dcSSimon Schubert This file is part of GDB.
65796c8dcSSimon Schubert
75796c8dcSSimon Schubert This program is free software; you can redistribute it and/or modify
85796c8dcSSimon Schubert it under the terms of the GNU General Public License as published by
95796c8dcSSimon Schubert the Free Software Foundation; either version 3 of the License, or
105796c8dcSSimon Schubert (at your option) any later version.
115796c8dcSSimon Schubert
125796c8dcSSimon Schubert This program is distributed in the hope that it will be useful,
135796c8dcSSimon Schubert but WITHOUT ANY WARRANTY; without even the implied warranty of
145796c8dcSSimon Schubert MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
155796c8dcSSimon Schubert GNU General Public License for more details.
165796c8dcSSimon Schubert
175796c8dcSSimon Schubert You should have received a copy of the GNU General Public License
185796c8dcSSimon Schubert along with this program. If not, see <http://www.gnu.org/licenses/>. */
195796c8dcSSimon Schubert
205796c8dcSSimon Schubert #include "defs.h"
215796c8dcSSimon Schubert #include "symtab.h"
225796c8dcSSimon Schubert #include "gdbtypes.h"
235796c8dcSSimon Schubert #include "expression.h"
245796c8dcSSimon Schubert #include "value.h"
255796c8dcSSimon Schubert #include "valprint.h"
265796c8dcSSimon Schubert #include "language.h"
275796c8dcSSimon Schubert #include "typeprint.h"
285796c8dcSSimon Schubert #include "c-lang.h"
295796c8dcSSimon Schubert #include "m2-lang.h"
305796c8dcSSimon Schubert #include "target.h"
315796c8dcSSimon Schubert
325796c8dcSSimon Schubert static int print_unpacked_pointer (struct type *type,
335796c8dcSSimon Schubert CORE_ADDR address, CORE_ADDR addr,
345796c8dcSSimon Schubert const struct value_print_options *options,
355796c8dcSSimon Schubert struct ui_file *stream);
365796c8dcSSimon Schubert static void
375796c8dcSSimon Schubert m2_print_array_contents (struct type *type, const gdb_byte *valaddr,
385796c8dcSSimon Schubert int embedded_offset, CORE_ADDR address,
395796c8dcSSimon Schubert struct ui_file *stream, int recurse,
40cf7f2e2dSJohn Marino const struct value *val,
415796c8dcSSimon Schubert const struct value_print_options *options,
425796c8dcSSimon Schubert int len);
435796c8dcSSimon Schubert
445796c8dcSSimon Schubert
455796c8dcSSimon Schubert /* get_long_set_bounds - assigns the bounds of the long set to low and
465796c8dcSSimon Schubert high. */
475796c8dcSSimon Schubert
485796c8dcSSimon Schubert int
get_long_set_bounds(struct type * type,LONGEST * low,LONGEST * high)495796c8dcSSimon Schubert get_long_set_bounds (struct type *type, LONGEST *low, LONGEST *high)
505796c8dcSSimon Schubert {
515796c8dcSSimon Schubert int len, i;
525796c8dcSSimon Schubert
535796c8dcSSimon Schubert if (TYPE_CODE (type) == TYPE_CODE_STRUCT)
545796c8dcSSimon Schubert {
555796c8dcSSimon Schubert len = TYPE_NFIELDS (type);
565796c8dcSSimon Schubert i = TYPE_N_BASECLASSES (type);
575796c8dcSSimon Schubert if (len == 0)
585796c8dcSSimon Schubert return 0;
595796c8dcSSimon Schubert *low = TYPE_LOW_BOUND (TYPE_INDEX_TYPE (TYPE_FIELD_TYPE (type, i)));
605796c8dcSSimon Schubert *high = TYPE_HIGH_BOUND (TYPE_INDEX_TYPE (TYPE_FIELD_TYPE (type,
615796c8dcSSimon Schubert len-1)));
625796c8dcSSimon Schubert return 1;
635796c8dcSSimon Schubert }
645796c8dcSSimon Schubert error (_("expecting long_set"));
655796c8dcSSimon Schubert return 0;
665796c8dcSSimon Schubert }
675796c8dcSSimon Schubert
685796c8dcSSimon Schubert static void
m2_print_long_set(struct type * type,const gdb_byte * valaddr,int embedded_offset,CORE_ADDR address,struct ui_file * stream)695796c8dcSSimon Schubert m2_print_long_set (struct type *type, const gdb_byte *valaddr,
705796c8dcSSimon Schubert int embedded_offset, CORE_ADDR address,
715796c8dcSSimon Schubert struct ui_file *stream)
725796c8dcSSimon Schubert {
735796c8dcSSimon Schubert int empty_set = 1;
745796c8dcSSimon Schubert int element_seen = 0;
755796c8dcSSimon Schubert LONGEST previous_low = 0;
765796c8dcSSimon Schubert LONGEST previous_high= 0;
775796c8dcSSimon Schubert LONGEST i, low_bound, high_bound;
785796c8dcSSimon Schubert LONGEST field_low, field_high;
795796c8dcSSimon Schubert struct type *range;
805796c8dcSSimon Schubert int len, field;
815796c8dcSSimon Schubert struct type *target;
825796c8dcSSimon Schubert int bitval;
835796c8dcSSimon Schubert
845796c8dcSSimon Schubert CHECK_TYPEDEF (type);
855796c8dcSSimon Schubert
865796c8dcSSimon Schubert fprintf_filtered (stream, "{");
875796c8dcSSimon Schubert len = TYPE_NFIELDS (type);
885796c8dcSSimon Schubert if (get_long_set_bounds (type, &low_bound, &high_bound))
895796c8dcSSimon Schubert {
905796c8dcSSimon Schubert field = TYPE_N_BASECLASSES (type);
915796c8dcSSimon Schubert range = TYPE_INDEX_TYPE (TYPE_FIELD_TYPE (type, field));
925796c8dcSSimon Schubert }
935796c8dcSSimon Schubert else
945796c8dcSSimon Schubert {
955796c8dcSSimon Schubert fprintf_filtered (stream, " %s }", _("<unknown bounds of set>"));
965796c8dcSSimon Schubert return;
975796c8dcSSimon Schubert }
985796c8dcSSimon Schubert
995796c8dcSSimon Schubert target = TYPE_TARGET_TYPE (range);
1005796c8dcSSimon Schubert
1015796c8dcSSimon Schubert if (get_discrete_bounds (range, &field_low, &field_high) >= 0)
1025796c8dcSSimon Schubert {
1035796c8dcSSimon Schubert for (i = low_bound; i <= high_bound; i++)
1045796c8dcSSimon Schubert {
1055796c8dcSSimon Schubert bitval = value_bit_index (TYPE_FIELD_TYPE (type, field),
1065796c8dcSSimon Schubert (TYPE_FIELD_BITPOS (type, field) / 8) +
1075796c8dcSSimon Schubert valaddr + embedded_offset, i);
1085796c8dcSSimon Schubert if (bitval < 0)
1095796c8dcSSimon Schubert error (_("bit test is out of range"));
1105796c8dcSSimon Schubert else if (bitval > 0)
1115796c8dcSSimon Schubert {
1125796c8dcSSimon Schubert previous_high = i;
1135796c8dcSSimon Schubert if (! element_seen)
1145796c8dcSSimon Schubert {
1155796c8dcSSimon Schubert if (! empty_set)
1165796c8dcSSimon Schubert fprintf_filtered (stream, ", ");
1175796c8dcSSimon Schubert print_type_scalar (target, i, stream);
1185796c8dcSSimon Schubert empty_set = 0;
1195796c8dcSSimon Schubert element_seen = 1;
1205796c8dcSSimon Schubert previous_low = i;
1215796c8dcSSimon Schubert }
1225796c8dcSSimon Schubert }
1235796c8dcSSimon Schubert else
1245796c8dcSSimon Schubert {
1255796c8dcSSimon Schubert /* bit is not set */
1265796c8dcSSimon Schubert if (element_seen)
1275796c8dcSSimon Schubert {
1285796c8dcSSimon Schubert if (previous_low+1 < previous_high)
1295796c8dcSSimon Schubert fprintf_filtered (stream, "..");
1305796c8dcSSimon Schubert if (previous_low+1 < previous_high)
1315796c8dcSSimon Schubert print_type_scalar (target, previous_high, stream);
1325796c8dcSSimon Schubert element_seen = 0;
1335796c8dcSSimon Schubert }
1345796c8dcSSimon Schubert }
1355796c8dcSSimon Schubert if (i == field_high)
1365796c8dcSSimon Schubert {
1375796c8dcSSimon Schubert field++;
1385796c8dcSSimon Schubert if (field == len)
1395796c8dcSSimon Schubert break;
1405796c8dcSSimon Schubert range = TYPE_INDEX_TYPE (TYPE_FIELD_TYPE (type, field));
1415796c8dcSSimon Schubert if (get_discrete_bounds (range, &field_low, &field_high) < 0)
1425796c8dcSSimon Schubert break;
1435796c8dcSSimon Schubert target = TYPE_TARGET_TYPE (range);
1445796c8dcSSimon Schubert }
1455796c8dcSSimon Schubert }
1465796c8dcSSimon Schubert if (element_seen)
1475796c8dcSSimon Schubert {
1485796c8dcSSimon Schubert if (previous_low+1 < previous_high)
1495796c8dcSSimon Schubert {
1505796c8dcSSimon Schubert fprintf_filtered (stream, "..");
1515796c8dcSSimon Schubert print_type_scalar (target, previous_high, stream);
1525796c8dcSSimon Schubert }
1535796c8dcSSimon Schubert element_seen = 0;
1545796c8dcSSimon Schubert }
1555796c8dcSSimon Schubert fprintf_filtered (stream, "}");
1565796c8dcSSimon Schubert }
1575796c8dcSSimon Schubert }
1585796c8dcSSimon Schubert
1595796c8dcSSimon Schubert static void
m2_print_unbounded_array(struct type * type,const gdb_byte * valaddr,int embedded_offset,CORE_ADDR address,struct ui_file * stream,int recurse,const struct value_print_options * options)1605796c8dcSSimon Schubert m2_print_unbounded_array (struct type *type, const gdb_byte *valaddr,
1615796c8dcSSimon Schubert int embedded_offset, CORE_ADDR address,
1625796c8dcSSimon Schubert struct ui_file *stream, int recurse,
1635796c8dcSSimon Schubert const struct value_print_options *options)
1645796c8dcSSimon Schubert {
1655796c8dcSSimon Schubert struct type *content_type;
1665796c8dcSSimon Schubert CORE_ADDR addr;
1675796c8dcSSimon Schubert LONGEST len;
1685796c8dcSSimon Schubert struct value *val;
1695796c8dcSSimon Schubert
1705796c8dcSSimon Schubert CHECK_TYPEDEF (type);
1715796c8dcSSimon Schubert content_type = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type, 0));
1725796c8dcSSimon Schubert
1735796c8dcSSimon Schubert addr = unpack_pointer (TYPE_FIELD_TYPE (type, 0),
1745796c8dcSSimon Schubert (TYPE_FIELD_BITPOS (type, 0) / 8) +
1755796c8dcSSimon Schubert valaddr + embedded_offset);
1765796c8dcSSimon Schubert
1775796c8dcSSimon Schubert val = value_at_lazy (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type, 0)),
1785796c8dcSSimon Schubert addr);
1795796c8dcSSimon Schubert len = unpack_field_as_long (type, valaddr + embedded_offset, 1);
1805796c8dcSSimon Schubert
1815796c8dcSSimon Schubert fprintf_filtered (stream, "{");
182c50c785cSJohn Marino m2_print_array_contents (value_type (val),
183c50c785cSJohn Marino value_contents_for_printing (val),
1845796c8dcSSimon Schubert value_embedded_offset (val), addr, stream,
185c50c785cSJohn Marino recurse, val, options, len);
1865796c8dcSSimon Schubert fprintf_filtered (stream, ", HIGH = %d}", (int) len);
1875796c8dcSSimon Schubert }
1885796c8dcSSimon Schubert
1895796c8dcSSimon Schubert static int
print_unpacked_pointer(struct type * type,CORE_ADDR address,CORE_ADDR addr,const struct value_print_options * options,struct ui_file * stream)1905796c8dcSSimon Schubert print_unpacked_pointer (struct type *type,
1915796c8dcSSimon Schubert CORE_ADDR address, CORE_ADDR addr,
1925796c8dcSSimon Schubert const struct value_print_options *options,
1935796c8dcSSimon Schubert struct ui_file *stream)
1945796c8dcSSimon Schubert {
1955796c8dcSSimon Schubert struct gdbarch *gdbarch = get_type_arch (type);
1965796c8dcSSimon Schubert struct type *elttype = check_typedef (TYPE_TARGET_TYPE (type));
197*ef5ccd6cSJohn Marino int want_space = 0;
1985796c8dcSSimon Schubert
1995796c8dcSSimon Schubert if (TYPE_CODE (elttype) == TYPE_CODE_FUNC)
2005796c8dcSSimon Schubert {
2015796c8dcSSimon Schubert /* Try to print what function it points to. */
202*ef5ccd6cSJohn Marino print_function_pointer_address (options, gdbarch, addr, stream);
2035796c8dcSSimon Schubert /* Return value is irrelevant except for string pointers. */
2045796c8dcSSimon Schubert return 0;
2055796c8dcSSimon Schubert }
2065796c8dcSSimon Schubert
2075796c8dcSSimon Schubert if (options->addressprint && options->format != 's')
208*ef5ccd6cSJohn Marino {
2095796c8dcSSimon Schubert fputs_filtered (paddress (gdbarch, address), stream);
210*ef5ccd6cSJohn Marino want_space = 1;
211*ef5ccd6cSJohn Marino }
2125796c8dcSSimon Schubert
2135796c8dcSSimon Schubert /* For a pointer to char or unsigned char, also print the string
2145796c8dcSSimon Schubert pointed to, unless pointer is null. */
2155796c8dcSSimon Schubert
2165796c8dcSSimon Schubert if (TYPE_LENGTH (elttype) == 1
2175796c8dcSSimon Schubert && TYPE_CODE (elttype) == TYPE_CODE_INT
2185796c8dcSSimon Schubert && (options->format == 0 || options->format == 's')
2195796c8dcSSimon Schubert && addr != 0)
220*ef5ccd6cSJohn Marino {
221*ef5ccd6cSJohn Marino if (want_space)
222*ef5ccd6cSJohn Marino fputs_filtered (" ", stream);
223c50c785cSJohn Marino return val_print_string (TYPE_TARGET_TYPE (type), NULL, addr, -1,
2245796c8dcSSimon Schubert stream, options);
225*ef5ccd6cSJohn Marino }
2265796c8dcSSimon Schubert
2275796c8dcSSimon Schubert return 0;
2285796c8dcSSimon Schubert }
2295796c8dcSSimon Schubert
2305796c8dcSSimon Schubert static void
print_variable_at_address(struct type * type,const gdb_byte * valaddr,struct ui_file * stream,int recurse,const struct value_print_options * options)2315796c8dcSSimon Schubert print_variable_at_address (struct type *type,
2325796c8dcSSimon Schubert const gdb_byte *valaddr,
2335796c8dcSSimon Schubert struct ui_file *stream,
2345796c8dcSSimon Schubert int recurse,
2355796c8dcSSimon Schubert const struct value_print_options *options)
2365796c8dcSSimon Schubert {
2375796c8dcSSimon Schubert struct gdbarch *gdbarch = get_type_arch (type);
2385796c8dcSSimon Schubert CORE_ADDR addr = unpack_pointer (type, valaddr);
2395796c8dcSSimon Schubert struct type *elttype = check_typedef (TYPE_TARGET_TYPE (type));
2405796c8dcSSimon Schubert
2415796c8dcSSimon Schubert fprintf_filtered (stream, "[");
2425796c8dcSSimon Schubert fputs_filtered (paddress (gdbarch, addr), stream);
2435796c8dcSSimon Schubert fprintf_filtered (stream, "] : ");
2445796c8dcSSimon Schubert
2455796c8dcSSimon Schubert if (TYPE_CODE (elttype) != TYPE_CODE_UNDEF)
2465796c8dcSSimon Schubert {
2475796c8dcSSimon Schubert struct value *deref_val =
2485796c8dcSSimon Schubert value_at (TYPE_TARGET_TYPE (type), unpack_pointer (type, valaddr));
249cf7f2e2dSJohn Marino
2505796c8dcSSimon Schubert common_val_print (deref_val, stream, recurse, options, current_language);
2515796c8dcSSimon Schubert }
2525796c8dcSSimon Schubert else
2535796c8dcSSimon Schubert fputs_filtered ("???", stream);
2545796c8dcSSimon Schubert }
2555796c8dcSSimon Schubert
2565796c8dcSSimon Schubert
2575796c8dcSSimon Schubert /* m2_print_array_contents - prints out the contents of an
2585796c8dcSSimon Schubert array up to a max_print values.
2595796c8dcSSimon Schubert It prints arrays of char as a string
2605796c8dcSSimon Schubert and all other data types as comma
2615796c8dcSSimon Schubert separated values. */
2625796c8dcSSimon Schubert
2635796c8dcSSimon Schubert static void
m2_print_array_contents(struct type * type,const gdb_byte * valaddr,int embedded_offset,CORE_ADDR address,struct ui_file * stream,int recurse,const struct value * val,const struct value_print_options * options,int len)2645796c8dcSSimon Schubert m2_print_array_contents (struct type *type, const gdb_byte *valaddr,
2655796c8dcSSimon Schubert int embedded_offset, CORE_ADDR address,
2665796c8dcSSimon Schubert struct ui_file *stream, int recurse,
267cf7f2e2dSJohn Marino const struct value *val,
2685796c8dcSSimon Schubert const struct value_print_options *options,
2695796c8dcSSimon Schubert int len)
2705796c8dcSSimon Schubert {
2715796c8dcSSimon Schubert CHECK_TYPEDEF (type);
2725796c8dcSSimon Schubert
2735796c8dcSSimon Schubert if (TYPE_LENGTH (type) > 0)
2745796c8dcSSimon Schubert {
2755796c8dcSSimon Schubert if (options->prettyprint_arrays)
2765796c8dcSSimon Schubert print_spaces_filtered (2 + 2 * recurse, stream);
2775796c8dcSSimon Schubert /* For an array of chars, print with string syntax. */
278*ef5ccd6cSJohn Marino if (TYPE_LENGTH (type) == 1 &&
2795796c8dcSSimon Schubert ((TYPE_CODE (type) == TYPE_CODE_INT)
2805796c8dcSSimon Schubert || ((current_language->la_language == language_m2)
2815796c8dcSSimon Schubert && (TYPE_CODE (type) == TYPE_CODE_CHAR)))
2825796c8dcSSimon Schubert && (options->format == 0 || options->format == 's'))
283c50c785cSJohn Marino val_print_string (type, NULL, address, len+1, stream, options);
2845796c8dcSSimon Schubert else
2855796c8dcSSimon Schubert {
2865796c8dcSSimon Schubert fprintf_filtered (stream, "{");
287c50c785cSJohn Marino val_print_array_elements (type, valaddr, embedded_offset,
288cf7f2e2dSJohn Marino address, stream, recurse, val,
289cf7f2e2dSJohn Marino options, 0);
2905796c8dcSSimon Schubert fprintf_filtered (stream, "}");
2915796c8dcSSimon Schubert }
2925796c8dcSSimon Schubert }
2935796c8dcSSimon Schubert }
2945796c8dcSSimon Schubert
295*ef5ccd6cSJohn Marino /* Decorations for Modula 2. */
296*ef5ccd6cSJohn Marino
297*ef5ccd6cSJohn Marino static const struct generic_val_print_decorations m2_decorations =
298*ef5ccd6cSJohn Marino {
299*ef5ccd6cSJohn Marino "",
300*ef5ccd6cSJohn Marino " + ",
301*ef5ccd6cSJohn Marino " * I",
302*ef5ccd6cSJohn Marino "TRUE",
303*ef5ccd6cSJohn Marino "FALSE",
304*ef5ccd6cSJohn Marino "void"
305*ef5ccd6cSJohn Marino };
3065796c8dcSSimon Schubert
307c50c785cSJohn Marino /* See val_print for a description of the various parameters of this
308*ef5ccd6cSJohn Marino function; they are identical. */
3095796c8dcSSimon Schubert
310*ef5ccd6cSJohn Marino void
m2_val_print(struct type * type,const gdb_byte * valaddr,int embedded_offset,CORE_ADDR address,struct ui_file * stream,int recurse,const struct value * original_value,const struct value_print_options * options)3115796c8dcSSimon Schubert m2_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset,
3125796c8dcSSimon Schubert CORE_ADDR address, struct ui_file *stream, int recurse,
313cf7f2e2dSJohn Marino const struct value *original_value,
3145796c8dcSSimon Schubert const struct value_print_options *options)
3155796c8dcSSimon Schubert {
3165796c8dcSSimon Schubert struct gdbarch *gdbarch = get_type_arch (type);
317c50c785cSJohn Marino unsigned int i = 0; /* Number of characters printed. */
3185796c8dcSSimon Schubert unsigned len;
3195796c8dcSSimon Schubert struct type *elttype;
3205796c8dcSSimon Schubert CORE_ADDR addr;
3215796c8dcSSimon Schubert
3225796c8dcSSimon Schubert CHECK_TYPEDEF (type);
3235796c8dcSSimon Schubert switch (TYPE_CODE (type))
3245796c8dcSSimon Schubert {
3255796c8dcSSimon Schubert case TYPE_CODE_ARRAY:
3265796c8dcSSimon Schubert if (TYPE_LENGTH (type) > 0 && TYPE_LENGTH (TYPE_TARGET_TYPE (type)) > 0)
3275796c8dcSSimon Schubert {
3285796c8dcSSimon Schubert elttype = check_typedef (TYPE_TARGET_TYPE (type));
329*ef5ccd6cSJohn Marino len = TYPE_LENGTH (type) / TYPE_LENGTH (elttype);
3305796c8dcSSimon Schubert if (options->prettyprint_arrays)
3315796c8dcSSimon Schubert print_spaces_filtered (2 + 2 * recurse, stream);
3325796c8dcSSimon Schubert /* For an array of chars, print with string syntax. */
333*ef5ccd6cSJohn Marino if (TYPE_LENGTH (elttype) == 1 &&
3345796c8dcSSimon Schubert ((TYPE_CODE (elttype) == TYPE_CODE_INT)
3355796c8dcSSimon Schubert || ((current_language->la_language == language_m2)
3365796c8dcSSimon Schubert && (TYPE_CODE (elttype) == TYPE_CODE_CHAR)))
3375796c8dcSSimon Schubert && (options->format == 0 || options->format == 's'))
3385796c8dcSSimon Schubert {
3395796c8dcSSimon Schubert /* If requested, look for the first null char and only print
3405796c8dcSSimon Schubert elements up to it. */
3415796c8dcSSimon Schubert if (options->stop_print_at_null)
3425796c8dcSSimon Schubert {
3435796c8dcSSimon Schubert unsigned int temp_len;
3445796c8dcSSimon Schubert
3455796c8dcSSimon Schubert /* Look for a NULL char. */
3465796c8dcSSimon Schubert for (temp_len = 0;
3475796c8dcSSimon Schubert (valaddr + embedded_offset)[temp_len]
3485796c8dcSSimon Schubert && temp_len < len && temp_len < options->print_max;
3495796c8dcSSimon Schubert temp_len++);
3505796c8dcSSimon Schubert len = temp_len;
3515796c8dcSSimon Schubert }
3525796c8dcSSimon Schubert
3535796c8dcSSimon Schubert LA_PRINT_STRING (stream, TYPE_TARGET_TYPE (type),
354cf7f2e2dSJohn Marino valaddr + embedded_offset, len, NULL,
355cf7f2e2dSJohn Marino 0, options);
3565796c8dcSSimon Schubert i = len;
3575796c8dcSSimon Schubert }
3585796c8dcSSimon Schubert else
3595796c8dcSSimon Schubert {
3605796c8dcSSimon Schubert fprintf_filtered (stream, "{");
361c50c785cSJohn Marino val_print_array_elements (type, valaddr, embedded_offset,
362c50c785cSJohn Marino address, stream,
363c50c785cSJohn Marino recurse, original_value,
364cf7f2e2dSJohn Marino options, 0);
3655796c8dcSSimon Schubert fprintf_filtered (stream, "}");
3665796c8dcSSimon Schubert }
3675796c8dcSSimon Schubert break;
3685796c8dcSSimon Schubert }
3695796c8dcSSimon Schubert /* Array of unspecified length: treat like pointer to first elt. */
3705796c8dcSSimon Schubert print_unpacked_pointer (type, address, address, options, stream);
3715796c8dcSSimon Schubert break;
3725796c8dcSSimon Schubert
3735796c8dcSSimon Schubert case TYPE_CODE_PTR:
3745796c8dcSSimon Schubert if (TYPE_CONST (type))
3755796c8dcSSimon Schubert print_variable_at_address (type, valaddr + embedded_offset,
3765796c8dcSSimon Schubert stream, recurse, options);
3775796c8dcSSimon Schubert else if (options->format && options->format != 's')
378c50c785cSJohn Marino val_print_scalar_formatted (type, valaddr, embedded_offset,
379c50c785cSJohn Marino original_value, options, 0, stream);
3805796c8dcSSimon Schubert else
3815796c8dcSSimon Schubert {
3825796c8dcSSimon Schubert addr = unpack_pointer (type, valaddr + embedded_offset);
3835796c8dcSSimon Schubert print_unpacked_pointer (type, addr, address, options, stream);
3845796c8dcSSimon Schubert }
3855796c8dcSSimon Schubert break;
3865796c8dcSSimon Schubert
3875796c8dcSSimon Schubert case TYPE_CODE_UNION:
3885796c8dcSSimon Schubert if (recurse && !options->unionprint)
3895796c8dcSSimon Schubert {
3905796c8dcSSimon Schubert fprintf_filtered (stream, "{...}");
3915796c8dcSSimon Schubert break;
3925796c8dcSSimon Schubert }
3935796c8dcSSimon Schubert /* Fall through. */
3945796c8dcSSimon Schubert case TYPE_CODE_STRUCT:
3955796c8dcSSimon Schubert if (m2_is_long_set (type))
3965796c8dcSSimon Schubert m2_print_long_set (type, valaddr, embedded_offset, address,
3975796c8dcSSimon Schubert stream);
3985796c8dcSSimon Schubert else if (m2_is_unbounded_array (type))
3995796c8dcSSimon Schubert m2_print_unbounded_array (type, valaddr, embedded_offset,
4005796c8dcSSimon Schubert address, stream, recurse, options);
4015796c8dcSSimon Schubert else
4025796c8dcSSimon Schubert cp_print_value_fields (type, type, valaddr, embedded_offset,
403cf7f2e2dSJohn Marino address, stream, recurse, original_value,
404cf7f2e2dSJohn Marino options, NULL, 0);
4055796c8dcSSimon Schubert break;
4065796c8dcSSimon Schubert
4075796c8dcSSimon Schubert case TYPE_CODE_SET:
4085796c8dcSSimon Schubert elttype = TYPE_INDEX_TYPE (type);
4095796c8dcSSimon Schubert CHECK_TYPEDEF (elttype);
4105796c8dcSSimon Schubert if (TYPE_STUB (elttype))
4115796c8dcSSimon Schubert {
4125796c8dcSSimon Schubert fprintf_filtered (stream, _("<incomplete type>"));
4135796c8dcSSimon Schubert gdb_flush (stream);
4145796c8dcSSimon Schubert break;
4155796c8dcSSimon Schubert }
4165796c8dcSSimon Schubert else
4175796c8dcSSimon Schubert {
4185796c8dcSSimon Schubert struct type *range = elttype;
4195796c8dcSSimon Schubert LONGEST low_bound, high_bound;
4205796c8dcSSimon Schubert int i;
4215796c8dcSSimon Schubert int need_comma = 0;
4225796c8dcSSimon Schubert
4235796c8dcSSimon Schubert fputs_filtered ("{", stream);
4245796c8dcSSimon Schubert
4255796c8dcSSimon Schubert i = get_discrete_bounds (range, &low_bound, &high_bound);
4265796c8dcSSimon Schubert maybe_bad_bstring:
4275796c8dcSSimon Schubert if (i < 0)
4285796c8dcSSimon Schubert {
4295796c8dcSSimon Schubert fputs_filtered (_("<error value>"), stream);
4305796c8dcSSimon Schubert goto done;
4315796c8dcSSimon Schubert }
4325796c8dcSSimon Schubert
4335796c8dcSSimon Schubert for (i = low_bound; i <= high_bound; i++)
4345796c8dcSSimon Schubert {
4355796c8dcSSimon Schubert int element = value_bit_index (type, valaddr + embedded_offset,
4365796c8dcSSimon Schubert i);
437cf7f2e2dSJohn Marino
4385796c8dcSSimon Schubert if (element < 0)
4395796c8dcSSimon Schubert {
4405796c8dcSSimon Schubert i = element;
4415796c8dcSSimon Schubert goto maybe_bad_bstring;
4425796c8dcSSimon Schubert }
443*ef5ccd6cSJohn Marino if (element)
4445796c8dcSSimon Schubert {
4455796c8dcSSimon Schubert if (need_comma)
4465796c8dcSSimon Schubert fputs_filtered (", ", stream);
4475796c8dcSSimon Schubert print_type_scalar (range, i, stream);
4485796c8dcSSimon Schubert need_comma = 1;
4495796c8dcSSimon Schubert
4505796c8dcSSimon Schubert if (i + 1 <= high_bound
4515796c8dcSSimon Schubert && value_bit_index (type, valaddr + embedded_offset,
4525796c8dcSSimon Schubert ++i))
4535796c8dcSSimon Schubert {
4545796c8dcSSimon Schubert int j = i;
455cf7f2e2dSJohn Marino
4565796c8dcSSimon Schubert fputs_filtered ("..", stream);
4575796c8dcSSimon Schubert while (i + 1 <= high_bound
4585796c8dcSSimon Schubert && value_bit_index (type,
4595796c8dcSSimon Schubert valaddr + embedded_offset,
4605796c8dcSSimon Schubert ++i))
4615796c8dcSSimon Schubert j = i;
4625796c8dcSSimon Schubert print_type_scalar (range, j, stream);
4635796c8dcSSimon Schubert }
4645796c8dcSSimon Schubert }
4655796c8dcSSimon Schubert }
4665796c8dcSSimon Schubert done:
4675796c8dcSSimon Schubert fputs_filtered ("}", stream);
4685796c8dcSSimon Schubert }
4695796c8dcSSimon Schubert break;
4705796c8dcSSimon Schubert
471*ef5ccd6cSJohn Marino case TYPE_CODE_RANGE:
472*ef5ccd6cSJohn Marino if (TYPE_LENGTH (type) == TYPE_LENGTH (TYPE_TARGET_TYPE (type)))
473*ef5ccd6cSJohn Marino {
474*ef5ccd6cSJohn Marino m2_val_print (TYPE_TARGET_TYPE (type), valaddr, embedded_offset,
475*ef5ccd6cSJohn Marino address, stream, recurse, original_value, options);
476*ef5ccd6cSJohn Marino break;
477*ef5ccd6cSJohn Marino }
478*ef5ccd6cSJohn Marino /* FIXME: create_range_type does not set the unsigned bit in a
479*ef5ccd6cSJohn Marino range type (I think it probably should copy it from the target
480*ef5ccd6cSJohn Marino type), so we won't print values which are too large to
481*ef5ccd6cSJohn Marino fit in a signed integer correctly. */
482*ef5ccd6cSJohn Marino /* FIXME: Doesn't handle ranges of enums correctly. (Can't just
483*ef5ccd6cSJohn Marino print with the target type, though, because the size of our type
484*ef5ccd6cSJohn Marino and the target type might differ). */
485*ef5ccd6cSJohn Marino /* FALLTHROUGH */
486*ef5ccd6cSJohn Marino
487*ef5ccd6cSJohn Marino case TYPE_CODE_REF:
488*ef5ccd6cSJohn Marino case TYPE_CODE_ENUM:
489*ef5ccd6cSJohn Marino case TYPE_CODE_FUNC:
490*ef5ccd6cSJohn Marino case TYPE_CODE_INT:
491*ef5ccd6cSJohn Marino case TYPE_CODE_FLT:
492*ef5ccd6cSJohn Marino case TYPE_CODE_METHOD:
4935796c8dcSSimon Schubert case TYPE_CODE_VOID:
4945796c8dcSSimon Schubert case TYPE_CODE_ERROR:
4955796c8dcSSimon Schubert case TYPE_CODE_UNDEF:
496*ef5ccd6cSJohn Marino case TYPE_CODE_BOOL:
497*ef5ccd6cSJohn Marino case TYPE_CODE_CHAR:
4985796c8dcSSimon Schubert default:
499*ef5ccd6cSJohn Marino generic_val_print (type, valaddr, embedded_offset, address,
500*ef5ccd6cSJohn Marino stream, recurse, original_value, options,
501*ef5ccd6cSJohn Marino &m2_decorations);
502*ef5ccd6cSJohn Marino break;
5035796c8dcSSimon Schubert }
5045796c8dcSSimon Schubert gdb_flush (stream);
5055796c8dcSSimon Schubert }
506