golang 调用 cgo coredump 获得方法
发布时间:2020-12-16 18:24:39 所属栏目:大数据 来源:网络整理
导读:写一个错误的c程序 package dlsymimport "testing"func Test_intercept(t *testing.T) { Intercept("gethostbynamex00")} package dlsym// #cgo CFLAGS: -I.// #include stddef.h// #include "dlsym_wrapper.h"import "C"import "unsafe"func Intercept(sym
写一个错误的c程序package dlsym import "testing" func Test_intercept(t *testing.T) { Intercept("gethostbynamex00") } package dlsym // #cgo CFLAGS: -I. // #include <stddef.h> // #include "dlsym_wrapper.h" import "C" import "unsafe" func Intercept(symbol string) { ptr := unsafe.Pointer(&([]byte(symbol)[0])) C.intercept((*C.char)(ptr),C.size_t(len(symbol))) } #include <dlfcn.h> #include <stddef.h> #include <stdio.h> void intercept(char *symbol,size_t symbol_len) { symbol = NULL; // will cause SIGSEGV printf("%sn",symbol); fflush(stdout); } 编译测试为可执行文件go test -c github.com/taowen/go-lib c/dlsym # will produce executable dlsym.test 这个是用于分析coredump的时候获得符号表使用的。 执行测试,获得coredumpGOTRACEBACK=crash ./dlsym.test # produced /tmp/core_dlsym.test.29937 如果找不到coredump的位置,执行之前先设置好coredump的写出条件 echo '/tmp/core_%e.%p' | sudo tee /proc/sys/kernel/core_pattern ulimit -c unlimited # coredump can be any large 用gdb分析coredumpgdb dlsym.test /tmp/core_dlsym.test /tmp/core_dlsym.test.29937
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |