Skip to contentSkip to conversation

qdev: keep track of property types, print properties.

PATCH New Gerd Hoffmann 1 participant 1 message May 28, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 qdev: keep track of property types, print properties.

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

Quoted 1 line

From a74479d447f79582eb624bcdcc6ffc9f53d38252 Mon Sep 17 00:00:00 2001

From: Gerd Hoffmann <[email protected]>
Date: Thu, 28 May 2009 17:33:54 +0200
Subject: [PATCH] qdev: keep track of property types, print properties.

---
 hw/qdev.c |   23 +++++++++++++++++++++--
 1 files changed, 21 insertions(+), 2 deletions(-)
hw/qdev.c +21 -2
index d2eeb9a..f271b7f 100644
@@ -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);
         }
Signature · 1 line
1.6.2.2