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

Commit

Permalink
copy based on runtimeidentifier
Browse files Browse the repository at this point in the history
  • Loading branch information
bruno-garcia committed Dec 28, 2020
1 parent 9fdc668 commit 43d9982
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 35 deletions.
30 changes: 17 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,6 @@ If you'd like to keep the minidump to inspect on Visual Studio, you need to opt-
# A .NET 5 crash on macOS
![dotnet native crash](.github/dotnet-native-crash.png)

# A .NET 5 crash on Windows
![dotnet-minidump-windows](.github/dotnet-minidump-windows.png)

# Download the minidump of a crash on Linux
![download-minidump](.github/download-minidump.png)

# Debug Symbols

In order to stack unwind and symbolicate the minidump, Sentry needs access the symbols.
Expand All @@ -51,17 +45,14 @@ Alternatively you can [add more Symbol Servers to lookup via your project settin
.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.

# 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.
# Run The Sample

To test it, build the [sample](sample/Sentry.Minidump.Sample) project and start the executable from the bin folder:
To test it out, build the [sample](sample/Sentry.Minidump.Sample) project and start the executable from the bin folder.

> Set your own DSN on [Program.cs](sample/Sentry.Minidump.Sample/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
Expand All @@ -87,6 +78,19 @@ Unhandled exception. System.AccessViolationException: Attempted to read or write
[1] 69205 abort dotnet Sentry.Minidump.Sample.dll
```

# A .NET 5 crash on Windows
![dotnet-minidump-windows](.github/dotnet-minidump-windows.png)

# Download the minidump
![download-minidump](.github/download-minidump.png)

# 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.
Expand Down
6 changes: 3 additions & 3 deletions src/Sentry.Minidump/Sentry.Minidump.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Configurations>Release;Debug</Configurations>
<Platforms>x64;x86</Platforms>
<Version>0.1.1</Version>
<Version>0.1.2</Version>
<Deterministic>true</Deterministic>

<Authors>Sentry Team and Contributors</Authors>
<Company>Sentry.io</Company>
<Product>Sentry</Product>
<Description>Official SDK to capture Minidumps with Sentry - Open-source error tracking that helps developers monitor and fix crashes in real time.</Description>

<PackageTags>Minidump;Sentry;GetSentry;Error-Reporting;Crash-Reporting;Exception-Handling</PackageTags>
<PackageTags>Native;Minidump;Sentry;GetSentry;Error-Reporting;Crash-Reporting;Exception-Handling</PackageTags>
<RepositoryType>git</RepositoryType>
<RepositoryRoot>$(MSBuildThisFileDirectory)</RepositoryRoot>
<RepositoryUrl>https://github.com/getsentry/sentry-dotnet-minidump</RepositoryUrl>
Expand All @@ -33,7 +33,7 @@
</PropertyGroup>

<ItemGroup>
<None Include="../../.github/sentry-nuget.png" Pack="true" PackagePath=""/>
<None Include="../../.github/sentry-nuget.png" Pack="true" PackagePath="" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.0" PrivateAssets="All" />
</ItemGroup>
Expand Down
48 changes: 41 additions & 7 deletions src/Sentry.Minidump/SentryMinidump.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ public static void Init(Action<SentryOptions> configure)
configure?.Invoke(o);
if (o.Dsn is null)
{
if (o.Debug)
{
Console.WriteLine("Sentry Native will be disabled: Dsn not provided.");
}
o.Log("Sentry Native will be disabled: Dsn not provided.");
return;
}

Expand All @@ -35,11 +32,38 @@ public static void Init(Action<SentryOptions> configure)
}
else
{
if (o.AddExecuteFlagCrashpadHandler)
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
Permission.SetExecute(Path.GetFullPath("crashpad_handler"));
crashpadHandler = "crashpad_handler_osx";
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
crashpadHandler = "crashpad_handler_linux";
}
}

if (!File.Exists(crashpadHandler))
{
o.Log("Can't find crashpad handler {0}", crashpadHandler);

var extraPath = Path.Combine(Path.GetDirectoryName(typeof(SentryMinidump).Assembly.Location) ?? ".", crashpadHandler);
if (!File.Exists(extraPath))
{
o.Log("Couldn't find crashpad handler at {0}. Will not initialize sentry-native.", extraPath);
return;
}

o.Log("Found at {0}", extraPath);
crashpadHandler = extraPath;
}

if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && o.AddExecuteFlagCrashpadHandler)
{
o.Log("Setting the execute flag to: {0}", crashpadHandler);
Permission.SetExecute(Path.GetFullPath(crashpadHandler));
}

o.Log("Initialize sentry-native with: {0}.", crashpadHandler);
SentryOptionsSetHandlerPath(options, crashpadHandler);
SentryInit(options);
}
Expand All @@ -55,7 +79,17 @@ public class SentryOptions
/// </summary>
public bool AddExecuteFlagCrashpadHandler { get; set; } = true;
}


internal static class SentryOptionsExtension
{
public static void Log(this SentryOptions o, string message, params object[] args)
{
if (o.Debug)
{
Console.WriteLine(message, args);
}
}
}
internal static class Permission
{
[DllImport("libc", SetLastError = false, EntryPoint = "chmod")]
Expand Down
6 changes: 3 additions & 3 deletions src/Sentry.Minidump/build/net47/Sentry.Minidump.targets
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

<ItemGroup>
<_SentryNativeFile Include="$(MSBuildThisFileDirectory)..\..\CppSharp.*" />
<_SentryNativeFile Include="$(MSBuildThisFileDirectory)..\..\runtimes\osx-x64\native\*" />
<_SentryNativeFile Include="$(MSBuildThisFileDirectory)..\..\runtimes\win-x64\native\*" />
<_SentryNativeFile Include="$(MSBuildThisFileDirectory)..\..\runtimes\linux-x64\native\*" />
<_SentryNativeFile Include="$(MSBuildThisFileDirectory)..\..\runtimes\osx-x64\native\*" Condition="'$(Runtimeidentifier)' == '' or '$(Runtimeidentifier)' == 'osx-x64'" />
<_SentryNativeFile Include="$(MSBuildThisFileDirectory)..\..\runtimes\win-x64\native\*" Condition="'$(Runtimeidentifier)' == '' or '$(Runtimeidentifier)' == 'win-x64'" />
<_SentryNativeFile Include="$(MSBuildThisFileDirectory)..\..\runtimes\linux-x64\native\*" Condition="'$(Runtimeidentifier)' == '' or '$(Runtimeidentifier)' == 'linux-x64'" />
<Content Include="@(_SentryNativeFile)">
<Link>%(Dir)%(Filename)%(Extension)</Link>
<Visible>False</Visible>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

<ItemGroup>
<_SentryNativeFile Include="$(MSBuildThisFileDirectory)..\..\CppSharp.*" />
<_SentryNativeFile Include="$(MSBuildThisFileDirectory)..\..\runtimes\osx-x64\native\*" />
<_SentryNativeFile Include="$(MSBuildThisFileDirectory)..\..\runtimes\win-x64\native\*" />
<_SentryNativeFile Include="$(MSBuildThisFileDirectory)..\..\runtimes\linux-x64\native\*" />
<_SentryNativeFile Include="$(MSBuildThisFileDirectory)..\..\runtimes\osx-x64\native\*" Condition="'$(Runtimeidentifier)' == '' or '$(Runtimeidentifier)' == 'osx-x64'" />
<_SentryNativeFile Include="$(MSBuildThisFileDirectory)..\..\runtimes\win-x64\native\*" Condition="'$(Runtimeidentifier)' == '' or '$(Runtimeidentifier)' == 'win-x64'" />
<_SentryNativeFile Include="$(MSBuildThisFileDirectory)..\..\runtimes\linux-x64\native\*" Condition="'$(Runtimeidentifier)' == '' or '$(Runtimeidentifier)' == 'linux-x64'" />
<Content Include="@(_SentryNativeFile)">
<Link>%(Dir)%(Filename)%(Extension)</Link>
<Visible>False</Visible>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

<ItemGroup>
<_SentryNativeFile Include="$(MSBuildThisFileDirectory)..\..\CppSharp.*" />
<_SentryNativeFile Include="$(MSBuildThisFileDirectory)..\..\runtimes\osx-x64\native\*" />
<_SentryNativeFile Include="$(MSBuildThisFileDirectory)..\..\runtimes\win-x64\native\*" />
<_SentryNativeFile Include="$(MSBuildThisFileDirectory)..\..\runtimes\linux-x64\native\*" />
<_SentryNativeFile Include="$(MSBuildThisFileDirectory)..\..\runtimes\osx-x64\native\*" Condition="'$(Runtimeidentifier)' == '' or '$(Runtimeidentifier)' == 'osx-x64'" />
<_SentryNativeFile Include="$(MSBuildThisFileDirectory)..\..\runtimes\win-x64\native\*" Condition="'$(Runtimeidentifier)' == '' or '$(Runtimeidentifier)' == 'win-x64'" />
<_SentryNativeFile Include="$(MSBuildThisFileDirectory)..\..\runtimes\linux-x64\native\*" Condition="'$(Runtimeidentifier)' == '' or '$(Runtimeidentifier)' == 'linux-x64'" />
<Content Include="@(_SentryNativeFile)">
<Link>%(Dir)%(Filename)%(Extension)</Link>
<Visible>False</Visible>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

<ItemGroup>
<_SentryNativeFile Include="$(MSBuildThisFileDirectory)..\..\CppSharp.*" />
<_SentryNativeFile Include="$(MSBuildThisFileDirectory)..\..\runtimes\osx-x64\native\*" />
<_SentryNativeFile Include="$(MSBuildThisFileDirectory)..\..\runtimes\win-x64\native\*" />
<_SentryNativeFile Include="$(MSBuildThisFileDirectory)..\..\runtimes\linux-x64\native\*" />
<_SentryNativeFile Include="$(MSBuildThisFileDirectory)..\..\runtimes\osx-x64\native\*" Condition="'$(Runtimeidentifier)' == '' or '$(Runtimeidentifier)' == 'osx-x64'" />
<_SentryNativeFile Include="$(MSBuildThisFileDirectory)..\..\runtimes\win-x64\native\*" Condition="'$(Runtimeidentifier)' == '' or '$(Runtimeidentifier)' == 'win-x64'" />
<_SentryNativeFile Include="$(MSBuildThisFileDirectory)..\..\runtimes\linux-x64\native\*" Condition="'$(Runtimeidentifier)' == '' or '$(Runtimeidentifier)' == 'linux-x64'" />
<Content Include="@(_SentryNativeFile)">
<Link>%(Dir)%(Filename)%(Extension)</Link>
<Visible>False</Visible>
Expand Down

0 comments on commit 43d9982

Please sign in to comment.