Re: [RFA 07/13] Use gdb::def_vector in sparc64-tdep.c

Simon Marchi
2017-11-03T01:25:52Z

On 2017-11-02 18:36, Tom Tromey wrote:
> This removes a cleanup from sparc64-tdep.c, replacing it with
> gdb::def_vector.
>
> gdb/ChangeLog
> 2017-11-02 Tom Tromey <tom@tromey.com>
>
> * sparc64-tdep.c (do_examine): Use gdb::def_vector.
> ---
> gdb/ChangeLog | 4 ++++
> gdb/sparc64-tdep.c | 10 +++-------
> 2 files changed, 7 insertions(+), 7 deletions(-)
>
> diff --git a/gdb/sparc64-tdep.c b/gdb/sparc64-tdep.c
> index a756834cba..eebfbdf96f 100644
> --- a/gdb/sparc64-tdep.c
> +++ b/gdb/sparc64-tdep.c
> @@ -415,21 +415,17 @@ static void
> do_examine (CORE_ADDR start, int bcnt)
> {
> CORE_ADDR vaddr = adi_normalize_address (start);
> - struct cleanup *cleanup;
>
> CORE_ADDR vstart = adi_align_address (vaddr);
> int cnt = adi_convert_byte_count (vaddr, bcnt, vstart);
> - unsigned char *buf = (unsigned char *) xmalloc (cnt);
> - cleanup = make_cleanup (xfree, buf);
> - int read_cnt = adi_read_versions (vstart, cnt, buf);
> + gdb::def_vector<unsigned char> buf (cnt);
> + int read_cnt = adi_read_versions (vstart, cnt, buf.data ());
> if (read_cnt == -1)
> error (_("No ADI information"));
> else if (read_cnt < cnt)
> error(_("No ADI information at %s"), paddress (target_gdbarch (),
> vaddr));
>
> - adi_print_versions (vstart, cnt, buf);
> -
> - do_cleanups (cleanup);
> + adi_print_versions (vstart, cnt, buf.data ());
> }
>
> static void

It seems to me like the code doesn't use this as text, but binary data.
So it should probably have used gdb_byte in the first place. I would
then suggest using gdb::byte_vector (if you agree that gdb_byte should
be used here).

Simon