qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Pierrick Bouvier <pierrick.bouvier@linaro.org>
To: "Alex Bennée" <alex.bennee@linaro.org>
Cc: qemu-devel@nongnu.org, "Peter Maydell" <peter.maydell@linaro.org>,
	"Juan Quintela" <quintela@redhat.com>,
	"Ilya Leoshkevich" <iii@linux.ibm.com>,
	"Thomas Huth" <thuth@redhat.com>,
	"Akihiko Odaki" <akihiko.odaki@daynix.com>,
	qemu-ppc@nongnu.org, "David Gibson" <david@gibson.dropbear.id.au>,
	qemu-s390x@nongnu.org,
	"Wainer dos Santos Moschetta" <wainersm@redhat.com>,
	"Peter Xu" <peterx@redhat.com>,
	"Markus Armbruster" <armbru@redhat.com>,
	"Daniel P. Berrangé" <berrange@redhat.com>,
	"Cédric Le Goater" <clg@kaod.org>,
	"Daniel Henrique Barboza" <danielhb413@gmail.com>,
	"David Hildenbrand" <david@redhat.com>,
	"Yonggang Luo" <luoyonggang@gmail.com>,
	"Richard Henderson" <richard.henderson@linaro.org>,
	"Beraldo Leal" <bleal@redhat.com>,
	qemu-arm@nongnu.org, "Greg Kurz" <groug@kaod.org>,
	"Philippe Mathieu-Daudé" <philmd@linaro.org>,
	"Nicholas Piggin" <npiggin@gmail.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Edgar E. Iglesias" <edgar.iglesias@gmail.com>
Subject: Re: [PATCH 02/10] gdbstub: introduce target independent gdb register helper
Date: Fri, 21 Mar 2025 10:24:40 -0700	[thread overview]
Message-ID: <f938d297-8593-4ff9-a41d-b8811f537d05@linaro.org> (raw)
In-Reply-To: <87ldsylins.fsf@draig.linaro.org>

