\u8fd8\u662f\u4ee5\u4e0a\u6587\u4e2d\u7684\u4f8b\u5b50\u4e3a\u4f8b\uff0c\u6211\u4eec\u901a\u8fc7\u8bbe\u7f6e GOTRACEBACK \u4e3a crash \u7ea7\u522b\u6765\u83b7\u53d6 core dump \u6587\u4ef6<\/p>\n
\r\n$ tree \r\n. \r\n\u2514\u2500\u2500 main.go \r\n$ ulimit -c unlimited \r\n$ go build main.go \r\n$ GOTRACEBACK=crash .\/main \r\n... \r\nAborted (core dumped) \r\n$ tree \r\n. \r\n\u251c\u2500\u2500 core \r\n\u251c\u2500\u2500 main \r\n\u2514\u2500\u2500 main.go \r\n$ ls -alh core \r\n-rw------- 1 slp slp 41M Oct 31 22:15 core \r\n<\/pre>\n\u6b64\u65f6\uff0c\u5728\u540c\u7ea7\u76ee\u5f55\u5f97\u5230\u4e86 core dump \u6587\u4ef6 core(\u6587\u4ef6\u540d\u3001\u5b58\u50a8\u8def\u5f84\u3001\u662f\u5426\u52a0\u4e0a\u8fdb\u7a0b\u53f7\u90fd\u53ef\u4ee5\u914d\u7f6e\u4fee\u6539)\u3002<\/p>\n
\u901a\u8fc7 dlv \u8c03\u8bd5\u5668\u6765\u8c03\u8bd5 core \u6587\u4ef6\uff0c\u6267\u884c\u547d\u4ee4\u683c\u5f0f dlv core \u53ef\u6267\u884c\u6587\u4ef6\u540d core\u6587\u4ef6<\/p>\n
\r\n$ dlv core main core \r\nType 'help' for list of commands. \r\n(dlv) \r\n<\/pre>\n\u547d\u4ee4 goroutines \u83b7\u53d6\u6240\u6709 goroutine \u76f8\u5173\u4fe1\u606f<\/p>\n
\r\n(dlv) goroutines \r\n* Goroutine 1 - User: .\/main.go:21 main.main (0x45b81a) (thread 18061) \r\n Goroutine 2 - User: \/usr\/local\/go\/src\/runtime\/proc.go:367 runtime.gopark (0x42ed96) [force gc (idle)] \r\n Goroutine 3 - User: \/usr\/local\/go\/src\/runtime\/proc.go:367 runtime.gopark (0x42ed96) [GC sweep wait] \r\n Goroutine 4 - User: \/usr\/local\/go\/src\/runtime\/proc.go:367 runtime.gopark (0x42ed96) [GC scavenge wait] \r\n[4 goroutines] \r\n(dlv)\r\n<\/pre>\nGoroutine 1 \u662f\u51fa\u95ee\u9898\u7684 goroutine (\u5e26\u6709 * \u4ee3\u8868\u5f53\u524d\u5e27)\uff0c\u901a\u8fc7\u547d\u4ee4 goroutine 1 \u5207\u6362\u5230\u5176\u6808\u5e27<\/p>\n
\r\n(dlv) goroutine 1 \r\nSwitched from 1 to 1 (thread 18061) \r\n(dlv) \r\n<\/pre>\n\u6267\u884c\u547d\u4ee4 bt(breakpoints trace) \u67e5\u770b\u5f53\u524d\u7684\u6808\u5e27\u8be6\u7ec6\u4fe1\u606f<\/p>\n
\r\n(dlv) bt \r\n0 0x0000000000454bc1 in runtime.raise \r\n at \/usr\/local\/go\/src\/runtime\/sys_linux_amd64.s:165 \r\n1 0x0000000000452f60 in runtime.systemstack_switch \r\n at \/usr\/local\/go\/src\/runtime\/asm_amd64.s:350 \r\n2 0x000000000042c530 in runtime.fatalthrow \r\n at \/usr\/local\/go\/src\/runtime\/panic.go:1250 \r\n3 0x000000000042c2f1 in runtime.throw \r\n at \/usr\/local\/go\/src\/runtime\/panic.go:1198 \r\n4 0x000000000043fa76 in runtime.sigpanic \r\n at \/usr\/local\/go\/src\/runtime\/signal_unix.go:742 \r\n5 0x000000000045b81a in main.Modify \r\n at .\/main.go:21 \r\n6 0x000000000045b81a in main.main \r\n at .\/main.go:25 \r\n7 0x000000000042e9c7 in runtime.main \r\n at \/usr\/local\/go\/src\/runtime\/proc.go:255 \r\n8 0x0000000000453361 in runtime.goexit \r\n at \/usr\/local\/go\/src\/runtime\/asm_amd64.s:1581 \r\n(dlv) \r\n<\/pre>\n\u901a\u8fc7 5 0x000000000045b81a in main.Modify \u53d1\u73b0\u4e86\u9519\u8bef\u4ee3\u7801\u6240\u5728\u51fd\u6570\uff0c\u6267\u884c\u547d\u4ee4 frame 5 \u8fdb\u5165\u51fd\u6570\u5177\u4f53\u4ee3\u7801<\/p>\n
\r\n(dlv) frame 5 \r\n> runtime.raise() \/usr\/local\/go\/src\/runtime\/sys_linux_amd64.s:165 (PC: 0x454bc1) \r\nWarning: debugging optimized function \r\nFrame 5: .\/main.go:21 (PC: 45b81a) \r\n 16: } \r\n 17: \r\n 18: func Modify() { \r\n 19: a := \"hello\" \r\n 20: b := String2Bytes(a) \r\n=> 21: b[0] = 'H' \r\n 22: } \r\n 23: \r\n 24: func main() { \r\n 25: Modify() \r\n 26: } \r\n(dlv) \r\n<\/pre>\n\u81ea\u6b64\uff0c\u7834\u6848\u4e86\uff0c\u95ee\u9898\u5c31\u51fa\u5728\u4e86\u64c5\u81ea\u4fee\u6539 string \u5e95\u5c42\u503c\u3002<\/p>\n
Mac \u4e0d\u80fd\u4f7f\u7528<\/strong><\/div>\n\u6709\u4e00\u70b9\u9700\u8981\u6ce8\u610f\uff0c\u4e0a\u6587 core dump \u751f\u6210\u7684\u4f8b\u5b50\uff0c\u6211\u662f\u5728 linux \u7cfb\u7edf\u4e0b\u5b8c\u6210\u7684\uff0cmac amd64 \u7cfb\u7edf\u6ca1\u6cd5\u5f04(\u5f88\u6c14\uff0c\u5bb3\u6211\u6298\u817e\u4e86\u4e24\u4e2a\u665a\u4e0a)\u3002<\/p>\n
\u8fd9\u662f\u7531\u4e8e mac \u7cfb\u7edf\u4e0b\u7684 Go \u9650\u5236\u4e86\u751f\u6210 core dump \u6587\u4ef6\uff0c\u8fd9\u4e2a\u5728 Go \u6e90\u7801 src\/runtime\/signal_unix.go \u4e2d\u6709\u76f8\u5173\u8bf4\u660e\u3002<\/p>\n
\r\n\/\/go:nosplit \r\nfunc crash() { \r\n \/\/ OS X core dumps are linear dumps of the mapped memory, \r\n \/\/ from the first virtual byte to the last, with zeros in the gaps. \r\n \/\/ Because of the way we arrange the address space on 64-bit systems, \r\n \/\/ this means the OS X core file will be >128 GB and even on a zippy \r\n \/\/ workstation can take OS X well over an hour to write (uninterruptible). \r\n \/\/ Save users from making that mistake. \r\n if GOOS == \"darwin\" && GOARCH == \"amd64\" { \r\n return \r\n } \r\n \r\n dieFromSignal(_SIGABRT) \r\n} \r\n<\/pre>\n\u603b\u7ed3<\/strong><\/div>\ncore dump \u6587\u4ef6\u662f\u64cd\u4f5c\u7cfb\u7edf\u63d0\u4f9b\u7ed9\u6211\u4eec\u7684\u4e00\u628a\u5229\u5668\uff0c\u5b83\u662f\u7a0b\u5e8f\u610f\u5916\u7ec8\u6b62\u65f6\u4ea7\u751f\u7684\u5185\u5b58\u5feb\u7167\u3002\u5229\u7528 core dump\uff0c\u6211\u4eec\u53ef\u4ee5\u5728\u7a0b\u5e8f\u5d29\u6e83\u540e\u66f4\u597d\u5730\u6062\u590d\u4e8b\u6545\u73b0\u573a\uff0c\u4e3a\u6545\u969c\u6392\u67e5\u4fdd\u9a7e\u62a4\u822a\u3002<\/p>\n
\u5f53\u7136\uff0ccore dump \u6587\u4ef6\u7684\u751f\u6210\u4e5f\u662f\u6709\u5f0a\u7aef\u7684\u3002core dump \u6587\u4ef6\u8f83\u5927\uff0c\u5982\u679c\u7ebf\u4e0a\u670d\u52a1\u672c\u8eab\u5185\u5b58\u5360\u7528\u5c31\u5f88\u9ad8\uff0c\u90a3\u5728\u751f\u6210 core dump \u6587\u4ef6\u4e0a\u7684\u5185\u5b58\u4e0e\u65f6\u95f4\u5f00\u9500\u90fd\u4f1a\u5f88\u5927\u3002\u53e6\u5916\uff0c\u6211\u4eec\u5f80\u5f80\u4f1a\u5e03\u7f6e\u670d\u52a1\u5b88\u62a4\u8fdb\u7a0b\uff0c\u5982\u679c\u6211\u4eec\u7684\u7a0b\u5e8f\u9891\u7e41\u5d29\u6e83\u548c\u91cd\u542f\uff0c\u90a3\u4f1a\u751f\u6210\u5927\u91cf\u7684 core dump \u6587\u4ef6(\u8bbe\u5b9a\u4e86core+pid \u547d\u540d\u89c4\u5219)\uff0c\u4ea7\u751f\u78c1\u76d8\u6253\u6ee1\u7684\u98ce\u9669(\u5982\u679c\u653e\u5f00\u4e86\u5185\u6838\u9650\u5236 ulimit -c unlimited)\u3002<\/p>\n
\u6700\u540e\uff0c\u5982\u679c\u62c5\u5fc3\u9519\u8bef\u65e5\u5fd7\u4e0d\u80fd\u5e2e\u52a9\u6211\u4eec\u5b9a\u4f4d Go \u4ee3\u7801\u95ee\u9898\uff0c\u6211\u4eec\u53ef\u4ee5\u4e3a\u5b83\u5f00\u542f core dump \u529f\u80fd\uff0c\u5728 hotfix \u4e0a\u589e\u52a0\u5947\u5175\u3002\u5bf9\u4e8e\u6709\u5b88\u62a4\u8fdb\u7a0b\u7684\u670d\u52a1\uff0c\u5efa\u8bae\u8bbe\u7f6e\u597d ulimt -c \u5927\u5c0f\u9650\u5236\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"
\u6ca1\u6709\u6d88\u706d\u4e00\u5207\u7684\u94f6\u5f39\uff0c\u4e5f\u6ca1\u6709\u53ef\u4ee5\u4fdd\u8bc1\u6c38\u4e0d\u51fa\u9519\u7684\u7a0b\u5e8f\u3002\u6211\u4eec\u5e94\u5f53\u5982\u4f55\u6355\u6349 Go \u7a0b\u5e8f\u9519\u8bef?\u6211\u60f3\u540c\u5b66\u4eec\u7684\u7b2c\u4e00\u53cd\u5e94\u662f\uff1a\u6253 […]<\/p>\n","protected":false},"author":1898,"featured_media":229666,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[765],"class_list":["post-229663","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread","tag-go"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/229663","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1898"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=229663"}],"version-history":[{"count":1,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/229663\/revisions"}],"predecessor-version":[{"id":229665,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/229663\/revisions\/229665"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/229666"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=229663"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=229663"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=229663"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}