From: Paul Gofman pgofman@codeweavers.com
--- dlls/kernelbase/debug.c | 2 ++ 1 file changed, 2 insertions(+)
diff --git a/dlls/kernelbase/debug.c b/dlls/kernelbase/debug.c index 9d9b4b36b41..453b6114c2b 100644 --- a/dlls/kernelbase/debug.c +++ b/dlls/kernelbase/debug.c @@ -181,6 +181,7 @@ static LONG WINAPI debug_exception_handler( EXCEPTION_POINTERS *eptr ) */ void WINAPI DECLSPEC_HOTPATCH OutputDebugStringA( LPCSTR str ) { + DWORD last_error = GetLastError(); static HANDLE DBWinMutex = NULL; static BOOL mutex_inited = FALSE; BOOL caught_by_dbg = TRUE; @@ -263,6 +264,7 @@ void WINAPI DECLSPEC_HOTPATCH OutputDebugStringA( LPCSTR str ) CloseHandle( mapping ); } } + SetLastError( last_error ); }
static LONG WINAPI debug_exception_handler_wide( EXCEPTION_POINTERS *eptr )
From: Paul Gofman pgofman@codeweavers.com
--- dlls/kernel32/debugger.c | 2 ++ 1 file changed, 2 insertions(+)
diff --git a/dlls/kernel32/debugger.c b/dlls/kernel32/debugger.c index 6ccce02a8f3..a1317464e67 100644 --- a/dlls/kernel32/debugger.c +++ b/dlls/kernel32/debugger.c @@ -52,6 +52,7 @@ void WINAPI DECLSPEC_HOTPATCH OutputDebugStringA( LPCSTR str ) static HANDLE DBWinMutex = NULL; static BOOL mutex_inited = FALSE; BOOL caught_by_dbg = TRUE; + DWORD last_error = GetLastError();
if (!str) str = ""; WARN( "%s\n", debugstr_a(str) ); @@ -131,6 +132,7 @@ void WINAPI DECLSPEC_HOTPATCH OutputDebugStringA( LPCSTR str ) CloseHandle( mapping ); } } + SetLastError( last_error ); }
From: Paul Gofman pgofman@codeweavers.com
--- dlls/kernel32/tests/debugger.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)
diff --git a/dlls/kernel32/tests/debugger.c b/dlls/kernel32/tests/debugger.c index 282eddb8162..13b6b13bfcd 100644 --- a/dlls/kernel32/tests/debugger.c +++ b/dlls/kernel32/tests/debugger.c @@ -2422,6 +2422,27 @@ static void test_kill_on_exit(const char *argv0) heap_free(cmd); }
+static void test_OutputDebugString(void) +{ + static void (WINAPI *pOutputDebugStringA)(const char *); + + pOutputDebugStringA = (void *)GetProcAddress(GetModuleHandleW(L"kernel32.dll"), "OutputDebugStringA"); + ok(!!pOutputDebugStringA, "got NULL"); + SetLastError(0xdeadbeef); + pOutputDebugStringA("test"); + ok(GetLastError() == 0xdeadbeef, "got %ld.\n", GetLastError()); + + pOutputDebugStringA = (void *)GetProcAddress(GetModuleHandleW(L"kernelbase.dll"), "OutputDebugStringA"); + ok(!!pOutputDebugStringA, "got NULL"); + SetLastError(0xdeadbeef); + pOutputDebugStringA("test"); + ok(GetLastError() == 0xdeadbeef, "got %ld.\n", GetLastError()); + + SetLastError(0xdeadbeef); + OutputDebugStringW(L"test"); + ok(GetLastError() == 0xdeadbeef, "got %ld.\n", GetLastError()); +} + START_TEST(debugger) { HMODULE hdll; @@ -2487,5 +2508,6 @@ START_TEST(debugger) test_debug_children(myARGV[0], DEBUG_ONLY_THIS_PROCESS, FALSE, TRUE); test_debugger(myARGV[0]); test_kill_on_exit(myARGV[0]); + test_OutputDebugString(); } }
From: Paul Gofman pgofman@codeweavers.com
--- dlls/ntdll/tests/exception.c | 4 ++++ 1 file changed, 4 insertions(+)
diff --git a/dlls/ntdll/tests/exception.c b/dlls/ntdll/tests/exception.c index 2a048aae674..3396e7b8f81 100644 --- a/dlls/ntdll/tests/exception.c +++ b/dlls/ntdll/tests/exception.c @@ -9281,10 +9281,12 @@ static void test_outputdebugstring(BOOL unicode, DWORD numexc_ansi, BOOL todo_an
outputdebugstring_exceptions_ansi = outputdebugstring_exceptions_unicode = 0;
+ SetLastError(0xdeadbeef); if (unicode) OutputDebugStringW(L"Hello World"); else OutputDebugStringA("Hello World"); + ok(GetLastError() == 0xdeadbeef, "got %#lx.\n", GetLastError());
todo_wine_if(todo_ansi) ok(outputdebugstring_exceptions_ansi == numexc_ansi, @@ -9368,10 +9370,12 @@ static void test_outputdebugstring_newmodel(void) outputdebugstring_exceptions_newmodel_order = 0; outputdebugstring_newmodel_return = tests[i].ret_code;
+ SetLastError(0xdeadbeef); if (tests[i].unicode) OutputDebugStringW(L"Hello World"); else OutputDebugStringA("Hello World"); + ok(GetLastError() == 0xdeadbeef, "got %#lx.\n", GetLastError());
ok(outputdebugstring_exceptions_newmodel_order == tests[i].exceptions_order, "OutputDebugString%c/%u generated exceptions %04lxs, expected %04lx\n",
I manually tested that last error is also preserved when DebugView is running and showing the debug output from the tests.