From 02ee9ddaab621c4d642c351638b09234882e6dc8 Mon Sep 17 00:00:00 2001 From: Eric Pouech Date: Thu, 13 Apr 2000 19:28:28 +0000 Subject: [PATCH] Added launching of a debugger when unhandled exception occurs. --- win32/except.c | 68 ++++++++++++++++++++++++++++++++++++++++++++----- winedefault.reg | 9 +++++++ 2 files changed, 70 insertions(+), 7 deletions(-) diff --git a/win32/except.c b/win32/except.c index 5dea00d1fd6..3bf9e629d90 100644 --- a/win32/except.c +++ b/win32/except.c @@ -72,8 +72,12 @@ void WINAPI RaiseException( DWORD code, DWORD flags, DWORD nbargs, const LPDWORD DWORD WINAPI UnhandledExceptionFilter(PEXCEPTION_POINTERS epointers) { struct exception_event_request *req = get_req_buffer(); - char message[80]; - PDB *pdb = PROCESS_Current(); + PDB* pdb = PROCESS_Current(); + char format[256]; + char buffer[256]; + HKEY hDbgConf; + DWORD bAuto; + DWORD ret = EXCEPTION_EXECUTE_HANDLER; /* send a last chance event to the debugger */ req->record = *epointers->ExceptionRecord; @@ -90,11 +94,61 @@ DWORD WINAPI UnhandledExceptionFilter(PEXCEPTION_POINTERS epointers) /* FIXME: Should check the current error mode */ - sprintf( message, "Unhandled exception 0x%08lx at address 0x%08lx.", - epointers->ExceptionRecord->ExceptionCode, - (DWORD)epointers->ExceptionRecord->ExceptionAddress ); - Callout.MessageBoxA( 0, message, "Error", MB_OK | MB_ICONHAND ); - return EXCEPTION_EXECUTE_HANDLER; + if (!RegOpenKeyA(HKEY_LOCAL_MACHINE, + "Software\\Microsoft\\Windows NT\\CurrentVersion\\AeDebug", + &hDbgConf)) { + DWORD type; + DWORD count; + + count = sizeof(format); + if (RegQueryValueExA(hDbgConf, "Debugger", 0, &type, format, &count)) + format[0] = 0; + + count = sizeof(bAuto); + if (RegQueryValueExA(hDbgConf, "Auto", 0, &type, (char*)&bAuto, &count)) + bAuto = FALSE; + + RegCloseKey(hDbgConf); + } else { + format[0] = 0; + } + + if (!bAuto) { + sprintf( buffer, "Unhandled exception 0x%08lx at address 0x%08lx.\n" + "Do you wish to debug it ?", + epointers->ExceptionRecord->ExceptionCode, + (DWORD)epointers->ExceptionRecord->ExceptionAddress ); + if (Callout.MessageBoxA( 0, buffer, "Error", MB_YESNO | MB_ICONHAND ) == IDNO) { + TRACE("Killing process\n"); + return EXCEPTION_EXECUTE_HANDLER; + } + } + + if (format[0]) { + HANDLE hEvent; + PROCESS_INFORMATION info; + STARTUPINFOA startup; + + TRACE("Starting debugger (fmt=%s)\n", format); + hEvent = ConvertToGlobalHandle(CreateEventA(NULL, FALSE, FALSE, NULL)); + sprintf(buffer, format, (unsigned long)pdb->server_pid, hEvent); + memset(&startup, 0, sizeof(startup)); + startup.cb = sizeof(startup); + startup.dwFlags = STARTF_USESHOWWINDOW; + startup.wShowWindow = SW_SHOWNORMAL; + if (CreateProcessA(NULL, buffer, NULL, NULL, + TRUE, 0, NULL, NULL, &startup, &info)) { + WaitForSingleObject(hEvent, INFINITE); + ret = EXCEPTION_CONTINUE_SEARCH; + } else { + ERR("Couldn't start debugger (%s)\n", buffer); + } + CloseHandle(hEvent); + } else { + ERR("No standard debugger defined in the registry => no debugging session\n"); + } + + return ret; } diff --git a/winedefault.reg b/winedefault.reg index 0905495594c..23ce9a2f942 100644 --- a/winedefault.reg +++ b/winedefault.reg @@ -57,6 +57,15 @@ [HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion] "ProgramFilesDir"="C:\Program Files" +# +# Configuration for unhandled exceptions +# +[MACHINE\Software\Microsoft\Windows NT\CurrentVersionAeDebug] +# command line to start a debugger when an exception occurs +"Debugger"="debugger/winedbg %ld %ld" +# to 1 if no message box has to be presented before running the debugger +"Auto"=dword:00000000 + # # This identifies the files for available code pages #