如何使用 MONO 进行线程转储?
如何在使用 MONO 运行的挂起应用程序中显示线程(堆栈跟踪)?
我知道我可以使用 Managed Stack Explorer (MSE) 在 .NET 中完成此操作。因为应用程序仅在 MONO 下挂起,所以我需要使用 MONO 来执行此操作。
或者还有其他想法如何找到悬挂的地方?
How can I show the threads (stacktraces) in a hanging application that run with MONO?
I know that I can do it in .NET with the Managed Stack Explorer (MSE). Because the application hang only with MONO that I need to do it with MONO.
Or there are any other ideas how I can find the place of hanging?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
假设您使用的是 Linux/Unix,而不是 Windows,请向您的程序发送 SIGQUIT 信号。 完成
这可以通过$PID 是程序的 pid 来 。然后 Mono 会将所有线程的堆栈跟踪转储到标准输出。请注意,尽管此后进程仍保持运行,但您不应期望它保持可用/稳定。
请参阅 http://en.wikipedia.org/wiki/SIGQUIT 了解一些背景信息。
注意:线程转储不会在您运行
kill
命令的终端窗口中打印出来。它将出现在 mono 进程的 stderr 中。Assuming you're on Linux/Unix, not Windows, send a SIGQUIT signal to your program. This can be done with
where $PID is the pid of your program. Mono will then dump stack traces of all threads to stdout. Note that although the process stays running after this, you should not expect it to remain usable/stable.
See http://en.wikipedia.org/wiki/SIGQUIT for some background.
Note: The thread dump will not print out in the terminal window where you ran the
kill
command. It will appear in the stderr of the mono process.还可以使用 GDB 快速获取托管堆栈跟踪。执行gdb;如果您不是 root 或调试用户拥有的进程,请使用 sudo。
执行我从 Mono- 上的 调试 Mono 页面获得的脚本project.org:
如果您愿意,可以将这些命令放入
~/.gdbinit
中,这样您就不必一直复制和粘贴。现在附加到您的 PID:
请注意,整个过程现在已暂停,因此如果您在生产中执行此操作,建议编写脚本,以便尽可能快。
要获取堆栈跟踪,请执行上面定义的
mono_stack
。请注意,您不会在 gdb 中看到输出,而是在 stdout 中看到输出。如果您使用 upstart 运行流程,则只需编辑 upstart 作业即可使用控制台日志
将其记录到/var/log/upstart
。然而,您可能对主线程以外的另一个线程感兴趣。为此,请执行
infothreads
获取线程列表,并执行thread2
切换到线程 #2。有关线程调试的更多信息,请参阅 GDB 文档中的调试具有多个线程的程序 。完成后,执行
quit
,您的程序将继续工作。It is also possible to quickly grab a managed stack trace using GDB. Execute
gdb
; use sudo if you're not root or debugging a process owned by your user.Execute this script which I got from the debugging Mono page on mono-project.org:
If you like you can drop these commands in your
~/.gdbinit
so you don't have to copy and paste all the time.Now attach to your PID:
Note that the whole process is now paused so if you're doing this in production it is advisable to script this so it's as fast as possible.
To get your stack trace, execute
mono_stack
as defined above. Note that you won't see the output in gdb but in stdout. If you run your process with upstart you can just edit the upstart job to useconsole log
to log it to/var/log/upstart
.You may be interested in another thread than your main thread however. To do so, execute
info threads
to get your thread list andthread 2
to switch to thread #2. For more information on thread debugging, see debugging programs with multiple threads in the GDB docs.Once you're done, execute
quit
, and your program will continue working.