[RFC PATCH v4 02/15] GDB: Use gdb::array_view for buffers used in register reading and unwinding

Thiago Jung Bauermann thiago.bauermann@linaro.org
Fri Jan 10 04:27:42 GMT 2025


"Aktemur, Tankut Baris" <tankut.baris.aktemur@intel.com> writes:

> On Saturday, November 2, 2024 3:56 AM, Thiago Jung Bauermann wrote:
>> This allows checking the size of the given buffer.  Changes
>> frame_register_unwind (), frame_unwind_register (), get_frame_register ()
>> and deprecated_frame_register_read ().
> ...
>> diff --git a/gdb/mips-tdep.c b/gdb/mips-tdep.c
>> index c00efbd02ad0..24970c7637ad 100644
>> --- a/gdb/mips-tdep.c
>> +++ b/gdb/mips-tdep.c
>> @@ -951,14 +951,17 @@ mips_register_to_value (const frame_info_ptr &frame, int
>> regnum,
>>
>>    if (mips_convert_register_float_case_p (gdbarch, regnum, type))
>>      {
>> -      get_frame_register (frame, regnum + 0, to + 4);
>> -      get_frame_register (frame, regnum + 1, to + 0);
>> +      gdb::array_view<gdb_byte> first_half = gdb::make_array_view (to, 4);
>> +      gdb::array_view<gdb_byte> second_half = gdb::make_array_view (to + 4, 4);
>>
>> -      if (!get_frame_register_bytes (next_frame, regnum + 0, 0, { to + 4, 4 },
>> +      get_frame_register (frame, regnum + 0, second_half);
>> +      get_frame_register (frame, regnum + 1, first_half);
>> +
>> +      if (!get_frame_register_bytes (next_frame, regnum + 0, 0, second_half,
>>  				     optimizedp, unavailablep))
>>  	return 0;
>>
>> -      if (!get_frame_register_bytes (next_frame, regnum + 1, 0, { to + 0, 4 },
>> +      if (!get_frame_register_bytes (next_frame, regnum + 1, 0, first_half,
>>  				     optimizedp, unavailablep))
>>  	return 0;
>>        *optimizedp = *unavailablep = 0;
>> @@ -6257,8 +6260,10 @@ mips_read_fp_register_single (const frame_info_ptr &frame, int
>> regno,
>>    struct gdbarch *gdbarch = get_frame_arch (frame);
>>    int raw_size = register_size (gdbarch, regno);
>>    gdb_byte *raw_buffer = (gdb_byte *) alloca (raw_size);
>> +  gdb::array_view<gdb_byte> raw_view = gdb::make_array_view (raw_buffer,
>> +							     raw_size);
>
> I noticed one thing after sending the previous email on this patch.
> For simpler code, can we use here
>
>   gdb::byte_vector raw_buffer (raw_size);
>
> and eliminate raw_view?

That's a good idea. I took this approach in order to make a minimally
invasive patch, given that I can't test on a MIPS system.

But I tried your suggestion and indeed it's better. In fact, I went
farther and also changed the rare_buffer arguments of
mips_read_fp_register_single and mips_read_fp_register_double to
array_views as well. Then I was also able to eliminate the rare_view
variable in mips_read_fp_register_double.

This required changing raw_buffer in mips_print_fp_register (the caller
of mips_read_fp_register_single and mips_read_fp_register_double) to a
gdb::byte_vector as well, so the patch is bigger but I think it's an
improvement overall.

--
Thiago


More information about the Gdb-patches mailing list