英文:
unwind stack for goroutine in GDB for a golang exe's core dump
问题
我需要分析一个使用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信息吗?任何解决方案都将不胜感激,谢谢!
英文:
I need analyze some core dump file for a server written in Golang. But I can't unwind the stack info(or even a little bit useful info) using GDB.
For example,I have a main.go, its code is:
package main
func main(){
panic("stupid")
}
And I use the following get the core file:
ulimit -c unlimited
GOTRACEBACK=crash ./main
And then I run gdb main core
.And in the gdb, the things like the following.
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.
I find issue here but it doesn't give me a solution, so anyone can tell me how can I view the goroutine info like stack trace in a core dump? Any solution is appreciated, thanks!
答案1
得分: 1
很遗憾,gdb中对于golang的支持相对较弱。通常最好使用delve调试器。
dlv core ./hello core.546
> bt
> ls
delve调试器的命令是dlv。使用bt可以获取回溯信息,ls可以列出代码/汇编的相应部分。
有关调试器的信息可以在https://github.com/derekparker/delve找到。
英文:
Unfortunately the golang support in gdb is pretty weak. Generally it is better to use the delve debugger.
dlv core ./hello core.546
> bt
> ls
The command name for the delve debugger is dlv. With bt you get a backtrace and ls list the corresponding parts of the code/assembly.
Information about the debugger can be found at https://github.com/derekparker/delve
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论