为了账号安全,请及时绑定邮箱和手机立即绑定

使用 golang 时无法从 cgo 例程中使用核心文件获取堆栈跟踪

使用 golang 时无法从 cgo 例程中使用核心文件获取堆栈跟踪

Go
慕斯709654 2021-12-07 18:51:21
我正在使用 Golang 和 cgo。当我的 C 代码引发 . 时assert(),我无法在使用cgo.相反,我看到了捕获断言的 golang 运行时的堆栈跟踪。这是我的 C 代码示例#include <stdio.h>#include <pthread.h>#include <assert.h>#include <string.h>void fn2(char *arg){    int stackvar2 = 256;    printf("Argument %s\n", arg);    assert(1 == 2);}void fn1(int arg){    int stackvar3 = 512;    char var[256];    strcpy(var, "deadbeef");    fn2(var);}void *thread(void *arg){    printf("Hello from the thread... going in for an assert\n");    fn1(1092);    return NULL;}void hello_world(char *str){    pthread_t tid;    printf("Hello World from C and here the str is from Go: %s\n", str);    pthread_create(&tid, NULL, thread, NULL);    sleep(100000);}Here is my Go codepackage main/*extern void hello_world(char *str);#cgo LDFLAGS: -L. -lhello#cgo CFLAGS: -g3*/import "C"import (    _ "fmt")func main() {    str := "From Golang"    cStr := C.CString(str)    C.hello_world(cStr)    select {}}这是我的 Makefileall:    gcc -g3 -O0 -c hello.c    ar cru libhello.a hello.o    go build hello.goclean:    rm -f *.o hello
查看完整描述

2 回答

?
米脂

TA贡献1836条经验 获得超3个赞

除了明显的检查之外ulimit -c,使用GOTRACEBACK=crash. 这将打印出更多信息,并允许程序退出SIGABRT以触发核心转储。


查看完整回答
反对 回复 2021-12-07
?
冉冉说

TA贡献1877条经验 获得超1个赞

实际上我需要将它添加到我的代码中:signal.Ignore(syscall.SIGABRT)。这让我可以看到崩溃的 C 代码的堆栈跟踪。


查看完整回答
反对 回复 2021-12-07
  • 2 回答
  • 0 关注
  • 158 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信