Commit 7001ac53 authored by Austin Clements's avatar Austin Clements

runtime: fix abort handling on Windows

On Windows, the IP recorded in the breakpoint exception caused by
runtime.abort is actually one byte after the INT3, unlike on UNIX
OSes. Account for this in isgoexception.

It turns out TestAbort was "passing" on Windows anyway because abort
still caused a fatal panic, just not the one we were expecting. This
CL tightens this test to check that the runtime specifically reports a
breakpoint exception.

Fixing this is related to #21382, since we use runtime.abort in
reporting g0 stack overflows, and it's important that we detect this
and not try to handle it.

Change-Id: I66120944d138eb80f839346b157a3759c1019e34
Reviewed-on: https://go-review.googlesource.com/122515
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
Reviewed-by: default avatarAlex Brainman <alex.brainman@gmail.com>
parent f5d48631
...@@ -640,18 +640,21 @@ func TestTimePprof(t *testing.T) { ...@@ -640,18 +640,21 @@ func TestTimePprof(t *testing.T) {
// Test that runtime.abort does so. // Test that runtime.abort does so.
func TestAbort(t *testing.T) { func TestAbort(t *testing.T) {
output := runTestProg(t, "testprog", "Abort") // Pass GOTRACEBACK to ensure we get runtime frames.
output := runTestProg(t, "testprog", "Abort", "GOTRACEBACK=system")
if want := "runtime.abort"; !strings.Contains(output, want) { if want := "runtime.abort"; !strings.Contains(output, want) {
t.Errorf("output does not contain %q:\n%s", want, output) t.Errorf("output does not contain %q:\n%s", want, output)
} }
if strings.Contains(output, "BAD") { if strings.Contains(output, "BAD") {
t.Errorf("output contains BAD:\n%s", output) t.Errorf("output contains BAD:\n%s", output)
} }
// Check that it's a signal-style traceback. // Check that it's a breakpoint traceback.
if runtime.GOOS != "windows" { want := "SIGTRAP"
if want := "PC="; !strings.Contains(output, want) { if runtime.GOOS == "windows" {
t.Errorf("output does not contain %q:\n%s", want, output) want = "Exception 0x80000003"
} }
if !strings.Contains(output, want) {
t.Errorf("output does not contain %q:\n%s", want, output)
} }
} }
......
...@@ -46,7 +46,9 @@ func isgoexception(info *exceptionrecord, r *context) bool { ...@@ -46,7 +46,9 @@ func isgoexception(info *exceptionrecord, r *context) bool {
return false return false
} }
if isAbortPC(r.ip()) { // In the case of an abort, the exception IP is one byte after
// the INT3 (this differs from UNIX OSes).
if isAbortPC(r.ip() - 1) {
// Never turn abort into a panic. // Never turn abort into a panic.
return false return false
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment