[RFA 09/13] Use gdb::def_vector in ppc-linux-tdep.c

Simon Marchi simon.marchi@polymtl.ca
Fri Nov 3 01:31:00 GMT 2017


On 2017-11-02 18:36, Tom Tromey wrote:
> This removes a cleanup from ppc-linux-tdep.c, replacing it with
> gdb::def_vector.
> 
> gdb/ChangeLog
> 2017-11-02  Tom Tromey  <tom@tromey.com>
> 
> 	* ppc-linux-tdep.c (ppc_linux_get_syscall_number): Use
> 	gdb::def_vector.
> ---
>  gdb/ChangeLog        |  5 +++++
>  gdb/ppc-linux-tdep.c | 13 ++++---------
>  2 files changed, 9 insertions(+), 9 deletions(-)
> 
> diff --git a/gdb/ppc-linux-tdep.c b/gdb/ppc-linux-tdep.c
> index 847908a6da..4d10a24ca9 100644
> --- a/gdb/ppc-linux-tdep.c
> +++ b/gdb/ppc-linux-tdep.c
> @@ -725,26 +725,21 @@ ppc_linux_get_syscall_number (struct gdbarch 
> *gdbarch,
>    struct regcache *regcache = get_thread_regcache (ptid);
>    struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
>    enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
> -  struct cleanup *cleanbuf;
> -  /* The content of a register */
> -  gdb_byte *buf;
>    /* The result */
>    LONGEST ret;
> 
>    /* Make sure we're in a 32- or 64-bit machine */
>    gdb_assert (tdep->wordsize == 4 || tdep->wordsize == 8);
> 
> -  buf = (gdb_byte *) xmalloc (tdep->wordsize * sizeof (gdb_byte));
> -
> -  cleanbuf = make_cleanup (xfree, buf);
> +  /* The content of a register */
> +  gdb::def_vector<gdb_byte> buf (tdep->wordsize);

I would prefer if you used gdb::byte_vector, so it's consistent across 
the codebase.

> 
>    /* Getting the system call number from the register.
>       When dealing with PowerPC architecture, this information
>       is stored at 0th register.  */
> -  regcache_cooked_read (regcache, tdep->ppc_gp0_regnum, buf);
> +  regcache_cooked_read (regcache, tdep->ppc_gp0_regnum, buf.data ());
> 
> -  ret = extract_signed_integer (buf, tdep->wordsize, byte_order);
> -  do_cleanups (cleanbuf);
> +  ret = extract_signed_integer (buf.data (), tdep->wordsize, 
> byte_order);
> 
>    return ret;
>  }

You can skip the ret variable.

Simon



More information about the Gdb-patches mailing list