]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Implemented debugging function rlookup() which you can call from gdb
authorMartin Mares <mj@ucw.cz>
Mon, 8 May 2000 22:33:38 +0000 (22:33 +0000)
committerMartin Mares <mj@ucw.cz>
Mon, 8 May 2000 22:33:38 +0000 (22:33 +0000)
to see what resource does the address given as a parameter belong to.

lib/mempool.c
lib/resource.c
lib/resource.h
lib/slab.c

index c9c1dd63c34f9e86fc5faef36277a5a556effe33..f21b3059c517badf9a7c03bbb8631e55439ee677 100644 (file)
@@ -14,6 +14,7 @@
 
 struct lp_chunk {
   struct lp_chunk *next;
+  unsigned int size;
   byte data[0];
 };
 
@@ -25,14 +26,16 @@ struct linpool {
   unsigned chunk_size, threshold, total, total_large;
 };
 
-void lp_free(resource *);
-void lp_dump(resource *);
+static void lp_free(resource *);
+static void lp_dump(resource *);
+static resource *lp_lookup(resource *, unsigned long);
 
 static struct resclass lp_class = {
   "LinPool",
   sizeof(struct linpool),
   lp_free,
-  lp_dump
+  lp_dump,
+  lp_lookup
 };
 
 linpool
@@ -70,6 +73,7 @@ lp_alloc(linpool *m, unsigned size)
          m->total_large += size;
          c->next = m->first_large;
          m->first_large = c->next;
+         c->size = size;
        }
       else
        {
@@ -87,6 +91,7 @@ lp_alloc(linpool *m, unsigned size)
              *m->plast = c;
              m->plast = &c->next;
              c->next = NULL;
+             c->size = m->chunk_size;
            }
          m->ptr = c->data + size;
          m->end = c->data + m->chunk_size;
@@ -134,7 +139,7 @@ lp_flush(linpool *m)
   m->total_large = 0;
 }
 
-void
+static void
 lp_free(resource *r)
 {
   linpool *m = (linpool *) r;
@@ -152,7 +157,7 @@ lp_free(resource *r)
     }
 }
 
-void
+static void
 lp_dump(resource *r)
 {
   linpool *m = (linpool *) r;
@@ -171,3 +176,18 @@ lp_dump(resource *r)
        m->total,
        m->total_large);
 }
+
+static resource *
+lp_lookup(resource *r, unsigned long a)
+{
+  linpool *m = (linpool *) r;
+  struct lp_chunk *c;
+
+  for(c=m->first; c; c=c->next)
+    if ((unsigned long) c->data <= a && (unsigned long) c->data + c->size > a)
+      return r;
+  for(c=m->first_large; c; c=c->next)
+    if ((unsigned long) c->data <= a && (unsigned long) c->data + c->size > a)
+      return r;
+  return NULL;
+}
index e67c05a5a589171c2f3955d838bc0579c1c83f36..3cfd0658ac3c8ce7b4c4082ac45d2381b473cf61 100644 (file)
@@ -21,12 +21,14 @@ struct pool {
 
 static void pool_dump(resource *);
 static void pool_free(resource *);
+static resource *pool_lookup(resource *, unsigned long);
 
 static struct resclass pool_class = {
   "Pool",
   sizeof(pool),
   pool_free,
-  pool_dump
+  pool_dump,
+  pool_lookup
 };
 
 pool root_pool;
@@ -70,6 +72,18 @@ pool_dump(resource *P)
   indent -= 3;
 }
 
+static resource *
+pool_lookup(resource *P, unsigned long a)
+{
+  pool *p = (pool *) P;
+  resource *r, *q;
+
+  WALK_LIST(r, p->inside)
+    if (r->class->lookup && (q = r->class->lookup(r, a)))
+      return q;
+  return NULL;
+}
+
 void
 rfree(void *res)
 {
@@ -111,6 +125,18 @@ ralloc(pool *p, struct resclass *c)
   return r;
 }
 
+void
+rlookup(unsigned long a)
+{
+  resource *r;
+
+  debug("Looking up %08lx\n", a);
+  if (r = pool_lookup(&root_pool.r, a))
+    rdump(r);
+  else
+    debug("Not found.\n");
+}
+
 void
 resource_init(void)
 {
@@ -140,11 +166,22 @@ static void mbl_debug(resource *r)
   debug("(size=%d)\n", m->size);
 }
 
+static resource *
+mbl_lookup(resource *r, unsigned long a)
+{
+  struct mblock *m = (struct mblock *) r;
+
+  if ((unsigned long) m->data <= a && (unsigned long) m->data + m->size > a)
+    return r;
+  return NULL;
+}
+
 static struct resclass mb_class = {
   "Memory",
   0,
   mbl_free,
   mbl_debug,
+  mbl_lookup
 };
 
 void *
index 1491fde7ca3d86055601058ff22b0e0194e136a2..ab530480330ca469f93058fb49b97aa72b88babc 100644 (file)
@@ -25,6 +25,7 @@ struct resclass {
   unsigned size;                       /* Standard size of single resource */
   void (*free)(resource *);            /* Freeing function */
   void (*dump)(resource *);            /* Dump to debug output */
+  resource *(*lookup)(resource *, unsigned long);      /* Look up address (only for debugging) */
 };
 
 /* Generic resource manipulation */
@@ -35,6 +36,7 @@ void resource_init(void);
 pool *rp_new(pool *, char *);          /* Create new pool */
 void rfree(void *);                    /* Free single resource */
 void rdump(void *);                    /* Dump to debug output */
+void rlookup(unsigned long);           /* Look up address (only for debugging) */
 
 void *ralloc(pool *, struct resclass *);
 
index e2e741c8679bf928562b4fbda1cf8113ee494ad4..0a3455fb0e1fb207a79221efd95fb063c1b75eb0 100644 (file)
@@ -18,6 +18,7 @@
 
 static void slab_free(resource *r);
 static void slab_dump(resource *r);
+static resource *slab_lookup(resource *r, unsigned long addr);
 
 #ifdef FAKE_SLAB
 
@@ -111,7 +112,8 @@ static struct resclass sl_class = {
   "Slab",
   sizeof(struct slab),
   slab_free,
-  slab_dump
+  slab_dump,
+  slab_lookup
 };
 
 struct sl_head {
@@ -269,4 +271,19 @@ slab_dump(resource *r)
   debug("(%de+%dp+%df blocks per %d objs per %d bytes)\n", ec, pc, fc, s->objs_per_slab, s->obj_size);
 }
 
+static resource *
+slab_lookup(resource *r, unsigned long a)
+{
+  slab *s = (slab *) r;
+  struct sl_head *h;
+
+  WALK_LIST(h, s->partial_heads)
+    if ((unsigned long) h < a && (unsigned long) h + SLAB_SIZE < a)
+      return r;
+  WALK_LIST(h, s->full_heads)
+    if ((unsigned long) h < a && (unsigned long) h + SLAB_SIZE < a)
+      return r;
+  return NULL;
+}
+
 #endif