From: Eric Pouech epouech@codeweavers.com
Always using GetModuleFileNameExW: - as it doesn't depend on information from debug event that are not always present (pointer to module name, or file handle), - it only uses a single server call (pointer to module name requires two). - and stop using GetModuleFileNameExW which implementation walks the module list in debuggee process, hence request time grows linearly with number of loaded modules.
This reduces significantly attachment time in auto mode.
Signed-off-by: Eric Pouech epouech@codeweavers.com --- programs/winedbg/debugger.h | 2 +- programs/winedbg/gdbproxy.c | 3 +-- programs/winedbg/tgt_active.c | 24 ++++++++++-------------- 3 files changed, 12 insertions(+), 17 deletions(-)
diff --git a/programs/winedbg/debugger.h b/programs/winedbg/debugger.h index 45a91e2a6f5..28b60c853fb 100644 --- a/programs/winedbg/debugger.h +++ b/programs/winedbg/debugger.h @@ -485,7 +485,7 @@ extern enum dbg_start dbg_active_auto(int argc, char* argv[]); extern enum dbg_start dbg_active_minidump(int argc, char* argv[]); extern void dbg_active_wait_for_first_exception(void); extern BOOL dbg_attach_debuggee(DWORD pid); -extern void fetch_module_name(void* name_addr, void* mod_addr, WCHAR* buffer, size_t bufsz); +extern void fetch_module_name(void* mod_addr, WCHAR* buffer, size_t bufsz);
/* tgt_minidump.c */ extern void minidump_write(const char*, const EXCEPTION_RECORD*); diff --git a/programs/winedbg/gdbproxy.c b/programs/winedbg/gdbproxy.c index e937c4edf32..cad357a02b7 100644 --- a/programs/winedbg/gdbproxy.c +++ b/programs/winedbg/gdbproxy.c @@ -572,8 +572,7 @@ static BOOL handle_debug_event(struct gdb_context* gdbctx, BOOL stop_on_dll_load return TRUE;
case LOAD_DLL_DEBUG_EVENT: - fetch_module_name( de->u.LoadDll.lpImageName, de->u.LoadDll.lpBaseOfDll, - u.buffer, ARRAY_SIZE(u.buffer) ); + fetch_module_name( de->u.LoadDll.lpBaseOfDll, u.buffer, ARRAY_SIZE(u.buffer) ); fprintf(stderr, "%04lx:%04lx: loads DLL %ls @%p (%lu<%lu>)\n", de->dwProcessId, de->dwThreadId, u.buffer, diff --git a/programs/winedbg/tgt_active.c b/programs/winedbg/tgt_active.c index a919f70a486..1b396b82c7c 100644 --- a/programs/winedbg/tgt_active.c +++ b/programs/winedbg/tgt_active.c @@ -315,22 +315,19 @@ static DWORD dbg_handle_exception(const EXCEPTION_RECORD* rec, BOOL first_chance
static BOOL tgt_process_active_close_process(struct dbg_process* pcs, BOOL kill);
-void fetch_module_name(void* name_addr, void* mod_addr, WCHAR* buffer, size_t bufsz) +void fetch_module_name(void* mod_addr, WCHAR* buffer, size_t bufsz) { - memory_get_string_indirect(dbg_curr_process, name_addr, TRUE, buffer, bufsz); - if (!buffer[0] && !GetModuleFileNameExW(dbg_curr_process->handle, mod_addr, buffer, bufsz)) + DWORD len; + if ((len = GetMappedFileNameW( dbg_curr_process->handle, mod_addr, buffer, bufsz ))) { - if (GetMappedFileNameW( dbg_curr_process->handle, mod_addr, buffer, bufsz )) - { - /* FIXME: proper NT->Dos conversion */ - static const WCHAR nt_prefixW[] = {'\','?','?','\'}; + /* FIXME: proper NT->Dos conversion */ + static const WCHAR nt_prefixW[] = {'\','?','?','\'};
- if (!wcsncmp( buffer, nt_prefixW, 4 )) - memmove( buffer, buffer + 4, (lstrlenW(buffer + 4) + 1) * sizeof(WCHAR) ); - } - else - swprintf(buffer, bufsz, L"DLL_%08lx", (ULONG_PTR)mod_addr); + if (!wcsncmp( buffer, nt_prefixW, 4 )) + memmove( buffer, buffer + 4, (len - 4 + 1) * sizeof(WCHAR) ); } + else + swprintf(buffer, bufsz, L"DLL_%08lx", (ULONG_PTR)mod_addr); }
static unsigned dbg_handle_debug_event(DEBUG_EVENT* de) @@ -485,8 +482,7 @@ static unsigned dbg_handle_debug_event(DEBUG_EVENT* de) WINE_ERR("Unknown thread\n"); break; } - fetch_module_name(de->u.LoadDll.lpImageName, de->u.LoadDll.lpBaseOfDll, - u.buffer, ARRAY_SIZE(u.buffer)); + fetch_module_name(de->u.LoadDll.lpBaseOfDll, u.buffer, ARRAY_SIZE(u.buffer));
WINE_TRACE("%04lx:%04lx: loads DLL %s @%p (%lu<%lu>)\n", de->dwProcessId, de->dwThreadId,