From 88aa6703af6ebc287d9c9391dd2ea7e1bd299f8f Mon Sep 17 00:00:00 2001 From: Eric Pouech Date: Mon, 20 Feb 2006 12:16:08 +0100 Subject: [PATCH] dbghelp: Virtual modules. Rewrote virtual modules handling so that it's an option to either PE or ELF modules rather than a specific type. --- dlls/dbghelp/dbghelp_private.h | 10 +++++----- dlls/dbghelp/elf_module.c | 9 +++++---- dlls/dbghelp/module.c | 33 ++++++++++++++++++--------------- dlls/dbghelp/path.c | 1 - dlls/dbghelp/pe_module.c | 6 +++--- 5 files changed, 31 insertions(+), 28 deletions(-) diff --git a/dlls/dbghelp/dbghelp_private.h b/dlls/dbghelp/dbghelp_private.h index 3f5fcf6728b..d7371a262fe 100644 --- a/dlls/dbghelp/dbghelp_private.h +++ b/dlls/dbghelp/dbghelp_private.h @@ -258,14 +258,14 @@ enum module_type DMT_ELF, /* a real ELF shared module */ DMT_PE, /* a native or builtin PE module */ DMT_PDB, /* PDB file */ - DMT_VIRTUAL, /* a virtual module (ie defined by caller) */ }; struct module { IMAGEHLP_MODULE module; struct module* next; - enum module_type type; + enum module_type type : 16; + unsigned short is_virtual : 1; struct elf_module_info* elf_info; /* memory allocation pool */ @@ -345,9 +345,9 @@ extern struct module* module_get_debug(const struct process* pcs, struct module*); extern struct module* module_new(struct process* pcs, const char* name, - enum module_type type, unsigned long addr, - unsigned long size, unsigned long stamp, - unsigned long checksum); + enum module_type type, BOOL virtual, + unsigned long addr, unsigned long size, + unsigned long stamp, unsigned long checksum); extern struct module* module_get_container(const struct process* pcs, const struct module* inner); diff --git a/dlls/dbghelp/elf_module.c b/dlls/dbghelp/elf_module.c index 92bb3f1b89c..ad1a4ffb8d0 100644 --- a/dlls/dbghelp/elf_module.c +++ b/dlls/dbghelp/elf_module.c @@ -1091,7 +1091,7 @@ static BOOL elf_load_file(struct process* pcs, const char* filename, struct elf_module_info *elf_module_info = HeapAlloc(GetProcessHeap(), 0, sizeof(struct elf_module_info)); if (!elf_module_info) goto leave; - elf_info->module = module_new(pcs, filename, DMT_ELF, + elf_info->module = module_new(pcs, filename, DMT_ELF, FALSE, (load_offset) ? load_offset : fmap.elf_start, fmap.elf_size, 0, calc_crc32(&fmap)); if (!elf_info->module) @@ -1292,7 +1292,8 @@ BOOL elf_synchronize_module_list(struct process* pcs) for (module = pcs->lmodules; module; module = module->next) { - if (module->type == DMT_ELF) module->elf_info->elf_mark = 0; + if (module->type == DMT_ELF && !module->is_virtual) + module->elf_info->elf_mark = 0; } es.pcs = pcs; @@ -1303,8 +1304,8 @@ BOOL elf_synchronize_module_list(struct process* pcs) module = pcs->lmodules; while (module) { - if (module->type == DMT_ELF && !module->elf_info->elf_mark && - !module->elf_info->elf_loader) + if (module->type == DMT_ELF && !module->is_virtual && + !module->elf_info->elf_mark && !module->elf_info->elf_loader) { module_remove(pcs, module); /* restart all over */ diff --git a/dlls/dbghelp/module.c b/dlls/dbghelp/module.c index 17974eff637..7f131678ca1 100644 --- a/dlls/dbghelp/module.c +++ b/dlls/dbghelp/module.c @@ -78,13 +78,12 @@ static void module_fill_module(const char* in, char* out, size_t size) while ((*out = tolower(*out))) out++; } -static const char* get_module_type(enum module_type type) +static const char* get_module_type(enum module_type type, BOOL virtual) { switch (type) { - case DMT_ELF: return "ELF"; - case DMT_PE: return "PE"; - case DMT_VIRTUAL: return "Virtual"; + case DMT_ELF: return virtual ? "Virtual ELF" : "ELF"; + case DMT_PE: return virtual ? "Virtual PE" : "PE"; default: return "---"; } } @@ -93,13 +92,13 @@ static const char* get_module_type(enum module_type type) * Creates and links a new module to a process */ struct module* module_new(struct process* pcs, const char* name, - enum module_type type, + enum module_type type, BOOL virtual, unsigned long mod_addr, unsigned long size, unsigned long stamp, unsigned long checksum) { struct module* module; - assert(type == DMT_ELF || type == DMT_PE || type == DMT_VIRTUAL); + assert(type == DMT_ELF || type == DMT_PE); if (!(module = HeapAlloc(GetProcessHeap(), 0, sizeof(*module)))) return NULL; @@ -109,7 +108,7 @@ struct module* module_new(struct process* pcs, const char* name, pcs->lmodules = module; TRACE("=> %s %08lx-%08lx %s\n", - get_module_type(type), mod_addr, mod_addr + size, name); + get_module_type(type, virtual), mod_addr, mod_addr + size, name); pool_init(&module->pool, 65536); @@ -126,6 +125,7 @@ struct module* module_new(struct process* pcs, const char* name, module->module.CheckSum = checksum; module->type = type; + module->is_virtual = virtual ? TRUE : FALSE; module->sortlist_valid = FALSE; module->addr_sorttab = NULL; /* FIXME: this seems a bit too high (on a per module basis) @@ -154,8 +154,7 @@ struct module* module_find_by_name(const struct process* pcs, if (type == DMT_UNKNOWN) { if ((module = module_find_by_name(pcs, name, DMT_PE)) || - (module = module_find_by_name(pcs, name, DMT_ELF)) || - (module = module_find_by_name(pcs, name, DMT_VIRTUAL))) + (module = module_find_by_name(pcs, name, DMT_ELF))) return module; } else @@ -243,8 +242,9 @@ struct module* module_get_debug(const struct process* pcs, struct module* module if (module->module.SymType == SymDeferred) { BOOL ret; - - switch (module->type) + + if (module->is_virtual) ret = FALSE; + else switch (module->type) { case DMT_ELF: ret = elf_load_debug_info(module, NULL); @@ -264,7 +264,6 @@ struct module* module_get_debug(const struct process* pcs, struct module* module ret ? CBA_DEFERRED_SYMBOL_LOAD_COMPLETE : CBA_DEFERRED_SYMBOL_LOAD_FAILURE, &idsl64); break; - case DMT_VIRTUAL: /* fall through */ default: ret = FALSE; break; @@ -290,8 +289,7 @@ struct module* module_find_by_addr(const struct process* pcs, unsigned long addr if (type == DMT_UNKNOWN) { if ((module = module_find_by_addr(pcs, addr, DMT_PE)) || - (module = module_find_by_addr(pcs, addr, DMT_ELF)) || - (module = module_find_by_addr(pcs, addr, DMT_VIRTUAL))) + (module = module_find_by_addr(pcs, addr, DMT_ELF))) return module; } else @@ -436,6 +434,10 @@ DWORD64 WINAPI SymLoadModuleEx(HANDLE hProcess, HANDLE hFile, PCSTR ImageName, PCSTR ModuleName, DWORD64 BaseOfDll, DWORD DllSize, PMODLOAD_DATA Data, DWORD Flags) { + TRACE("(%p %p %s %s %s %08lx %p %08lx)\n", + hProcess, hFile, debugstr_a(ImageName), debugstr_a(ModuleName), + wine_dbgstr_longlong(BaseOfDll), DllSize, Data, Flags); + if (Data) FIXME("Unsupported load data parameter %p for %s\n", Data, ImageName); if (!validate_addr64(BaseOfDll)) return FALSE; @@ -445,7 +447,8 @@ DWORD64 WINAPI SymLoadModuleEx(HANDLE hProcess, HANDLE hFile, PCSTR ImageName, struct module* module; if (!pcs) return FALSE; - module = module_new(pcs, ImageName, DMT_VIRTUAL, (DWORD)BaseOfDll, DllSize, 0, 0); + module = module_new(pcs, ImageName, module_get_type_by_name(ImageName), TRUE, + (DWORD)BaseOfDll, DllSize, 0, 0); if (!module) return FALSE; if (ModuleName) lstrcpynA(module->module.ModuleName, ModuleName, sizeof(module->module.ModuleName)); diff --git a/dlls/dbghelp/path.c b/dlls/dbghelp/path.c index 2362ca19b28..80339674917 100644 --- a/dlls/dbghelp/path.c +++ b/dlls/dbghelp/path.c @@ -282,7 +282,6 @@ static BOOL CALLBACK sffip_cb(LPCSTR buffer, void* user) } break; case DMT_PDB: - case DMT_VIRTUAL: FIXME("NIY on '%s'\n", buffer); break; default: diff --git a/dlls/dbghelp/pe_module.c b/dlls/dbghelp/pe_module.c index 417aadbe103..395f398c33e 100644 --- a/dlls/dbghelp/pe_module.c +++ b/dlls/dbghelp/pe_module.c @@ -360,7 +360,7 @@ struct module* pe_load_module(struct process* pcs, const char* name, if (!base) base = nth->OptionalHeader.ImageBase; if (!size) size = nth->OptionalHeader.SizeOfImage; - module = module_new(pcs, loaded_name, DMT_PE, base, size, + module = module_new(pcs, loaded_name, DMT_PE, FALSE, base, size, nth->FileHeader.TimeDateStamp, nth->OptionalHeader.CheckSum); if (module) @@ -428,11 +428,11 @@ struct module* pe_load_module_from_pcs(struct process* pcs, const char* name, if (pe_load_nt_header(pcs->handle, base, &nth)) { if (!size) size = nth.OptionalHeader.SizeOfImage; - module = module_new(pcs, name, DMT_PE, base, size, + module = module_new(pcs, name, DMT_PE, FALSE, base, size, nth.FileHeader.TimeDateStamp, nth.OptionalHeader.CheckSum); } } else if (size) - module = module_new(pcs, name, DMT_PE, base, size, 0 /* FIXME */, 0 /* FIXME */); + module = module_new(pcs, name, DMT_PE, FALSE, base, size, 0 /* FIXME */, 0 /* FIXME */); } return module; }