如何使用 MONO 进行线程转储?

发布于 2024-08-17 20:55:10 字数 165 浏览 7 评论 0原文

如何在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

迷你仙 2024-08-24 20:55:10

假设您使用的是 Linux/Unix,而不是 Windows,请向您的程序发送 SIGQUIT 信号。 完成

kill -QUIT $PID

这可以通过$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

kill -QUIT $PID

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.

累赘 2024-08-24 20:55:10

还可以使用 GDB 快速获取托管堆栈跟踪。执行gdb;如果您不是 root 或调试用户拥有的进程,请使用 sudo。

执行我从 Mono- 上的 调试 Mono 页面获得的脚本project.org:

handle SIGXCPU SIG33 SIG35 SIGPWR nostop noprint

define mono_stack
 set $mono_thread = mono_thread_current ()
 if ($mono_thread == 0x00)
   printf "No mono thread associated with this thread\n"
 else
   set $ucp = malloc (sizeof (ucontext_t))
   call (void) getcontext ($ucp)
   call (void) mono_print_thread_dump ($ucp)
   call (void) free ($ucp)
 end
end

如果您愿意,可以将这些命令放入 ~/.gdbinit 中,这样您就不必一直复制和粘贴。

现在附加到您的 PID:

attach 12345

请注意,整个过程现在已暂停,因此如果您在生产中执行此操作,建议编写脚本,以便尽可能快。

要获取堆栈跟踪,请执行上面定义的 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:

handle SIGXCPU SIG33 SIG35 SIGPWR nostop noprint

define mono_stack
 set $mono_thread = mono_thread_current ()
 if ($mono_thread == 0x00)
   printf "No mono thread associated with this thread\n"
 else
   set $ucp = malloc (sizeof (ucontext_t))
   call (void) getcontext ($ucp)
   call (void) mono_print_thread_dump ($ucp)
   call (void) free ($ucp)
 end
end

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:

attach 12345

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 use console 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 and thread 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文