Signed-off-by: Derek Lesho dlesho@codeweavers.com --- I've found this useful for situations where you can't use winedbg to launch the app (steam games), and the apps fail too quickly for you to manually retrieve their PID. --- programs/winedbg/dbg.y | 1 + programs/winedbg/debugger.h | 1 + programs/winedbg/winedbg.c | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+)
diff --git a/programs/winedbg/dbg.y b/programs/winedbg/dbg.y index ac76b5baf8a..205ea167b67 100644 --- a/programs/winedbg/dbg.y +++ b/programs/winedbg/dbg.y @@ -138,6 +138,7 @@ command: | tSYMBOLFILE pathname expr_rvalue { symbol_read_symtable($2, $3); } | tWHATIS expr_lvalue { dbg_printf("type = "); types_print_type(&$2.type, FALSE); dbg_printf("\n"); } | tATTACH tNUM { dbg_attach_debuggee($2); dbg_active_wait_for_first_exception(); } + | tATTACH tSTRING { dbg_attach_debuggee(dbg_find_process($2)); dbg_active_wait_for_first_exception(); } | tDETACH { dbg_curr_process->process_io->close_process(dbg_curr_process, FALSE); } | tTHREAD tNUM { dbg_set_curr_thread($2); } | tKILL { dbg_curr_process->process_io->close_process(dbg_curr_process, TRUE); } diff --git a/programs/winedbg/debugger.h b/programs/winedbg/debugger.h index ddac129bab5..754e7d5b22f 100644 --- a/programs/winedbg/debugger.h +++ b/programs/winedbg/debugger.h @@ -473,6 +473,7 @@ extern void dbg_set_process_name(struct dbg_process* p, const WCHAR* extern struct dbg_process* dbg_get_process(DWORD pid); extern struct dbg_process* dbg_get_process_h(HANDLE handle); extern void dbg_del_process(struct dbg_process* p); +extern DWORD dbg_find_process(const char *filename); struct dbg_thread* dbg_add_thread(struct dbg_process* p, DWORD tid, HANDLE h, void* teb); extern struct dbg_thread* dbg_get_thread(struct dbg_process* p, DWORD tid); extern void dbg_del_thread(struct dbg_thread* t); diff --git a/programs/winedbg/winedbg.c b/programs/winedbg/winedbg.c index 19f30f04e5d..27ce57607a0 100644 --- a/programs/winedbg/winedbg.c +++ b/programs/winedbg/winedbg.c @@ -25,6 +25,7 @@ #include <string.h> #include "debugger.h"
+#include "tlhelp32.h" #include "winternl.h" #include "wine/exception.h" #include "wine/library.h" @@ -377,6 +378,42 @@ void dbg_del_process(struct dbg_process* p) HeapFree(GetProcessHeap(), 0, p); }
+DWORD dbg_find_process(const char *search) +{ + HANDLE snap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); + const char *process_name; + PROCESSENTRY32 cur_proc; + DWORD ret = -1; + + if (snap == INVALID_HANDLE_VALUE) + return ret; + + cur_proc.dwSize = sizeof(cur_proc); + if (!(Process32First(snap, &cur_proc))) + goto done; + + do + { + if (cur_proc.th32ProcessID == GetCurrentProcessId()) + continue; + + if (!(strcasecmp(search, cur_proc.szExeFile))) + { + ret = cur_proc.th32ProcessID; + break; + } + + cur_proc.dwSize = sizeof(cur_proc); + } + while ((Process32Next(snap, &cur_proc))); + + done: + if (ret == -1) + dbg_printf("Could not find running process with name "%s"\n", search); + CloseHandle(snap); + return ret; +} + /****************************************************************** * dbg_init *