Dump hashes

This commit is contained in:
Lucas De Marchi 2013-08-13 10:31:11 -03:00
parent 05f7fdacf5
commit 54ea7920b2
3 changed files with 38 additions and 0 deletions

View File

@ -330,6 +330,37 @@ int hash_add(struct hash *hash, const char *key, const void *value)
return 0;
}
void hash_dump(struct hash *hash)
{
unsigned int i _unused_;
fprintf(stderr, "#####\n");
fprintf(stderr, "%p %d %u\n", hash, hash->count, hash->n_buckets);
fprintf(stderr, "#####\n");
for (i = 0; i < hash->n_buckets; i++) {
struct hash_bucket *bucket = hash->buckets + i;
fprintf(stderr, "%u %d\n", i, bucket->used);
}
fprintf(stderr, "#####\n");
hash_dump_keys(hash);
fprintf(stderr, "#####\n");
}
void hash_dump_keys(struct hash *hash)
{
unsigned int i;
for (i = 0; i < hash->n_buckets; i++) {
struct hash_bucket *bucket = hash->buckets + i;
struct hash_entry *entry, *entry_end;
entry = bucket->entries;
entry_end = entry + bucket->used;
for (; entry < entry_end; entry++)
fprintf(stderr, "%s\n", entry->key);
}
}
/* similar to hash_add(), but fails if key already exists */
int hash_add_unique(struct hash *hash, const char *key, const void *value)
{

View File

@ -20,3 +20,6 @@ unsigned int hash_get_count(const struct hash *hash);
void hash_iter_init(const struct hash *hash, struct hash_iter *iter);
bool hash_iter_next(struct hash_iter *iter, const char **key,
const void **value);
void hash_dump(struct hash *hash);
void hash_dump_keys(struct hash *hash);

View File

@ -1032,6 +1032,10 @@ static void depmod_shutdown(struct depmod *depmod)
{
size_t i;
hash_dump(depmod->symbols);
hash_dump(depmod->modules_by_name);
hash_dump(depmod->modules_by_uncrelpath);
hash_free(depmod->symbols);
hash_free(depmod->modules_by_uncrelpath);