如何在 Linux 上转储 .NET Core 应用程序 [英] How to Dump a .NET Core Application on Linux
问题描述
我有一个已移植到 .NET Core 的 .NET 应用程序.我正在 Ubuntu 14.04 上测试它.
I have a .NET application that I have ported to .NET Core. I am testing it on Ubuntu 14.04.
我想知道如何在程序崩溃时获取 .dmp 文件或 Linux 等效文件.我调用 Environment.FailFast
但据我所知,这不会像在 Windows 上那样生成 .dmp 文件.根据 这种情况 Environment.FailFast
应该创建一个转储,但如果是我找不到.
I am trying to figure out how to get a .dmp file or the Linux equivalent when the program crashes. I call Environment.FailFast
but as far as I can tell this doesn't generate a .dmp file like it does on Windows. Acording to this case Environment.FailFast
should be creating a dump but if it is I can't find it.
此外,我尝试使用 gcore
手动创建转储.这有效,但是生成转储需要很长时间(我的应用程序不是那么大)并且我无法在 gdb 中获得正确的调用堆栈,因为当我将 gdb 指向我的应用程序 dll 时它无法识别它.
In addition I have tried manually creating a dump using gcore
. This works however it takes a long time to generate the dump (my application isn't that big) and I am unable to get the correct callstacks in gdb after the fact as when I point gdb to my application dll it doesn't recognize it.
在 Linux 上获取 .NET Core 应用程序转储的最佳方法是什么?
What it he best way to get a dump of a .NET Core application on Linux?
谢谢!
推荐答案
linux coredumps 的生成由 /proc/sys/kernel/core_pattern
中的内容定义.如果某些信号(例如 SIGSEGV
或 SIGQUIT
)导致进程终止,则进程内存的映像基本上会写入该文件.如果它以管道符号 |
开头,则可以将其流式传输到执行转储分析的应用程序中.它记录在这里:http://man7.org/linux/man-pages/man5/core.5.html
The generation of linux coredumps is defined by what's in /proc/sys/kernel/core_pattern
. If certain signals (e.g. SIGSEGV
or SIGQUIT
) cause a process to terminate, an image of the process's memory is basically written into that file. If it starts with a pipe-symbol |
, it can be streamed into an application which does dump analysis. It's documented here: http://man7.org/linux/man-pages/man5/core.5.html
如果你这样配置:
echo coredump > /proc/sys/kernel/core_pattern
它会将名为 coredump
的文件写入当前目录.
it will write a file named coredump
into the current directory.
如果你这样配置:
echo "/tmp/cores/core.%e.%p.%h.%t" > /proc/sys/kernel/core_pattern
它将创建一个类似于 /tmp/cores/core.bash.8539.drehbahn-mbp.1236975953
的文件(参见 https://sigquit.wordpress.com/2009/03/13/the-core-pattern/)
It will create a file like /tmp/cores/core.bash.8539.drehbahn-mbp.1236975953
(see https://sigquit.wordpress.com/2009/03/13/the-core-pattern/)
正如其他人所建议的,还要设置 ulimit -S -c unlimited
以允许任何大小的核心转储.
As others suggested, also set ulimit -S -c unlimited
to allow coredumps of any size.
这是一篇博客文章,展示了如何在 linux 下创建和分析 .NET Core coredumps:http://blogs.microsoft.co.il/sasha/2017/02/26/analyzing-a-net-core-core-dump-on-linux/
Here is a blog-post which shows how to create and analyze .NET Core coredumps under linux: http://blogs.microsoft.co.il/sasha/2017/02/26/analyzing-a-net-core-core-dump-on-linux/
这篇关于如何在 Linux 上转储 .NET Core 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!