>From a9796082f36381a85a2ec1427717f3d1202a3daa Mon Sep 17 00:00:00 2001 From: Gerd Hoffmann Date: Wed, 27 May 2009 14:21:53 +0200 Subject: [PATCH 05/21] qdev: add monitor command to dump the tree. Signed-off-by: Gerd Hoffmann --- hw/pci.c | 6 ++++++ hw/qdev.c | 22 ++++++++++++++++++++++ hw/qdev.h | 8 ++++++++ monitor.c | 5 +++++ 4 files changed, 41 insertions(+), 0 deletions(-) diff --git a/hw/pci.c b/hw/pci.c index 0ab5b94..7e2e73f 100644 --- a/hw/pci.c +++ b/hw/pci.c @@ -947,3 +947,9 @@ PCIDevice *pci_create_simple(PCIBus *bus, int devfn, const char *name) return (PCIDevice *)dev; } + +void do_info_qtreepci(Monitor *mon) +{ + if (first_bus) + qbus_print(mon, &first_bus->qbus, 0); +} diff --git a/hw/qdev.c b/hw/qdev.c index cedb772..d2eeb9a 100644 --- a/hw/qdev.c +++ b/hw/qdev.c @@ -29,6 +29,7 @@ #include "net.h" #include "qdev.h" #include "sysemu.h" +#include "monitor.h" struct DeviceProperty { const char *name; @@ -312,3 +313,24 @@ BusState *qbus_create(BusType type, size_t size, } return bus; } + +void qbus_print(Monitor *mon, BusState *bus, int indent) +{ + struct DeviceState *dev; + struct BusState *child; + + monitor_printf(mon, "%*sbus: name %s, type %d\n", indent, "", + bus->name, bus->type); + LIST_FOREACH(dev, &bus->children, sibling) { + monitor_printf(mon, "%*sdev: %s\n", indent+2, "", dev->type->name); + LIST_FOREACH(child, &dev->child_bus, sibling) { + qbus_print(mon, child, indent+4); + } + } +} + +void do_info_qtree(Monitor *mon) +{ + if (main_system_bus) + qbus_print(mon, main_system_bus, 0); +} diff --git a/hw/qdev.h b/hw/qdev.h index b3cc3ec..0842d3b 100644 --- a/hw/qdev.h +++ b/hw/qdev.h @@ -102,4 +102,12 @@ BusState *qbus_create(BusType type, size_t size, #define FROM_QBUS(type, dev) DO_UPCAST(type, qbus, dev) +/*** monitor commands ***/ + +void qbus_print(Monitor *mon, BusState *bus, int indent); +void do_info_qtree(Monitor *mon); + +/* temporary hack, pci_bus isn't hooked up anywhere (yet) */ +void do_info_qtreepci(Monitor *mon); + #endif diff --git a/monitor.c b/monitor.c index 0f38c71..a2d4e3d 100644 --- a/monitor.c +++ b/monitor.c @@ -23,6 +23,7 @@ */ #include #include "hw/hw.h" +#include "hw/qdev.h" #include "hw/usb.h" #include "hw/pcmcia.h" #include "hw/pc.h" @@ -1852,6 +1853,10 @@ static const mon_cmd_t info_cmds[] = { { "migrate", "", do_info_migrate, "", "show migration status" }, { "balloon", "", do_info_balloon, "", "show balloon information" }, + { "qtree", "", do_info_qtree, + "", "show device tree" }, + { "qtreepci", "", do_info_qtreepci, + "", "show pci device tree" }, { NULL, NULL, }, }; -- 1.6.2.2