aboutsummaryrefslogtreecommitdiff
path: root/gdb/ia64-tdep.c
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@polymtl.ca>2021-10-04 20:47:06 -0400
committerSimon Marchi <simon.marchi@polymtl.ca>2021-10-25 14:51:44 -0400
commit50888e42dcd32b30e1144c0aa6d1c1490da45cd9 (patch)
tree72fad89d67057ecb53f26bac0464542829053e3e /gdb/ia64-tdep.c
parentd9f82e931394efed68858eb7c7bb5832ad888482 (diff)
downloadfsf-binutils-gdb-50888e42dcd32b30e1144c0aa6d1c1490da45cd9.zip
fsf-binutils-gdb-50888e42dcd32b30e1144c0aa6d1c1490da45cd9.tar.gz
fsf-binutils-gdb-50888e42dcd32b30e1144c0aa6d1c1490da45cd9.tar.bz2
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
Diffstat (limited to 'gdb/ia64-tdep.c')
-rw-r--r--gdb/ia64-tdep.c34
1 files changed, 17 insertions, 17 deletions
diff --git a/gdb/ia64-tdep.c b/gdb/ia64-tdep.c
index aa47b21..b6816cb 100644
--- a/gdb/ia64-tdep.c
+++ b/gdb/ia64-tdep.c
@@ -1935,7 +1935,7 @@ ia64_frame_prev_register (struct frame_info *this_frame, void **this_cache,
that frame by adding the size of output:
(sof (size of frame) - sol (size of locals)). */
val = ia64_frame_prev_register (this_frame, this_cache, IA64_CFM_REGNUM);
- prev_cfm = extract_unsigned_integer (value_contents_all (val),
+ prev_cfm = extract_unsigned_integer (value_contents_all (val).data (),
8, byte_order);
bsp = rse_address_add (cache->bsp, -(cache->sof));
prev_bsp =
@@ -1985,7 +1985,7 @@ ia64_frame_prev_register (struct frame_info *this_frame, void **this_cache,
/* Adjust the register number to account for register rotation. */
regnum = VP16_REGNUM + ((regnum - VP16_REGNUM) + rrb_pr) % 48;
}
- prN = extract_bit_field (value_contents_all (pr_val),
+ prN = extract_bit_field (value_contents_all (pr_val).data (),
regnum - VP0_REGNUM, 1);
return frame_unwind_got_constant (this_frame, regnum, prN);
}
@@ -1996,7 +1996,7 @@ ia64_frame_prev_register (struct frame_info *this_frame, void **this_cache,
ULONGEST unatN;
unat_val = ia64_frame_prev_register (this_frame, this_cache,
IA64_UNAT_REGNUM);
- unatN = extract_bit_field (value_contents_all (unat_val),
+ unatN = extract_bit_field (value_contents_all (unat_val).data (),
regnum - IA64_NAT0_REGNUM, 1);
return frame_unwind_got_constant (this_frame, regnum, unatN);
}
@@ -2118,12 +2118,12 @@ ia64_frame_prev_register (struct frame_info *this_frame, void **this_cache,
regnum = IA64_GR32_REGNUM + (regnum - V32_REGNUM);
reg_val = ia64_frame_prev_register (this_frame, this_cache,
IA64_CFM_REGNUM);
- prev_cfm = extract_unsigned_integer (value_contents_all (reg_val),
- 8, byte_order);
+ prev_cfm = extract_unsigned_integer
+ (value_contents_all (reg_val).data (), 8, byte_order);
reg_val = ia64_frame_prev_register (this_frame, this_cache,
IA64_BSP_REGNUM);
- prev_bsp = extract_unsigned_integer (value_contents_all (reg_val),
- 8, byte_order);
+ prev_bsp = extract_unsigned_integer
+ (value_contents_all (reg_val).data (), 8, byte_order);
prev_bof = rse_address_add (prev_bsp, -(prev_cfm & 0x7f));
addr = rse_address_add (prev_bof, (regnum - IA64_GR32_REGNUM));
@@ -2956,7 +2956,7 @@ ia64_libunwind_frame_prev_register (struct frame_info *this_frame,
/* Adjust the register number to account for register rotation. */
regnum = VP16_REGNUM + ((regnum - VP16_REGNUM) + rrb_pr) % 48;
}
- prN_val = extract_bit_field (value_contents_all (val),
+ prN_val = extract_bit_field (value_contents_all (val).data (),
regnum - VP0_REGNUM, 1);
return frame_unwind_got_constant (this_frame, regnum, prN_val);
}
@@ -2965,7 +2965,7 @@ ia64_libunwind_frame_prev_register (struct frame_info *this_frame,
{
ULONGEST unatN_val;
- unatN_val = extract_bit_field (value_contents_all (val),
+ unatN_val = extract_bit_field (value_contents_all (val).data (),
regnum - IA64_NAT0_REGNUM, 1);
return frame_unwind_got_constant (this_frame, regnum, unatN_val);
}
@@ -2980,11 +2980,11 @@ ia64_libunwind_frame_prev_register (struct frame_info *this_frame,
register will be if we pop the frame back which is why we might
have been called. We know that libunwind will pass us back the
beginning of the current frame so we should just add sof to it. */
- prev_bsp = extract_unsigned_integer (value_contents_all (val),
+ prev_bsp = extract_unsigned_integer (value_contents_all (val).data (),
8, byte_order);
cfm_val = libunwind_frame_prev_register (this_frame, this_cache,
IA64_CFM_REGNUM);
- prev_cfm = extract_unsigned_integer (value_contents_all (cfm_val),
+ prev_cfm = extract_unsigned_integer (value_contents_all (cfm_val).data (),
8, byte_order);
prev_bsp = rse_address_add (prev_bsp, (prev_cfm & 0x7f));
@@ -3067,7 +3067,7 @@ ia64_libunwind_sigtramp_frame_prev_register (struct frame_info *this_frame,
method of getting previous registers. */
prev_ip_val = libunwind_frame_prev_register (this_frame, this_cache,
IA64_IP_REGNUM);
- prev_ip = extract_unsigned_integer (value_contents_all (prev_ip_val),
+ prev_ip = extract_unsigned_integer (value_contents_all (prev_ip_val).data (),
8, byte_order);
if (prev_ip == 0)
@@ -3747,8 +3747,8 @@ ia64_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
&& TYPE_TARGET_TYPE (type)->code () == TYPE_CODE_FUNC)
{
gdb_byte val_buf[8];
- ULONGEST faddr = extract_unsigned_integer (value_contents (arg),
- 8, byte_order);
+ ULONGEST faddr = extract_unsigned_integer
+ (value_contents (arg).data (), 8, byte_order);
store_unsigned_integer (val_buf, 8, byte_order,
find_func_descr (regcache, faddr,
&funcdescaddr));
@@ -3780,7 +3780,7 @@ ia64_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
This is why we use store_unsigned_integer. */
store_unsigned_integer
(val_buf, 8, byte_order,
- extract_unsigned_integer (value_contents (arg), len,
+ extract_unsigned_integer (value_contents (arg).data (), len,
byte_order));
}
else
@@ -3794,7 +3794,7 @@ ia64_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
In this case, the data is Byte0-aligned. Happy news,
this means that we don't need to differentiate the
handling of 8byte blocks and less-than-8bytes blocks. */
- memcpy (val_buf, value_contents (arg) + argoffset,
+ memcpy (val_buf, value_contents (arg).data () + argoffset,
(len > 8) ? 8 : len);
}
@@ -3818,7 +3818,7 @@ ia64_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
while (len > 0 && floatreg < IA64_FR16_REGNUM)
{
gdb_byte to[IA64_FP_REGISTER_SIZE];
- target_float_convert (value_contents (arg) + argoffset,
+ target_float_convert (value_contents (arg).data () + argoffset,
float_elt_type, to,
ia64_ext_type (gdbarch));
regcache->cooked_write (floatreg, to);