}
}
+func TestCgoPanicCallback(t *testing.T) {
+ t.Parallel()
+ got := runTestProg(t, "testprogcgo", "PanicCallback")
+ t.Log(got)
+ want := "panic: runtime error: invalid memory address or nil pointer dereference"
+ if !strings.Contains(got, want) {
+ t.Errorf("did not see %q in output", want)
+ }
+ want = "panic_callback"
+ if !strings.Contains(got, want) {
+ t.Errorf("did not see %q in output", want)
+ }
+ want = "PanicCallback"
+ if !strings.Contains(got, want) {
+ t.Errorf("did not see %q in output", want)
+ }
+ // No runtime errors like "runtime: unexpected return pc".
+ nowant := "runtime: "
+ if strings.Contains(got, nowant) {
+ t.Errorf("did not see %q in output", want)
+ }
+}
+
// Test that C code called via cgo can use large Windows thread stacks
// and call back in to Go without crashing. See issue #20975.
//
}
}
+func TestAbortInCgo(t *testing.T) {
+ switch runtime.GOOS {
+ case "plan9", "windows":
+ // N.B. On Windows, C abort() causes the program to exit
+ // without going through the runtime at all.
+ t.Skipf("no signals on %s", runtime.GOOS)
+ }
+
+ t.Parallel()
+ got := runTestProg(t, "testprogcgo", "Abort")
+ t.Log(got)
+ want := "SIGABRT"
+ if !strings.Contains(got, want) {
+ t.Errorf("did not see %q in output", want)
+ }
+ // No runtime errors like "runtime: unknown pc".
+ nowant := "runtime: "
+ if strings.Contains(got, nowant) {
+ t.Errorf("did not see %q in output", want)
+ }
+}
+
// TestEINTR tests that we handle EINTR correctly.
// See issue #20400 and friends.
func TestEINTR(t *testing.T) {
}
print("PC=", hex(c.sigpc()), " m=", _g_.m.id, " sigcode=", c.sigcode(), "\n")
- if _g_.m.lockedg != 0 && _g_.m.ncgo > 0 && gp == _g_.m.g0 {
+ if _g_.m.incgo && gp == _g_.m.g0 && _g_.m.curg != nil {
print("signal arrived during cgo execution\n")
- gp = _g_.m.lockedg.ptr()
+ // Switch to curg so that we get a traceback of the Go code
+ // leading up to the cgocall, which switched from curg to g0.
+ gp = _g_.m.curg
}
if sig == _SIGILL || sig == _SIGFPE {
// It would be nice to know how long the instruction is.
print("Exception ", hex(info.exceptioncode), " ", hex(info.exceptioninformation[0]), " ", hex(info.exceptioninformation[1]), " ", hex(r.ip()), "\n")
print("PC=", hex(r.ip()), "\n")
- if _g_.m.lockedg != 0 && _g_.m.ncgo > 0 && gp == _g_.m.g0 {
+ if _g_.m.incgo && gp == _g_.m.g0 && _g_.m.curg != nil {
if iscgo {
print("signal arrived during external code execution\n")
}
- gp = _g_.m.lockedg.ptr()
+ gp = _g_.m.curg
}
print("\n")