From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58690) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YW6DD-0001FF-JT for qemu-devel@nongnu.org; Thu, 12 Mar 2015 12:43:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YW6D5-0001Kf-Pc for qemu-devel@nongnu.org; Thu, 12 Mar 2015 12:43:55 -0400 Received: from cantor2.suse.de ([195.135.220.15]:47925 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YW6D5-0001Jy-FE for qemu-devel@nongnu.org; Thu, 12 Mar 2015 12:43:47 -0400 From: =?UTF-8?q?Andreas=20F=C3=A4rber?= Date: Thu, 12 Mar 2015 17:43:39 +0100 Message-Id: <1426178624-32638-5-git-send-email-afaerber@suse.de> In-Reply-To: <1426178624-32638-1-git-send-email-afaerber@suse.de> References: <1426178624-32638-1-git-send-email-afaerber@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH v2 4/9] qom: Implement info qom-tree HMP command List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Andreas=20F=C3=A4rber?= , Luiz Capitulino To complement qdev's bus-oriented info qtree, info qom-tree prints a hierarchical view of the QOM composition tree. By default, the machine composition tree is shown. This can be overriden by supplying a path argument, such as "info qom-tree /". Signed-off-by: Andreas F=C3=A4rber --- hmp-commands.hx | 2 ++ include/monitor/qdev.h | 1 + monitor.c | 7 +++++++ qdev-monitor.c | 57 ++++++++++++++++++++++++++++++++++++++++++++= ++++++ 4 files changed, 67 insertions(+) diff --git a/hmp-commands.hx b/hmp-commands.hx index 1a6cd3e..3c1915a 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -1766,6 +1766,8 @@ show balloon information show device tree @item info qdm show qdev device model list +@item info qom-tree +show object composition tree @item info roms show roms @item info tpm diff --git a/include/monitor/qdev.h b/include/monitor/qdev.h index 5eb4a11..7190752 100644 --- a/include/monitor/qdev.h +++ b/include/monitor/qdev.h @@ -8,6 +8,7 @@ =20 void hmp_info_qtree(Monitor *mon, const QDict *qdict); void hmp_info_qdm(Monitor *mon, const QDict *qdict); +void hmp_info_qom_tree(Monitor *mon, const QDict *dict); int do_device_add(Monitor *mon, const QDict *qdict, QObject **ret_data); int qdev_device_help(QemuOpts *opts); DeviceState *qdev_device_add(QemuOpts *opts); diff --git a/monitor.c b/monitor.c index c86a89e..48f7f5a 100644 --- a/monitor.c +++ b/monitor.c @@ -2889,6 +2889,13 @@ static mon_cmd_t info_cmds[] =3D { .mhandler.cmd =3D hmp_info_qdm, }, { + .name =3D "qom-tree", + .args_type =3D "path:s?", + .params =3D "[path]", + .help =3D "show QOM composition tree", + .mhandler.cmd =3D hmp_info_qom_tree, + }, + { .name =3D "roms", .args_type =3D "", .params =3D "", diff --git a/qdev-monitor.c b/qdev-monitor.c index 5d30ac5..1d87f57 100644 --- a/qdev-monitor.c +++ b/qdev-monitor.c @@ -678,6 +678,63 @@ void hmp_info_qdm(Monitor *mon, const QDict *qdict) qdev_print_devinfos(true); } =20 +typedef struct QOMCompositionState { + Monitor *mon; + int indent; +} QOMCompositionState; + +static void print_qom_composition(Monitor *mon, Object *obj, int indent)= ; + +static int print_qom_composition_child(Object *obj, void *opaque) +{ + QOMCompositionState *s =3D opaque; + + print_qom_composition(s->mon, obj, s->indent); + + return 0; +} + +static void print_qom_composition(Monitor *mon, Object *obj, int indent) +{ + QOMCompositionState s =3D { + .mon =3D mon, + .indent =3D indent + 2, + }; + char *name; + + if (obj =3D=3D object_get_root()) { + name =3D g_strdup(""); + } else { + name =3D object_get_canonical_path_component(obj); + } + monitor_printf(mon, "%*s/%s (%s)\n", indent, "", name, + object_get_typename(obj)); + g_free(name); + object_child_foreach(obj, print_qom_composition_child, &s); +} + +void hmp_info_qom_tree(Monitor *mon, const QDict *dict) +{ + const char *path =3D qdict_get_try_str(dict, "path"); + Object *obj; + bool ambiguous =3D false; + + if (path) { + obj =3D object_resolve_path(path, &ambiguous); + if (!obj) { + monitor_printf(mon, "Path '%s' could not be resolved.\n", pa= th); + return; + } + if (ambiguous) { + monitor_printf(mon, "Warning: Path '%s' is ambiguous.\n", pa= th); + return; + } + } else { + obj =3D qdev_get_machine(); + } + print_qom_composition(mon, obj, 0); +} + int do_device_add(Monitor *mon, const QDict *qdict, QObject **ret_data) { Error *local_err =3D NULL; --=20 2.1.4