Signed-off-by: Jinoh Kang jinoh.kang.kr@gmail.com ---
Notes: v1 -> v2: - Capitalise subject - Fix passing incorrect length to dbg_W2A() - Remove a gratuitous blank line
programs/winedbg/gdbproxy.c | 40 ++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 16 deletions(-)
diff --git a/programs/winedbg/gdbproxy.c b/programs/winedbg/gdbproxy.c index 522e4fdb506..605da512a27 100644 --- a/programs/winedbg/gdbproxy.c +++ b/programs/winedbg/gdbproxy.c @@ -396,10 +396,8 @@ static BOOL handle_debug_event(struct gdb_context* gdbctx, BOOL stop_on_dll_load DEBUG_EVENT *de = &gdbctx->de; struct dbg_thread *thread;
- union { - char bufferA[256]; - WCHAR buffer[256]; - } u; + char bufferA[512]; + LPWSTR name; DWORD size;
gdbctx->exec_tid = de->dwThreadId; @@ -414,44 +412,54 @@ static BOOL handle_debug_event(struct gdb_context* gdbctx, BOOL stop_on_dll_load if (!gdbctx->process) return TRUE;
- size = ARRAY_SIZE(u.buffer); - QueryFullProcessImageNameW( gdbctx->process->handle, 0, u.buffer, &size ); - dbg_set_process_name(gdbctx->process, u.buffer); + size = UNICODE_STRING_MAX_CHARS + 1UL; + name = HeapAlloc(GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS, sizeof(WCHAR) * size); + if (!QueryFullProcessImageNameW( gdbctx->process->handle, 0, name, &size )) + { + size = 0; + name[size] = L'\0'; + } + + dbg_set_process_name(gdbctx->process, name);
fprintf(stderr, "%04x:%04x: create process '%s'/%p @%p (%u<%u>)\n", de->dwProcessId, de->dwThreadId, - dbg_W2A(u.buffer, -1), + dbg_W2A(name, -1), de->u.CreateProcessInfo.lpImageName, de->u.CreateProcessInfo.lpStartAddress, de->u.CreateProcessInfo.dwDebugInfoFileOffset, de->u.CreateProcessInfo.nDebugInfoSize);
/* de->u.CreateProcessInfo.lpStartAddress; */ - if (!dbg_init(gdbctx->process->handle, u.buffer, TRUE)) + if (!dbg_init(gdbctx->process->handle, name, TRUE)) ERR("Couldn't initiate DbgHelp\n");
fprintf(stderr, "%04x:%04x: create thread I @%p\n", de->dwProcessId, de->dwThreadId, de->u.CreateProcessInfo.lpStartAddress);
- dbg_load_module(gdbctx->process->handle, de->u.CreateProcessInfo.hFile, u.buffer, + dbg_load_module(gdbctx->process->handle, de->u.CreateProcessInfo.hFile, name, (DWORD_PTR)de->u.CreateProcessInfo.lpBaseOfImage, 0);
dbg_add_thread(gdbctx->process, de->dwThreadId, de->u.CreateProcessInfo.hThread, de->u.CreateProcessInfo.lpThreadLocalBase); + + HeapFree(GetProcessHeap(), 0, name); return TRUE;
case LOAD_DLL_DEBUG_EVENT: - fetch_module_name( de->u.LoadDll.lpImageName, de->u.LoadDll.lpBaseOfDll, - u.buffer, ARRAY_SIZE(u.buffer) ); + size = UNICODE_STRING_MAX_CHARS + 1UL; + name = HeapAlloc(GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS, sizeof(WCHAR) * size); + fetch_module_name( de->u.LoadDll.lpImageName, de->u.LoadDll.lpBaseOfDll, name, size ); fprintf(stderr, "%04x:%04x: loads DLL %s @%p (%u<%u>)\n", de->dwProcessId, de->dwThreadId, - dbg_W2A(u.buffer, -1), + dbg_W2A(name, -1), de->u.LoadDll.lpBaseOfDll, de->u.LoadDll.dwDebugInfoFileOffset, de->u.LoadDll.nDebugInfoSize); - dbg_load_module(gdbctx->process->handle, de->u.LoadDll.hFile, u.buffer, + dbg_load_module(gdbctx->process->handle, de->u.LoadDll.hFile, name, (DWORD_PTR)de->u.LoadDll.lpBaseOfDll, 0); + HeapFree(GetProcessHeap(), 0, name); if (stop_on_dll_load_unload) break; return TRUE; @@ -501,9 +509,9 @@ static BOOL handle_debug_event(struct gdb_context* gdbctx, BOOL stop_on_dll_load case OUTPUT_DEBUG_STRING_EVENT: memory_get_string(gdbctx->process, de->u.DebugString.lpDebugStringData, TRUE, - de->u.DebugString.fUnicode, u.bufferA, sizeof(u.bufferA)); + de->u.DebugString.fUnicode, bufferA, sizeof(bufferA)); fprintf(stderr, "%08x:%08x: output debug string (%s)\n", - de->dwProcessId, de->dwThreadId, debugstr_a(u.bufferA)); + de->dwProcessId, de->dwThreadId, debugstr_a(bufferA)); return TRUE;
case RIP_EVENT: