SIGTRAP:在运行go test时,Golang包装C库时发生的跟踪陷阱错误。

huangapple go评论97阅读模式
英文:

SIGTRAP: trace trap error in Golang wrapping C library, but only when running go test

问题

我已经设置了一个最小的代码库来复制错误并尽可能清楚地解释这个错误:https://github.com/soroushjp/go_wrapper_c_err

我目前正在使用一个Go包go-secp256k1进行ECDSA签名,该包包装了C secp256k1库

如果我直接导入go-secp256k1中的函数(如main.go中所示),它可以正常工作。因此,在该代码库中,运行main.go会正常运行并打印出公钥。

这里是奇怪的错误:如果我尝试为使用go-secp256k1的包编写一个测试,我会收到一个奇怪的错误。要复制,请运行:

go test github.com/soroushjp/go_wrapper_c_err/cryptoutil -v

我收到的错误信息:

=== RUN TestNewPublicKey
SIGTRAP: trace trap
PC=0x4031730
signal arrived during cgo execution

goroutine 20 [syscall]:
runtime.cgocall(0x40013d0, 0x436ddd0)
	/usr/local/go/src/pkg/runtime/cgocall.c:143 +0xe5 fp=0x436ddb8 sp=0x436dd70
github.com/toxeus/go-secp256k1._Cfunc_secp256k1_start(0x404c14d)
	github.com/toxeus/go-secp256k1/_obj/_cgo_defun.c:99 +0x31 fp=0x436ddd0 sp=0x436ddb8
github.com/toxeus/go-secp256k1.Start()
	/Users/soroushjp/Desktop/Dropbox/Development/go/src/github.com/toxeus/go-secp256k1/secp256k1.go:9 +0x1a fp=0x436ddd8 sp=0x436ddd0
github.com/soroushjp/go_wrapper_c_err/cryptoutil.NewPublicKey(0xc20800e080, 0x20, 0x20, 0x0, 0x0, 0x0, 0x0, 0x0)
	/Users/soroushjp/go/src/github.com/soroushjp/go_wrapper_c_err/cryptoutil/cryptoutil.go:35 +0xbd fp=0x436de98 sp=0x436ddd8
github.com/soroushjp/go_wrapper_c_err/cryptoutil.TestNewPublicKey(0xc20804c090)
	/Users/soroushjp/go/src/github.com/soroushjp/go_wrapper_c_err/cryptoutil/cryptoutil_test.go:10 +0x5f fp=0x436df68 sp=0x436de98
testing.tRunner(0xc20804c090, 0x420e110)
	/usr/local/go/src/pkg/testing/testing.go:422 +0x8b fp=0x436df98 sp=0x436df68
runtime.goexit()
	/usr/local/go/src/pkg/runtime/proc.c:1445 fp=0x436dfa0 sp=0x436df98
created by testing.RunTests
	/usr/local/go/src/pkg/testing/testing.go:504 +0x8db

goroutine 16 [chan receive]:
testing.RunTests(0x418fe08, 0x420e110, 0x1, 0x1, 0x1)
	/usr/local/go/src/pkg/testing/testing.go:505 +0x923
testing.Main(0x418fe08, 0x420e110, 0x1, 0x1, 0x4216960, 0x0, 0x0, 0x4216960, 0x0, 0x0)
	/usr/local/go/src/pkg/testing/testing.go:435 +0x84
main.main()
	github.com/soroushjp/go_wrapper_c_err/cryptoutil/_test/_testmain.go:47 +0x9c

goroutine 19 [finalizer wait]:
runtime.park(0x401c710, 0x4231e98, 0x4215dc9)
	/usr/local/go/src/pkg/runtime/proc.c:1369 +0x89
runtime.parkunlock(0x4231e98, 0x4215dc9)
	/usr/local/go/src/pkg/runtime/proc.c:1385 +0x3b
runfinq()
	/usr/local/go/src/pkg/runtime/mgc0.c:2644 +0xcf
runtime.goexit()
	/usr/local/go/src/pkg/runtime/proc.c:1445

goroutine 17 [syscall]:
runtime.goexit()
	/usr/local/go/src/pkg/runtime/proc.c:1445

rax     0x4031720
rbx     0xc208018d80
rcx     0xc208002a20
rdx     0x0
rdi     0x4403a90
rsi     0xc208002a20
rbp     0xb0103e30
rsp     0xb006efc0
r8      0x1
r9      0x3f
r10     0x3
r11     0x7fffffffffffffff
r12     0x7fff74c4e420
r13     0x1b8f53c9daf8
r14     0x4403a78
r15     0x4403a30
rip     0x4031730
rflags  0x246
cs      0x2b
fs      0x0
gs      0x0
exit status 2
FAIL	github.com/soroushjp/go_wrapper_c_err/cryptoutil	0.016s

我的测试代码非常简单,几乎与main.go中的代码相同:

package cryptoutil

import (
	"fmt"
	"testing"
)

func TestNewPublicKey(t *testing.T) {
	privateKey := NewPrivateKey()
	publicKey, err := NewPublicKey(privateKey)
	if err != nil {
		t.Error(err)
	}
	fmt.Println(publicKey)
}

你知道这里发生了什么吗?在'go test'和'go run'之间有什么不同导致ECDSA包装器遇到这个错误?

英文:

I've set up a minimal codebase repo to replicate the error and explain this error as clearly as possible: https://github.com/soroushjp/go_wrapper_c_err

I'm currently working on a project doing ECDSA signing using a Go package go-secp256k1 that wraps the C secp256k1 library.

If I use the functions in go-secp256k1 directly by importing them (as seen in main.go), it works fine. So in the repo, running main.go works beautifully and a public key is printed out.

So here's the strange error: If I try to write a test for a package using go-secp256k1, I receive a strange error. To replicate, run:

go test github.com/soroushjp/go_wrapper_c_err/cryptoutil -v

The error I receive:

=== RUN TestNewPublicKey
SIGTRAP: trace trap
PC=0x4031730
signal arrived during cgo execution

goroutine 20 [syscall]:
runtime.cgocall(0x40013d0, 0x436ddd0)
	/usr/local/go/src/pkg/runtime/cgocall.c:143 +0xe5 fp=0x436ddb8 sp=0x436dd70
github.com/toxeus/go-secp256k1._Cfunc_secp256k1_start(0x404c14d)
	github.com/toxeus/go-secp256k1/_obj/_cgo_defun.c:99 +0x31 fp=0x436ddd0 sp=0x436ddb8
github.com/toxeus/go-secp256k1.Start()
	/Users/soroushjp/Desktop/Dropbox/Development/go/src/github.com/toxeus/go-secp256k1/secp256k1.go:9 +0x1a fp=0x436ddd8 sp=0x436ddd0
github.com/soroushjp/go_wrapper_c_err/cryptoutil.NewPublicKey(0xc20800e080, 0x20, 0x20, 0x0, 0x0, 0x0, 0x0, 0x0)
	/Users/soroushjp/go/src/github.com/soroushjp/go_wrapper_c_err/cryptoutil/cryptoutil.go:35 +0xbd fp=0x436de98 sp=0x436ddd8
github.com/soroushjp/go_wrapper_c_err/cryptoutil.TestNewPublicKey(0xc20804c090)
	/Users/soroushjp/go/src/github.com/soroushjp/go_wrapper_c_err/cryptoutil/cryptoutil_test.go:10 +0x5f fp=0x436df68 sp=0x436de98
testing.tRunner(0xc20804c090, 0x420e110)
	/usr/local/go/src/pkg/testing/testing.go:422 +0x8b fp=0x436df98 sp=0x436df68
runtime.goexit()
	/usr/local/go/src/pkg/runtime/proc.c:1445 fp=0x436dfa0 sp=0x436df98
created by testing.RunTests
	/usr/local/go/src/pkg/testing/testing.go:504 +0x8db

goroutine 16 [chan receive]:
testing.RunTests(0x418fe08, 0x420e110, 0x1, 0x1, 0x1)
	/usr/local/go/src/pkg/testing/testing.go:505 +0x923
testing.Main(0x418fe08, 0x420e110, 0x1, 0x1, 0x4216960, 0x0, 0x0, 0x4216960, 0x0, 0x0)
	/usr/local/go/src/pkg/testing/testing.go:435 +0x84
main.main()
	github.com/soroushjp/go_wrapper_c_err/cryptoutil/_test/_testmain.go:47 +0x9c

goroutine 19 [finalizer wait]:
runtime.park(0x401c710, 0x4231e98, 0x4215dc9)
	/usr/local/go/src/pkg/runtime/proc.c:1369 +0x89
runtime.parkunlock(0x4231e98, 0x4215dc9)
	/usr/local/go/src/pkg/runtime/proc.c:1385 +0x3b
runfinq()
	/usr/local/go/src/pkg/runtime/mgc0.c:2644 +0xcf
runtime.goexit()
	/usr/local/go/src/pkg/runtime/proc.c:1445

goroutine 17 [syscall]:
runtime.goexit()
	/usr/local/go/src/pkg/runtime/proc.c:1445

rax     0x4031720
rbx     0xc208018d80
rcx     0xc208002a20
rdx     0x0
rdi     0x4403a90
rsi     0xc208002a20
rbp     0xb0103e30
rsp     0xb006efc0
r8      0x1
r9      0x3f
r10     0x3
r11     0x7fffffffffffffff
r12     0x7fff74c4e420
r13     0x1b8f53c9daf8
r14     0x4403a78
r15     0x4403a30
rip     0x4031730
rflags  0x246
cs      0x2b
fs      0x0
gs      0x0
exit status 2
FAIL	github.com/soroushjp/go_wrapper_c_err/cryptoutil	0.016s

My testing code is extremely minimal and almost identical to what is going on in main.go:

package cryptoutil

import (
	"fmt"
	"testing"
)

func TestNewPublicKey(t *testing.T) {
	privateKey := NewPrivateKey()
	publicKey, err := NewPublicKey(privateKey)
	if err != nil {
		t.Error(err)
	}
	fmt.Println(publicKey)
}

Any idea what is going on here? What is happening different between 'go test' and 'go run' that's causing the ECDSA wrapper to run into this error?

答案1

得分: 0

只需将Go 1.3更新为Go 1.4,问题就解决了。在OS X Mavericks上,golang.org上的Go安装程序将在安装1.4时删除任何旧版本的Go。

英文:

Simply updating from Go 1.4 from 1.3 solved the issue for me on OS X Mavericks. The Go installer at golang.org will remove any older versions of Go when installing 1.4

huangapple
  • 本文由 发表于 2014年12月12日 16:52:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/27439942.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定