Merge remote-tracking branch 'remotes/dgilbert/tags/pull-migration-20190814a' into...
[qemu/ar7.git] / qom / qom-hmp-cmds.c
bloba268e01eb4c0273a236c108a840dd558469f9d34
1 /*
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.
6 */
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;
21 Error *err = NULL;
23 if (path == NULL) {
24 monitor_printf(mon, "/\n");
25 return;
28 list = qmp_qom_list(path, &err);
29 if (err == NULL) {
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);
36 list = list->next;
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");
48 Error *err = NULL;
49 bool ambiguous = false;
50 Object *obj;
52 obj = object_resolve_path(path, &ambiguous);
53 if (obj == NULL) {
54 error_set(&err, ERROR_CLASS_DEVICE_NOT_FOUND,
55 "Device '%s' not found", path);
56 } else {
57 if (ambiguous) {
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 {
66 Monitor *mon;
67 int indent;
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);
78 return 0;
81 static void print_qom_composition(Monitor *mon, Object *obj, int indent)
83 QOMCompositionState s = {
84 .mon = mon,
85 .indent = indent + 2,
87 char *name;
89 if (obj == object_get_root()) {
90 name = g_strdup("");
91 } else {
92 name = object_get_canonical_path_component(obj);
94 monitor_printf(mon, "%*s/%s (%s)\n", indent, "", name,
95 object_get_typename(obj));
96 g_free(name);
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");
103 Object *obj;
104 bool ambiguous = false;
106 if (path) {
107 obj = object_resolve_path(path, &ambiguous);
108 if (!obj) {
109 monitor_printf(mon, "Path '%s' could not be resolved.\n", path);
110 return;
112 if (ambiguous) {
113 monitor_printf(mon, "Warning: Path '%s' is ambiguous.\n", path);
114 return;
116 } else {
117 obj = qdev_get_machine();
119 print_qom_composition(mon, obj, 0);