diff options
author | Pedro Alves <pedro@palves.net> | 2023-11-09 20:44:12 +0000 |
---|---|---|
committer | Pedro Alves <pedro@palves.net> | 2023-12-20 20:04:04 +0000 |
commit | d5cebea18e7a9a927f4dd4915d093feb7df0e029 (patch) | |
tree | 47a2f86caa6eb4d5ca55b28fd4181087e5ea2eef | |
parent | 5ac2d81b64af547cd7ac7251e9180730348572ad (diff) | |
download | gdb-d5cebea18e7a9a927f4dd4915d093feb7df0e029.zip gdb-d5cebea18e7a9a927f4dd4915d093feb7df0e029.tar.gz gdb-d5cebea18e7a9a927f4dd4915d093feb7df0e029.tar.bz2 |
Make cached_reg_t own its data
struct cached_reg_t owns its data buffer, but currently that is
managed manually. Convert it to use a unique_xmalloc_ptr.
Approved-By: Tom Tromey <tom@tromey.com>
Change-Id: I05a107098b717299e76de76aaba00d7fbaeac77b
-rw-r--r-- | gdb/python/py-unwind.c | 13 | ||||
-rw-r--r-- | gdb/regcache.h | 5 | ||||
-rw-r--r-- | gdb/remote.c | 24 |
3 files changed, 16 insertions, 26 deletions
diff --git a/gdb/python/py-unwind.c b/gdb/python/py-unwind.c index f1162f2..31b74c6 100644 --- a/gdb/python/py-unwind.c +++ b/gdb/python/py-unwind.c @@ -785,7 +785,7 @@ pyuw_prev_register (frame_info_ptr this_frame, void **cache_ptr, for (; reg_info < reg_info_end; ++reg_info) { if (regnum == reg_info->num) - return frame_unwind_got_bytes (this_frame, regnum, reg_info->data); + return frame_unwind_got_bytes (this_frame, regnum, reg_info->data.get ()); } return frame_unwind_got_optimized (this_frame, regnum); @@ -903,15 +903,14 @@ pyuw_sniffer (const struct frame_unwind *self, frame_info_ptr this_frame, struct value *value = value_object_to_value (reg->value.get ()); size_t data_size = register_size (gdbarch, reg->number); - cached_frame->reg[i].num = reg->number; - /* `value' validation was done before, just assert. */ gdb_assert (value != NULL); gdb_assert (data_size == value->type ()->length ()); - cached_frame->reg[i].data = (gdb_byte *) xmalloc (data_size); - memcpy (cached_frame->reg[i].data, - value->contents ().data (), data_size); + cached_reg_t *cached = new (&cached_frame->reg[i]) cached_reg_t (); + cached->num = reg->number; + cached->data.reset ((gdb_byte *) xmalloc (data_size)); + memcpy (cached->data.get (), value->contents ().data (), data_size); } } @@ -928,7 +927,7 @@ pyuw_dealloc_cache (frame_info *this_frame, void *cache) cached_frame_info *cached_frame = (cached_frame_info *) cache; for (int i = 0; i < cached_frame->reg_count; i++) - xfree (cached_frame->reg[i].data); + cached_frame->reg[i].~cached_reg_t (); xfree (cache); } diff --git a/gdb/regcache.h b/gdb/regcache.h index d90f74b..85890b6 100644 --- a/gdb/regcache.h +++ b/gdb/regcache.h @@ -176,7 +176,10 @@ using register_read_ftype struct cached_reg_t { int num; - gdb_byte *data; + gdb::unique_xmalloc_ptr<gdb_byte> data; + + cached_reg_t () = default; + cached_reg_t (cached_reg_t &&rhs) = default; }; /* Buffer of registers. */ diff --git a/gdb/remote.c b/gdb/remote.c index 84daa85..7611396 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -1353,8 +1353,6 @@ public: struct stop_reply : public notif_event { - ~stop_reply (); - /* The identifier of the thread about this event */ ptid_t ptid; @@ -7604,12 +7602,6 @@ remote_notif_stop_can_get_pending_events (remote_target *remote, return 0; } -stop_reply::~stop_reply () -{ - for (cached_reg_t ® : regcache) - xfree (reg.data); -} - static notif_event_up remote_notif_stop_alloc_reply () { @@ -8094,17 +8086,18 @@ Packet: '%s'\n"), hex_string (pnum), p, buf); cached_reg.num = reg->regnum; - cached_reg.data = (gdb_byte *) - xmalloc (register_size (event->arch, reg->regnum)); + cached_reg.data.reset ((gdb_byte *) + xmalloc (register_size (event->arch, + reg->regnum))); p = p1 + 1; - fieldsize = hex2bin (p, cached_reg.data, + fieldsize = hex2bin (p, cached_reg.data.get (), register_size (event->arch, reg->regnum)); p += 2 * fieldsize; if (fieldsize < register_size (event->arch, reg->regnum)) warning (_("Remote reply is too short: %s"), buf); - event->regcache.push_back (cached_reg); + event->regcache.push_back (std::move (cached_reg)); } else { @@ -8436,12 +8429,7 @@ remote_target::process_stop_reply (struct stop_reply *stop_reply, stop_reply->arch); for (cached_reg_t ® : stop_reply->regcache) - { - regcache->raw_supply (reg.num, reg.data); - xfree (reg.data); - } - - stop_reply->regcache.clear (); + regcache->raw_supply (reg.num, reg.data.get ()); } remote_thread_info *remote_thr = get_remote_thread_info (this, ptid); |