Commit a1a87936 authored by Eric Pouech's avatar Eric Pouech Committed by Alexandre Julliard

dbghelp: Added a field to the hash table to store the number of elements in the hash table.

Make use of it to get rid to module_compute_num_syms.
parent 4806320b
...@@ -82,6 +82,7 @@ struct hash_table_elt ...@@ -82,6 +82,7 @@ struct hash_table_elt
struct hash_table struct hash_table
{ {
unsigned num_elts;
unsigned num_buckets; unsigned num_buckets;
struct hash_table_elt** buckets; struct hash_table_elt** buckets;
}; };
...@@ -422,7 +423,6 @@ extern int elf_is_in_thunk_area(unsigned long addr, const struct elf_th ...@@ -422,7 +423,6 @@ extern int elf_is_in_thunk_area(unsigned long addr, const struct elf_th
extern DWORD WINAPI addr_to_linear(HANDLE hProcess, HANDLE hThread, ADDRESS* addr); extern DWORD WINAPI addr_to_linear(HANDLE hProcess, HANDLE hThread, ADDRESS* addr);
/* module.c */ /* module.c */
extern int module_compute_num_syms(struct module* module);
extern struct module* extern struct module*
module_find_by_addr(const struct process* pcs, unsigned long addr, module_find_by_addr(const struct process* pcs, unsigned long addr,
enum module_type type); enum module_type type);
......
...@@ -284,7 +284,7 @@ BOOL module_get_debug(struct module_pair* pair) ...@@ -284,7 +284,7 @@ BOOL module_get_debug(struct module_pair* pair)
} }
if (!ret) pair->effective->module.SymType = SymNone; if (!ret) pair->effective->module.SymType = SymNone;
assert(pair->effective->module.SymType != SymDeferred); assert(pair->effective->module.SymType != SymDeferred);
module_compute_num_syms(pair->effective); pair->effective->module.NumSyms = pair->effective->ht_symbols.num_elts;
} }
return pair->effective->module.SymType != SymNone; return pair->effective->module.SymType != SymNone;
} }
...@@ -372,18 +372,6 @@ enum module_type module_get_type_by_name(const char* name) ...@@ -372,18 +372,6 @@ enum module_type module_get_type_by_name(const char* name)
return DMT_PE; return DMT_PE;
} }
int module_compute_num_syms(struct module* module)
{
struct hash_table_iter hti;
void* ptr;
module->module.NumSyms = 0;
hash_table_iter_init(&module->ht_symbols, &hti, NULL);
while ((ptr = hash_table_iter_up(&hti)))
module->module.NumSyms++;
return module->module.NumSyms;
}
/*********************************************************************** /***********************************************************************
* SymLoadModule (DBGHELP.@) * SymLoadModule (DBGHELP.@)
*/ */
...@@ -429,7 +417,7 @@ DWORD WINAPI SymLoadModule(HANDLE hProcess, HANDLE hFile, const char* ImageName, ...@@ -429,7 +417,7 @@ DWORD WINAPI SymLoadModule(HANDLE hProcess, HANDLE hFile, const char* ImageName,
WARN("Couldn't locate %s\n", ImageName); WARN("Couldn't locate %s\n", ImageName);
return 0; return 0;
} }
module_compute_num_syms(module); module->module.NumSyms = module->ht_symbols.num_elts;
done: done:
/* by default pe_load_module fills module.ModuleName from a derivation /* by default pe_load_module fills module.ModuleName from a derivation
* of ImageName. Overwrite it, if we have better information * of ImageName. Overwrite it, if we have better information
......
...@@ -327,6 +327,7 @@ unsigned hash_table_hash(const char* name, unsigned num_buckets) ...@@ -327,6 +327,7 @@ unsigned hash_table_hash(const char* name, unsigned num_buckets)
void hash_table_init(struct pool* pool, struct hash_table* ht, unsigned num_buckets) void hash_table_init(struct pool* pool, struct hash_table* ht, unsigned num_buckets)
{ {
ht->num_elts = 0;
ht->buckets = pool_alloc(pool, num_buckets * sizeof(struct hash_table_elt*)); ht->buckets = pool_alloc(pool, num_buckets * sizeof(struct hash_table_elt*));
assert(ht->buckets); assert(ht->buckets);
ht->num_buckets = num_buckets; ht->num_buckets = num_buckets;
...@@ -338,7 +339,7 @@ void hash_table_destroy(struct hash_table* ht) ...@@ -338,7 +339,7 @@ void hash_table_destroy(struct hash_table* ht)
#if defined(USE_STATS) #if defined(USE_STATS)
int i; int i;
unsigned len; unsigned len;
unsigned num = 0, min = 0xffffffff, max = 0, sq = 0; unsigned min = 0xffffffff, max = 0, sq = 0;
struct hash_table_elt* elt; struct hash_table_elt* elt;
double mean, variance; double mean, variance;
...@@ -347,13 +348,12 @@ void hash_table_destroy(struct hash_table* ht) ...@@ -347,13 +348,12 @@ void hash_table_destroy(struct hash_table* ht)
for (len = 0, elt = ht->buckets[i]; elt; elt = elt->next) len++; for (len = 0, elt = ht->buckets[i]; elt; elt = elt->next) len++;
if (len < min) min = len; if (len < min) min = len;
if (len > max) max = len; if (len > max) max = len;
num += len;
sq += len * len; sq += len * len;
} }
mean = (double)num / ht->num_buckets; mean = (double)ht->num_elts / ht->num_buckets;
variance = (double)sq / ht->num_buckets - mean * mean; variance = (double)sq / ht->num_buckets - mean * mean;
FIXME("STATS: elts[num:%-4u size:%u mean:%f] buckets[min:%-4u variance:%+f max:%-4u]\n", FIXME("STATS: elts[num:%-4u size:%u mean:%f] buckets[min:%-4u variance:%+f max:%-4u]\n",
num, ht->num_buckets, mean, min, variance, max); ht->num_elts, ht->num_buckets, mean, min, variance, max);
#if 1 #if 1
for (i = 0; i < ht->num_buckets; i++) for (i = 0; i < ht->num_buckets; i++)
{ {
...@@ -382,6 +382,7 @@ void hash_table_add(struct hash_table* ht, struct hash_table_elt* elt) ...@@ -382,6 +382,7 @@ void hash_table_add(struct hash_table* ht, struct hash_table_elt* elt)
for (p = &ht->buckets[hash]; *p; p = &((*p)->next)); for (p = &ht->buckets[hash]; *p; p = &((*p)->next));
*p = elt; *p = elt;
elt->next = NULL; elt->next = NULL;
ht->num_elts++;
} }
void* hash_table_find(const struct hash_table* ht, const char* name) void* hash_table_find(const struct hash_table* ht, const char* name)
......
...@@ -623,7 +623,8 @@ static BOOL resort_symbols(struct module* module) ...@@ -623,7 +623,8 @@ static BOOL resort_symbols(struct module* module)
struct symt_ht* sym; struct symt_ht* sym;
struct hash_table_iter hti; struct hash_table_iter hti;
if (!module_compute_num_syms(module)) return FALSE; if (!(module->module.NumSyms = module->ht_symbols.num_elts))
return FALSE;
if (module->addr_sorttab) if (module->addr_sorttab)
module->addr_sorttab = HeapReAlloc(GetProcessHeap(), 0, module->addr_sorttab = HeapReAlloc(GetProcessHeap(), 0,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment