[PATCH v4 17/32] monitor: Do not check TARGET_I386/RISCV to build 'info mem' command

Philippe Mathieu-Daudé posted 32 patches 2 months, 3 weeks ago
Maintainers: "Marc-André Lureau" <marcandre.lureau@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>, "Dr. David Alan Gilbert" <dave@treblig.org>, David Woodhouse <dwmw2@infradead.org>, Paul Durrant <paul@xen.org>, "Michael S. Tsirkin" <mst@redhat.com>, Richard Henderson <richard.henderson@linaro.org>, Marcelo Tosatti <mtosatti@redhat.com>, Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>, Halil Pasic <pasic@linux.ibm.com>, Christian Borntraeger <borntraeger@linux.ibm.com>, Jason Herne <jjherne@linux.ibm.com>, Eric Farman <farman@linux.ibm.com>, Matthew Rosato <mjrosato@linux.ibm.com>, Cornelia Huck <cohuck@redhat.com>, Ilya Leoshkevich <iii@linux.ibm.com>, David Hildenbrand <david@kernel.org>, Peter Xu <peterx@redhat.com>, Fabiano Rosas <farosas@suse.de>, Markus Armbruster <armbru@redhat.com>, Jason Wang <jasowang@redhat.com>, "Daniel P. Berrangé" <berrange@redhat.com>, Zhao Liu <zhao1.liu@intel.com>, Laurent Vivier <laurent@vivier.eu>, Nicholas Piggin <npiggin@gmail.com>, Chinmay Rath <rathc@linux.ibm.com>, Glenn Miles <milesg@linux.ibm.com>, Palmer Dabbelt <palmer@dabbelt.com>, Alistair Francis <alistair.francis@wdc.com>, Weiwei Li <liwei1518@gmail.com>, Daniel Henrique Barboza <daniel.barboza@oss.qualcomm.com>, Liu Zhiwei <zhiwei_liu@linux.alibaba.com>, Chao Liu <chao.liu.zevorn@gmail.com>, Yoshinori Sato <yoshinori.sato@nifty.com>, Artyom Tarasenko <atar4qemu@gmail.com>, Max Filippov <jcmvbkbc@gmail.com>, Stefan Hajnoczi <stefanha@redhat.com>
[PATCH v4 17/32] monitor: Do not check TARGET_I386/RISCV to build 'info mem' command
Posted by Philippe Mathieu-Daudé 2 months, 3 weeks ago
This command is filtered at build-time for i386/x86_64 and
riscv32/riscv64 binaries. By using the recently introduced
HMPCommand::arch_bitmask flag we can filter it at runtime,
making it possible to compile hmp-commands-info.hx once.

Since the method depends on a pair of distinct targets,
define it in its own stub file.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---
 stubs/hmp-cmd-info_mem.c | 12 ++++++++++++
 hmp-commands-info.hx     |  3 +--
 stubs/meson.build        |  1 +
 3 files changed, 14 insertions(+), 2 deletions(-)
 create mode 100644 stubs/hmp-cmd-info_mem.c

