@samitouri / QOSamiQemu / commits / 2ac017c97b

monitor: Merge hmp-target.c code within hmp-cmds.c

hmp-target.c doesn't contain any target-specific code anymore. Merge it within hmp-cmds.c (which is already built once). Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Message-Id: <20260427080738.77138-32-philmd@linaro.org>

Philippe Mathieu-Daudé committed Apr 10, 2026 at 16:14 UTC 2ac017c97b4e3abc5b03683789826a2c7ca8f0b7
4 files changed +40 -78
MAINTAINERS
-1
@@ -3408,7 +3408,6 @@ Human Monitor (HMP)
3408 M: Dr. David Alan Gilbert <dave@treblig.org>
3409 S: Maintained
3410 F: monitor/monitor-internal.h
3411 -F: monitor/hmp-target.c
3411 F: monitor/monitor.c
3412 F: monitor/hmp*
3413 F: hmp.h
monitor/hmp-cmds.c
+40
@@ -14,6 +14,7 @@
14 */
15
16 #include "qemu/osdep.h"
17 +#include "qemu/base-arch-defs.h"
18 #include "system/address-spaces.h"
19 #include "system/ioport.h"
20 #include "exec/gdbstub.h"
@@ -22,19 +23,58 @@
23 #include "monitor/hmp.h"
24 #include "qemu/help_option.h"
25 #include "monitor/hmp.h"
26 +#include "monitor/hmp-completion.h"
27 #include "monitor/monitor-internal.h"
28 +#include "monitor/qdev.h"
29 #include "qapi/error.h"
30 #include "qapi/qapi-commands-control.h"
31 #include "qapi/qapi-commands-machine.h"
32 #include "qapi/qapi-commands-misc.h"
33 +#include "block/block-hmp-cmds.h"
34 #include "qobject/qdict.h"
35 #include "qemu/cutils.h"
36 #include "qemu/log.h"
37 +#include "net/slirp.h"
38 +#include "system/device_tree.h"
39 #include "system/hw_accel.h"
40 #include "system/memory.h"
41 #include "system/system.h"
42 #include "disas/disas.h"
43
44 +/* Please update hmp-commands.hx when adding or changing commands */
45 +static HMPCommand hmp_info_cmds[] = {
46 +#include "hmp-commands-info.h"
47 + { NULL, NULL, },
48 +};
49 +
50 +/* hmp_cmds and hmp_info_cmds would be sorted at runtime */
51 +static HMPCommand hmp_cmds[] = {
52 +#include "hmp-commands.h"
53 + { NULL, NULL, },
54 +};
55 +
56 +HMPCommand *hmp_cmds_for_target(bool info_command)
57 +{
58 + return info_command ? hmp_info_cmds : hmp_cmds;
59 +}
60 +
61 +static int
62 +compare_mon_cmd(const void *a, const void *b)
63 +{
64 + return strcmp(((const HMPCommand *)a)->name,
65 + ((const HMPCommand *)b)->name);
66 +}
67 +
68 +static void __attribute__((__constructor__)) sortcmdlist(void)
69 +{
70 + qsort(hmp_cmds, ARRAY_SIZE(hmp_cmds) - 1,
71 + sizeof(*hmp_cmds),
72 + compare_mon_cmd);
73 + qsort(hmp_info_cmds, ARRAY_SIZE(hmp_info_cmds) - 1,
74 + sizeof(*hmp_info_cmds),
75 + compare_mon_cmd);
76 +}
77 +
78 bool hmp_handle_error(Monitor *mon, Error *err)
79 {
80 if (err) {
monitor/hmp-target.c deleted
-74
@@ -1,74 +0,0 @@
1 -/*
2 - * QEMU monitor, target-dependent part
3 - *
4 - * Copyright (c) 2003-2004 Fabrice Bellard
5 - *
6 - * Permission is hereby granted, free of charge, to any person obtaining a copy
7 - * of this software and associated documentation files (the "Software"), to deal
8 - * in the Software without restriction, including without limitation the rights
9 - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 - * copies of the Software, and to permit persons to whom the Software is
11 - * furnished to do so, subject to the following conditions:
12 - *
13 - * The above copyright notice and this permission notice shall be included in
14 - * all copies or substantial portions of the Software.
15 - *
16 - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 - * THE SOFTWARE.
23 - */
24 -
25 -#include "qemu/osdep.h"
26 -#include "qemu/base-arch-defs.h"
27 -#include "monitor-internal.h"
28 -#include "monitor/qdev.h"
29 -#include "net/slirp.h"
30 -#include "system/device_tree.h"
31 -#include "monitor/hmp.h"
32 -#include "monitor/hmp-completion.h"
33 -#include "block/block-hmp-cmds.h"
34 -#include "qapi/qapi-commands-control.h"
35 -#include "qapi/qapi-commands-misc.h"
36 -#include "qapi/qapi-commands-machine.h"
37 -#include "hw/core/sysemu-cpu-ops.h"
38 -
39 -/* Make devices configuration available for use in hmp-commands*.hx templates */
40 -#include CONFIG_DEVICES
41 -
42 -/* Please update hmp-commands.hx when adding or changing commands */
43 -static HMPCommand hmp_info_cmds[] = {
44 -#include "hmp-commands-info.h"
45 - { NULL, NULL, },
46 -};
47 -
48 -/* hmp_cmds and hmp_info_cmds would be sorted at runtime */
49 -static HMPCommand hmp_cmds[] = {
50 -#include "hmp-commands.h"
51 - { NULL, NULL, },
52 -};
53 -
54 -HMPCommand *hmp_cmds_for_target(bool info_command)
55 -{
56 - return info_command ? hmp_info_cmds : hmp_cmds;
57 -}
58 -
59 -static int
60 -compare_mon_cmd(const void *a, const void *b)
61 -{
62 - return strcmp(((const HMPCommand *)a)->name,
63 - ((const HMPCommand *)b)->name);
64 -}
65 -
66 -static void __attribute__((__constructor__)) sortcmdlist(void)
67 -{
68 - qsort(hmp_cmds, ARRAY_SIZE(hmp_cmds) - 1,
69 - sizeof(*hmp_cmds),
70 - compare_mon_cmd);
71 - qsort(hmp_info_cmds, ARRAY_SIZE(hmp_info_cmds) - 1,
72 - sizeof(*hmp_info_cmds),
73 - compare_mon_cmd);
74 -}
monitor/meson.build
-3
@@ -7,6 +7,3 @@ system_ss.add(files(
7 'qemu-config-qmp.c',
8 'qmp-cmds.c',
9 ))
10 -
11 -specific_ss.add(when: 'CONFIG_SYSTEM_ONLY',
12 - if_true: [files('hmp-target.c')])