2 * HMP commands related to QOM
4 * This work is licensed under the terms of the GNU GPL, version 2 or
5 * later. See the COPYING file in the top-level directory.
8 #include "qemu/osdep.h"
9 #include "hw/qdev-core.h"
10 #include "monitor/hmp.h"
11 #include "monitor/monitor.h"
12 #include "qapi/error.h"
13 #include "qapi/qapi-commands-qom.h"
14 #include "qapi/qmp/qdict.h"
15 #include "qom/object.h"
17 void hmp_qom_list(Monitor
*mon
, const QDict
*qdict
)
19 const char *path
= qdict_get_try_str(qdict
, "path");
20 ObjectPropertyInfoList
*list
;
24 monitor_printf(mon
, "/\n");
28 list
= qmp_qom_list(path
, &err
);
30 ObjectPropertyInfoList
*start
= list
;
31 while (list
!= NULL
) {
32 ObjectPropertyInfo
*value
= list
->value
;
34 monitor_printf(mon
, "%s (%s)\n",
35 value
->name
, value
->type
);
38 qapi_free_ObjectPropertyInfoList(start
);
40 hmp_handle_error(mon
, &err
);
43 void hmp_qom_set(Monitor
*mon
, const QDict
*qdict
)
45 const char *path
= qdict_get_str(qdict
, "path");
46 const char *property
= qdict_get_str(qdict
, "property");
47 const char *value
= qdict_get_str(qdict
, "value");
49 bool ambiguous
= false;
52 obj
= object_resolve_path(path
, &ambiguous
);
54 error_set(&err
, ERROR_CLASS_DEVICE_NOT_FOUND
,
55 "Device '%s' not found", path
);
58 monitor_printf(mon
, "Warning: Path '%s' is ambiguous\n", path
);
60 object_property_parse(obj
, value
, property
, &err
);
62 hmp_handle_error(mon
, &err
);
65 typedef struct QOMCompositionState
{
68 } QOMCompositionState
;
70 static void print_qom_composition(Monitor
*mon
, Object
*obj
, int indent
);
72 static int print_qom_composition_child(Object
*obj
, void *opaque
)
74 QOMCompositionState
*s
= opaque
;
76 print_qom_composition(s
->mon
, obj
, s
->indent
);
81 static void print_qom_composition(Monitor
*mon
, Object
*obj
, int indent
)
83 QOMCompositionState s
= {
89 if (obj
== object_get_root()) {
92 name
= object_get_canonical_path_component(obj
);
94 monitor_printf(mon
, "%*s/%s (%s)\n", indent
, "", name
,
95 object_get_typename(obj
));
97 object_child_foreach(obj
, print_qom_composition_child
, &s
);
100 void hmp_info_qom_tree(Monitor
*mon
, const QDict
*dict
)
102 const char *path
= qdict_get_try_str(dict
, "path");
104 bool ambiguous
= false;
107 obj
= object_resolve_path(path
, &ambiguous
);
109 monitor_printf(mon
, "Path '%s' could not be resolved.\n", path
);
113 monitor_printf(mon
, "Warning: Path '%s' is ambiguous.\n", path
);
117 obj
= qdev_get_machine();
119 print_qom_composition(mon
, obj
, 0);