qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Alex Bennée" <alex.bennee@linaro.org>
To: "Philippe Mathieu-Daudé" <philmd@redhat.com>
Cc: Peter Maydell <peter.maydell@linaro.org>,
	qemu-arm@nongnu.org, qemu-devel@nongnu.org,
	Max Filippov <jcmvbkbc@gmail.com>
Subject: Re: [PATCH-for-5.0] gdbstub: Do not use memset() on GByteArray
Date: Tue, 14 Apr 2020 17:09:30 +0100	[thread overview]
Message-ID: <87y2qy82x1.fsf@linaro.org> (raw)
In-Reply-To: <20200414102427.7459-1-philmd@redhat.com>


Philippe Mathieu-Daudé <philmd@redhat.com> writes:

> Introduce gdb_get_zeroes() to fill a GByteArray with zeroes.
>
> Fixes: a010bdbe719 ("extend GByteArray to read register helpers")
> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>

Queued to for-5.0/more-random-fixes with Peter's alternative.

> ---
>  include/exec/gdbstub.h  | 9 +++++++++
>  target/arm/gdbstub.c    | 3 +--
>  target/xtensa/gdbstub.c | 6 ++----
>  3 files changed, 12 insertions(+), 6 deletions(-)
>
> diff --git a/include/exec/gdbstub.h b/include/exec/gdbstub.h
> index 30b909ebd2..b52d9933ee 100644
> --- a/include/exec/gdbstub.h
> +++ b/include/exec/gdbstub.h
> @@ -125,6 +125,15 @@ static inline int gdb_get_reg128(GByteArray *buf, uint64_t val_hi,
>      return 16;
>  }
>  
> +static inline int gdb_get_zeroes(GByteArray *array, size_t len)
> +{
> +    for (size_t i = 0; i < len; i++) {
> +        gdb_get_reg8(array, '\0');
> +    }
> +
> +    return len;
> +}
> +
>  /**
>   * gdb_get_reg_ptr: get pointer to start of last element
>   * @len: length of element
> diff --git a/target/arm/gdbstub.c b/target/arm/gdbstub.c
> index 8efc535f2a..063551df23 100644
> --- a/target/arm/gdbstub.c
> +++ b/target/arm/gdbstub.c
> @@ -47,8 +47,7 @@ int arm_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n)
>          if (gdb_has_xml) {
>              return 0;
>          }
> -        memset(mem_buf, 0, 12);
> -        return 12;
> +        return gdb_get_zeroes(mem_buf, 12);
>      }
>      switch (n) {
>      case 24:
> diff --git a/target/xtensa/gdbstub.c b/target/xtensa/gdbstub.c
> index 0ee3feabe5..4d43f1340a 100644
> --- a/target/xtensa/gdbstub.c
> +++ b/target/xtensa/gdbstub.c
> @@ -105,8 +105,7 @@ int xtensa_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n)
>          default:
>              qemu_log_mask(LOG_UNIMP, "%s from reg %d of unsupported size %d\n",
>                            __func__, n, reg->size);
> -            memset(mem_buf, 0, reg->size);
> -            return reg->size;
> +            return gdb_get_zeroes(mem_buf, reg->size);
>          }
>  
>      case xtRegisterTypeWindow: /*a*/
> @@ -115,8 +114,7 @@ int xtensa_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n)
>      default:
>          qemu_log_mask(LOG_UNIMP, "%s from reg %d of unsupported type %d\n",
>                        __func__, n, reg->type);
> -        memset(mem_buf, 0, reg->size);
> -        return reg->size;
> +        return gdb_get_zeroes(mem_buf, reg->size);
>      }
>  }


-- 
Alex Bennée


      parent reply	other threads:[~2020-04-14 16:12 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-14 10:24 [PATCH-for-5.0] gdbstub: Do not use memset() on GByteArray Philippe Mathieu-Daudé
2020-04-14 10:52 ` Peter Maydell
2020-04-14 11:05   ` Philippe Mathieu-Daudé
2020-04-14 11:49     ` Peter Maydell
2020-04-14 14:22       ` Alex Bennée
2020-04-14 16:09 ` Alex Bennée [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87y2qy82x1.fsf@linaro.org \
    --to=alex.bennee@linaro.org \
    --cc=jcmvbkbc@gmail.com \
    --cc=peter.maydell@linaro.org \
    --cc=philmd@redhat.com \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).