From 50888e42dcd32b30e1144c0aa6d1c1490da45cd9 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Mon, 4 Oct 2021 20:47:06 -0400 Subject: gdb: change functions returning value contents to use gdb::array_view The bug fixed by this [1] patch was caused by an out-of-bounds access to a value's content. The code gets the value's content (just a pointer) and then indexes it with a non-sensical index. This made me think of changing functions that return value contents to return array_views instead of a plain pointer. This has the advantage that when GDB is built with _GLIBCXX_DEBUG, accesses to the array_view are checked, making bugs more apparent / easier to find. This patch changes the return types of these functions, and updates callers to call .data() on the result, meaning it's not changing anything in practice. Additional work will be needed (which can be done little by little) to make callers propagate the use of array_view and reap the benefits. [1] https://sourceware.org/pipermail/gdb-patches/2021-September/182306.html Change-Id: I5151f888f169e1c36abe2cbc57620110673816f3 --- gdb/frame.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'gdb/frame.c') diff --git a/gdb/frame.c b/gdb/frame.c index 1667325..b121892 100644 --- a/gdb/frame.c +++ b/gdb/frame.c @@ -1156,7 +1156,7 @@ frame_register_unwind (frame_info *next_frame, int regnum, if (bufferp) { if (!*optimizedp && !*unavailablep) - memcpy (bufferp, value_contents_all (value), + memcpy (bufferp, value_contents_all (value).data (), TYPE_LENGTH (value_type (value))); else memset (bufferp, 0, TYPE_LENGTH (value_type (value))); @@ -1261,7 +1261,7 @@ frame_unwind_register_value (frame_info *next_frame, int regnum) else { int i; - const gdb_byte *buf = value_contents (value); + const gdb_byte *buf = value_contents (value).data (); fprintf_unfiltered (&debug_file, " bytes="); fprintf_unfiltered (&debug_file, "["); @@ -1304,7 +1304,7 @@ frame_unwind_register_signed (frame_info *next_frame, int regnum) _("Register %d is not available"), regnum); } - LONGEST r = extract_signed_integer (value_contents_all (value), size, + LONGEST r = extract_signed_integer (value_contents_all (value).data (), size, byte_order); release_value (value); @@ -1338,8 +1338,8 @@ frame_unwind_register_unsigned (frame_info *next_frame, int regnum) _("Register %d is not available"), regnum); } - ULONGEST r = extract_unsigned_integer (value_contents_all (value), size, - byte_order); + ULONGEST r = extract_unsigned_integer (value_contents_all (value).data (), + size, byte_order); release_value (value); return r; @@ -1364,7 +1364,8 @@ read_frame_register_unsigned (frame_info *frame, int regnum, enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); int size = register_size (gdbarch, VALUE_REGNUM (regval)); - *val = extract_unsigned_integer (value_contents (regval), size, byte_order); + *val = extract_unsigned_integer (value_contents (regval).data (), size, + byte_order); return true; } @@ -1496,7 +1497,8 @@ get_frame_register_bytes (frame_info *frame, int regnum, return false; } - memcpy (myaddr, value_contents_all (value) + offset, curr_len); + memcpy (myaddr, value_contents_all (value).data () + offset, + curr_len); release_value (value); } @@ -1546,9 +1548,10 @@ put_frame_register_bytes (struct frame_info *frame, int regnum, regnum); gdb_assert (value != NULL); - memcpy ((char *) value_contents_writeable (value) + offset, myaddr, - curr_len); - put_frame_register (frame, regnum, value_contents_raw (value)); + memcpy ((char *) value_contents_writeable (value).data () + offset, + myaddr, curr_len); + put_frame_register (frame, regnum, + value_contents_raw (value).data ()); release_value (value); } -- cgit v1.1