From c976342828d5de3d16b59d623f4f7fb03f52acc9 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Mon, 8 May 2000 22:33:38 +0000 Subject: Implemented debugging function rlookup() which you can call from gdb to see what resource does the address given as a parameter belong to. --- lib/mempool.c | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) (limited to 'lib/mempool.c') diff --git a/lib/mempool.c b/lib/mempool.c index c9c1dd6..f21b305 100644 --- a/lib/mempool.c +++ b/lib/mempool.c @@ -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; +} -- cgit v1.2.3