+ *bytes_read = bufptr - *buffer;
+
+ QUIT;
+
+ discard_cleanups (old_chain);
+
+ return errcode;
+}
+
+/* Print a string from the inferior, starting at ADDR and printing up to LEN
+ characters, of WIDTH bytes a piece, to STREAM. If LEN is -1, printing
+ stops at the first null byte, otherwise printing proceeds (including null
+ bytes) until either print_max or LEN characters have been printed,
+ whichever is smaller. */
+
+int
+val_print_string (struct type *elttype, CORE_ADDR addr, int len,
+ struct ui_file *stream,
+ const struct value_print_options *options)
+{
+ int force_ellipsis = 0; /* Force ellipsis to be printed if nonzero. */
+ int errcode; /* Errno returned from bad reads. */
+ int found_nul; /* Non-zero if we found the nul char */
+ unsigned int fetchlimit; /* Maximum number of chars to print. */
+ int bytes_read;
+ gdb_byte *buffer = NULL; /* Dynamically growable fetch buffer. */
+ struct cleanup *old_chain = NULL; /* Top of the old cleanup chain. */
+ struct gdbarch *gdbarch = get_type_arch (elttype);
+ enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
+ int width = TYPE_LENGTH (elttype);
+
+ /* First we need to figure out the limit on the number of characters we are
+ going to attempt to fetch and print. This is actually pretty simple. If
+ LEN >= zero, then the limit is the minimum of LEN and print_max. If
+ LEN is -1, then the limit is print_max. This is true regardless of
+ whether print_max is zero, UINT_MAX (unlimited), or something in between,
+ because finding the null byte (or available memory) is what actually
+ limits the fetch. */
+
+ fetchlimit = (len == -1 ? options->print_max : min (len, options->print_max));
+
+ errcode = read_string (addr, len, width, fetchlimit, byte_order,
+ &buffer, &bytes_read);
+ old_chain = make_cleanup (xfree, buffer);
+
+ addr += bytes_read;