diff --git a/programs/winedbg/dbg.y b/programs/winedbg/dbg.y index dc64209b62c..e98bb16f344 100644 --- a/programs/winedbg/dbg.y +++ b/programs/winedbg/dbg.y @@ -150,7 +150,7 @@ command: | tSYMBOLFILE pathname tEOL { DEBUG_ReadSymbolTable($2, 0); } | tSYMBOLFILE pathname tNUM tEOL { DEBUG_ReadSymbolTable($2, $3); } | tWHATIS expr_addr tEOL { DEBUG_PrintType(&$2); DEBUG_FreeExprMem(); } - | tATTACH tNUM tEOL { DEBUG_Attach($2, FALSE); } + | tATTACH tNUM tEOL { DEBUG_Attach($2, FALSE, TRUE); } | tDETACH tEOL { return DEBUG_Detach(); /* FIXME: we shouldn't return, but since we cannot simply clean the symbol table, exit debugger for now */ } | list_command | disassemble_command @@ -426,7 +426,7 @@ static void set_default_channels(void) /*********************************************************************** * DEBUG_Parser * - * Debugger editline parser + * Debugger command line parser */ void DEBUG_Parser(LPCSTR filename) { @@ -453,7 +453,7 @@ void DEBUG_Parser(LPCSTR filename) do { __TRY - { + { ret_ok = TRUE; yyparse(); } diff --git a/programs/winedbg/debugger.h b/programs/winedbg/debugger.h index 66ef468c545..95636a1910c 100644 --- a/programs/winedbg/debugger.h +++ b/programs/winedbg/debugger.h @@ -531,7 +531,7 @@ extern int DEBUG_Printf(int chn, const char* format, ...) __attribute__( extern int DEBUG_Printf(int chn, const char* format, ...); #endif extern DBG_INTVAR* DEBUG_GetIntVar(const char*); -extern BOOL DEBUG_Attach(DWORD pid, BOOL cofe); +extern BOOL DEBUG_Attach(DWORD pid, BOOL cofe, BOOL wfe); extern BOOL DEBUG_Detach(void); extern void DEBUG_Run(const char* args); extern DBG_PROCESS* DEBUG_AddProcess(DWORD pid, HANDLE h, const char* imageName); diff --git a/programs/winedbg/winedbg.c b/programs/winedbg/winedbg.c index 6ffbe905534..cf0e1f9bd62 100644 --- a/programs/winedbg/winedbg.c +++ b/programs/winedbg/winedbg.c @@ -262,7 +262,7 @@ DBG_THREAD* DEBUG_AddThread(DBG_PROCESS* p, DWORD tid, t->exec_mode = EXEC_CONT; t->exec_count = 0; - sprintf(t->name, "%08lx", tid); + snprintf(t->name, sizeof(t->name), "%08lx", tid); p->num_threads++; t->next = p->threads; @@ -303,17 +303,40 @@ void DEBUG_DelThread(DBG_THREAD* t) DBG_free(t); } -BOOL DEBUG_Attach(DWORD pid, BOOL cofe) +static BOOL DEBUG_HandleDebugEvent(DEBUG_EVENT* de); + +/****************************************************************** + * DEBUG_Attach + * + * Sets the debuggee to + * cofe instructs winedbg what to do when first exception is received + * (break=FALSE, continue=TRUE) + * wfe is set to TRUE if DEBUG_Attach should also proceed with all debug events + * until the first exception is received (aka: attach to an already running process) + */ +BOOL DEBUG_Attach(DWORD pid, BOOL cofe, BOOL wfe) { + DEBUG_EVENT de; + if (!(DEBUG_CurrProcess = DEBUG_AddProcess(pid, 0, NULL))) return FALSE; if (!DebugActiveProcess(pid)) { DEBUG_Printf(DBG_CHN_MESG, "Can't attach process %lx: error %ld\n", pid, GetLastError()); DEBUG_DelProcess(DEBUG_CurrProcess); - DEBUG_CurrProcess = NULL; return FALSE; } DEBUG_CurrProcess->continue_on_first_exception = cofe; + + if (wfe) /* shall we proceed all debug events until we get an exception ? */ + { + DEBUG_InteractiveP = FALSE; + while (DEBUG_CurrProcess && WaitForDebugEvent(&de, INFINITE)) + { + if (DEBUG_HandleDebugEvent(&de)) break; + ContinueDebugEvent(de.dwProcessId, de.dwThreadId, DBG_CONTINUE); + } + if (DEBUG_CurrProcess) DEBUG_InteractiveP = TRUE; + } return TRUE; } @@ -329,7 +352,6 @@ BOOL DEBUG_Detach(void) SetThreadContext(DEBUG_CurrThread->handle, &DEBUG_context); DebugActiveProcessStop(DEBUG_CurrProcess->pid); DEBUG_DelProcess(DEBUG_CurrProcess); - DEBUG_CurrProcess = NULL; /* FIXME: should zero out the symbol table too */ return TRUE; } @@ -1040,18 +1062,18 @@ int main(int argc, char** argv) if (local_mode == none_mode) local_mode = winedbg_mode; - /* try the from pid */ + /* try the form pid */ if (DEBUG_CurrPid == 0 && argc == 2) { char* ptr; DEBUG_CurrPid = strtol(argv[1], &ptr, 10); if (DEBUG_CurrPid == 0 || ptr == NULL || - !DEBUG_Attach(DEBUG_CurrPid, local_mode != gdb_mode)) + !DEBUG_Attach(DEBUG_CurrPid, local_mode != gdb_mode, FALSE)) DEBUG_CurrPid = 0; } - /* try the from pid evt (Win32 JIT debugger) */ + /* try the form pid evt (Win32 JIT debugger) */ if (DEBUG_CurrPid == 0 && argc == 3) { HANDLE hEvent; @@ -1061,7 +1083,7 @@ int main(int argc, char** argv) if ((pid = strtol(argv[1], &ptr, 10)) != 0 && ptr != NULL && (hEvent = (HANDLE)strtol(argv[2], &ptr, 10)) != 0 && ptr != NULL) { - if (!DEBUG_Attach(pid, TRUE)) + if (!DEBUG_Attach(pid, TRUE, FALSE)) { /* don't care about result */ SetEvent(hEvent);