Commit 6afa412
committed
cmd/cgo: improve cgoCheckResult error message
When an unpinned Go pointer is returned to a C function, this error shows up:
panic: runtime error: cgo result is unpinned Go pointer or points to unpinned Go pointer
> goroutine 17 [running, locked to thread]:
> panic({0x78fa15d1e5c0?, 0xc00001e050?})
> /usr/lib/go/src/runtime/panic.go:802 +0x168
> runtime.cgoCheckArg(0x78fa15d1bf20, 0xc000066e50, 0x0?, 0x0, {0x78fa15cfaa62, 0x42})
> /usr/lib/go/src/runtime/cgocall.go:679 +0x35b
> runtime.cgoCheckResult({0x78fa15d1bf20, 0xc000066e50})
> /usr/lib/go/src/runtime/cgocall.go:795 +0x4b
> _cgoexp_1ff3739d54a6_foo(0x7fff7f7b0220)
> _cgo_gotypes.go:65 +0x5d
> runtime.cgocallbackg1(0x78fa15cf16c0, 0x7fff7f7b0220, 0x0)
> /usr/lib/go/src/runtime/cgocall.go:446 +0x289
> runtime.cgocallbackg(0x78fa15cf16c0, 0x7fff7f7b0220, 0x0)
> /usr/lib/go/src/runtime/cgocall.go:350 +0x132
> runtime.cgocallbackg(0x78fa15cf16c0, 0x7fff7f7b0220, 0x0)
> <autogenerated>:1 +0x2b
> runtime.cgocallback(0x0, 0x0, 0x0)
> /usr/lib/go/src/runtime/asm_amd64.s:1082 +0xcd
> runtime.goexit({})
> /usr/lib/go/src/runtime/asm_amd64.s:1693 +0x1
_cgoexp_1ff3739d54a6_foo is the faulty caller; it is not obvious to
find it in the stack trace.
Retrieve the caller name, and use it in the error message:
panic: runtime error: result of cgo function foo is unpinned Go pointer or points to unpinned Go pointer
> goroutine 17 [running, locked to thread]:
> panic({0x7feae6c50640?, 0x26fcc9896000?})
> /mnt/go/src/runtime/panic.go:877 +0x16f
> runtime.cgoCheckArg(0x7feae6c4dee0, 0x26fcc9774e50, 0x0?, 0x0, {0x26fcc9894000, 0x52})
> /mnt/go/src/runtime/cgocall.go:678 +0x35b
> runtime.cgoCheckResult({0x7feae6c4dee0, 0x26fcc9774e50})
> /mnt/go/src/runtime/cgocall.go:797 +0x85
> _cgoexp_9ed4cd31b2e5_foo(0x7ffcc89baf10)
> _cgo_gotypes.go:65 +0x5d
> runtime.cgocallbackg1(0x7feae6c1d340, 0x7ffcc89baf10, 0x0)
> /mnt/go/src/runtime/cgocall.go:446 +0x289
> runtime.cgocallbackg(0x7feae6c1d340, 0x7ffcc89baf10, 0x0)
> /mnt/go/src/runtime/cgocall.go:350 +0x132
> runtime.cgocallbackg(0x7feae6c1d340, 0x7ffcc89baf10, 0x0)
> <autogenerated>:1 +0x2b
> runtime.cgocallback(0x0, 0x0, 0x0)
> /mnt/go/src/runtime/asm_amd64.s:1098 +0xcd
> runtime.goexit({})
> /mnt/go/src/runtime/asm_amd64.s:1709 +0x1
Cc: Keith Randall <khr@golang.org>
Cc: Sean Liao <sean@liao.dev>
Suggested-by: Ian Lance Taylor <iant@golang.org>
GH: #758561 parent ee5af46 commit 6afa412
1 file changed
+13
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
592 | 592 | | |
593 | 593 | | |
594 | 594 | | |
595 | | - | |
596 | 595 | | |
597 | 596 | | |
598 | 597 | | |
| |||
786 | 785 | | |
787 | 786 | | |
788 | 787 | | |
| 788 | + | |
| 789 | + | |
789 | 790 | | |
790 | 791 | | |
791 | 792 | | |
792 | 793 | | |
| 794 | + | |
| 795 | + | |
| 796 | + | |
| 797 | + | |
| 798 | + | |
| 799 | + | |
| 800 | + | |
| 801 | + | |
| 802 | + | |
| 803 | + | |
| 804 | + | |
793 | 805 | | |
794 | 806 | | |
795 | 807 | | |
| |||
0 commit comments