void f_type_print_base (struct type *type, struct ui_file *stream, int show, int level) { int upper_bound; int index; QUIT; wrap_here (" "); if (type == NULL) { fputs_filtered ("<type unknown>", stream); return; } /* When SHOW is zero or less, and there is a valid type name, then always just print the type name directly from the type. */ if ((show <= 0) && (TYPE_NAME (type) != NULL)) { fputs_filtered (TYPE_NAME (type), stream); return; } if (TYPE_CODE (type) != TYPE_CODE_TYPEDEF) CHECK_TYPEDEF (type); switch (TYPE_CODE (type)) { case TYPE_CODE_TYPEDEF: f_type_print_base (TYPE_TARGET_TYPE (type), stream, 0, level); break; case TYPE_CODE_ARRAY: case TYPE_CODE_FUNC: f_type_print_base (TYPE_TARGET_TYPE (type), stream, show, level); break; case TYPE_CODE_PTR: fprintf_filtered (stream, "PTR TO -> ( "); f_type_print_base (TYPE_TARGET_TYPE (type), stream, 0, level); break; case TYPE_CODE_REF: fprintf_filtered (stream, "REF TO -> ( "); f_type_print_base (TYPE_TARGET_TYPE (type), stream, 0, level); break; case TYPE_CODE_VOID: fprintfi_filtered (level, stream, "VOID"); break; case TYPE_CODE_UNDEF: fprintfi_filtered (level, stream, "struct <unknown>"); break; case TYPE_CODE_ERROR: fprintfi_filtered (level, stream, "%s", TYPE_ERROR_NAME (type)); break; case TYPE_CODE_RANGE: /* This should not occur. */ fprintfi_filtered (level, stream, "<range type>"); break; case TYPE_CODE_CHAR: case TYPE_CODE_INT: /* There may be some character types that attempt to come through as TYPE_CODE_INT since dbxstclass.h is so C-oriented, we must change these to "character" from "char". */ if (strcmp (TYPE_NAME (type), "char") == 0) fprintfi_filtered (level, stream, "character"); else goto default_case; break; case TYPE_CODE_STRING: /* Strings may have dynamic upperbounds (lengths) like arrays. */ if (TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (type)) fprintfi_filtered (level, stream, "character*(*)"); else { upper_bound = f77_get_upperbound (type); fprintf_filtered (stream, "character*%d", upper_bound); } break; case TYPE_CODE_STRUCT: case TYPE_CODE_UNION: if (TYPE_CODE (type) == TYPE_CODE_UNION) fprintfi_filtered (level, stream, "Type, C_Union :: "); else fprintfi_filtered (level, stream, "Type "); fputs_filtered (TYPE_TAG_NAME (type), stream); fputs_filtered ("\n", stream); for (index = 0; index < TYPE_NFIELDS (type); index++) { f_type_print_base (TYPE_FIELD_TYPE (type, index), stream, show, level + 4); fputs_filtered (" :: ", stream); fputs_filtered (TYPE_FIELD_NAME (type, index), stream); f_type_print_varspec_suffix (TYPE_FIELD_TYPE (type, index), stream, 0, 0, 0, 0); fputs_filtered ("\n", stream); } fprintfi_filtered (level, stream, "End Type "); fputs_filtered (TYPE_TAG_NAME (type), stream); break; case TYPE_CODE_MODULE: fprintfi_filtered (level, stream, "module %s", TYPE_TAG_NAME (type)); break; default_case: default: /* Handle types not explicitly handled by the other cases, such as fundamental types. For these, just print whatever the type name is, as recorded in the type itself. If there is no type name, then complain. */ if (TYPE_NAME (type) != NULL) fprintfi_filtered (level, stream, "%s", TYPE_NAME (type)); else error (_("Invalid type code (%d) in symbol table."), TYPE_CODE (type)); break; } }
static void java_print_value_fields (struct type *type, const gdb_byte *valaddr, CORE_ADDR address, struct ui_file *stream, int recurse, const struct value_print_options *options) { int i, len, n_baseclasses; CHECK_TYPEDEF (type); fprintf_filtered (stream, "{"); len = TYPE_NFIELDS (type); n_baseclasses = TYPE_N_BASECLASSES (type); if (n_baseclasses > 0) { int i, n_baseclasses = TYPE_N_BASECLASSES (type); for (i = 0; i < n_baseclasses; i++) { int boffset; struct type *baseclass = check_typedef (TYPE_BASECLASS (type, i)); char *basename = TYPE_NAME (baseclass); const gdb_byte *base_valaddr; if (BASETYPE_VIA_VIRTUAL (type, i)) continue; if (basename != NULL && strcmp (basename, "java.lang.Object") == 0) continue; boffset = 0; if (options->pretty) { fprintf_filtered (stream, "\n"); print_spaces_filtered (2 * (recurse + 1), stream); } fputs_filtered ("<", stream); /* Not sure what the best notation is in the case where there is no baseclass name. */ fputs_filtered (basename ? basename : "", stream); fputs_filtered ("> = ", stream); base_valaddr = valaddr; java_print_value_fields (baseclass, base_valaddr, address + boffset, stream, recurse + 1, options); fputs_filtered (", ", stream); } } if (!len && n_baseclasses == 1) fprintf_filtered (stream, "<No data fields>"); else { int fields_seen = 0; for (i = n_baseclasses; i < len; i++) { /* If requested, skip printing of static fields. */ if (field_is_static (&TYPE_FIELD (type, i))) { char *name = TYPE_FIELD_NAME (type, i); if (!options->static_field_print) continue; if (name != NULL && strcmp (name, "class") == 0) continue; } if (fields_seen) fprintf_filtered (stream, ", "); else if (n_baseclasses > 0) { if (options->pretty) { fprintf_filtered (stream, "\n"); print_spaces_filtered (2 + 2 * recurse, stream); fputs_filtered ("members of ", stream); fputs_filtered (type_name_no_tag (type), stream); fputs_filtered (": ", stream); } } fields_seen = 1; if (options->pretty) { fprintf_filtered (stream, "\n"); print_spaces_filtered (2 + 2 * recurse, stream); } else { wrap_here (n_spaces (2 + 2 * recurse)); } if (options->inspect_it) { if (TYPE_CODE (TYPE_FIELD_TYPE (type, i)) == TYPE_CODE_PTR) fputs_filtered ("\"( ptr \"", stream); else fputs_filtered ("\"( nodef \"", stream); if (field_is_static (&TYPE_FIELD (type, i))) fputs_filtered ("static ", stream); fprintf_symbol_filtered (stream, TYPE_FIELD_NAME (type, i), language_cplus, DMGL_PARAMS | DMGL_ANSI); fputs_filtered ("\" \"", stream); fprintf_symbol_filtered (stream, TYPE_FIELD_NAME (type, i), language_cplus, DMGL_PARAMS | DMGL_ANSI); fputs_filtered ("\") \"", stream); } else { annotate_field_begin (TYPE_FIELD_TYPE (type, i)); if (field_is_static (&TYPE_FIELD (type, i))) fputs_filtered ("static ", stream); fprintf_symbol_filtered (stream, TYPE_FIELD_NAME (type, i), language_cplus, DMGL_PARAMS | DMGL_ANSI); annotate_field_name_end (); fputs_filtered (": ", stream); annotate_field_value (); } if (!field_is_static (&TYPE_FIELD (type, i)) && TYPE_FIELD_PACKED (type, i)) { struct value *v; /* Bitfields require special handling, especially due to byte order problems. */ if (TYPE_FIELD_IGNORE (type, i)) { fputs_filtered ("<optimized out or zero length>", stream); } else { struct value_print_options opts; v = value_from_longest (TYPE_FIELD_TYPE (type, i), unpack_field_as_long (type, valaddr, i)); opts = *options; opts.deref_ref = 0; common_val_print (v, stream, recurse + 1, &opts, current_language); } } else { if (TYPE_FIELD_IGNORE (type, i)) { fputs_filtered ("<optimized out or zero length>", stream); } else if (field_is_static (&TYPE_FIELD (type, i))) { struct value *v = value_static_field (type, i); if (v == NULL) fputs_filtered ("<optimized out>", stream); else { struct value_print_options opts; struct type *t = check_typedef (value_type (v)); if (TYPE_CODE (t) == TYPE_CODE_STRUCT) v = value_addr (v); opts = *options; opts.deref_ref = 0; common_val_print (v, stream, recurse + 1, &opts, current_language); } } else if (TYPE_FIELD_TYPE (type, i) == NULL) fputs_filtered ("<unknown type>", stream); else { struct value_print_options opts = *options; opts.deref_ref = 0; val_print (TYPE_FIELD_TYPE (type, i), valaddr + TYPE_FIELD_BITPOS (type, i) / 8, 0, address + TYPE_FIELD_BITPOS (type, i) / 8, stream, recurse + 1, &opts, current_language); } } annotate_field_end (); } if (options->pretty) { fprintf_filtered (stream, "\n"); print_spaces_filtered (2 * recurse, stream); } } fprintf_filtered (stream, "}"); }
static int print_field_values (struct type *type, const gdb_byte *valaddr, struct ui_file *stream, int format, int recurse, enum val_prettyprint pretty, int comma_needed, struct type *outer_type, const gdb_byte *outer_valaddr) { int i, len; len = TYPE_NFIELDS (type); for (i = 0; i < len; i += 1) { if (ada_is_ignored_field (type, i)) continue; if (ada_is_wrapper_field (type, i)) { comma_needed = print_field_values (TYPE_FIELD_TYPE (type, i), valaddr + TYPE_FIELD_BITPOS (type, i) / HOST_CHAR_BIT, stream, format, recurse, pretty, comma_needed, type, valaddr); continue; } else if (ada_is_variant_part (type, i)) { comma_needed = print_variant_part (type, i, valaddr, stream, format, recurse, pretty, comma_needed, outer_type, outer_valaddr); continue; } if (comma_needed) fprintf_filtered (stream, ", "); comma_needed = 1; if (pretty) { fprintf_filtered (stream, "\n"); print_spaces_filtered (2 + 2 * recurse, stream); } else { wrap_here (n_spaces (2 + 2 * recurse)); } if (inspect_it) { if (TYPE_CODE (TYPE_FIELD_TYPE (type, i)) == TYPE_CODE_PTR) fputs_filtered ("\"( ptr \"", stream); else fputs_filtered ("\"( nodef \"", stream); fprintf_symbol_filtered (stream, TYPE_FIELD_NAME (type, i), language_cplus, DMGL_NO_OPTS); fputs_filtered ("\" \"", stream); fprintf_symbol_filtered (stream, TYPE_FIELD_NAME (type, i), language_cplus, DMGL_NO_OPTS); fputs_filtered ("\") \"", stream); } else { annotate_field_begin (TYPE_FIELD_TYPE (type, i)); fprintf_filtered (stream, "%.*s", ada_name_prefix_len (TYPE_FIELD_NAME (type, i)), TYPE_FIELD_NAME (type, i)); annotate_field_name_end (); fputs_filtered (" => ", stream); annotate_field_value (); } if (TYPE_FIELD_PACKED (type, i)) { struct value *v; /* Bitfields require special handling, especially due to byte order problems. */ if (TYPE_CPLUS_SPECIFIC (type) != NULL && TYPE_FIELD_IGNORE (type, i)) { fputs_filtered (_("<optimized out or zero length>"), stream); } else { int bit_pos = TYPE_FIELD_BITPOS (type, i); int bit_size = TYPE_FIELD_BITSIZE (type, i); adjust_type_signedness (TYPE_FIELD_TYPE (type, i)); v = ada_value_primitive_packed_val (NULL, valaddr, bit_pos / HOST_CHAR_BIT, bit_pos % HOST_CHAR_BIT, bit_size, TYPE_FIELD_TYPE (type, i)); val_print (TYPE_FIELD_TYPE (type, i), value_contents (v), 0, 0, stream, format, 0, recurse + 1, pretty); } } else ada_val_print (TYPE_FIELD_TYPE (type, i), valaddr + TYPE_FIELD_BITPOS (type, i) / HOST_CHAR_BIT, 0, 0, stream, format, 0, recurse + 1, pretty); annotate_field_end (); } return comma_needed; }
static void f_type_print_varspec_suffix (struct type *type, struct ui_file *stream, int show, int passed_a_ptr, int demangled_args, int arrayprint_recurse_level) { int upper_bound, lower_bound; /* No static variables are permitted as an error call may occur during execution of this function. */ if (type == 0) return; if (TYPE_NAME (type) && show <= 0) return; QUIT; switch (TYPE_CODE (type)) { case TYPE_CODE_ARRAY: arrayprint_recurse_level++; if (arrayprint_recurse_level == 1) fprintf_filtered (stream, "("); if (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_ARRAY) f_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 0, 0, arrayprint_recurse_level); lower_bound = f77_get_lowerbound (type); if (lower_bound != 1) /* Not the default. */ fprintf_filtered (stream, "%d:", lower_bound); /* Make sure that, if we have an assumed size array, we print out a warning and print the upperbound as '*'. */ if (TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (type)) fprintf_filtered (stream, "*"); else { upper_bound = f77_get_upperbound (type); fprintf_filtered (stream, "%d", upper_bound); } if (TYPE_CODE (TYPE_TARGET_TYPE (type)) != TYPE_CODE_ARRAY) f_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 0, 0, arrayprint_recurse_level); if (arrayprint_recurse_level == 1) fprintf_filtered (stream, ")"); else fprintf_filtered (stream, ","); arrayprint_recurse_level--; break; case TYPE_CODE_PTR: case TYPE_CODE_REF: f_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 1, 0, arrayprint_recurse_level); fprintf_filtered (stream, ")"); break; case TYPE_CODE_FUNC: f_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, passed_a_ptr, 0, arrayprint_recurse_level); if (passed_a_ptr) fprintf_filtered (stream, ")"); fprintf_filtered (stream, "()"); break; case TYPE_CODE_UNDEF: case TYPE_CODE_STRUCT: case TYPE_CODE_UNION: case TYPE_CODE_ENUM: case TYPE_CODE_INT: case TYPE_CODE_FLT: case TYPE_CODE_VOID: case TYPE_CODE_ERROR: case TYPE_CODE_CHAR: case TYPE_CODE_BOOL: case TYPE_CODE_SET: case TYPE_CODE_RANGE: case TYPE_CODE_STRING: case TYPE_CODE_BITSTRING: case TYPE_CODE_METHOD: case TYPE_CODE_COMPLEX: case TYPE_CODE_TYPEDEF: /* These types do not need a suffix. They are listed so that gcc -Wall will report types that may not have been considered. */ break; } }
static void printstr (struct ui_file *stream, const gdb_byte *string, unsigned int length, int force_ellipses, int type_len) { unsigned int i; unsigned int things_printed = 0; int in_quotes = 0; int need_comma = 0; if (length == 0) { fputs_filtered ("\"\"", stream); return; } for (i = 0; i < length && things_printed < print_max; i += 1) { /* Position of the character we are examining to see whether it is repeated. */ unsigned int rep1; /* Number of repetitions we have detected so far. */ unsigned int reps; QUIT; if (need_comma) { fputs_filtered (", ", stream); need_comma = 0; } rep1 = i + 1; reps = 1; while (rep1 < length && char_at (string, rep1, type_len) == char_at (string, i, type_len)) { rep1 += 1; reps += 1; } if (reps > repeat_count_threshold) { if (in_quotes) { if (inspect_it) fputs_filtered ("\\\", ", stream); else fputs_filtered ("\", ", stream); in_quotes = 0; } fputs_filtered ("'", stream); ada_emit_char (char_at (string, i, type_len), stream, '\'', type_len); fputs_filtered ("'", stream); fprintf_filtered (stream, _(" <repeats %u times>"), reps); i = rep1 - 1; things_printed += repeat_count_threshold; need_comma = 1; } else { if (!in_quotes) { if (inspect_it) fputs_filtered ("\\\"", stream); else fputs_filtered ("\"", stream); in_quotes = 1; } ada_emit_char (char_at (string, i, type_len), stream, '"', type_len); things_printed += 1; } } /* Terminate the quotes if necessary. */ if (in_quotes) { if (inspect_it) fputs_filtered ("\\\"", stream); else fputs_filtered ("\"", stream); } if (force_ellipses || i < length) fputs_filtered ("...", stream); }
static int ada_val_print_1 (struct type *type, const gdb_byte *valaddr0, int embedded_offset, CORE_ADDR address, struct ui_file *stream, int format, int deref_ref, int recurse, enum val_prettyprint pretty) { unsigned int len; int i; struct type *elttype; unsigned int eltlen; LONGEST val; const gdb_byte *valaddr = valaddr0 + embedded_offset; type = ada_check_typedef (type); if (ada_is_array_descriptor_type (type) || ada_is_packed_array_type (type)) { int retn; struct value *mark = value_mark (); struct value *val; val = value_from_contents_and_address (type, valaddr, address); val = ada_coerce_to_simple_array_ptr (val); if (val == NULL) { fprintf_filtered (stream, "(null)"); retn = 0; } else retn = ada_val_print_1 (value_type (val), value_contents (val), 0, VALUE_ADDRESS (val), stream, format, deref_ref, recurse, pretty); value_free_to_mark (mark); return retn; } valaddr = ada_aligned_value_addr (type, valaddr); embedded_offset -= valaddr - valaddr0 - embedded_offset; type = printable_val_type (type, valaddr); switch (TYPE_CODE (type)) { default: return c_val_print (type, valaddr0, embedded_offset, address, stream, format, deref_ref, recurse, pretty); case TYPE_CODE_PTR: { int ret = c_val_print (type, valaddr0, embedded_offset, address, stream, format, deref_ref, recurse, pretty); if (ada_is_tag_type (type)) { struct value *val = value_from_contents_and_address (type, valaddr, address); const char *name = ada_tag_name (val); if (name != NULL) fprintf_filtered (stream, " (%s)", name); return 0; } return ret; } case TYPE_CODE_INT: case TYPE_CODE_RANGE: if (ada_is_fixed_point_type (type)) { LONGEST v = unpack_long (type, valaddr); int len = TYPE_LENGTH (type); fprintf_filtered (stream, len < 4 ? "%.11g" : "%.17g", (double) ada_fixed_to_float (type, v)); return 0; } else if (ada_is_vax_floating_type (type)) { struct value *val = value_from_contents_and_address (type, valaddr, address); struct value *func = ada_vax_float_print_function (type); if (func != 0) { static struct type *parray_of_char = NULL; struct value *printable_val; if (parray_of_char == NULL) parray_of_char = make_pointer_type (create_array_type (NULL, builtin_type_char, create_range_type (NULL, builtin_type_int, 0, 32)), NULL); printable_val = value_ind (value_cast (parray_of_char, call_function_by_hand (func, 1, &val))); fprintf_filtered (stream, "%s", value_contents (printable_val)); return 0; } /* No special printing function. Do as best we can. */ } else if (TYPE_CODE (type) == TYPE_CODE_RANGE) { struct type *target_type = TYPE_TARGET_TYPE (type); if (TYPE_LENGTH (type) != TYPE_LENGTH (target_type)) { /* Obscure case of range type that has different length from its base type. Perform a conversion, or we will get a nonsense value. Actually, we could use the same code regardless of lengths; I'm just avoiding a cast. */ struct value *v = value_cast (target_type, value_from_contents_and_address (type, valaddr, 0)); return ada_val_print_1 (target_type, value_contents (v), 0, 0, stream, format, 0, recurse + 1, pretty); } else return ada_val_print_1 (TYPE_TARGET_TYPE (type), valaddr0, embedded_offset, address, stream, format, deref_ref, recurse, pretty); } else { format = format ? format : output_format; if (format) { print_scalar_formatted (valaddr, type, format, 0, stream); } else if (ada_is_system_address_type (type)) { /* FIXME: We want to print System.Address variables using the same format as for any access type. But for some reason GNAT encodes the System.Address type as an int, so we have to work-around this deficiency by handling System.Address values as a special case. */ fprintf_filtered (stream, "("); type_print (type, "", stream, -1); fprintf_filtered (stream, ") "); deprecated_print_address_numeric (extract_typed_address (valaddr, builtin_type_void_data_ptr), 1, stream); } else { val_print_type_code_int (type, valaddr, stream); if (ada_is_character_type (type)) { fputs_filtered (" ", stream); ada_printchar ((unsigned char) unpack_long (type, valaddr), stream); } } return 0; } case TYPE_CODE_ENUM: if (format) { print_scalar_formatted (valaddr, type, format, 0, stream); break; } len = TYPE_NFIELDS (type); val = unpack_long (type, valaddr); for (i = 0; i < len; i++) { QUIT; if (val == TYPE_FIELD_BITPOS (type, i)) { break; } } if (i < len) { const char *name = ada_enum_name (TYPE_FIELD_NAME (type, i)); if (name[0] == '\'') fprintf_filtered (stream, "%ld %s", (long) val, name); else fputs_filtered (name, stream); } else { print_longest (stream, 'd', 0, val); } break; case TYPE_CODE_FLT: if (format) return c_val_print (type, valaddr0, embedded_offset, address, stream, format, deref_ref, recurse, pretty); else ada_print_floating (valaddr0 + embedded_offset, type, stream); break; case TYPE_CODE_UNION: case TYPE_CODE_STRUCT: if (ada_is_bogus_array_descriptor (type)) { fprintf_filtered (stream, "(...?)"); return 0; } else { print_record (type, valaddr, stream, format, recurse, pretty); return 0; } case TYPE_CODE_ARRAY: elttype = TYPE_TARGET_TYPE (type); if (elttype == NULL) eltlen = 0; else eltlen = TYPE_LENGTH (elttype); /* FIXME: This doesn't deal with non-empty arrays of 0-length items (not a typical case!) */ if (eltlen == 0) len = 0; else len = TYPE_LENGTH (type) / eltlen; /* For an array of chars, print with string syntax. */ if (ada_is_string_type (type) && (format == 0 || format == 's')) { if (prettyprint_arrays) { print_spaces_filtered (2 + 2 * recurse, stream); } /* If requested, look for the first null char and only print elements up to it. */ if (stop_print_at_null) { int temp_len; /* Look for a NULL char. */ for (temp_len = 0; temp_len < len && temp_len < print_max && char_at (valaddr, temp_len, eltlen) != 0; temp_len += 1); len = temp_len; } printstr (stream, valaddr, len, 0, eltlen); } else { len = 0; fprintf_filtered (stream, "("); print_optional_low_bound (stream, type); if (TYPE_FIELD_BITSIZE (type, 0) > 0) val_print_packed_array_elements (type, valaddr, 0, stream, format, recurse, pretty); else val_print_array_elements (type, valaddr, address, stream, format, deref_ref, recurse, pretty, 0); fprintf_filtered (stream, ")"); } gdb_flush (stream); return len; case TYPE_CODE_REF: elttype = check_typedef (TYPE_TARGET_TYPE (type)); /* De-reference the reference */ if (deref_ref) { if (TYPE_CODE (elttype) != TYPE_CODE_UNDEF) { LONGEST deref_val_int = (LONGEST) unpack_pointer (lookup_pointer_type (builtin_type_void), valaddr); if (deref_val_int != 0) { struct value *deref_val = ada_value_ind (value_from_longest (lookup_pointer_type (elttype), deref_val_int)); val_print (value_type (deref_val), value_contents (deref_val), 0, VALUE_ADDRESS (deref_val), stream, format, deref_ref, recurse + 1, pretty); } else fputs_filtered ("(null)", stream); } else fputs_filtered ("???", stream); } break; } gdb_flush (stream); return 0; }
void ada_print_scalar (struct type *type, LONGEST val, struct ui_file *stream) { unsigned int i; unsigned len; type = ada_check_typedef (type); switch (TYPE_CODE (type)) { case TYPE_CODE_ENUM: len = TYPE_NFIELDS (type); for (i = 0; i < len; i++) { if (TYPE_FIELD_BITPOS (type, i) == val) { break; } } if (i < len) { fputs_filtered (ada_enum_name (TYPE_FIELD_NAME (type, i)), stream); } else { print_longest (stream, 'd', 0, val); } break; case TYPE_CODE_INT: print_longest (stream, TYPE_UNSIGNED (type) ? 'u' : 'd', 0, val); break; case TYPE_CODE_CHAR: LA_PRINT_CHAR ((unsigned char) val, stream); break; case TYPE_CODE_BOOL: fprintf_filtered (stream, val ? "true" : "false"); break; case TYPE_CODE_RANGE: ada_print_scalar (TYPE_TARGET_TYPE (type), val, stream); return; case TYPE_CODE_UNDEF: case TYPE_CODE_PTR: case TYPE_CODE_ARRAY: case TYPE_CODE_STRUCT: case TYPE_CODE_UNION: case TYPE_CODE_FUNC: case TYPE_CODE_FLT: case TYPE_CODE_VOID: case TYPE_CODE_SET: case TYPE_CODE_STRING: case TYPE_CODE_ERROR: case TYPE_CODE_MEMBER: case TYPE_CODE_METHOD: case TYPE_CODE_REF: warning (_("internal error: unhandled type in ada_print_scalar")); break; default: error (_("Invalid type code in symbol table.")); } gdb_flush (stream); }
static void val_print_packed_array_elements (struct type *type, const gdb_byte *valaddr, int bitoffset, struct ui_file *stream, int format, int recurse, enum val_prettyprint pretty) { unsigned int i; unsigned int things_printed = 0; unsigned len; struct type *elttype, *index_type; unsigned eltlen; unsigned long bitsize = TYPE_FIELD_BITSIZE (type, 0); struct value *mark = value_mark (); LONGEST low = 0; elttype = TYPE_TARGET_TYPE (type); eltlen = TYPE_LENGTH (check_typedef (elttype)); index_type = TYPE_INDEX_TYPE (type); { LONGEST high; if (get_discrete_bounds (TYPE_FIELD_TYPE (type, 0), &low, &high) < 0) len = 1; else len = high - low + 1; } i = 0; annotate_array_section_begin (i, elttype); while (i < len && things_printed < print_max) { struct value *v0, *v1; int i0; if (i != 0) { if (prettyprint_arrays) { fprintf_filtered (stream, ",\n"); print_spaces_filtered (2 + 2 * recurse, stream); } else { fprintf_filtered (stream, ", "); } } wrap_here (n_spaces (2 + 2 * recurse)); maybe_print_array_index (index_type, i + low, stream, format, pretty); i0 = i; v0 = ada_value_primitive_packed_val (NULL, valaddr, (i0 * bitsize) / HOST_CHAR_BIT, (i0 * bitsize) % HOST_CHAR_BIT, bitsize, elttype); while (1) { i += 1; if (i >= len) break; v1 = ada_value_primitive_packed_val (NULL, valaddr, (i * bitsize) / HOST_CHAR_BIT, (i * bitsize) % HOST_CHAR_BIT, bitsize, elttype); if (memcmp (value_contents (v0), value_contents (v1), eltlen) != 0) break; } if (i - i0 > repeat_count_threshold) { val_print (elttype, value_contents (v0), 0, 0, stream, format, 0, recurse + 1, pretty); annotate_elt_rep (i - i0); fprintf_filtered (stream, _(" <repeats %u times>"), i - i0); annotate_elt_rep_end (); } else { int j; for (j = i0; j < i; j += 1) { if (j > i0) { if (prettyprint_arrays) { fprintf_filtered (stream, ",\n"); print_spaces_filtered (2 + 2 * recurse, stream); } else { fprintf_filtered (stream, ", "); } wrap_here (n_spaces (2 + 2 * recurse)); maybe_print_array_index (index_type, j + low, stream, format, pretty); } val_print (elttype, value_contents (v0), 0, 0, stream, format, 0, recurse + 1, pretty); annotate_elt (); } } things_printed += i - i0; } annotate_array_section_end (); if (i < len) { fprintf_filtered (stream, "..."); } value_free_to_mark (mark); }
int dump_subexp_body_standard (struct expression *exp, struct ui_file *stream, int elt) { int opcode = exp->elts[elt++].opcode; switch (opcode) { case TERNOP_COND: case TERNOP_SLICE: case TERNOP_SLICE_COUNT: elt = dump_subexp (exp, stream, elt); /* FALL THROUGH */ case BINOP_ADD: case BINOP_SUB: case BINOP_MUL: case BINOP_DIV: case BINOP_REM: case BINOP_MOD: case BINOP_LSH: case BINOP_RSH: case BINOP_LOGICAL_AND: case BINOP_LOGICAL_OR: case BINOP_BITWISE_AND: case BINOP_BITWISE_IOR: case BINOP_BITWISE_XOR: case BINOP_EQUAL: case BINOP_NOTEQUAL: case BINOP_LESS: case BINOP_GTR: case BINOP_LEQ: case BINOP_GEQ: case BINOP_REPEAT: case BINOP_ASSIGN: case BINOP_COMMA: case BINOP_SUBSCRIPT: case BINOP_EXP: case BINOP_MIN: case BINOP_MAX: case BINOP_INTDIV: case BINOP_ASSIGN_MODIFY: case BINOP_VAL: case BINOP_CONCAT: case BINOP_IN: case BINOP_RANGE: case BINOP_END: case STRUCTOP_MEMBER: case STRUCTOP_MPTR: elt = dump_subexp (exp, stream, elt); /* FALL THROUGH */ case UNOP_NEG: case UNOP_LOGICAL_NOT: case UNOP_COMPLEMENT: case UNOP_IND: case UNOP_ADDR: case UNOP_PREINCREMENT: case UNOP_POSTINCREMENT: case UNOP_PREDECREMENT: case UNOP_POSTDECREMENT: case UNOP_SIZEOF: case UNOP_PLUS: case UNOP_CAP: case UNOP_CHR: case UNOP_ORD: case UNOP_ABS: case UNOP_FLOAT: case UNOP_HIGH: case UNOP_MAX: case UNOP_MIN: case UNOP_ODD: case UNOP_TRUNC: elt = dump_subexp (exp, stream, elt); break; case OP_LONG: fprintf_filtered (stream, "Type @"); gdb_print_host_address (exp->elts[elt].type, stream); fprintf_filtered (stream, " ("); type_print (exp->elts[elt].type, NULL, stream, 0); fprintf_filtered (stream, "), value %ld (0x%lx)", (long) exp->elts[elt + 1].longconst, (long) exp->elts[elt + 1].longconst); elt += 3; break; case OP_DOUBLE: fprintf_filtered (stream, "Type @"); gdb_print_host_address (exp->elts[elt].type, stream); fprintf_filtered (stream, " ("); type_print (exp->elts[elt].type, NULL, stream, 0); fprintf_filtered (stream, "), value %g", (double) exp->elts[elt + 1].doubleconst); elt += 3; break; case OP_VAR_VALUE: fprintf_filtered (stream, "Block @"); gdb_print_host_address (exp->elts[elt].block, stream); fprintf_filtered (stream, ", symbol @"); gdb_print_host_address (exp->elts[elt + 1].symbol, stream); fprintf_filtered (stream, " (%s)", SYMBOL_PRINT_NAME (exp->elts[elt + 1].symbol)); elt += 3; break; case OP_LAST: fprintf_filtered (stream, "History element %ld", (long) exp->elts[elt].longconst); elt += 2; break; case OP_REGISTER: fprintf_filtered (stream, "Register $%s", &exp->elts[elt + 1].string); elt += 3 + BYTES_TO_EXP_ELEM (exp->elts[elt].longconst + 1); break; case OP_INTERNALVAR: fprintf_filtered (stream, "Internal var @"); gdb_print_host_address (exp->elts[elt].internalvar, stream); fprintf_filtered (stream, " (%s)", internalvar_name (exp->elts[elt].internalvar)); elt += 2; break; case OP_FUNCALL: { int i, nargs; nargs = longest_to_int (exp->elts[elt].longconst); fprintf_filtered (stream, "Number of args: %d", nargs); elt += 2; for (i = 1; i <= nargs + 1; i++) elt = dump_subexp (exp, stream, elt); } break; case OP_ARRAY: { int lower, upper; int i; lower = longest_to_int (exp->elts[elt].longconst); upper = longest_to_int (exp->elts[elt + 1].longconst); fprintf_filtered (stream, "Bounds [%d:%d]", lower, upper); elt += 3; for (i = 1; i <= upper - lower + 1; i++) elt = dump_subexp (exp, stream, elt); } break; case UNOP_MEMVAL: case UNOP_CAST: case UNOP_DYNAMIC_CAST: case UNOP_REINTERPRET_CAST: fprintf_filtered (stream, "Type @"); gdb_print_host_address (exp->elts[elt].type, stream); fprintf_filtered (stream, " ("); type_print (exp->elts[elt].type, NULL, stream, 0); fprintf_filtered (stream, ")"); elt = dump_subexp (exp, stream, elt + 2); break; case UNOP_MEMVAL_TLS: fprintf_filtered (stream, "TLS type @"); gdb_print_host_address (exp->elts[elt + 1].type, stream); fprintf_filtered (stream, " (__thread /* \"%s\" */ ", (exp->elts[elt].objfile == NULL ? "(null)" : exp->elts[elt].objfile->name)); type_print (exp->elts[elt + 1].type, NULL, stream, 0); fprintf_filtered (stream, ")"); elt = dump_subexp (exp, stream, elt + 3); break; case OP_TYPE: fprintf_filtered (stream, "Type @"); gdb_print_host_address (exp->elts[elt].type, stream); fprintf_filtered (stream, " ("); type_print (exp->elts[elt].type, NULL, stream, 0); fprintf_filtered (stream, ")"); elt += 2; break; case STRUCTOP_STRUCT: case STRUCTOP_PTR: { char *elem_name; int len; len = longest_to_int (exp->elts[elt].longconst); elem_name = &exp->elts[elt + 1].string; fprintf_filtered (stream, "Element name: `%.*s'", len, elem_name); elt = dump_subexp (exp, stream, elt + 3 + BYTES_TO_EXP_ELEM (len + 1)); } break; case OP_SCOPE: { char *elem_name; int len; fprintf_filtered (stream, "Type @"); gdb_print_host_address (exp->elts[elt].type, stream); fprintf_filtered (stream, " ("); type_print (exp->elts[elt].type, NULL, stream, 0); fprintf_filtered (stream, ") "); len = longest_to_int (exp->elts[elt + 1].longconst); elem_name = &exp->elts[elt + 2].string; fprintf_filtered (stream, "Field name: `%.*s'", len, elem_name); elt += 4 + BYTES_TO_EXP_ELEM (len + 1); } break; case TYPE_INSTANCE: { char *elem_name; LONGEST len; len = exp->elts[elt++].longconst; fprintf_filtered (stream, "%s TypeInstance: ", plongest (len)); while (len-- > 0) { fprintf_filtered (stream, "Type @"); gdb_print_host_address (exp->elts[elt].type, stream); fprintf_filtered (stream, " ("); type_print (exp->elts[elt].type, NULL, stream, 0); fprintf_filtered (stream, ")"); elt++; if (len > 0) fputs_filtered (", ", stream); } /* Ending LEN and ending TYPE_INSTANCE. */ elt += 2; elt = dump_subexp (exp, stream, elt); } break; default: case OP_NULL: case MULTI_SUBSCRIPT: case OP_F77_UNDETERMINED_ARGLIST: case OP_COMPLEX: case OP_STRING: case OP_BITSTRING: case OP_BOOL: case OP_M2_STRING: case OP_THIS: case OP_LABELED: case OP_NAME: fprintf_filtered (stream, "Unknown format"); } return elt; }
/* Standard implementation of print_subexp for use in language_defn vectors. */ void print_subexp_standard (struct expression *exp, int *pos, struct ui_file *stream, enum precedence prec) { unsigned tem; const struct op_print *op_print_tab; int pc; unsigned nargs; char *op_str; int assign_modify = 0; enum exp_opcode opcode; enum precedence myprec = PREC_NULL; /* Set to 1 for a right-associative operator. */ int assoc = 0; struct value *val; char *tempstr = NULL; op_print_tab = exp->language_defn->la_op_print_tab; pc = (*pos)++; opcode = exp->elts[pc].opcode; switch (opcode) { /* Common ops */ case OP_SCOPE: myprec = PREC_PREFIX; assoc = 0; fputs_filtered (type_name_no_tag (exp->elts[pc + 1].type), stream); fputs_filtered ("::", stream); nargs = longest_to_int (exp->elts[pc + 2].longconst); (*pos) += 4 + BYTES_TO_EXP_ELEM (nargs + 1); fputs_filtered (&exp->elts[pc + 3].string, stream); return; case OP_LONG: { struct value_print_options opts; get_raw_print_options (&opts); (*pos) += 3; value_print (value_from_longest (exp->elts[pc + 1].type, exp->elts[pc + 2].longconst), stream, &opts); } return; case OP_DOUBLE: { struct value_print_options opts; get_raw_print_options (&opts); (*pos) += 3; value_print (value_from_double (exp->elts[pc + 1].type, exp->elts[pc + 2].doubleconst), stream, &opts); } return; case OP_VAR_VALUE: { struct block *b; (*pos) += 3; b = exp->elts[pc + 1].block; if (b != NULL && BLOCK_FUNCTION (b) != NULL && SYMBOL_PRINT_NAME (BLOCK_FUNCTION (b)) != NULL) { fputs_filtered (SYMBOL_PRINT_NAME (BLOCK_FUNCTION (b)), stream); fputs_filtered ("::", stream); } fputs_filtered (SYMBOL_PRINT_NAME (exp->elts[pc + 2].symbol), stream); } return; case OP_LAST: (*pos) += 2; fprintf_filtered (stream, "$%d", longest_to_int (exp->elts[pc + 1].longconst)); return; case OP_REGISTER: { const char *name = &exp->elts[pc + 2].string; (*pos) += 3 + BYTES_TO_EXP_ELEM (exp->elts[pc + 1].longconst + 1); fprintf_filtered (stream, "$%s", name); return; } case OP_BOOL: (*pos) += 2; fprintf_filtered (stream, "%s", longest_to_int (exp->elts[pc + 1].longconst) ? "TRUE" : "FALSE"); return; case OP_INTERNALVAR: (*pos) += 2; fprintf_filtered (stream, "$%s", internalvar_name (exp->elts[pc + 1].internalvar)); return; case OP_FUNCALL: (*pos) += 2; nargs = longest_to_int (exp->elts[pc + 1].longconst); print_subexp (exp, pos, stream, PREC_SUFFIX); fputs_filtered (" (", stream); for (tem = 0; tem < nargs; tem++) { if (tem != 0) fputs_filtered (", ", stream); print_subexp (exp, pos, stream, PREC_ABOVE_COMMA); } fputs_filtered (")", stream); return; case OP_NAME: nargs = longest_to_int (exp->elts[pc + 1].longconst); (*pos) += 3 + BYTES_TO_EXP_ELEM (nargs + 1); fputs_filtered (&exp->elts[pc + 2].string, stream); return; case OP_STRING: { struct value_print_options opts; nargs = longest_to_int (exp->elts[pc + 1].longconst); (*pos) += 3 + BYTES_TO_EXP_ELEM (nargs + 1); /* LA_PRINT_STRING will print using the current repeat count threshold. If necessary, we can temporarily set it to zero, or pass it as an additional parameter to LA_PRINT_STRING. -fnf */ get_user_print_options (&opts); LA_PRINT_STRING (stream, builtin_type (exp->gdbarch)->builtin_char, &exp->elts[pc + 2].string, nargs, NULL, 0, &opts); } return; case OP_BITSTRING: nargs = longest_to_int (exp->elts[pc + 1].longconst); (*pos) += 3 + BYTES_TO_EXP_ELEM ((nargs + HOST_CHAR_BIT - 1) / HOST_CHAR_BIT); fprintf_unfiltered (stream, "B'<unimplemented>'"); return; case OP_OBJC_NSSTRING: /* Objective-C Foundation Class NSString constant. */ { struct value_print_options opts; nargs = longest_to_int (exp->elts[pc + 1].longconst); (*pos) += 3 + BYTES_TO_EXP_ELEM (nargs + 1); fputs_filtered ("@\"", stream); get_user_print_options (&opts); LA_PRINT_STRING (stream, builtin_type (exp->gdbarch)->builtin_char, &exp->elts[pc + 2].string, nargs, NULL, 0, &opts); fputs_filtered ("\"", stream); } return; case OP_OBJC_MSGCALL: { /* Objective C message (method) call. */ char *selector; (*pos) += 3; nargs = longest_to_int (exp->elts[pc + 2].longconst); fprintf_unfiltered (stream, "["); print_subexp (exp, pos, stream, PREC_SUFFIX); if (0 == target_read_string (exp->elts[pc + 1].longconst, &selector, 1024, NULL)) { error (_("bad selector")); return; } if (nargs) { char *s, *nextS; s = alloca (strlen (selector) + 1); strcpy (s, selector); for (tem = 0; tem < nargs; tem++) { nextS = strchr (s, ':'); gdb_assert (nextS); /* Make sure we found ':'. */ *nextS = '\0'; fprintf_unfiltered (stream, " %s: ", s); s = nextS + 1; print_subexp (exp, pos, stream, PREC_ABOVE_COMMA); } } else { fprintf_unfiltered (stream, " %s", selector); } fprintf_unfiltered (stream, "]"); /* "selector" was malloc'd by target_read_string. Free it. */ xfree (selector); return; } case OP_ARRAY: (*pos) += 3; nargs = longest_to_int (exp->elts[pc + 2].longconst); nargs -= longest_to_int (exp->elts[pc + 1].longconst); nargs++; tem = 0; if (exp->elts[pc + 4].opcode == OP_LONG && exp->elts[pc + 5].type == builtin_type (exp->gdbarch)->builtin_char && exp->language_defn->la_language == language_c) { /* Attempt to print C character arrays using string syntax. Walk through the args, picking up one character from each of the OP_LONG expression elements. If any array element does not match our expection of what we should find for a simple string, revert back to array printing. Note that the last expression element is an explicit null terminator byte, which doesn't get printed. */ tempstr = alloca (nargs); pc += 4; while (tem < nargs) { if (exp->elts[pc].opcode != OP_LONG || exp->elts[pc + 1].type != builtin_type (exp->gdbarch)->builtin_char) { /* Not a simple array of char, use regular array printing. */ tem = 0; break; } else { tempstr[tem++] = longest_to_int (exp->elts[pc + 2].longconst); pc += 4; } } } if (tem > 0) { struct value_print_options opts; get_user_print_options (&opts); LA_PRINT_STRING (stream, builtin_type (exp->gdbarch)->builtin_char, tempstr, nargs - 1, NULL, 0, &opts); (*pos) = pc; } else { fputs_filtered (" {", stream); for (tem = 0; tem < nargs; tem++) { if (tem != 0) { fputs_filtered (", ", stream); } print_subexp (exp, pos, stream, PREC_ABOVE_COMMA); } fputs_filtered ("}", stream); } return; case OP_LABELED: tem = longest_to_int (exp->elts[pc + 1].longconst); (*pos) += 3 + BYTES_TO_EXP_ELEM (tem + 1); /* Gcc support both these syntaxes. Unsure which is preferred. */ #if 1 fputs_filtered (&exp->elts[pc + 2].string, stream); fputs_filtered (": ", stream); #else fputs_filtered (".", stream); fputs_filtered (&exp->elts[pc + 2].string, stream); fputs_filtered ("=", stream); #endif print_subexp (exp, pos, stream, PREC_SUFFIX); return; case TERNOP_COND: if ((int) prec > (int) PREC_COMMA) fputs_filtered ("(", stream); /* Print the subexpressions, forcing parentheses around any binary operations within them. This is more parentheses than are strictly necessary, but it looks clearer. */ print_subexp (exp, pos, stream, PREC_HYPER); fputs_filtered (" ? ", stream); print_subexp (exp, pos, stream, PREC_HYPER); fputs_filtered (" : ", stream); print_subexp (exp, pos, stream, PREC_HYPER); if ((int) prec > (int) PREC_COMMA) fputs_filtered (")", stream); return; case TERNOP_SLICE: case TERNOP_SLICE_COUNT: print_subexp (exp, pos, stream, PREC_SUFFIX); fputs_filtered ("(", stream); print_subexp (exp, pos, stream, PREC_ABOVE_COMMA); fputs_filtered (opcode == TERNOP_SLICE ? " : " : " UP ", stream); print_subexp (exp, pos, stream, PREC_ABOVE_COMMA); fputs_filtered (")", stream); return; case STRUCTOP_STRUCT: tem = longest_to_int (exp->elts[pc + 1].longconst); (*pos) += 3 + BYTES_TO_EXP_ELEM (tem + 1); print_subexp (exp, pos, stream, PREC_SUFFIX); fputs_filtered (".", stream); fputs_filtered (&exp->elts[pc + 2].string, stream); return; /* Will not occur for Modula-2. */ case STRUCTOP_PTR: tem = longest_to_int (exp->elts[pc + 1].longconst); (*pos) += 3 + BYTES_TO_EXP_ELEM (tem + 1); print_subexp (exp, pos, stream, PREC_SUFFIX); fputs_filtered ("->", stream); fputs_filtered (&exp->elts[pc + 2].string, stream); return; case STRUCTOP_MEMBER: print_subexp (exp, pos, stream, PREC_SUFFIX); fputs_filtered (".*", stream); print_subexp (exp, pos, stream, PREC_SUFFIX); return; case STRUCTOP_MPTR: print_subexp (exp, pos, stream, PREC_SUFFIX); fputs_filtered ("->*", stream); print_subexp (exp, pos, stream, PREC_SUFFIX); return; case BINOP_SUBSCRIPT: print_subexp (exp, pos, stream, PREC_SUFFIX); fputs_filtered ("[", stream); print_subexp (exp, pos, stream, PREC_ABOVE_COMMA); fputs_filtered ("]", stream); return; case UNOP_POSTINCREMENT: print_subexp (exp, pos, stream, PREC_SUFFIX); fputs_filtered ("++", stream); return; case UNOP_POSTDECREMENT: print_subexp (exp, pos, stream, PREC_SUFFIX); fputs_filtered ("--", stream); return; case UNOP_CAST: (*pos) += 2; if ((int) prec > (int) PREC_PREFIX) fputs_filtered ("(", stream); fputs_filtered ("(", stream); type_print (exp->elts[pc + 1].type, "", stream, 0); fputs_filtered (") ", stream); print_subexp (exp, pos, stream, PREC_PREFIX); if ((int) prec > (int) PREC_PREFIX) fputs_filtered (")", stream); return; case UNOP_DYNAMIC_CAST: case UNOP_REINTERPRET_CAST: fputs_filtered (opcode == UNOP_DYNAMIC_CAST ? "dynamic_cast" : "reinterpret_cast", stream); fputs_filtered ("<", stream); (*pos) += 2; type_print (exp->elts[pc + 1].type, "", stream, 0); fputs_filtered ("> (", stream); print_subexp (exp, pos, stream, PREC_PREFIX); fputs_filtered (")", stream); return; case UNOP_MEMVAL: (*pos) += 2; if ((int) prec > (int) PREC_PREFIX) fputs_filtered ("(", stream); if (TYPE_CODE (exp->elts[pc + 1].type) == TYPE_CODE_FUNC && exp->elts[pc + 3].opcode == OP_LONG) { struct value_print_options opts; /* We have a minimal symbol fn, probably. It's encoded as a UNOP_MEMVAL (function-type) of an OP_LONG (int, address). Swallow the OP_LONG (including both its opcodes); ignore its type; print the value in the type of the MEMVAL. */ (*pos) += 4; val = value_at_lazy (exp->elts[pc + 1].type, (CORE_ADDR) exp->elts[pc + 5].longconst); get_raw_print_options (&opts); value_print (val, stream, &opts); } else { fputs_filtered ("{", stream); type_print (exp->elts[pc + 1].type, "", stream, 0); fputs_filtered ("} ", stream); print_subexp (exp, pos, stream, PREC_PREFIX); } if ((int) prec > (int) PREC_PREFIX) fputs_filtered (")", stream); return; case UNOP_MEMVAL_TLS: (*pos) += 3; if ((int) prec > (int) PREC_PREFIX) fputs_filtered ("(", stream); fputs_filtered ("{", stream); type_print (exp->elts[pc + 2].type, "", stream, 0); fputs_filtered ("} ", stream); print_subexp (exp, pos, stream, PREC_PREFIX); if ((int) prec > (int) PREC_PREFIX) fputs_filtered (")", stream); return; case BINOP_ASSIGN_MODIFY: opcode = exp->elts[pc + 1].opcode; (*pos) += 2; myprec = PREC_ASSIGN; assoc = 1; assign_modify = 1; op_str = "???"; for (tem = 0; op_print_tab[tem].opcode != OP_NULL; tem++) if (op_print_tab[tem].opcode == opcode) { op_str = op_print_tab[tem].string; break; } if (op_print_tab[tem].opcode != opcode) /* Not found; don't try to keep going because we don't know how to interpret further elements. */ error (_("Invalid expression")); break; /* C++ ops */ case OP_THIS: ++(*pos); fputs_filtered ("this", stream); return; /* Objective-C ops */ case OP_OBJC_SELF: ++(*pos); fputs_filtered ("self", stream); /* The ObjC equivalent of "this". */ return; /* Modula-2 ops */ case MULTI_SUBSCRIPT: (*pos) += 2; nargs = longest_to_int (exp->elts[pc + 1].longconst); print_subexp (exp, pos, stream, PREC_SUFFIX); fprintf_unfiltered (stream, " ["); for (tem = 0; tem < nargs; tem++) { if (tem != 0) fprintf_unfiltered (stream, ", "); print_subexp (exp, pos, stream, PREC_ABOVE_COMMA); } fprintf_unfiltered (stream, "]"); return; case BINOP_VAL: (*pos) += 2; fprintf_unfiltered (stream, "VAL("); type_print (exp->elts[pc + 1].type, "", stream, 0); fprintf_unfiltered (stream, ","); print_subexp (exp, pos, stream, PREC_PREFIX); fprintf_unfiltered (stream, ")"); return; case TYPE_INSTANCE: { LONGEST count = exp->elts[pc + 1].longconst; /* The COUNT. */ (*pos)++; fputs_unfiltered ("TypesInstance(", stream); while (count-- > 0) { type_print (exp->elts[(*pos)++].type, "", stream, 0); if (count > 0) fputs_unfiltered (",", stream); } fputs_unfiltered (",", stream); /* Ending COUNT and ending TYPE_INSTANCE. */ (*pos) += 2; print_subexp (exp, pos, stream, PREC_PREFIX); fputs_unfiltered (")", stream); return; } /* Default ops */ default: op_str = "???"; for (tem = 0; op_print_tab[tem].opcode != OP_NULL; tem++) if (op_print_tab[tem].opcode == opcode) { op_str = op_print_tab[tem].string; myprec = op_print_tab[tem].precedence; assoc = op_print_tab[tem].right_assoc; break; } if (op_print_tab[tem].opcode != opcode) /* Not found; don't try to keep going because we don't know how to interpret further elements. For example, this happens if opcode is OP_TYPE. */ error (_("Invalid expression")); } /* Note that PREC_BUILTIN will always emit parentheses. */ if ((int) myprec < (int) prec) fputs_filtered ("(", stream); if ((int) opcode > (int) BINOP_END) { if (assoc) { /* Unary postfix operator. */ print_subexp (exp, pos, stream, PREC_SUFFIX); fputs_filtered (op_str, stream); } else { /* Unary prefix operator. */ fputs_filtered (op_str, stream); if (myprec == PREC_BUILTIN_FUNCTION) fputs_filtered ("(", stream); print_subexp (exp, pos, stream, PREC_PREFIX); if (myprec == PREC_BUILTIN_FUNCTION) fputs_filtered (")", stream); } } else { /* Binary operator. */ /* Print left operand. If operator is right-associative, increment precedence for this operand. */ print_subexp (exp, pos, stream, (enum precedence) ((int) myprec + assoc)); /* Print the operator itself. */ if (assign_modify) fprintf_filtered (stream, " %s= ", op_str); else if (op_str[0] == ',') fprintf_filtered (stream, "%s ", op_str); else fprintf_filtered (stream, " %s ", op_str); /* Print right operand. If operator is left-associative, increment precedence for this operand. */ print_subexp (exp, pos, stream, (enum precedence) ((int) myprec + !assoc)); } if ((int) myprec < (int) prec) fputs_filtered (")", stream); }
void c_printstr (struct ui_file *stream, char *string, unsigned int length, int width, int force_ellipses) { unsigned int i; unsigned int things_printed = 0; int in_quotes = 0; int need_comma = 0; /* If the string was not truncated due to `set print elements', and the last byte of it is a null, we don't print that, in traditional C style. */ if (!force_ellipses && length > 0 && (extract_unsigned_integer (string + (length - 1) * width, width) == '\0')) length--; if (length == 0) { fputs_filtered ("\"\"", stream); return; } for (i = 0; i < length && things_printed < print_max; ++i) { /* Position of the character we are examining to see whether it is repeated. */ unsigned int rep1; /* Number of repetitions we have detected so far. */ unsigned int reps; unsigned long current_char; QUIT; if (need_comma) { fputs_filtered (", ", stream); need_comma = 0; } current_char = extract_unsigned_integer (string + i * width, width); rep1 = i + 1; reps = 1; while (rep1 < length && extract_unsigned_integer (string + rep1 * width, width) == current_char) { ++rep1; ++reps; } if (reps > repeat_count_threshold) { if (in_quotes) { if (inspect_it) fputs_filtered ("\\\", ", stream); else fputs_filtered ("\", ", stream); in_quotes = 0; } LA_PRINT_CHAR (current_char, stream); fprintf_filtered (stream, " <repeats %u times>", reps); i = rep1 - 1; things_printed += repeat_count_threshold; need_comma = 1; } else { if (!in_quotes) { if (inspect_it) fputs_filtered ("\\\"", stream); else fputs_filtered ("\"", stream); in_quotes = 1; } LA_EMIT_CHAR (current_char, stream, '"'); ++things_printed; } } /* Terminate the quotes if necessary. */ if (in_quotes) { if (inspect_it) fputs_filtered ("\\\"", stream); else fputs_filtered ("\"", stream); } if (force_ellipses || i < length) fputs_filtered ("...", stream); }