diff options
| author | qmuntal <quimmuntal@gmail.com> | 2023-03-09 14:55:31 +0100 |
|---|---|---|
| committer | Quim Muntal <quimmuntal@gmail.com> | 2023-04-10 18:52:58 +0000 |
| commit | 65ea4c5021d44395db8728eea16eb8f7fc7420eb (patch) | |
| tree | af729f4aed221fc5d7515141fd1c8cab28056654 /src/runtime/syscall_windows_test.go | |
| parent | 5e93a2c2042484ee7a941e967294a5248ab6a593 (diff) | |
| download | go-65ea4c5021d44395db8728eea16eb8f7fc7420eb.tar.xz | |
runtime: support GOTRACEBACK=wer on Windows
GOTRACEBACK=wer is a new traceback level that acts as "crash" and
also enables WER. The same effect can be achieved using
debug.SetTraceback("wer").
The Go runtime currently crashes using exit(2), which bypasses WER
even if it is enabled. To best way to trigger WER is calling
RaiseFailFastException [1] instead, which internally launches the
WER machinery.
This CL also changes how GOTRACEBACK=crash crashes, so both "wer" and
"crash" crash using RaiseFailFastException, which simplifies the
implementation and resolves a longstanding TODO.
Fixes #57441
Fixes #20498
[1] https://learn.microsoft.com/en-us/windows/win32/api/errhandlingapi/nf-errhandlingapi-raisefailfastexception
Change-Id: I45669d619fbbd2f6413ce5e5f08425ed1d9aeb64
Reviewed-on: https://go-review.googlesource.com/c/go/+/474915
Reviewed-by: Davis Goodin <dagood@microsoft.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
Run-TryBot: Quim Muntal <quimmuntal@gmail.com>
Diffstat (limited to 'src/runtime/syscall_windows_test.go')
| -rw-r--r-- | src/runtime/syscall_windows_test.go | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/src/runtime/syscall_windows_test.go b/src/runtime/syscall_windows_test.go index b49da32384..8686d3f7f8 100644 --- a/src/runtime/syscall_windows_test.go +++ b/src/runtime/syscall_windows_test.go @@ -648,21 +648,26 @@ func TestZeroDivisionException(t *testing.T) { } func TestWERDialogue(t *testing.T) { - if os.Getenv("TESTING_WER_DIALOGUE") == "1" { - defer os.Exit(0) - - *runtime.TestingWER = true + const exitcode = 0xbad + if os.Getenv("TEST_WER_DIALOGUE") == "1" { const EXCEPTION_NONCONTINUABLE = 1 mod := syscall.MustLoadDLL("kernel32.dll") proc := mod.MustFindProc("RaiseException") - proc.Call(0xbad, EXCEPTION_NONCONTINUABLE, 0, 0) - println("RaiseException should not return") + proc.Call(exitcode, EXCEPTION_NONCONTINUABLE, 0, 0) + t.Fatal("RaiseException should not return") return } - cmd := exec.Command(os.Args[0], "-test.run=TestWERDialogue") - cmd.Env = []string{"TESTING_WER_DIALOGUE=1"} + cmd := testenv.CleanCmdEnv(exec.Command(os.Args[0], "-test.run=TestWERDialogue")) + cmd.Env = append(cmd.Env, "TEST_WER_DIALOGUE=1", "GOTRACEBACK=wer") // Child process should not open WER dialogue, but return immediately instead. - cmd.CombinedOutput() + _, err := cmd.CombinedOutput() + if err == nil { + t.Error("test program succeeded unexpectedly") + } else if ee, ok := err.(*exec.ExitError); !ok { + t.Errorf("error (%v) has type %T; expected exec.ExitError", err, err) + } else if got := ee.ExitCode(); got != exitcode { + t.Fatalf("got exit code %d; want %d", got, exitcode) + } } func TestWindowsStackMemory(t *testing.T) { |
