From 6cfa7d9011879898a079614077a605c812cb440e Mon Sep 17 00:00:00 2001 From: Sebastian Lackner Date: Sun, 28 Sep 2014 23:39:51 +0200 Subject: [PATCH] ntdll: OutputDebugString should throw the exception a second time, if a debugger is attached. --- dlls/kernelbase/debug.c | 17 +++++++++++++++++ dlls/ntdll/tests/exception.c | 9 ++++----- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/dlls/kernelbase/debug.c b/dlls/kernelbase/debug.c index 9488f2e2399..1cea4b5ba3c 100644 --- a/dlls/kernelbase/debug.c +++ b/dlls/kernelbase/debug.c @@ -200,6 +200,23 @@ void WINAPI DECLSPEC_HOTPATCH OutputDebugStringA( LPCSTR str ) __ENDTRY if (caught_by_dbg) return; + /* for some unknown reason Windows sends the exception a second time, if a + * debugger is attached, and the event wasn't handled in the first attempt */ + if (NtCurrentTeb()->Peb->BeingDebugged) + { + __TRY + { + ULONG_PTR args[2]; + args[0] = strlen(str) + 1; + args[1] = (ULONG_PTR)str; + RaiseException( DBG_PRINTEXCEPTION_C, 0, 2, args ); + } + __EXCEPT(debug_exception_handler) + { + } + __ENDTRY + } + /* send string to a system-wide monitor */ if (!mutex_inited) { diff --git a/dlls/ntdll/tests/exception.c b/dlls/ntdll/tests/exception.c index c4413d4d66e..4fe2c2b04db 100644 --- a/dlls/ntdll/tests/exception.c +++ b/dlls/ntdll/tests/exception.c @@ -8327,7 +8327,7 @@ static LONG CALLBACK outputdebugstring_vectored_handler(EXCEPTION_POINTERS *Exce return EXCEPTION_CONTINUE_SEARCH; } -static void test_outputdebugstring(DWORD numexc, BOOL todo) +static void test_outputdebugstring(DWORD numexc) { PVOID vectored_handler; @@ -8343,7 +8343,6 @@ static void test_outputdebugstring(DWORD numexc, BOOL todo) outputdebugstring_exceptions = 0; OutputDebugStringA("Hello World"); - todo_wine_if(todo) ok(outputdebugstring_exceptions == numexc, "OutputDebugStringA generated %ld exceptions, expected %ld\n", outputdebugstring_exceptions, numexc); @@ -10660,9 +10659,9 @@ START_TEST(exception) else skip( "RtlRaiseException not found\n" ); #endif test_stage = 3; - test_outputdebugstring(0, FALSE); + test_outputdebugstring(0); test_stage = 4; - test_outputdebugstring(2, TRUE); /* is this a Windows bug? */ + test_outputdebugstring(2); test_stage = 5; test_ripevent(0); test_stage = 6; @@ -10766,7 +10765,7 @@ START_TEST(exception) test_debugger(DBG_EXCEPTION_HANDLED); test_debugger(DBG_CONTINUE); test_thread_context(); - test_outputdebugstring(1, FALSE); + test_outputdebugstring(1); test_ripevent(1); test_breakpoint(1); test_closehandle(0, (HANDLE)0xdeadbeef); -- 2.35.1