diff options
author | Tom Tromey <tom@tromey.com> | 2023-06-17 13:36:40 -0600 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2023-06-20 07:52:28 -0600 |
commit | 6b19f38ae331d2d889354fcd749e2478a868251c (patch) | |
tree | 39b6c72b5e7d9ea6073d5f69231e287a46497db9 /gdb | |
parent | b68e4ea64e99831032c5fc613ec432448cfc0c84 (diff) | |
download | gdb-6b19f38ae331d2d889354fcd749e2478a868251c.zip gdb-6b19f38ae331d2d889354fcd749e2478a868251c.tar.gz gdb-6b19f38ae331d2d889354fcd749e2478a868251c.tar.bz2 |
Use byte_vector in remote.c:readahead_cache
This patch changes the remote.c readahead_cache to use
gdb::byte_vector. This simplifies the code by removing manual memory
management.
Reviewed-by: John Baldwin <jhb@FreeBSD.org>
Diffstat (limited to 'gdb')
-rw-r--r-- | gdb/remote.c | 19 |
1 files changed, 8 insertions, 11 deletions
diff --git a/gdb/remote.c b/gdb/remote.c index 02ff3a1..513214c 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -354,10 +354,7 @@ struct readahead_cache ULONGEST offset = 0; /* The buffer holding the cache contents. */ - gdb_byte *buf = nullptr; - /* The buffer's size. We try to read as much as fits into a packet - at a time. */ - size_t bufsize = 0; + gdb::byte_vector buf; /* Cache hit and miss counters. */ ULONGEST hit_count = 0; @@ -12605,14 +12602,14 @@ readahead_cache::pread (int fd, gdb_byte *read_buf, size_t len, { if (this->fd == fd && this->offset <= offset - && offset < this->offset + this->bufsize) + && offset < this->offset + this->buf.size ()) { - ULONGEST max = this->offset + this->bufsize; + ULONGEST max = this->offset + this->buf.size (); if (offset + len > max) len = max - offset; - memcpy (read_buf, this->buf + offset - this->offset, len); + memcpy (read_buf, &this->buf[offset - this->offset], len); return len; } @@ -12646,10 +12643,10 @@ remote_target::remote_hostio_pread (int fd, gdb_byte *read_buf, int len, cache->fd = fd; cache->offset = offset; - cache->bufsize = get_remote_packet_size (); - cache->buf = (gdb_byte *) xrealloc (cache->buf, cache->bufsize); + cache->buf.resize (get_remote_packet_size ()); - ret = remote_hostio_pread_vFile (cache->fd, cache->buf, cache->bufsize, + ret = remote_hostio_pread_vFile (cache->fd, &cache->buf[0], + cache->buf.size (), cache->offset, remote_errno); if (ret <= 0) { @@ -12657,7 +12654,7 @@ remote_target::remote_hostio_pread (int fd, gdb_byte *read_buf, int len, return ret; } - cache->bufsize = ret; + cache->buf.resize (ret); return cache->pread (fd, read_buf, len, offset); } |