T119: work in progress, use mdb tree call-back function to gather data
authorMoritz Hoffmann <moritz.hoffmann@inf.ethz.ch>
Mon, 15 Jun 2015 07:52:12 +0000 (09:52 +0200)
committerMoritz Hoffmann <moritz.hoffmann@inf.ethz.ch>
Tue, 16 Jun 2015 11:37:41 +0000 (13:37 +0200)
Signed-off-by: Moritz Hoffmann <moritz.hoffmann@inf.ethz.ch>

kernel/capabilities.c
kernel/include/capabilities.h
kernel/syscall.c
usr/fish/fish_common.c

index 677af1f..f90a3a0 100644 (file)
@@ -1326,32 +1326,80 @@ STATIC_ASSERT(27 == ObjType_Num, "Knowledge of all cap types");
 
 
 errval_t
-caps_debug_print(struct cte *c)
+caps_debug_print(struct cte *c, struct cap_visited_list *parent)
 {
-    printk(LOG_NOTE, "%s\n", __FUNCTION__);
+    genpaddr_t base;
+    uint8_t bits;
+    char* name = NULL;
+
+    struct cap_visited_list this = { .parent = parent, .c = c };
+
     switch (c->cap.type) {
     // all cap types
     case ObjType_CNode: {
         struct CNode *cn = &(c->cap.u.cnode);
         for (cslot_t slot = 0; slot < 1UL << cn->bits; slot++) {
 
-            errval_t err = caps_debug_print(
-                    (struct cte *) local_phys_to_mem(
-                            cn->cnode + slot * sizeof(*c)));
-            if (err_is_fail(err)) {
-                return err;
+            struct cte *child = (struct cte *) local_phys_to_mem(
+                    cn->cnode + slot * sizeof(*c));
+
+            uint8_t recurse = 1;
+
+            struct cap_visited_list *p = parent;
+            int depth = 0;
+            while (p && recurse) {
+                recurse = p->c != child;
+                p = p->parent;
+                depth++;
+            }
+            if (recurse && depth < 4) {
+                errval_t err = caps_debug_print(child, &this);
+                if (err_is_fail(err)) {
+                    return err;
+                }
             }
         }
         break;
     }
+    case ObjType_PhysAddr: {
+        base = c->cap.u.physaddr.base;
+        bits = c->cap.u.physaddr.bits;
+        name = "PhysAddr";
+        break;
+    }
+    case ObjType_RAM: {
+        base = c->cap.u.ram.base;
+        bits = c->cap.u.ram.bits;
+        name = "RAM";
+        break;
+    }
     case ObjType_Frame: {
+        base = c->cap.u.frame.base;
+        bits = c->cap.u.frame.bits;
+        name = "Frame";
+        break;
+    }
+    case ObjType_DevFrame: {
+        base = c->cap.u.devframe.base;
+        bits = c->cap.u.devframe.bits;
+        name = "DevFrame";
+        break;
+    }
+    case ObjType_Null: {
         break;
     }
     default: {
         // Unhandled source type for mint
-        return SYS_ERR_INVALID_SOURCE_TYPE;
+        printk(LOG_NOTE, "Unknown capability type: %d\n", c->cap.type);
+        break;
     }
     }
 
+    if (name) {
+        printk(LOG_NOTE,
+                "%s: base=0x%"PRIxGENPADDR" bits=%d end=0x%"PRIxGENPADDR"\n",
+                name, base, bits, base + (1UL << bits));
+    }
+
     return SYS_ERR_OK;
 }
index bb20376..8d6dab4 100644 (file)
@@ -122,8 +122,12 @@ errval_t caps_revoke(struct cte *cte);
 /*
  * Cap debugging
  */
+struct cap_visited_list {
+    struct cap_visited_list *parent;
+    struct cte *c;
+};
 
-errval_t caps_debug_print(struct cte *cte);
+errval_t caps_debug_print(struct cte *cte, struct cap_visited_list *);
 
 /*
  * Cap tracing
index 6a43c6b..43d4928 100644 (file)
@@ -16,6 +16,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <syscall.h>
+#include <barrelfish_kpi/init.h>
 #include <barrelfish_kpi/syscalls.h>
 #include <capabilities.h>
 #include <cap_predicates.h>
@@ -631,10 +632,82 @@ struct sysret sys_get_absolute_time(void)
     };
 }
 
+
+static bool sys_debug_print_capabilities_check_cnode(struct cte *cte, struct cte **dispatcher) {
+    enum objtype type = cte->cap.type;
+
+    if (type == ObjType_Dispatcher) {
+        *dispatcher = cte;
+        return true;
+    }
+
+    struct cte *cn = (struct cte*) local_phys_to_mem(get_address(&cte->cap));
+
+    if (type == ObjType_CNode) {
+        // are we task cnode?
+        if (cn[TASKCN_SLOT_DISPATCHER].cap.type == ObjType_Dispatcher) {
+            *dispatcher = &cn[TASKCN_SLOT_DISPATCHER];
+            return true;
+        }
+
+        if (cn[ROOTCN_SLOT_TASKCN].cap.type == ObjType_CNode) {
+            struct cte *cn_task = (struct cte*) local_phys_to_mem(get_address(&cn[ROOTCN_SLOT_TASKCN].cap));
+
+            if (cn_task[TASKCN_SLOT_DISPATCHER].cap.type == ObjType_Dispatcher) {
+                *dispatcher = &cn_task[TASKCN_SLOT_DISPATCHER];
+                return true;
+            }
+        }
+    }
+
+    return false;
+}
+
+static errval_t sys_debug_print_capabilities_cb(struct cte *cte, void *data) {
+//    printk(LOG_NOTE, "cte=%p\n", cte);
+
+    struct dcb *my_dcb = (struct dcb *) data;
+
+    struct cte *result;
+    errval_t err = mdb_find_cap_for_address(mem_to_local_phys((lvaddr_t) cte), &result);
+    if (err_is_fail(err)) {
+        printk(LOG_ERR, "Type of cap: %d\n", cte->cap.type);
+        printk(LOG_ERR, "%s:%s:%d \n", __FILE__, __FUNCTION__, __LINE__);
+        return err;
+    }
+
+    assert(result->cap.type == ObjType_CNode);
+
+    struct cte *dispatcher;
+
+    while (!sys_debug_print_capabilities_check_cnode(result, &dispatcher)) {
+        err = mdb_find_cap_for_address(mem_to_local_phys((lvaddr_t) result), &result);
+        if (err_is_fail(err)) {
+            printk(LOG_ERR, "Type of cap: %d\n", cte->cap.type);
+            printk(LOG_ERR, "%s:%s:%d \n", __FILE__, __FUNCTION__, __LINE__);
+            return err;
+        }
+    }
+
+    struct dcb *dcb = dispatcher->cap.u.dispatcher.dcb;
+    dispatcher_handle_t handle = dcb->disp;
+    struct dispatcher_shared_generic *disp =
+        get_dispatcher_shared_generic(handle);
+
+    if (my_dcb == dcb) {
+        printk(LOG_NOTE, "disp->name=%s\n", disp->name);
+    }
+
+    return SYS_ERR_OK;
+}
+
 struct sysret
 sys_debug_print_capabilities(void) {
 
-    caps_debug_print(&dcb_current->cspace);
+    errval_t err = mdb_traverse(MDB_TRAVERSAL_ORDER_ASCENDING, sys_debug_print_capabilities_cb, dcb_current);
 
-    return SYSRET(SYS_ERR_OK);
+
+//    caps_debug_print(&dcb_current->cspace, NULL);
+
+    return SYSRET(err);
 }
index 208bd06..1fe4117 100644 (file)
@@ -125,7 +125,19 @@ static int print_cspace(int argc, char *argv[])
 }
 
 static int debug_print_caps(int argc, char *argv[]) {
-    monitor_debug_print_cababilities();
+    errval_t err;
+    if (argc > 1 && strncmp("monitor", argv[1], 7)) {
+        err = monitor_debug_print_cababilities();
+    } else {
+        err = sys_debug_print_capabilities();
+    }
+    if (err_is_fail(err)) {
+        printf("%s: error debug print cababilities: %s\n", argv[0], err_getstring(err));
+        DEBUG_ERR(err, "Error\n");
+        return EXIT_FAILURE;
+    }
+
+
     return EXIT_SUCCESS;
 }