From: Eric Pouech eric.pouech@gmail.com
This preserves order in which modules are loaded, and enumeration is done according to this order.
Signed-off-by: Eric Pouech eric.pouech@gmail.com --- dlls/dbghelp/dbghelp.c | 6 ++---- dlls/dbghelp/module.c | 6 ++++-- dlls/dbghelp/tests/dbghelp.c | 12 ++++-------- 3 files changed, 10 insertions(+), 14 deletions(-)
diff --git a/dlls/dbghelp/dbghelp.c b/dlls/dbghelp/dbghelp.c index 81a0d50f25d..3341bea442e 100644 --- a/dlls/dbghelp/dbghelp.c +++ b/dlls/dbghelp/dbghelp.c @@ -333,10 +333,8 @@ const struct cpu* process_get_cpu(const struct process* pcs) { const struct module* m = pcs->lmodules;
- /* main module is the last one in list */ - if (!m) return dbghelp_current_cpu; - while (m->next) m = m->next; - return m->cpu; + /* return cpu of main module, which is the first module in process's modules list */ + return (m) ? m->cpu : dbghelp_current_cpu; }
/****************************************************************** diff --git a/dlls/dbghelp/module.c b/dlls/dbghelp/module.c index 4bd7b0e5009..b6f36b1f28a 100644 --- a/dlls/dbghelp/module.c +++ b/dlls/dbghelp/module.c @@ -177,14 +177,16 @@ struct module* module_new(struct process* pcs, const WCHAR* name, ULONG_PTR stamp, ULONG_PTR checksum, WORD machine) { struct module* module; + struct module** pmodule; unsigned i;
assert(type == DMT_ELF || type == DMT_PE || type == DMT_MACHO); if (!(module = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*module)))) return NULL;
- module->next = pcs->lmodules; - pcs->lmodules = module; + for (pmodule = &pcs->lmodules; *pmodule; pmodule = &(*pmodule)->next); + module->next = NULL; + *pmodule = module;
TRACE("=> %s %I64x-%I64x %s\n", get_module_type(type, virtual), mod_addr, mod_addr + size, debugstr_w(name)); diff --git a/dlls/dbghelp/tests/dbghelp.c b/dlls/dbghelp/tests/dbghelp.c index b7ecb790441..6b7c6b8d5b8 100644 --- a/dlls/dbghelp/tests/dbghelp.c +++ b/dlls/dbghelp/tests/dbghelp.c @@ -285,7 +285,6 @@ struct nth_module unsigned int index; BOOL will_fail; IMAGEHLP_MODULE64 module; - BOOL with_todo_wine; };
static BOOL CALLBACK nth_module_cb(const char* name, DWORD64 base, void* usr) @@ -296,8 +295,6 @@ static BOOL CALLBACK nth_module_cb(const char* name, DWORD64 base, void* usr) if (nth->index--) return TRUE; nth->module.SizeOfStruct = sizeof(nth->module); ret = SymGetModuleInfo64(nth->proc, base, &nth->module); - todo_wine_if(nth->with_todo_wine) - { if (nth->will_fail) { ok(!ret, "SymGetModuleInfo64 should have failed\n"); @@ -308,7 +305,6 @@ static BOOL CALLBACK nth_module_cb(const char* name, DWORD64 base, void* usr) ok(ret, "SymGetModuleInfo64 failed: %lu\n", GetLastError()); ok(nth->module.BaseOfImage == base, "Wrong base\n"); } - } return FALSE; }
@@ -465,7 +461,7 @@ static void test_modules_overlap(void) } for (j = 0; j < ARRAY_SIZE(tests[i].outputs); j++) { - struct nth_module nth = {dummy, j, !tests[i].outputs[j].name, {0}, i == 9 || i == 11}; + struct nth_module nth = {dummy, j, !tests[i].outputs[j].name, {0}};
ret = SymEnumerateModules64(dummy, nth_module_cb, &nth); ok(ret, "SymEnumerateModules64 failed: %lu\n", GetLastError()); @@ -475,13 +471,13 @@ static void test_modules_overlap(void) break; } ok(nth.index == -1, "Expecting more modules\n"); - todo_wine_if(i >= 6) + todo_wine_if(i == 6 || i == 7) ok(nth.module.BaseOfImage == tests[i].outputs[j].base, "Wrong base\n"); if (!nth.will_fail) { - todo_wine_if(i == 7 || i == 9 || i == 11) + todo_wine_if(i == 7) ok(nth.module.ImageSize == tests[i].outputs[j].size, "Wrong size\n"); - todo_wine_if(i >= 6 && i != 8) + todo_wine_if(i == 6 || i == 7) ok(!strcasecmp(nth.module.ModuleName, tests[i].outputs[j].name), "Wrong name\n"); } }