How to Dump a .NET Core Application on Linux

后端 未结 4 1642
余生分开走
余生分开走 2021-01-07 19:12

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

相关标签:
4条回答
  • 2021-01-07 19:32

    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.

    0 讨论(0)
  • 2021-01-07 19:37

    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

    0 讨论(0)
  • 2021-01-07 19:39

    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/

    0 讨论(0)
  • 2021-01-07 19:41

    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

    0 讨论(0)
提交回复
热议问题