On 3/21/25 04:36, Alex Bennée wrote:
> Pierrick Bouvier <pierrick.bouvier@linaro.org> writes:
> 
>> On 3/20/25 12:30, Pierrick Bouvier wrote:
>>> On 3/19/25 11:22, Alex Bennée wrote:
>>>> The current helper.h functions rely on hard coded assumptions about
>>>> target endianess to use the tswap macros. We also end up double
>>>> swapping a bunch of values if the target can run in multiple endianess
>>>> modes. Avoid this by getting the target to pass the endianess and size
>>>> via a MemOp and fixing up appropriately.
>>>>
>>>> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
>>>> ---
>>>>     include/gdbstub/registers.h | 30 ++++++++++++++++++++++++++++++
>>>>     gdbstub/gdbstub.c           | 22 ++++++++++++++++++++++
>>>>     2 files changed, 52 insertions(+)
>>>>     create mode 100644 include/gdbstub/registers.h
>>>>
>>>> diff --git a/include/gdbstub/registers.h b/include/gdbstub/registers.h
>>>> new file mode 100644
>>>> index 0000000000..4abc7a6ae7
>>>> --- /dev/null
>>>> +++ b/include/gdbstub/registers.h
>>>> @@ -0,0 +1,30 @@
>>>> +/*
>>>> + * GDB Common Register Helpers
>>>> + *
>>>> + * Copyright (c) 2025 Linaro Ltd
>>>> + *
>>>> + * SPDX-License-Identifier: GPL-2.0-or-later
>>>> + */
>>>> +
>>>> +#ifndef GDB_REGISTERS_H
>>>> +#define GDB_REGISTERS_H
>>>> +
>>>> +#include "exec/memop.h"
>>>> +
>>>> +/**
>>>> + * gdb_get_register_value() - get register value for gdb
>>>> + * mo: size and endian MemOp
>>>> + * buf: GByteArray to store in target order
>>>> + * val: pointer to value in host order
>>>> + *
>>>> + * This replaces the previous legacy read functions with a single
>>>> + * function to handle all sizes. Passing @mo allows the target mode to
>>>> + * be taken into account and avoids using hard coded tswap() macros.
>>>> + *
>>>> + * Returns the number of bytes written to the array.
>>>> + */
>>>> +int gdb_get_register_value(MemOp op, GByteArray *buf, uint8_t *val);
>>>> +
>>>> +#endif /* GDB_REGISTERS_H */
>>>> +
>>>> +
>>>> diff --git a/gdbstub/gdbstub.c b/gdbstub/gdbstub.c
>>>> index 282e13e163..3d7b1028e4 100644
>>>> --- a/gdbstub/gdbstub.c
>>>> +++ b/gdbstub/gdbstub.c
>>>> @@ -32,6 +32,7 @@
>>>>     #include "exec/gdbstub.h"
>>>>     #include "gdbstub/commands.h"
>>>>     #include "gdbstub/syscalls.h"
>>>> +#include "gdbstub/registers.h"
>>>>     #ifdef CONFIG_USER_ONLY
>>>>     #include "accel/tcg/vcpu-state.h"
>>>>     #include "gdbstub/user.h"
>>>> @@ -45,6 +46,7 @@
>>>>     #include "system/runstate.h"
>>>>     #include "exec/replay-core.h"
>>>>     #include "exec/hwaddr.h"
>>>> +#include "exec/memop.h"
>>>>        #include "internals.h"
>>>>     @@ -551,6 +553,26 @@ static int gdb_write_register(CPUState
>>>> *cpu, uint8_t *mem_buf, int reg)
>>>>         return 0;
>>>>     }
>>>>     +/*
>>>> + * Target helper function to read value into GByteArray, target
>>>> + * supplies the size and target endianess via the MemOp.
>>>> + */
>>>> +int gdb_get_register_value(MemOp op, GByteArray *buf, uint8_t *val)
>>>> +{
>>>> +    size_t bytes = memop_size(op);
>>>> +
>>>> +    if (op & MO_BSWAP) {
>>>> +        for ( int i = bytes ; i > 0; i--) {
>>>> +            g_byte_array_append(buf, &val[i - 1], 1);
>>>> +        };
>>>> +    } else {
>>>> +        g_byte_array_append(buf, val, bytes);
>>>> +    }
>>>> +
>>>> +    return bytes;
>>>> +}
>>>> +
>>>> +
>>>>     static void gdb_register_feature(CPUState *cpu, int base_reg,
>>>>                                      gdb_get_reg_cb get_reg, gdb_set_reg_cb set_reg,
>>>>                                      const GDBFeature *feature)
>>> It could be preferable to set buf with the value, instead of simply
>>> appending the value. This way, there is no need to return the size, as
>>> it's contained in buffer size itself.
>>> If we insist on returning the size, it's better to make it a
>>> parameter
>>> (and use a void parameter type), because at the moment, it gives the
>>> impression the function itself returns the value, which may be confusing.
>>
>> Seems like it's the existing convention through
>> gdb_set_reg_cb/gdb_get_reg_cb, so we have to follow this.
> 
> For the "g" packet we append multiple registers so the buffer size grows
> as we append each one.
> 