diff --git a/stubs/hmp-cmd-info_mem.c b/stubs/hmp-cmd-info_mem.c
new file mode 100644
index 00000000000..8a53e367a9f
--- /dev/null
+++ b/stubs/hmp-cmd-info_mem.c
@@ -0,0 +1,12 @@
+/*
+ * Human Monitor 'info mem' stub
+ *
+ * Copyright (c) Linaro
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "monitor/hmp.h"
+
+HMP_STUB(info_mem)
diff --git a/hmp-commands-info.hx b/hmp-commands-info.hx
index 336ab870a2c..2d0a8f7d48f 100644
--- a/hmp-commands-info.hx
+++ b/hmp-commands-info.hx
@@ -209,15 +209,14 @@ SRST
     Show virtual to physical memory mappings.
 ERST
 
-#if defined(TARGET_I386) || defined(TARGET_RISCV)
     {
         .name       = "mem",
         .args_type  = "",
         .params     = "",
         .help       = "show the active virtual memory mappings",
         .cmd        = hmp_info_mem,
+        .arch_bitmask = QEMU_ARCH_I386 | QEMU_ARCH_RISCV,
     },
-#endif
 
 SRST
   ``info mem``
diff --git a/stubs/meson.build b/stubs/meson.build
index f086521cde4..33053d932c8 100644
--- a/stubs/meson.build
+++ b/stubs/meson.build
@@ -87,6 +87,7 @@ if have_system
   stub_ss.add(files('qmp-cpu.c'))
   stub_ss.add(files('qmp-cpu-s390x.c'))
   stub_ss.add(files('qmp-cpu-s390x-kvm.c'))
+  stub_ss.add(files('hmp-cmd-info_mem.c'))
   stub_ss.add(files('hmp-cmd-info_sev.c'))
   stub_ss.add(files('hmp-cmds-hw-s390x.c'))
   stub_ss.add(files('hmp-cmds-target-i386.c'))
-- 
2.53.0


Re: [PATCH v4 17/32] monitor: Do not check TARGET_I386/RISCV to build 'info mem' command
Posted by Alistair Francis 2 months, 3 weeks ago
On Mon, Apr 27, 2026 at 6:11 PM Philippe Mathieu-Daudé
<philmd@linaro.org> wrote:
>
> This command is filtered at build-time for i386/x86_64 and
> riscv32/riscv64 binaries. By using the recently introduced
> HMPCommand::arch_bitmask flag we can filter it at runtime,
> making it possible to compile hmp-commands-info.hx once.
>
> Since the method depends on a pair of distinct targets,
> define it in its own stub file.
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

Acked-by: Alistair Francis <alistair.francis@wdc.com>

Alistair

> ---
>  stubs/hmp-cmd-info_mem.c | 12 ++++++++++++
>  hmp-commands-info.hx     |  3 +--
>  stubs/meson.build        |  1 +
>  3 files changed, 14 insertions(+), 2 deletions(-)
>  create mode 100644 stubs/hmp-cmd-info_mem.c
>
> diff --git a/stubs/hmp-cmd-info_mem.c b/stubs/hmp-cmd-info_mem.c
> new file mode 100644
> index 00000000000..8a53e367a9f
> --- /dev/null
> +++ b/stubs/hmp-cmd-info_mem.c
> @@ -0,0 +1,12 @@
> +/*
> + * Human Monitor 'info mem' stub
> + *
> + * Copyright (c) Linaro
> + *
> + * SPDX-License-Identifier: GPL-2.0-or-later
> + */
> +
> +#include "qemu/osdep.h"
> +#include "monitor/hmp.h"
> +
> +HMP_STUB(info_mem)
> diff --git a/hmp-commands-info.hx b/hmp-commands-info.hx
> index 336ab870a2c..2d0a8f7d48f 100644
> --- a/hmp-commands-info.hx
> +++ b/hmp-commands-info.hx
> @@ -209,15 +209,14 @@ SRST
>      Show virtual to physical memory mappings.
>  ERST
>
> -#if defined(TARGET_I386) || defined(TARGET_RISCV)
>      {
>          .name       = "mem",
>          .args_type  = "",
>          .params     = "",
>          .help       = "show the active virtual memory mappings",
>          .cmd        = hmp_info_mem,
> +        .arch_bitmask = QEMU_ARCH_I386 | QEMU_ARCH_RISCV,
>      },
> -#endif
>
>  SRST
>    ``info mem``
> diff --git a/stubs/meson.build b/stubs/meson.build
> index f086521cde4..33053d932c8 100644
> --- a/stubs/meson.build
> +++ b/stubs/meson.build
> @@ -87,6 +87,7 @@ if have_system
>    stub_ss.add(files('qmp-cpu.c'))
>    stub_ss.add(files('qmp-cpu-s390x.c'))
>    stub_ss.add(files('qmp-cpu-s390x-kvm.c'))
> +  stub_ss.add(files('hmp-cmd-info_mem.c'))
>    stub_ss.add(files('hmp-cmd-info_sev.c'))
>    stub_ss.add(files('hmp-cmds-hw-s390x.c'))
>    stub_ss.add(files('hmp-cmds-target-i386.c'))
> --
> 2.53.0
>
>