-
- switch (TYPE_CODE (type))
- {
- case TYPE_CODE_ARRAY:
- if (TYPE_LENGTH (type) > 0
- && TYPE_LENGTH (TYPE_TARGET_TYPE (type)) > 0)
- {
- elttype = TYPE_TARGET_TYPE (type);
- eltlen = TYPE_LENGTH (elttype);
- len = TYPE_LENGTH (type) / eltlen;
- if (arrayprint)
- print_spaces_filtered (2 + 2 * recurse, stream);
- fprintf_filtered (stream, "{");
- /* For an array of chars, print with string syntax. */
- if (eltlen == 1 && TYPE_CODE (elttype) == TYPE_CODE_INT
- && (format == 0 || format == 's') )
- print_string (stream, valaddr, len, 0);
- else
- {
- unsigned int things_printed = 0;
-
- /* If this is a virtual function table, print the 0th
- entry specially, and the rest of the members normally. */
- if (is_vtbl_ptr_type (elttype))
- {
- fprintf_filtered (stream, "%d vtable entries", len-1);
- i = 1;
- }
- else
- i = 0;
-
- for (; i < len && things_printed < print_max; i++)
- {
- /* Position of the array element we are examining to see
- whether it is repeated. */
- unsigned int rep1;
- /* Number of repetitions we have detected so far. */
- unsigned int reps;
-
- if (i != 0)
- if (arrayprint)
- {
- fprintf_filtered (stream, ",\n");
- print_spaces_filtered (2 + 2 * recurse, stream);
- }
- else
- fprintf_filtered (stream, ", ");
- wrap_here (n_spaces (2 + 2 * recurse));
-
- rep1 = i + 1;
- reps = 1;
- while (rep1 < len
- && !memcmp (valaddr + i * eltlen,
- valaddr + rep1 * eltlen, eltlen))
- {
- ++reps;
- ++rep1;
- }
-
- if (reps > REPEAT_COUNT_THRESHOLD)
- {
- val_print (elttype, valaddr + i * eltlen,
- 0, stream, format, deref_ref,
- recurse + 1, pretty);
- fprintf_filtered (stream, " <repeats %u times>", reps);
- i = rep1 - 1;
- things_printed += REPEAT_COUNT_THRESHOLD;
- }
- else
- {
- val_print (elttype, valaddr + i * eltlen,
- 0, stream, format, deref_ref,
- recurse + 1, pretty);
- things_printed++;
- }
- }
- if (i < len)
- fprintf_filtered (stream, "...");
- }
- fprintf_filtered (stream, "}");
- break;
- }
- /* Array of unspecified length: treat like pointer to first elt. */
- valaddr = (char *) &address;
-
- case TYPE_CODE_PTR:
- if (format && format != 's')
- {
- print_scalar_formatted (valaddr, type, format, 0, stream);
- break;
- }
- if (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_METHOD)
- {
- struct type *domain = TYPE_DOMAIN_TYPE (TYPE_TARGET_TYPE (type));
- struct fn_field *f;
- int j, len2;
- char *kind = "";
- CORE_ADDR addr;
-
- addr = unpack_pointer (lookup_pointer_type (builtin_type_void),
- valaddr);
- if (addr < 128) /* FIXME! What is this 128? */
- {
- len = TYPE_NFN_FIELDS (domain);
- for (i = 0; i < len; i++)
- {
- f = TYPE_FN_FIELDLIST1 (domain, i);
- len2 = TYPE_FN_FIELDLIST_LENGTH (domain, i);
-
- for (j = 0; j < len2; j++)
- {
- QUIT;
- if (TYPE_FN_FIELD_VOFFSET (f, j) == addr)
- {
- kind = "virtual";
- goto common;
- }
- }
- }
- }
- else
- {
- struct symbol *sym = find_pc_function (addr);
- if (sym == 0)
- error ("invalid pointer to member function");
- len = TYPE_NFN_FIELDS (domain);
- for (i = 0; i < len; i++)
- {
- f = TYPE_FN_FIELDLIST1 (domain, i);
- len2 = TYPE_FN_FIELDLIST_LENGTH (domain, i);
-
- for (j = 0; j < len2; j++)
- {
- QUIT;
- if (!strcmp (SYMBOL_NAME (sym), TYPE_FN_FIELD_PHYSNAME (f, j)))
- goto common;
- }
- }
- }
- common:
- if (i < len)
- {
- fprintf_filtered (stream, "&");
- type_print_varspec_prefix (TYPE_FN_FIELD_TYPE (f, j), stream, 0, 0);
- fprintf (stream, kind);
- if (TYPE_FN_FIELD_PHYSNAME (f, j)[0] == '_'
- && TYPE_FN_FIELD_PHYSNAME (f, j)[1] == CPLUS_MARKER)
- type_print_method_args
- (TYPE_FN_FIELD_ARGS (f, j) + 1, "~",
- TYPE_FN_FIELDLIST_NAME (domain, i), 0, stream);
- else
- type_print_method_args
- (TYPE_FN_FIELD_ARGS (f, j), "",
- TYPE_FN_FIELDLIST_NAME (domain, i), 0, stream);
- break;
- }
- fprintf_filtered (stream, "(");
- type_print (type, "", stream, -1);
- fprintf_filtered (stream, ") %d", (int) addr >> 3);
- }
- else if (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_MEMBER)
- {
- print_class_member (valaddr,
- TYPE_DOMAIN_TYPE (TYPE_TARGET_TYPE (type)),
- stream, "&");
- }
- else
- {
- CORE_ADDR addr = unpack_pointer (type, valaddr);
- elttype = TYPE_TARGET_TYPE (type);
-
- if (TYPE_CODE (elttype) == TYPE_CODE_FUNC)
- {
- /* Try to print what function it points to. */
- print_address_demangle (addr, stream, demangle);
- /* Return value is irrelevant except for string pointers. */
- return 0;
- }
-
- if (addressprint && format != 's')
- fprintf_filtered (stream, "0x%x", addr);
-
- /* For a pointer to char or unsigned char,
- also print the string pointed to, unless pointer is null. */
- i = 0; /* Number of characters printed. */
- if (TYPE_LENGTH (elttype) == 1
- && TYPE_CODE (elttype) == TYPE_CODE_INT
- && (format == 0 || format == 's')
- && addr != 0
- /* If print_max is UINT_MAX, the alloca below will fail.
- In that case don't try to print the string. */
- && print_max < UINT_MAX)
- {
- int first_addr_err = 0;
- int errcode = 0;
-
- /* Get first character. */
- errcode = target_read_memory (addr, (char *)&c, 1);
- if (errcode != 0)
- {
- /* First address out of bounds. */
- first_addr_err = 1;
- }
- else
- {
- /* A real string. */
- char *string = (char *) alloca (print_max);
-
- /* If the loop ends by us hitting print_max characters,
- we need to have elipses at the end. */
- int force_ellipses = 1;
-
- /* This loop always fetches print_max characters, even
- though print_string might want to print more or fewer
- (with repeated characters). This is so that
- we don't spend forever fetching if we print
- a long string consisting of the same character
- repeated. Also so we can do it all in one memory
- operation, which is faster. However, this will be
- slower if print_max is set high, e.g. if you set
- print_max to 1000, not only will it take a long
- time to fetch short strings, but if you are near
- the end of the address space, it might not work. */
- QUIT;
- errcode = target_read_memory (addr, string, print_max);
- if (errcode != 0)
- {
- /* Try reading just one character. If that succeeds,
- assume we hit the end of the address space, but
- the initial part of the string is probably safe. */
- char x[1];
- errcode = target_read_memory (addr, x, 1);
- }
- if (errcode != 0)
- force_ellipses = 0;
- else
- for (i = 0; i < print_max; i++)
- if (string[i] == '\0')
- {
- force_ellipses = 0;
- break;
- }
- QUIT;
-
- if (addressprint)
- fputs_filtered (" ", stream);
- print_string (stream, string, i, force_ellipses);
- }
-
- if (errcode != 0)
- {
- if (errcode == EIO)
- {
- fprintf_filtered (stream,
- (" <Address 0x%x out of bounds>"
- + first_addr_err),
- addr + i);
- }
- else
- {
- error ("Error reading memory address 0x%x: %s.",
- addr + i, safe_strerror (errcode));
- }
- }
-
- fflush (stream);
- }
- else /* print vtbl's nicely */
- if (is_vtbl_member(type))
- {
- CORE_ADDR vt_address = unpack_pointer (type, valaddr);
-
- struct minimal_symbol *msymbol =
- lookup_minimal_symbol_by_pc (vt_address);
- if ((msymbol != NULL) && (vt_address == msymbol -> address))
- {
- fputs_filtered (" <", stream);
- fputs_demangled (msymbol -> name, stream,
- DMGL_ANSI | DMGL_PARAMS);
- fputs_filtered (">", stream);
- }
- if (vtblprint)
- {
- value vt_val;
-
- vt_val = value_at (TYPE_TARGET_TYPE (type), vt_address);
- val_print (VALUE_TYPE (vt_val), VALUE_CONTENTS (vt_val),
- VALUE_ADDRESS (vt_val), stream, format,
- deref_ref, recurse + 1, pretty);
- if (pretty)
- {
- fprintf_filtered (stream, "\n");
- print_spaces_filtered (2 + 2 * recurse, stream);
- }
- }
- }