Implemented debugging function rlookup() which you can call from gdb

to see what resource does the address given as a parameter belong to.
This commit is contained in:
Martin Mares 2000-05-08 22:33:38 +00:00
parent 0521e4f684
commit c976342828
4 changed files with 83 additions and 7 deletions

View file

@ -14,6 +14,7 @@
struct lp_chunk { struct lp_chunk {
struct lp_chunk *next; struct lp_chunk *next;
unsigned int size;
byte data[0]; byte data[0];
}; };
@ -25,14 +26,16 @@ struct linpool {
unsigned chunk_size, threshold, total, total_large; unsigned chunk_size, threshold, total, total_large;
}; };
void lp_free(resource *); static void lp_free(resource *);
void lp_dump(resource *); static void lp_dump(resource *);
static resource *lp_lookup(resource *, unsigned long);
static struct resclass lp_class = { static struct resclass lp_class = {
"LinPool", "LinPool",
sizeof(struct linpool), sizeof(struct linpool),
lp_free, lp_free,
lp_dump lp_dump,
lp_lookup
}; };
linpool linpool
@ -70,6 +73,7 @@ lp_alloc(linpool *m, unsigned size)
m->total_large += size; m->total_large += size;
c->next = m->first_large; c->next = m->first_large;
m->first_large = c->next; m->first_large = c->next;
c->size = size;
} }
else else
{ {
@ -87,6 +91,7 @@ lp_alloc(linpool *m, unsigned size)
*m->plast = c; *m->plast = c;
m->plast = &c->next; m->plast = &c->next;
c->next = NULL; c->next = NULL;
c->size = m->chunk_size;
} }
m->ptr = c->data + size; m->ptr = c->data + size;
m->end = c->data + m->chunk_size; m->end = c->data + m->chunk_size;
@ -134,7 +139,7 @@ lp_flush(linpool *m)
m->total_large = 0; m->total_large = 0;
} }
void static void
lp_free(resource *r) lp_free(resource *r)
{ {
linpool *m = (linpool *) r; linpool *m = (linpool *) r;
@ -152,7 +157,7 @@ lp_free(resource *r)
} }
} }
void static void
lp_dump(resource *r) lp_dump(resource *r)
{ {
linpool *m = (linpool *) r; linpool *m = (linpool *) r;
@ -171,3 +176,18 @@ lp_dump(resource *r)
m->total, m->total,
m->total_large); 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;
}

View file

@ -21,12 +21,14 @@ struct pool {
static void pool_dump(resource *); static void pool_dump(resource *);
static void pool_free(resource *); static void pool_free(resource *);
static resource *pool_lookup(resource *, unsigned long);
static struct resclass pool_class = { static struct resclass pool_class = {
"Pool", "Pool",
sizeof(pool), sizeof(pool),
pool_free, pool_free,
pool_dump pool_dump,
pool_lookup
}; };
pool root_pool; pool root_pool;
@ -70,6 +72,18 @@ pool_dump(resource *P)
indent -= 3; 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 void
rfree(void *res) rfree(void *res)
{ {
@ -111,6 +125,18 @@ ralloc(pool *p, struct resclass *c)
return r; 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 void
resource_init(void) resource_init(void)
{ {
@ -140,11 +166,22 @@ static void mbl_debug(resource *r)
debug("(size=%d)\n", m->size); 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 = { static struct resclass mb_class = {
"Memory", "Memory",
0, 0,
mbl_free, mbl_free,
mbl_debug, mbl_debug,
mbl_lookup
}; };
void * void *

View file

@ -25,6 +25,7 @@ struct resclass {
unsigned size; /* Standard size of single resource */ unsigned size; /* Standard size of single resource */
void (*free)(resource *); /* Freeing function */ void (*free)(resource *); /* Freeing function */
void (*dump)(resource *); /* Dump to debug output */ void (*dump)(resource *); /* Dump to debug output */
resource *(*lookup)(resource *, unsigned long); /* Look up address (only for debugging) */
}; };
/* Generic resource manipulation */ /* Generic resource manipulation */
@ -35,6 +36,7 @@ void resource_init(void);
pool *rp_new(pool *, char *); /* Create new pool */ pool *rp_new(pool *, char *); /* Create new pool */
void rfree(void *); /* Free single resource */ void rfree(void *); /* Free single resource */
void rdump(void *); /* Dump to debug output */ void rdump(void *); /* Dump to debug output */
void rlookup(unsigned long); /* Look up address (only for debugging) */
void *ralloc(pool *, struct resclass *); void *ralloc(pool *, struct resclass *);

View file

@ -18,6 +18,7 @@
static void slab_free(resource *r); static void slab_free(resource *r);
static void slab_dump(resource *r); static void slab_dump(resource *r);
static resource *slab_lookup(resource *r, unsigned long addr);
#ifdef FAKE_SLAB #ifdef FAKE_SLAB
@ -111,7 +112,8 @@ static struct resclass sl_class = {
"Slab", "Slab",
sizeof(struct slab), sizeof(struct slab),
slab_free, slab_free,
slab_dump slab_dump,
slab_lookup
}; };
struct sl_head { 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); 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 #endif