monitor: Add hmp_cmds_for_target() helper

HMPCommand arrays are filled with target-specific
commands, so defined in a target-specific unit.
Introduce the hmp_cmds_for_target() to allow
target-agnostic code to access the arrays.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Dr. David Alan Gilbert <dave@treblig.org>
Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
Message-Id: <20260129164039.58472-4-philmd@linaro.org>
This commit is contained in:
Philippe Mathieu-Daudé
2026-01-08 17:47:48 +01:00
parent a9edda7250
commit f863b32569
3 changed files with 20 additions and 10 deletions

View File

@@ -44,8 +44,6 @@
/* Make devices configuration available for use in hmp-commands*.hx templates */
#include CONFIG_DEVICES
static HMPCommand hmp_info_cmds[];
/**
* Is @name in the '|' separated list of names @list?
*/
@@ -76,11 +74,16 @@ static HMPCommand hmp_info_cmds[] = {
};
/* hmp_cmds and hmp_info_cmds would be sorted at runtime */
HMPCommand hmp_cmds[] = {
static HMPCommand hmp_cmds[] = {
#include "hmp-commands.h"
{ NULL, NULL, },
};
HMPCommand *hmp_cmds_for_target(bool info_command)
{
return info_command ? hmp_info_cmds : hmp_cmds;
}
/*
* Set @pval to the value in the register identified by @name.
* return 0 if OK, -1 if not found
@@ -148,7 +151,7 @@ static void __attribute__((__constructor__)) sortcmdlist(void)
void monitor_register_hmp(const char *name, bool info,
void (*cmd)(Monitor *mon, const QDict *qdict))
{
HMPCommand *table = info ? hmp_info_cmds : hmp_cmds;
HMPCommand *table = hmp_cmds_for_target(info);
while (table->name != NULL) {
if (strcmp(table->name, name) == 0) {
@@ -164,7 +167,7 @@ void monitor_register_hmp(const char *name, bool info,
void monitor_register_hmp_info_hrt(const char *name,
HumanReadableText *(*handler)(Error **errp))
{
HMPCommand *table = hmp_info_cmds;
HMPCommand *table = hmp_cmds_for_target(true);
while (table->name != NULL) {
if (strcmp(table->name, name) == 0) {

View File

@@ -301,7 +301,7 @@ void hmp_help_cmd(Monitor *mon, const char *name)
}
/* 2. dump the contents according to parsed args */
help_cmd_dump(mon, hmp_cmds, args, nb_args, 0);
help_cmd_dump(mon, hmp_cmds_for_target(false), args, nb_args, 0);
free_cmdline_args(args, nb_args);
}
@@ -1131,7 +1131,8 @@ void handle_hmp_command(MonitorHMP *mon, const char *cmdline)
trace_handle_hmp_command(mon, cmdline);
cmd = monitor_parse_command(mon, cmdline, &cmdline, hmp_cmds);
cmd = monitor_parse_command(mon, cmdline, &cmdline,
hmp_cmds_for_target(false));
if (!cmd) {
return;
}
@@ -1375,7 +1376,8 @@ static void monitor_find_completion(void *opaque,
}
/* 2. auto complete according to args */
monitor_find_completion_by_table(mon, hmp_cmds, args, nb_args);
monitor_find_completion_by_table(mon, hmp_cmds_for_target(false),
args, nb_args);
cleanup:
free_cmdline_args(args, nb_args);

View File

@@ -169,8 +169,6 @@ extern QmpCommandList qmp_commands, qmp_cap_negotiation_commands;
extern QemuMutex monitor_lock;
extern MonitorList mon_list;
extern HMPCommand hmp_cmds[];
void monitor_data_init(Monitor *mon, bool is_qmp, bool skip_flush,
bool use_io_thread);
void monitor_data_destroy(Monitor *mon);
@@ -187,4 +185,11 @@ int get_monitor_def(Monitor *mon, int64_t *pval, const char *name);
void handle_hmp_command(MonitorHMP *mon, const char *cmdline);
int hmp_compare_cmd(const char *name, const char *list);
/*
* hmp_cmds_for_target: Return array of HMPCommand entries
*
* If @info_command is true, return the particular 'info foo' commands array.
*/
HMPCommand *hmp_cmds_for_target(bool info_command);
#endif