All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Alex Bennée" <alex.bennee@linaro.org>
To: "Philippe Mathieu-Daudé" <philmd@redhat.com>
Cc: Kyle Evans <kevans@freebsd.org>, Greg Kurz <groug@kaod.org>,
	qemu-devel@nongnu.org, Paolo Bonzini <pbonzini@redhat.com>,
	Warner Losh <imp@bsdimp.com>,
	David Gibson <david@gibson.dropbear.id.au>
Subject: Re: [PATCH 3/5] gdbstub: Use fixed-size array in GdbCmdParseEntry instead of pointer
Date: Thu, 06 May 2021 13:01:57 +0100	[thread overview]
Message-ID: <877dkcnk7c.fsf@linaro.org> (raw)
In-Reply-To: <20210505170055.1415360-4-philmd@redhat.com>


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

> GdbCmdParseEntry should have enough room with 20 chars for the command
> string, and 8 for the schema. Add the GDB_CMD_PARSE_ENTRY_CMD_SIZE and
> GDB_CMD_PARSE_ENTRY_SCHEMA_SIZE definitions.
>
> Do not use pointer to string of unknown length, but array of fixed
> size. Having constant size will help use to remove the alloca() call
> in process_string_cmd() in the next commit.

I don't understand how this helps. The alloca is being used for an array
of GdbCmdVariant so why do we want to enlarge the size of the parse
table entries?

>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> ---
>  gdbstub.c | 10 ++++++----
>  1 file changed, 6 insertions(+), 4 deletions(-)
>
> diff --git a/gdbstub.c b/gdbstub.c
> index 6f663cbd8dd..0d5569ee539 100644
> --- a/gdbstub.c
> +++ b/gdbstub.c
> @@ -1457,11 +1457,13 @@ typedef void (*GdbCmdHandler)(GdbCmdContext *gdb_ctx, void *user_ctx);
>   * '.' -> Skip 1 char unless reached "\0"
>   * Any other value is treated as the delimiter value itself
>   */
> +#define GDB_CMD_PARSE_ENTRY_CMD_SIZE    20
> +#define GDB_CMD_PARSE_ENTRY_SCHEMA_SIZE 8
>  typedef struct GdbCmdParseEntry {
>      GdbCmdHandler handler;
> -    const char *cmd;
> +    const char cmd[GDB_CMD_PARSE_ENTRY_CMD_SIZE];
>      bool cmd_startswith;
> -    const char *schema;
> +    const char schema[GDB_CMD_PARSE_ENTRY_SCHEMA_SIZE];
>  } GdbCmdParseEntry;
>  
>  static inline int startswith(const char *string, const char *pattern)
> @@ -1481,14 +1483,14 @@ static int process_string_cmd(void *user_ctx, const char *data,
>  
>      for (i = 0; i < num_cmds; i++) {
>          const GdbCmdParseEntry *cmd = &cmds[i];
> -        g_assert(cmd->handler && cmd->cmd);
> +        g_assert(cmd->handler && *cmd->cmd);
>  
>          if ((cmd->cmd_startswith && !startswith(data, cmd->cmd)) ||
>              (!cmd->cmd_startswith && strcmp(cmd->cmd, data))) {
>              continue;
>          }
>  
> -        if (cmd->schema) {
> +        if (*cmd->schema) {
>              schema_len = strlen(cmd->schema);
>              if (schema_len % 2) {
>                  return -2;


-- 
Alex Bennée


  reply	other threads:[~2021-05-06 12:06 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-05 17:00 [PATCH 0/5] misc: Replace alloca() by g_malloc() Philippe Mathieu-Daudé
2021-05-05 17:00 ` [PATCH 1/5] bsd-user/syscall: Replace alloca() by g_new() Philippe Mathieu-Daudé
2021-05-05 17:00 ` [PATCH 2/5] gdbstub: Constify GdbCmdParseEntry Philippe Mathieu-Daudé
2021-05-06 11:50   ` Alex Bennée
2021-05-05 17:00 ` [PATCH 3/5] gdbstub: Use fixed-size array in GdbCmdParseEntry instead of pointer Philippe Mathieu-Daudé
2021-05-06 12:01   ` Alex Bennée [this message]
2021-05-06 12:39     ` Philippe Mathieu-Daudé
2021-05-06 15:15       ` Alex Bennée
2021-05-05 17:00 ` [PATCH 4/5] gdbstub: Replace alloca() by g_new() Philippe Mathieu-Daudé
2021-05-06 16:07   ` [ALT PATCH] gdbstub: Replace GdbCmdContext with plain g_array() Alex Bennée
2021-05-05 17:00 ` [PATCH 5/5] target/ppc/kvm: Replace alloca() by g_malloc() Philippe Mathieu-Daudé
2021-05-05 17:00   ` Philippe Mathieu-Daudé
2021-05-06  2:18   ` David Gibson
2021-05-06  2:18     ` David Gibson
2021-05-06  8:41   ` Greg Kurz
2021-05-06  8:41     ` Greg Kurz
2021-05-06 13:09     ` Philippe Mathieu-Daudé
2021-05-06 13:09       ` Philippe Mathieu-Daudé

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=877dkcnk7c.fsf@linaro.org \
    --to=alex.bennee@linaro.org \
    --cc=david@gibson.dropbear.id.au \
    --cc=groug@kaod.org \
    --cc=imp@bsdimp.com \
    --cc=kevans@freebsd.org \
    --cc=pbonzini@redhat.com \
    --cc=philmd@redhat.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.