26
votes

I have a .NET application that I have ported to .NET Core. I am testing it on Ubuntu 14.04.

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.

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.

What it he best way to get a dump of a .NET Core application on Linux?

Thanks!

4
Do you have an entry in /var/crash? It should create an entry there when an application crashes.Mihail Stancescu
@MihailStancescu nope, /var/crash is empty.shortspider
@MihailStancescu I didn't see any link to say that folder /var/crash will be the place for dump, could you clarify?Shawn

4 Answers

5
votes

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

If you configure it like that:

   echo coredump > /proc/sys/kernel/core_pattern

it will write a file named coredump into the current directory.

If you configure it like that:

   echo "/tmp/cores/core.%e.%p.%h.%t" > /proc/sys/kernel/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/)

As others suggested, also set ulimit -S -c unlimited to allow coredumps of any size.

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/

2
votes

you want a core dump, this is built into the OS.

first ulimit -Sc unlimited as the user you want to run the process as so allow creating a core file of any size. Then kill -4 <pid>

This should generate the core dump. It should probably be in the directory where the process was run from.

If you can't login as the user the application runs as, you will need to put this into limits.conf.

2
votes

Good news!: Now you can install a tool to get the dump automatically.

First you run dotnet tool install -g dotnet-dump then you can dotnet-dump [-h|--help] [--version] <command>

For more info and examples see: https://docs.microsoft.com/en-us/dotnet/core/diagnostics/dotnet-dump

-1
votes

I can get core dump by Using Environment.FailFast("core dump") in my C# code. Maybe you need to set core dump size and location with ulimit -c unlimited and echo coredump > /proc/sys/kernel/core_pattern first.

[xxx/tmp]$ ls core*

core.dotnet.10470