Signed-off-by: Eric Pouech eric.pouech@gmail.com
--- dlls/dbghelp/tests/dbghelp.c | 52 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+)
diff --git a/dlls/dbghelp/tests/dbghelp.c b/dlls/dbghelp/tests/dbghelp.c index b0302b85ad1..a6c524177bf 100644 --- a/dlls/dbghelp/tests/dbghelp.c +++ b/dlls/dbghelp/tests/dbghelp.c @@ -27,6 +27,8 @@ struct debuggee BOOL external_process; HANDLE hProcess; HANDLE hThread; /* either new thread calling stack_walk_thread, or main thread */ + DWORD64 base; + DWORD64 size; };
#if defined(__i386__) || defined(__x86_64__) @@ -127,9 +129,44 @@ static void test_stack_walk(const struct debuggee* dbg)
#endif /* __i386__ || __x86_64__ */
+static BOOL CALLBACK find_main_module_cb(PCSTR name, DWORD64 base, PVOID in_user) +{ + struct debuggee* dbg = in_user; + IMAGEHLP_MODULE im; + + memset(&im, 0, sizeof(im)); + im.SizeOfStruct = sizeof(im); + ok(SymGetModuleInfo(dbg->hProcess, base, &im), "SymGetModuleInfo failed: %u\n", GetLastError()); + + if (dbg->external_process) + { + /* lookup external exec path as module name */ + const char* ff; + const char* fb; + const char* ext; + + if (!(ff = strrchr(dbg->name, '/'))) ff = dbg->name; else ++ff; + if (!(fb = strrchr(ff, '\'))) fb = ff; else ++fb; + + ext = strchr(fb, '.'); + if ((!ext || !_strcmpi(ext, ".exe")) && !_strnicmp(fb, im.ModuleName, ext ? ext - fb : strlen(fb))) + { + dbg->base = im.BaseOfImage; + dbg->size = im.ImageSize; + } + } + else + { + dbg->base = im.BaseOfImage; + dbg->size = im.ImageSize; + } + return TRUE; +} + static BOOL start_process(struct debuggee* dbg, const char* other) { DWORD count; + BOOL ret;
memset(dbg, 0, sizeof(*dbg)); if (other) @@ -176,6 +213,21 @@ static BOOL start_process(struct debuggee* dbg, const char* other) } while (!count);
+ /* init base and size fields */ + if (dbg->external_process) + { + dbg->base = dbg->size = 0; + ret = SymEnumerateModules64(dbg->hProcess, find_main_module_cb, dbg); + ok(ret && dbg->base != 0, "No base for main module: %u\n", GetLastError()); + if (!ret || dbg->base == 0) + return FALSE; + } + else + { + /* force the main module */ + find_main_module_cb(dbg->name, (DWORD_PTR)&start_process, dbg); + } + return TRUE; }