From: "Dr. David Alan Gilbert" <dave@treblig.org>
To: "Philippe Mathieu-Daudé" <philmd@linaro.org>
Cc: qemu-devel@nongnu.org, "Laurent Vivier" <laurent@vivier.eu>,
"Nicholas Piggin" <npiggin@gmail.com>,
"Chinmay Rath" <rathc@linux.ibm.com>,
"Alex Bennée" <alex.bennee@linaro.org>,
"Zhao Liu" <zhao1.liu@intel.com>,
"Mark Cave-Ayland" <mark.cave-ayland@ilande.co.uk>,
"Pierrick Bouvier" <pierrick.bouvier@linaro.org>,
"Artyom Tarasenko" <atar4qemu@gmail.com>,
"Akihiko Odaki" <odaki@rsg.ci.i.u-tokyo.ac.jp>,
"Gustavo Romero" <gustavo.romero@linaro.org>,
"Paolo Bonzini" <pbonzini@redhat.com>,
unisono@quyllur.org, qemu-ppc@nongnu.org
Subject: Re: [PATCH 07/11] monitor/hmp: Handle gdb-xml exposed registers via gdb_get_register()
Date: Wed, 18 Feb 2026 13:54:10 +0000 [thread overview]
Message-ID: <aZXEgrLH1Jsjz_Cc@gallifrey> (raw)
In-Reply-To: <20260216225228.53959-8-philmd@linaro.org>
* Philippe Mathieu-Daudé (philmd@linaro.org) wrote:
> Implement the gdb_get_register() helper and call it before the
> regular get_monitor_def() one. Registers is exposed via the
> GDB XML files will be directly handled, possibily allowing new
> registers added to XML files to be automatically accessible in
> QEMU monitor. All targets having GDB XML files can now be used
> within the monitor.
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Nice; I might be tempted to add more checks on the return size of
gdb_read_register(..) just in case any arch is a bit screwy
(e.g. if they're 0 for example?) - but it should fine.
So for HMP;
Reviewed-by: Dr. David Alan Gilbert <dave@treblig.org>
> ---
> monitor/hmp.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++---
> 1 file changed, 46 insertions(+), 3 deletions(-)
>
> diff --git a/monitor/hmp.c b/monitor/hmp.c
> index 0a5bbf82197..0e5913fabb1 100644
> --- a/monitor/hmp.c
> +++ b/monitor/hmp.c
> @@ -27,14 +27,18 @@
> #include "hw/core/qdev.h"
> #include "monitor-internal.h"
> #include "monitor/hmp.h"
> +#include "monitor/hmp-target.h"
> #include "qobject/qdict.h"
> #include "qobject/qnum.h"
> +#include "qemu/bswap.h"
> #include "qemu/config-file.h"
> #include "qemu/ctype.h"
> #include "qemu/cutils.h"
> #include "qemu/log.h"
> #include "qemu/option.h"
> +#include "qemu/target-info.h"
> #include "qemu/units.h"
> +#include "exec/gdbstub.h"
> #include "system/block-backend.h"
> #include "trace.h"
>
> @@ -306,6 +310,46 @@ void hmp_help_cmd(Monitor *mon, const char *name)
> free_cmdline_args(args, nb_args);
> }
>
> +/*
> + * Set @pval to the value in the register identified by @name.
> + * return %true if the register is found, %false otherwise.
> + */
> +static bool gdb_get_register(Monitor *mon, int64_t *pval, const char *name)
> +{
> + g_autoptr(GArray) regs = NULL;
> + CPUState *cs = mon_get_cpu(mon);
> +
> + if (cs == NULL) {
> + return false;
> + }
> +
> + regs = gdb_get_register_list(cs);
> +
> + for (int i = 0; i < regs->len; i++) {
> + GDBRegDesc *reg = &g_array_index(regs, GDBRegDesc, i);
> + g_autoptr(GByteArray) buf = NULL;
> + int reg_size;
> +
> + if (!reg->name || g_strcmp0(name, reg->name)) {
> + continue;
> + }
> +
> + buf = g_byte_array_new();
> + reg_size = gdb_read_register(cs, buf, reg->gdb_reg);
> + if (reg_size > sizeof(*pval)) {
> + return false;
> + }
> +
> + if (target_big_endian()) {
> + *pval = ldn_be_p(buf->data, reg_size);
> + } else {
> + *pval = ldn_le_p(buf->data, reg_size);
> + }
> + return true;
> + }
> + return false;
> +}
> +
> /*******************************************************************/
>
> static const char *pch;
> @@ -338,7 +382,6 @@ static int64_t expr_unary(Monitor *mon)
> {
> int64_t n;
> char *p;
> - int ret;
>
> switch (*pch) {
> case '+':
> @@ -393,8 +436,8 @@ static int64_t expr_unary(Monitor *mon)
> pch++;
> }
> *q = 0;
> - ret = get_monitor_def(mon, ®, buf);
> - if (ret < 0) {
> + if (!gdb_get_register(mon, ®, buf)
> + && get_monitor_def(mon, ®, buf) < 0) {
> expr_error(mon, "unknown register");
> }
> n = reg;
> --
> 2.52.0
>
--
-----Open up your eyes, open up your mind, open up your code -------
/ Dr. David Alan Gilbert | Running GNU/Linux | Happy \
\ dave @ treblig.org | | In Hex /
\ _________________________|_____ http://www.treblig.org |_______/
next prev parent reply other threads:[~2026-02-18 13:55 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-16 22:52 [PATCH 00/11] monitor/hmp: Automatically handle gdb-xml exposed registers Philippe Mathieu-Daudé
2026-02-16 22:52 ` [PATCH 01/11] target/sparc: Introduce sparc_cpu_register_gdb_regs() stub Philippe Mathieu-Daudé
2026-02-16 22:52 ` [PATCH 02/11] target/sparc: Restore 'gdb-xml/sparc64-cp0.xml' Philippe Mathieu-Daudé
2026-02-16 22:52 ` [PATCH 03/11] target/sparc: Restore 'gdb-xml/sparc64-fpu.xml' Philippe Mathieu-Daudé
2026-02-16 22:52 ` [PATCH 04/11] target/sparc: Restore 'gdb-xml/sparc64-cpu.xml' Philippe Mathieu-Daudé
2026-02-16 22:52 ` [PATCH 05/11] target/sparc: Expose gdbstub registers to sparc32plus target Philippe Mathieu-Daudé
2026-02-16 22:52 ` [PATCH 06/11] target/sparc: Expose gdbstub registers to sparc32 targets Philippe Mathieu-Daudé
2026-02-16 22:52 ` [PATCH 07/11] monitor/hmp: Handle gdb-xml exposed registers via gdb_get_register() Philippe Mathieu-Daudé
2026-02-17 6:51 ` Philippe Mathieu-Daudé
2026-02-18 13:54 ` Dr. David Alan Gilbert [this message]
2026-02-16 22:52 ` [PATCH 08/11] target/sparc: Remove MonitorDef register entries available via gdbstub Philippe Mathieu-Daudé
2026-02-16 22:52 ` [PATCH 09/11] target/i386: " Philippe Mathieu-Daudé
2026-02-16 22:52 ` [PATCH 10/11] target/m68k: " Philippe Mathieu-Daudé
2026-02-16 22:52 ` [PATCH 11/11] target/ppc: " Philippe Mathieu-Daudé
2026-02-16 23:10 ` BALATON Zoltan
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=aZXEgrLH1Jsjz_Cc@gallifrey \
--to=dave@treblig.org \
--cc=alex.bennee@linaro.org \
--cc=atar4qemu@gmail.com \
--cc=gustavo.romero@linaro.org \
--cc=laurent@vivier.eu \
--cc=mark.cave-ayland@ilande.co.uk \
--cc=npiggin@gmail.com \
--cc=odaki@rsg.ci.i.u-tokyo.ac.jp \
--cc=pbonzini@redhat.com \
--cc=philmd@linaro.org \
--cc=pierrick.bouvier@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@nongnu.org \
--cc=rathc@linux.ibm.com \
--cc=unisono@quyllur.org \
--cc=zhao1.liu@intel.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 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.