This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH] Removal of uses of MAX_REGISTER_SIZE
> On 8 Feb 2017, at 17:36, Yao Qi <qiyaoltc@gmail.com> wrote:
>
> Alan Hayward <Alan.Hayward@arm.com> writes:
>
>> @@ -1279,7 +1335,7 @@ regcache_dump (struct regcache *regcache, struct ui_file *file,
>> int footnote_register_offset = 0;
>> int footnote_register_type_name_null = 0;
>> long register_offset = 0;
>> - gdb_byte buf[MAX_REGISTER_SIZE];
>> + std::vector<gdb_byte> buf (max_register_size (gdbarch));
>>
>> #if 0
>> fprintf_unfiltered (file, "nr_raw_registers %d\n",
>> @@ -1406,8 +1462,8 @@ regcache_dump (struct regcache *regcache, struct ui_file *file,
>> fprintf_unfiltered (file, "<unavailable>");
>> else
>> {
>> - regcache_raw_read (regcache, regnum, buf);
>> - print_hex_chars (file, buf,
>> + regcache_raw_update (regcache, regnum);
>> + print_hex_chars (file, register_buffer (regcache, regnum),
>> regcache->descr->sizeof_register[regnum],
>> gdbarch_byte_order (gdbarch));
>> }
>> @@ -1422,13 +1478,13 @@ regcache_dump (struct regcache *regcache, struct ui_file *file,
>> {
>> enum register_status status;
>>
>> - status = regcache_cooked_read (regcache, regnum, buf);
>> + status = regcache_cooked_read (regcache, regnum, buf.data ());
>
> Can we use regcache_cooked_read_value so that we don't need buf at all.
Yes, that would work.
However, this cooked read is in the middle of a for() loop of every register value.
With the patch currently, we have the allocation of buf once, and then re-use it for each
iteration.
Switching to regcache_cooked_read_value() would result in a call to allocate_value()
(within the regcache_cooked_read_value code) every iteration, which would then be freed
after printing it.
>
>> if (status == REG_UNKNOWN)
>> fprintf_unfiltered (file, "<invalid>");
>> else if (status == REG_UNAVAILABLE)
>> fprintf_unfiltered (file, "<unavailable>");
>> else
>> - print_hex_chars (file, buf,
>> + print_hex_chars (file, buf.data (),
>> regcache->descr->sizeof_register[regnum],
>> gdbarch_byte_order (gdbarch));
>> }
>
> --
> Yao (齐尧)