Skip to content

Commit 2ed209e

Browse files
committed
runtime: allow OutputDebugString to be sent to debugger
We mark DBG_PRINTEXCEPTION_C messages in VEH handler as handled, thus preventing debugger from seeing them. I don't see reason for doing that. The comment warns of crashes, but I added test and don't see any crashes. This is also simplify VEH handler before making changes to fix issue 8006. Update #8006 LGTM=rsc R=golang-codereviews, rsc CC=golang-codereviews https://golang.org/cl/146800043
1 parent dd8f29e commit 2ed209e

File tree

3 files changed

+6
-30
lines changed

3 files changed

+6
-30
lines changed

src/runtime/os_windows_386.c

-15
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ runtime·dumpregs(Context *r)
2424
runtime·printf("gs %x\n", r->SegGs);
2525
}
2626

27-
#define DBG_PRINTEXCEPTION_C 0x40010006
28-
2927
// Called by sigtramp from Windows VEH handler.
3028
// Return value signals whether the exception has been handled (-1)
3129
// or should be made available to other handlers in the chain (0).
@@ -36,19 +34,6 @@ runtime·sighandler(ExceptionRecord *info, Context *r, G *gp)
3634
uintptr *sp;
3735
extern byte runtime·text[], runtime·etext[];
3836

39-
if(info->ExceptionCode == DBG_PRINTEXCEPTION_C) {
40-
// This exception is intended to be caught by debuggers.
41-
// There is a not-very-informational message like
42-
// "Invalid parameter passed to C runtime function"
43-
// sitting at info->ExceptionInformation[0] (a wchar_t*),
44-
// with length info->ExceptionInformation[1].
45-
// The default behavior is to ignore this exception,
46-
// but somehow returning 0 here (meaning keep going)
47-
// makes the program crash instead. Maybe Windows has no
48-
// other handler registered? In any event, ignore it.
49-
return -1;
50-
}
51-
5237
// Only handle exception if executing instructions in Go binary
5338
// (not Windows library code).
5439
if(r->Eip < (uint32)runtime·text || (uint32)runtime·etext < r->Eip)

src/runtime/os_windows_amd64.c

-15
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ runtime·dumpregs(Context *r)
3232
runtime·printf("gs %X\n", (uint64)r->SegGs);
3333
}
3434

35-
#define DBG_PRINTEXCEPTION_C 0x40010006
36-
3735
// Called by sigtramp from Windows VEH handler.
3836
// Return value signals whether the exception has been handled (-1)
3937
// or should be made available to other handlers in the chain (0).
@@ -44,19 +42,6 @@ runtime·sighandler(ExceptionRecord *info, Context *r, G *gp)
4442
uintptr *sp;
4543
extern byte runtime·text[], runtime·etext[];
4644

47-
if(info->ExceptionCode == DBG_PRINTEXCEPTION_C) {
48-
// This exception is intended to be caught by debuggers.
49-
// There is a not-very-informational message like
50-
// "Invalid parameter passed to C runtime function"
51-
// sitting at info->ExceptionInformation[0] (a wchar_t*),
52-
// with length info->ExceptionInformation[1].
53-
// The default behavior is to ignore this exception,
54-
// but somehow returning 0 here (meaning keep going)
55-
// makes the program crash instead. Maybe Windows has no
56-
// other handler registered? In any event, ignore it.
57-
return -1;
58-
}
59-
6045
// Only handle exception if executing instructions in Go binary
6146
// (not Windows library code).
6247
if(r->Rip < (uint64)runtime·text || (uint64)runtime·etext < r->Rip)

src/runtime/syscall_windows_test.go

+6
Original file line numberDiff line numberDiff line change
@@ -488,3 +488,9 @@ func TestRegisterClass(t *testing.T) {
488488
t.Fatalf("UnregisterClass failed: %v", err)
489489
}
490490
}
491+
492+
func TestOutputDebugString(t *testing.T) {
493+
d := GetDLL(t, "kernel32.dll")
494+
p := syscall.StringToUTF16Ptr("testing OutputDebugString")
495+
d.Proc("OutputDebugStringW").Call(uintptr(unsafe.Pointer(p)))
496+
}

0 commit comments

Comments
 (0)