From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1M9hgo-0007JM-5y for qemu-devel@nongnu.org; Thu, 28 May 2009 11:38:42 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1M9hgj-00074p-0r for qemu-devel@nongnu.org; Thu, 28 May 2009 11:38:41 -0400 Received: from [199.232.76.173] (port=40576 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1M9hgi-00074J-RG for qemu-devel@nongnu.org; Thu, 28 May 2009 11:38:36 -0400 Received: from mx2.redhat.com ([66.187.237.31]:43599) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1M9hgi-0004kJ-Eo for qemu-devel@nongnu.org; Thu, 28 May 2009 11:38:36 -0400 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.8/8.13.8) with ESMTP id n4SFcZ4Y003459 for ; Thu, 28 May 2009 11:38:35 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx2.corp.redhat.com (8.13.1/8.13.1) with ESMTP id n4SFcYbN012538 for ; Thu, 28 May 2009 11:38:35 -0400 Received: from zweiblum.home.kraxel.org (vpn-10-220.str.redhat.com [10.32.10.220]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id n4SFcWpU022892 for ; Thu, 28 May 2009 11:38:33 -0400 Message-ID: <4A1EAFF8.4070400@redhat.com> Date: Thu, 28 May 2009 17:38:32 +0200 From: Gerd Hoffmann MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------090809070000000507010405" Subject: [Qemu-devel] [PATCH] qdev: keep track of property types, print properties. List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "qemu-devel@nongnu.org" This is a multi-part message in MIME format. --------------090809070000000507010405 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Hi, This patch makes qemu keep track od property types. Types are checked when reading them and the information is also used to print them. The patch depends on the "info qtree" monitor command patch sent earlier today. please apply, Gerd --------------090809070000000507010405 Content-Type: text/plain; name="0001-qdev-keep-track-of-property-types-print-properties.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0001-qdev-keep-track-of-property-types-print-properties.patc"; filename*1="h" >>From a74479d447f79582eb624bcdcc6ffc9f53d38252 Mon Sep 17 00:00:00 2001 From: Gerd Hoffmann Date: Thu, 28 May 2009 17:33:54 +0200 Subject: [PATCH] qdev: keep track of property types, print properties. Signed-off-by: Gerd Hoffmann --- hw/qdev.c | 23 +++++++++++++++++++++-- 1 files changed, 21 insertions(+), 2 deletions(-) diff --git a/hw/qdev.c b/hw/qdev.c index d2eeb9a..f271b7f 100644 --- a/hw/qdev.c +++ b/hw/qdev.c @@ -33,6 +33,10 @@ struct DeviceProperty { const char *name; + enum { + PROP_INT, + PROP_PTR, + } type; union { uint64_t i; void *ptr; @@ -138,6 +142,7 @@ void qdev_set_prop_int(DeviceState *dev, const char *name, uint64_t value) DeviceProperty *prop; prop = create_prop(dev, name); + prop->type = PROP_INT; prop->value.i = value; } @@ -146,6 +151,7 @@ void qdev_set_prop_ptr(DeviceState *dev, const char *name, void *value) DeviceProperty *prop; prop = create_prop(dev, name); + prop->type = PROP_PTR; prop->value.ptr = value; } @@ -191,7 +197,7 @@ uint64_t qdev_get_prop_int(DeviceState *dev, const char *name, uint64_t def) DeviceProperty *prop; prop = find_prop(dev, name); - if (!prop) + if (!prop || prop->type != PROP_INT) return def; return prop->value.i; @@ -203,6 +209,7 @@ void *qdev_get_prop_ptr(DeviceState *dev, const char *name) prop = find_prop(dev, name); assert(prop); + assert(prop->type == PROP_PTR); return prop->value.ptr; } @@ -318,11 +325,23 @@ void qbus_print(Monitor *mon, BusState *bus, int indent) { struct DeviceState *dev; struct BusState *child; + struct DeviceProperty *prop; 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); + monitor_printf(mon, "%*sdev: %s", indent+2, "", dev->type->name); + for (prop = dev->props; prop; prop = prop->next) { + switch (prop->type) { + case PROP_INT: + monitor_printf(mon, ", %s=%" PRId64, prop->name, prop->value.i); + break; + case PROP_PTR: + monitor_printf(mon, ", %s=%p", prop->name, prop->value.ptr); + break; + } + } + monitor_printf(mon, "\n"); LIST_FOREACH(child, &dev->child_bus, sibling) { qbus_print(mon, child, indent+4); } -- 1.6.2.2 --------------090809070000000507010405--