Thanks for sharing the rationale behind this.

  reply	other threads:[~2025-03-21 17:25 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-19 18:22 [PATCH 00/10] gdbstub: conversion to runtime endianess helpers Alex Bennée
2025-03-19 18:22 ` [PATCH 01/10] include/gdbstub: fix include guard in commands.h Alex Bennée
2025-03-20  7:09   ` Philippe Mathieu-Daudé
2025-03-20 19:37   ` Pierrick Bouvier
2025-03-19 18:22 ` [PATCH 02/10] gdbstub: introduce target independent gdb register helper Alex Bennée
2025-03-20  6:19   ` Akihiko Odaki
2025-03-20  7:24     ` Philippe Mathieu-Daudé
2025-03-20  7:16   ` Philippe Mathieu-Daudé
2025-03-20 19:30   ` Pierrick Bouvier
2025-03-20 19:36     ` Pierrick Bouvier
2025-03-21 11:36       ` Alex Bennée
2025-03-21 17:24         ` Pierrick Bouvier [this message]
2025-03-20 19:37   ` Pierrick Bouvier
2025-03-19 18:22 ` [PATCH 03/10] target/arm: convert 32 bit gdbstub to new helper Alex Bennée
2025-03-20  6:21   ` Akihiko Odaki
2025-03-20 19:38   ` Pierrick Bouvier
2025-03-19 18:22 ` [PATCH 04/10] target/arm: convert 64 " Alex Bennée
2025-03-20  7:39   ` Philippe Mathieu-Daudé
2025-03-20 19:42   ` Pierrick Bouvier
2025-03-21 11:38     ` Alex Bennée
2025-03-19 18:22 ` [PATCH 05/10] target/ppc: expand comment on FP/VMX/VSX access functions Alex Bennée
2025-03-20 19:42   ` Pierrick Bouvier
2025-03-19 18:22 ` [PATCH 06/10] target/ppc: make ppc_maybe_bswap_register static Alex Bennée
2025-03-20  6:55   ` Philippe Mathieu-Daudé
2025-03-20 19:42   ` Pierrick Bouvier
2025-03-19 18:22 ` [PATCH 07/10] target/ppc: convert gdbstub to new helper (!hacky) Alex Bennée
2025-03-19 18:22 ` [PATCH 08/10] gdbstub: assert earlier in handle_read_all_regs Alex Bennée
2025-03-20  6:57   ` Philippe Mathieu-Daudé
2025-03-19 18:22 ` [PATCH 09/10] include/exec: fix assert in size_memop Alex Bennée
2025-03-20  6:29   ` Akihiko Odaki
2025-03-20  7:30     ` Philippe Mathieu-Daudé
2025-03-19 18:22 ` [PATCH 10/10] target/microblaze: convert gdbstub to new helper Alex Bennée
2025-03-20  7:09   ` Philippe Mathieu-Daudé
2025-03-20 19:52 ` [PATCH 00/10] gdbstub: conversion to runtime endianess helpers Pierrick Bouvier
2025-03-20 20:16   ` Pierrick Bouvier
2025-03-21 13:02     ` Philippe Mathieu-Daudé
2025-03-21 17:27       ` Pierrick Bouvier
2025-03-21 11:46   ` Alex Bennée
2025-03-21 17:31     ` Pierrick Bouvier
2025-03-23 15:41       ` Philippe Mathieu-Daudé
2025-03-23 17:32         ` Pierrick Bouvier

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=f938d297-8593-4ff9-a41d-b8811f537d05@linaro.org \
    --to=pierrick.bouvier@linaro.org \
    --cc=akihiko.odaki@daynix.com \
    --cc=alex.bennee@linaro.org \
    --cc=armbru@redhat.com \
    --cc=berrange@redhat.com \
    --cc=bleal@redhat.com \
    --cc=clg@kaod.org \
    --cc=danielhb413@gmail.com \
    --cc=david@gibson.dropbear.id.au \
    --cc=david@redhat.com \
    --cc=edgar.iglesias@gmail.com \
    --cc=groug@kaod.org \
    --cc=iii@linux.ibm.com \
    --cc=luoyonggang@gmail.com \
    --cc=npiggin@gmail.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=peterx@redhat.com \
    --cc=philmd@linaro.org \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.org \
    --cc=qemu-s390x@nongnu.org \
    --cc=quintela@redhat.com \
    --cc=richard.henderson@linaro.org \
    --cc=thuth@redhat.com \
    --cc=wainersm@redhat.com \
    /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).