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/s390-tdep.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'gdb/s390-tdep.c') diff --git a/gdb/s390-tdep.c b/gdb/s390-tdep.c index d3bb2ba..0a4a574 100644 --- a/gdb/s390-tdep.c +++ b/gdb/s390-tdep.c @@ -1764,7 +1764,7 @@ s390_handle_arg (struct s390_arg_state *as, struct value *arg, it occupies the leftmost bits. */ if (write_mode) as->regcache->cooked_write_part (S390_F0_REGNUM + as->fr, 0, length, - value_contents (arg)); + value_contents (arg).data ()); as->fr += 2; } else @@ -1773,7 +1773,7 @@ s390_handle_arg (struct s390_arg_state *as, struct value *arg, it occupies the rightmost bits. */ as->argp = align_up (as->argp + length, word_size); if (write_mode) - write_memory (as->argp - length, value_contents (arg), + write_memory (as->argp - length, value_contents (arg).data (), length); } } @@ -1788,13 +1788,13 @@ s390_handle_arg (struct s390_arg_state *as, struct value *arg, if (write_mode) as->regcache->cooked_write_part (regnum, 0, length, - value_contents (arg)); + value_contents (arg).data ()); as->vr++; } else { if (write_mode) - write_memory (as->argp, value_contents (arg), length); + write_memory (as->argp, value_contents (arg).data (), length); as->argp = align_up (as->argp + length, word_size); } } @@ -1809,9 +1809,9 @@ s390_handle_arg (struct s390_arg_state *as, struct value *arg, memory word and sign- or zero-extend to full word size. This also applies to a struct or union. */ val = type->is_unsigned () - ? extract_unsigned_integer (value_contents (arg), + ? extract_unsigned_integer (value_contents (arg).data (), length, byte_order) - : extract_signed_integer (value_contents (arg), + : extract_signed_integer (value_contents (arg).data (), length, byte_order); } @@ -1838,9 +1838,10 @@ s390_handle_arg (struct s390_arg_state *as, struct value *arg, if (write_mode) { as->regcache->cooked_write (S390_R0_REGNUM + as->gr, - value_contents (arg)); - as->regcache->cooked_write (S390_R0_REGNUM + as->gr + 1, - value_contents (arg) + word_size); + value_contents (arg).data ()); + as->regcache->cooked_write + (S390_R0_REGNUM + as->gr + 1, + value_contents (arg).data () + word_size); } as->gr += 2; } @@ -1851,7 +1852,7 @@ s390_handle_arg (struct s390_arg_state *as, struct value *arg, as->gr = 7; if (write_mode) - write_memory (as->argp, value_contents (arg), length); + write_memory (as->argp, value_contents (arg).data (), length); as->argp += length; } } @@ -1862,7 +1863,7 @@ s390_handle_arg (struct s390_arg_state *as, struct value *arg, alignment as a conservative assumption. */ as->copy = align_down (as->copy - length, 8); if (write_mode) - write_memory (as->copy, value_contents (arg), length); + write_memory (as->copy, value_contents (arg).data (), length); if (as->gr <= 6) { -- cgit v1.1