diff options
Diffstat (limited to 'gdb/valprint.c')
-rw-r--r-- | gdb/valprint.c | 172 |
1 files changed, 0 insertions, 172 deletions
diff --git a/gdb/valprint.c b/gdb/valprint.c index 8f99547..4711467 100644 --- a/gdb/valprint.c +++ b/gdb/valprint.c @@ -85,9 +85,6 @@ struct cmd_list_element *showprintrawlist; /* Prototypes for local functions */ -static int partial_memory_read (CORE_ADDR memaddr, gdb_byte *myaddr, - int len, int *errptr); - static void set_input_radix_1 (int, unsigned); static void set_output_radix_1 (int, unsigned); @@ -1989,175 +1986,6 @@ value_print_array_elements (struct value *val, struct ui_file *stream, } } -/* Read LEN bytes of target memory at address MEMADDR, placing the - results in GDB's memory at MYADDR. Returns a count of the bytes - actually read, and optionally a target_xfer_status value in the - location pointed to by ERRPTR if ERRPTR is non-null. */ - -/* FIXME: cagney/1999-10-14: Only used by val_print_string. Can this - function be eliminated. */ - -static int -partial_memory_read (CORE_ADDR memaddr, gdb_byte *myaddr, - int len, int *errptr) -{ - int nread; /* Number of bytes actually read. */ - int errcode; /* Error from last read. */ - - /* First try a complete read. */ - errcode = target_read_memory (memaddr, myaddr, len); - if (errcode == 0) - { - /* Got it all. */ - nread = len; - } - else - { - /* Loop, reading one byte at a time until we get as much as we can. */ - for (errcode = 0, nread = 0; len > 0 && errcode == 0; nread++, len--) - { - errcode = target_read_memory (memaddr++, myaddr++, 1); - } - /* If an error, the last read was unsuccessful, so adjust count. */ - if (errcode != 0) - { - nread--; - } - } - if (errptr != NULL) - { - *errptr = errcode; - } - return (nread); -} - -/* Read a string from the inferior, at ADDR, with LEN characters of - WIDTH bytes each. Fetch at most FETCHLIMIT characters. BUFFER - will be set to a newly allocated buffer containing the string, and - BYTES_READ will be set to the number of bytes read. Returns 0 on - success, or a target_xfer_status on failure. - - If LEN > 0, reads the lesser of LEN or FETCHLIMIT characters - (including eventual NULs in the middle or end of the string). - - If LEN is -1, stops at the first null character (not necessarily - the first null byte) up to a maximum of FETCHLIMIT characters. Set - FETCHLIMIT to UINT_MAX to read as many characters as possible from - the string. - - Unless an exception is thrown, BUFFER will always be allocated, even on - failure. In this case, some characters might have been read before the - failure happened. Check BYTES_READ to recognize this situation. */ - -int -target_read_string (CORE_ADDR addr, int len, int width, - unsigned int fetchlimit, - gdb::unique_xmalloc_ptr<gdb_byte> *buffer, - int *bytes_read) -{ - int errcode; /* Errno returned from bad reads. */ - unsigned int nfetch; /* Chars to fetch / chars fetched. */ - gdb_byte *bufptr; /* Pointer to next available byte in - buffer. */ - - /* Loop until we either have all the characters, or we encounter - some error, such as bumping into the end of the address space. */ - - buffer->reset (nullptr); - - if (len > 0) - { - /* We want fetchlimit chars, so we might as well read them all in - one operation. */ - unsigned int fetchlen = std::min ((unsigned) len, fetchlimit); - - buffer->reset ((gdb_byte *) xmalloc (fetchlen * width)); - bufptr = buffer->get (); - - nfetch = partial_memory_read (addr, bufptr, fetchlen * width, &errcode) - / width; - addr += nfetch * width; - bufptr += nfetch * width; - } - else if (len == -1) - { - unsigned long bufsize = 0; - unsigned int chunksize; /* Size of each fetch, in chars. */ - int found_nul; /* Non-zero if we found the nul char. */ - gdb_byte *limit; /* First location past end of fetch buffer. */ - - found_nul = 0; - /* We are looking for a NUL terminator to end the fetching, so we - might as well read in blocks that are large enough to be efficient, - but not so large as to be slow if fetchlimit happens to be large. - So we choose the minimum of 8 and fetchlimit. We used to use 200 - instead of 8 but 200 is way too big for remote debugging over a - serial line. */ - chunksize = std::min (8u, fetchlimit); - - do - { - nfetch = std::min ((unsigned long) chunksize, fetchlimit - bufsize); - - if (*buffer == NULL) - buffer->reset ((gdb_byte *) xmalloc (nfetch * width)); - else - buffer->reset ((gdb_byte *) xrealloc (buffer->release (), - (nfetch + bufsize) * width)); - - bufptr = buffer->get () + bufsize * width; - bufsize += nfetch; - - /* Read as much as we can. */ - nfetch = partial_memory_read (addr, bufptr, nfetch * width, &errcode) - / width; - - /* Scan this chunk for the null character that terminates the string - to print. If found, we don't need to fetch any more. Note - that bufptr is explicitly left pointing at the next character - after the null character, or at the next character after the end - of the buffer. */ - - limit = bufptr + nfetch * width; - while (bufptr < limit) - { - bool found_nonzero = false; - - for (int i = 0; !found_nonzero && i < width; ++i) - if (bufptr[i] != 0) - found_nonzero = true; - - addr += width; - bufptr += width; - if (!found_nonzero) - { - /* We don't care about any error which happened after - the NUL terminator. */ - errcode = 0; - found_nul = 1; - break; - } - } - } - while (errcode == 0 /* no error */ - && bufptr - buffer->get () < fetchlimit * width /* no overrun */ - && !found_nul); /* haven't found NUL yet */ - } - else - { /* Length of string is really 0! */ - /* We always allocate *buffer. */ - buffer->reset ((gdb_byte *) xmalloc (1)); - bufptr = buffer->get (); - errcode = 0; - } - - /* bufptr and addr now point immediately beyond the last byte which we - consider part of the string (including a '\0' which ends the string). */ - *bytes_read = bufptr - buffer->get (); - - return errcode; -} - /* Return true if print_wchar can display W without resorting to a numeric escape, false otherwise. */ |