Skip to content
This repository has been archived by the owner on Feb 9, 2024. It is now read-only.

Latest commit

 

History

History
140 lines (95 loc) · 8.09 KB

README.md

File metadata and controls

140 lines (95 loc) · 8.09 KB

This repository is deprecated in favor of the Sentry NuGet package.

sentry-native is bundled by default on Sentry and can capture native crashes for AOT compiled .NET apps.

Sentry

Sentry Minidump SDK for .NET

NuGet Downloads Discord Chat

This repository bundles sentry-native with Google's crashpad and distribute via NuGet with a .NET API to initialize. It allows capturing minidumps of .NET applications caused by native libraries or the .NET runtime itself.

Current supported platforms are: Windows, macOS and Linux all on x64. We can extend this as needed.

At this time this minimum frameworks supported are .NET Standard 2.1 or .NET Framework 4.7. This is due to the current bindings generated by CppSharp. We can likely lower it to .NET Standard 2.0 and .NET Framework 4.6.1 if there's demand.

If this is useful to you, help us in building this on Discord, #dotnet.

Processed Minidumps from Windows, macOS and Linux

minidumps from windows macOS and Linux

How does it work?

When Init is called, the sentry-native SDK initializes crashpad which monitors the process for crashes. In the event of a crash, a minidump is generated and uploaded to Sentry. Sentry will notify you with a few seconds of the crash and you can inspect the event in Sentry.

By default Sentry throws away the minidump after processing it.
If you'd like to keep the minidump to inspect on Visual Studio, you need to opt-in. Sentry has extensive docs on attachments, minidumps and data scrubbing.

A .NET 5 crash on macOS

dotnet native crash

Debug Symbols

In order to stack unwind and symbolicate the minidump, Sentry needs access the symbols.

You can upload the symbols of your app with sentry-cli.

Alternatively you can add more Symbol Servers to lookup via your project settings in case you host your own.

.NET provides debug symbols of all official releases on a Microsoft symbol server and Sentry includes it out of the box. Currently it's not probing it though so you can add it yourself: The endpoint is: http://msdl.microsoft.com/download/symbols, with SSQP layout. Sentry will resolve these automatically soon so you won't need to add it yourself.

Run The Sample

To test it out, build the sample project and start the executable from the bin folder.

Set your own DSN on Program.cs first so the test event goes to yours Sentry dashboard.

The example below is for macOS (osx-x64). If you're on Windows, use win-x64. For Linux, linux-x64:

cd sample/Sentry.Minidump.Sample
dotnet build -c Release -r osx-x64

cd bin/Release/net5.0/osx-x64

dotnet Sentry.Minidump.Sample.dll

Example:

➜  osx-x64 git:(main) ✗ dotnet Sentry.Minidump.Sample.dll
[sentry] INFO using database path "/Users/bruno/git/sentry-dotnet-native/sample/Sentry.Minidump.Sample/bin/Release/net5.0/osx-x64/.sentry-native"
[sentry] DEBUG starting backend
[sentry] DEBUG starting crashpad backend with handler "/Users/bruno/git/sentry-dotnet-native/sample/Sentry.Minidump.Sample/bin/Release/net5.0/osx-x64/crashpad_handler"
[sentry] DEBUG using minidump url "http://sentry.garcia.in:80/api/5428537/minidump/?sentry_client=sentry.native/0.4.4&sentry_key=80aed643f81249d4bed3e30687b310ab"
[sentry] INFO started crashpad client handler
Unhandled exception. System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
   at System.Runtime.InteropServices.Marshal.ReadInt32(IntPtr ptr, Int32 ofs)
   at System.Runtime.InteropServices.Marshal.ReadInt32(IntPtr ptr)
   at Sentry.Minidump.Sample.Program.Main(String[] args) in /Users/bruno/git/sentry-dotnet-native/sample/Sentry.Minidump.Sample/Program.cs:line 16
[69212:36013020:20201227,230059.285955:WARNING process_memory_mac.cc:93] mach_vm_read(0x7ffee9bf8000, 0x2000): (os/kern) invalid address (1)
[1]    69205 abort      dotnet Sentry.Minidump.Sample.dll

A .NET 5 crash on Windows

dotnet-minidump-windows

Download the minidump

download-minidump

Note On Platform Requirement

This package bundles an executable called crashpad_handler (or crashpad_handler.exe on Windows). This process creates a memory dump of your .NET process and uploads to Sentry. That means the executable needs to be deployed with your app, and needs +x access in order to get started (on macOS and Linux). NuGet packaging makes sure the file is actually copied to the output directory, and the SDK will attempt to set +x when running on macOS and Linux. You can opt out of that with AddExecuteFlagCrashpadHandler=false but unless you set +x yourself, no minidump will be created.

Build from source

The result of building sentry-native on Windows, macOS and Linux for x64 is already checked in, and the CppSharp binding generated too. So you can just dotnet pack if you only want to change the .NET solution. If you want to modify sentry-native, you'll need to regenerate the CppSharp bindings. There are scripts for everything in this repository.

Requirements:

  • .NET 5 SDK
  • Whatever is required to build sentry-native (depends on platform)
  • Whatever is required to build CppSharp (depends on platform)

If you want to build all artifacts from source, the steps involved are:

Init submodules

Run setup.sh on macOS or Linux or setup.cmd on Windows This will initialize all git submodules.

Build native dependencies

Under sentry-native: Run build.sh on macOS or Linux or build.cmd.

This will build sentry-native, and copy the generated native library and the crashpad_handler to the relevant folder under sentry-native/sentry-native-artifacts. These are bundled in the NuGet package.

On Linux, make sure to install openssl lib, otherwise crashpad will fail to compile. For example, on Ubuntu: sudo apt-get install libssl-dev

Resources

  • Documentation
  • Forum
  • Discord Chat
  • Stack Overflow
  • Twitter Follow