1
0
mirror of https://github.com/wine-mirror/wine synced 2024-07-05 17:28:47 +00:00

dbghelp: Grow all arrays by doubling the size.

This commit is contained in:
Alexandre Julliard 2009-07-10 14:46:55 +02:00
parent 73d9ffbdb4
commit 75792a3e69
8 changed files with 90 additions and 37 deletions

View File

@ -108,12 +108,18 @@ static int coff_add_file(struct CoffFileSet* coff_files, struct module* module,
if (coff_files->nfiles + 1 >= coff_files->nfiles_alloc)
{
coff_files->nfiles_alloc += 10;
coff_files->files = (coff_files->files) ?
HeapReAlloc(GetProcessHeap(), 0, coff_files->files,
coff_files->nfiles_alloc * sizeof(struct CoffFile)) :
HeapAlloc(GetProcessHeap(), 0,
coff_files->nfiles_alloc * sizeof(struct CoffFile));
if (coff_files->files)
{
coff_files->nfiles_alloc *= 2;
coff_files->files = HeapReAlloc(GetProcessHeap(), 0, coff_files->files,
coff_files->nfiles_alloc * sizeof(struct CoffFile));
}
else
{
coff_files->nfiles_alloc = 16;
coff_files->files = HeapAlloc(GetProcessHeap(), 0,
coff_files->nfiles_alloc * sizeof(struct CoffFile));
}
}
file = coff_files->files + coff_files->nfiles;
file->startaddr = 0xffffffff;
@ -132,7 +138,7 @@ static void coff_add_symbol(struct CoffFile* coff_file, struct symt* sym)
{
if (coff_file->neps + 1 >= coff_file->neps_alloc)
{
coff_file->neps_alloc += 10;
coff_file->neps_alloc *= 2;
coff_file->entries = (coff_file->entries) ?
HeapReAlloc(GetProcessHeap(), 0, coff_file->entries,
coff_file->neps_alloc * sizeof(struct symt*)) :

View File

@ -338,6 +338,7 @@ struct module
int sortlist_valid;
unsigned num_sorttab; /* number of symbols with addresses */
unsigned num_symbols;
unsigned sorttab_size;
struct symt_ht** addr_sorttab;
struct hash_table ht_symbols;
void (*loc_compute)(struct process* pcs,

View File

@ -59,6 +59,7 @@ struct dump_context
/* module information */
struct dump_module* modules;
unsigned num_modules;
unsigned alloc_modules;
/* exception information */
/* output information */
MINIDUMP_TYPE type;
@ -66,6 +67,7 @@ struct dump_context
RVA rva;
struct dump_memory* mem;
unsigned num_mem;
unsigned alloc_mem;
/* callback information */
MINIDUMP_CALLBACK_INFORMATION* cb;
};
@ -253,11 +255,17 @@ static BOOL add_module(struct dump_context* dc, const WCHAR* name,
BOOL is_elf)
{
if (!dc->modules)
{
dc->alloc_modules = 32;
dc->modules = HeapAlloc(GetProcessHeap(), 0,
++dc->num_modules * sizeof(*dc->modules));
dc->alloc_modules * sizeof(*dc->modules));
}
else
{
dc->alloc_modules *= 2;
dc->modules = HeapReAlloc(GetProcessHeap(), 0, dc->modules,
++dc->num_modules * sizeof(*dc->modules));
dc->alloc_modules * sizeof(*dc->modules));
}
if (!dc->modules) return FALSE;
if (is_elf ||
!GetModuleFileNameExW(dc->hProcess, (HMODULE)base,
@ -382,17 +390,23 @@ static void fetch_module_versioninfo(LPCWSTR filename, VS_FIXEDFILEINFO* ffi)
static void add_memory_block(struct dump_context* dc, ULONG64 base, ULONG size, ULONG rva)
{
if (dc->mem)
dc->mem = HeapReAlloc(GetProcessHeap(), 0, dc->mem,
++dc->num_mem * sizeof(*dc->mem));
{
dc->alloc_mem *= 2;
dc->mem = HeapReAlloc(GetProcessHeap(), 0, dc->mem,
dc->alloc_mem * sizeof(*dc->mem));
}
else
dc->mem = HeapAlloc(GetProcessHeap(), 0, ++dc->num_mem * sizeof(*dc->mem));
{
dc->alloc_mem = 32;
dc->mem = HeapAlloc(GetProcessHeap(), 0, dc->alloc_mem * sizeof(*dc->mem));
}
if (dc->mem)
{
dc->mem[dc->num_mem - 1].base = base;
dc->mem[dc->num_mem - 1].size = size;
dc->mem[dc->num_mem - 1].rva = rva;
}
else dc->num_mem = 0;
else dc->num_mem = dc->alloc_mem = 0;
}
/******************************************************************
@ -867,10 +881,12 @@ BOOL WINAPI MiniDumpWriteDump(HANDLE hProcess, DWORD pid, HANDLE hFile,
dc.pid = pid;
dc.modules = NULL;
dc.num_modules = 0;
dc.alloc_modules = 0;
dc.cb = CallbackParam;
dc.type = DumpType;
dc.mem = NULL;
dc.num_mem = 0;
dc.alloc_mem = 0;
dc.rva = 0;
if (!fetch_processes_info(&dc)) return FALSE;

View File

@ -168,6 +168,7 @@ struct module* module_new(struct process* pcs, const WCHAR* name,
module->type = type;
module->is_virtual = virtual ? TRUE : FALSE;
module->sortlist_valid = FALSE;
module->sorttab_size = 0;
module->addr_sorttab = NULL;
module->num_sorttab = 0;
module->num_symbols = 0;
@ -1037,6 +1038,7 @@ DWORD64 WINAPI SymGetModuleBase64(HANDLE hProcess, DWORD64 dwAddr)
void module_reset_debug_info(struct module* module)
{
module->sortlist_valid = TRUE;
module->sorttab_size = 0;
module->addr_sorttab = NULL;
module->num_sorttab = module->num_symbols = 0;
hash_table_destroy(&module->ht_symbols);

View File

@ -486,18 +486,23 @@ static int codeview_add_type(unsigned int typeno, struct symt* dt)
if ((typeno >> 24) != 0)
FIXME("No module index while inserting type-id assumption is wrong %x\n",
typeno);
while (typeno - FIRST_DEFINABLE_TYPE >= cv_current_module->num_defined_types)
if (typeno - FIRST_DEFINABLE_TYPE >= cv_current_module->num_defined_types)
{
cv_current_module->num_defined_types += 0x100;
if (cv_current_module->defined_types)
{
cv_current_module->num_defined_types = max( cv_current_module->num_defined_types * 2,
typeno - FIRST_DEFINABLE_TYPE + 1 );
cv_current_module->defined_types = HeapReAlloc(GetProcessHeap(),
HEAP_ZERO_MEMORY, cv_current_module->defined_types,
cv_current_module->num_defined_types * sizeof(struct symt*));
}
else
{
cv_current_module->num_defined_types = max( 256, typeno - FIRST_DEFINABLE_TYPE + 1 );
cv_current_module->defined_types = HeapAlloc(GetProcessHeap(),
HEAP_ZERO_MEMORY,
cv_current_module->num_defined_types * sizeof(struct symt*));
}
if (cv_current_module->defined_types == NULL) return FALSE;
}
if (cv_current_module->defined_types[typeno - FIRST_DEFINABLE_TYPE])

View File

@ -76,13 +76,18 @@ unsigned source_new(struct module* module, const char* base, const char* name)
int len = strlen(full) + 1;
if (module->sources_used + len + 1 > module->sources_alloc)
{
/* Alloc by block of 256 bytes */
module->sources_alloc = (module->sources_used + len + 1 + 255) & ~255;
if (!module->sources)
{
module->sources_alloc = (module->sources_used + len + 1 + 255) & ~255;
module->sources = HeapAlloc(GetProcessHeap(), 0, module->sources_alloc);
}
else
{
module->sources_alloc = max( module->sources_alloc * 2,
(module->sources_used + len + 1 + 255) & ~255 );
module->sources = HeapReAlloc(GetProcessHeap(), 0, module->sources,
module->sources_alloc);
}
}
ret = module->sources_used;
memcpy(module->sources + module->sources_used, full, len);

View File

@ -180,14 +180,18 @@ static int stabs_new_include(const char* file, unsigned long val)
{
if (num_include_def == num_alloc_include_def)
{
num_alloc_include_def += 256;
if (!include_defs)
include_defs = HeapAlloc(GetProcessHeap(), 0,
{
num_alloc_include_def = 256;
include_defs = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
sizeof(include_defs[0]) * num_alloc_include_def);
}
else
include_defs = HeapReAlloc(GetProcessHeap(), 0, include_defs,
{
num_alloc_include_def *= 2;
include_defs = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, include_defs,
sizeof(include_defs[0]) * num_alloc_include_def);
memset(include_defs + num_include_def, 0, sizeof(include_defs[0]) * 256);
}
}
include_defs[num_include_def].name = strcpy(HeapAlloc(GetProcessHeap(), 0, strlen(file) + 1), file);
include_defs[num_include_def].value = val;
@ -262,13 +266,13 @@ static struct symt** stabs_find_ref(long filenr, long subnr)
{
if (cu_nrofentries <= subnr)
{
cu_nrofentries = max( cu_nrofentries * 2, subnr + 1 );
if (!cu_vector)
cu_vector = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
sizeof(cu_vector[0]) * (subnr+1));
cu_vector = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
sizeof(cu_vector[0]) * cu_nrofentries);
else
cu_vector = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
cu_vector, sizeof(cu_vector[0]) * (subnr+1));
cu_nrofentries = subnr + 1;
cu_vector = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
cu_vector, sizeof(cu_vector[0]) * cu_nrofentries);
}
ret = &cu_vector[subnr];
}
@ -281,13 +285,13 @@ static struct symt** stabs_find_ref(long filenr, long subnr)
if (idef->nrofentries <= subnr)
{
idef->nrofentries = max( idef->nrofentries * 2, subnr + 1 );
if (!idef->vector)
idef->vector = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
sizeof(idef->vector[0]) * (subnr+1));
idef->vector = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
sizeof(idef->vector[0]) * idef->nrofentries);
else
idef->vector = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
idef->vector, sizeof(idef->vector[0]) * (subnr+1));
idef->nrofentries = subnr + 1;
idef->vector = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
idef->vector, sizeof(idef->vector[0]) * idef->nrofentries);
}
ret = &idef->vector[subnr];
}
@ -1154,13 +1158,18 @@ static inline void pending_make_room(struct pending_list* pending)
{
if (pending->num == pending->allocated)
{
pending->allocated += 8;
if (!pending->objs)
{
pending->allocated = 8;
pending->objs = HeapAlloc(GetProcessHeap(), 0,
pending->allocated * sizeof(pending->objs[0]));
else
}
else
{
pending->allocated *= 2;
pending->objs = HeapReAlloc(GetProcessHeap(), 0, pending->objs,
pending->allocated * sizeof(pending->objs[0]));
}
}
}
@ -1311,7 +1320,7 @@ BOOL stabs_parse(struct module* module, unsigned long load_offset,
unsigned len = strlen(ptr);
if (strlen(stabbuff) + len > stabbufflen)
{
stabbufflen += 65536;
stabbufflen *= 2;
stabbuff = HeapReAlloc(GetProcessHeap(), 0, stabbuff, stabbufflen);
}
strncat(stabbuff, ptr, len - 1);

View File

@ -70,13 +70,22 @@ int symt_cmp_addr(const void* p1, const void* p2)
static BOOL symt_grow_sorttab(struct module* module, unsigned sz)
{
struct symt_ht** new;
unsigned int size;
if (sz <= module->sorttab_size) return TRUE;
if (module->addr_sorttab)
{
size = module->sorttab_size * 2;
new = HeapReAlloc(GetProcessHeap(), 0, module->addr_sorttab,
sz * sizeof(struct symt_ht*));
size * sizeof(struct symt_ht*));
}
else
new = HeapAlloc(GetProcessHeap(), 0, sz * sizeof(struct symt_ht*));
{
size = 64;
new = HeapAlloc(GetProcessHeap(), 0, size * sizeof(struct symt_ht*));
}
if (!new) return FALSE;
module->sorttab_size = size;
module->addr_sorttab = new;
return TRUE;
}