go - GDB 中 goroutine 的展开堆栈,用于 golang exe 的核心转储

标签 go gdb core

我需要分析一些用 Golang 编写的服务器的核心转储文件。但我无法使用 GDB 展开堆栈信息(甚至一点点有用的信息)。

比如我有一个main.go,它的代码是:

package main

func main(){
    panic("stupid")
}

然后我使用以下方法获取核心文件:

ulimit -c unlimited
GOTRACEBACK=crash ./main

然后我运行 gdb main core。在 gdb 中,如下所示。

xxx@ubuntu:/tmp/crash$ gdb main core
GNU gdb (Ubuntu 7.12.50.20170314-0ubuntu1.1) 7.12.50.20170314-git
Copyright (C) 2017 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from main...done.
[New LWP 5735]
[New LWP 5736]
[New LWP 5738]
[New LWP 5739]
[New LWP 5737]
Core was generated by `./main'.
Program terminated with signal SIGABRT, Aborted.
#0  runtime.raise () at /usr/lib/go-1.7/src/runtime/sys_linux_amd64.s:110
110        RET
[Current thread is 1 (LWP 5735)]
(gdb) source /usr/share/go-1.7/src/runtime/runtime-gdb.py
Loading Go Runtime support.
(gdb) info goroutines
* 1 running  runtime.systemstack_switch
  2 waiting  runtime.gopark
  3 waiting  runtime.gopark
(gdb) goroutine 1 bt
Python Exception <class 'gdb.error'> You can't do that without a process to debug.: 
Error occurred in Python command: You can't do that without a process to debug.
(gdb) goroutine 1 info r
Python Exception <class 'gdb.error'> You can't do that without a process to debug.: 
Error occurred in Python command: You can't do that without a process to debug.

我找到了 issue在这里,但它没有给我解决方案,所以任何人都可以告诉我如何查看 goroutine 信息,如核心转储中的堆栈跟踪?感谢任何解决方案,谢谢!

最佳答案

不幸的是,gdb 中的 golang 支持非常薄弱。通常最好使用 delve 调试器。

dlv core ./hello core.546
> bt
> ls

delve 调试器的命令名称是 dlv。使用 bt 你会得到一个回溯,而 ls 会列出代码/程序集的相应部分。

有关调试器的信息可以在 https://github.com/derekparker/delve 找到

关于go - GDB 中 goroutine 的展开堆栈,用于 golang exe 的核心转储,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45855414/

相关文章:

windows - Go 编译器是否有窗口设置选项?

Golang token 验证错误

python - 如何使用 Python 从 gdb 访问 C++ 程序的变量

java - while 循环问题

java - 如何使用接口(interface)引用保护匿名类的创建

go - golang 中的结构概念需要帮助

operators - 运算符 '<<' 和 '>>' 有什么作用?

c++ - 当存在多个相同名称的类型时,在 gdb 中按名称指定正确的类型

linux - 无法分析多线程应用程序的核心转储问题.........(需要帮助)

tomcat - 如何限制对 SOLR 特定页面(例如 "Core Admin")的访问?