getsentry / sentry-dotnet

Sentry SDK for .NET
https://docs.sentry.io/platforms/dotnet
MIT License
575 stars 206 forks source link

logcat.log is not attached to unhandled event (SIGSEGV Segfault) #3461

Open espenrl opened 6 days ago

espenrl commented 6 days ago

Package

Sentry.Maui

.NET Flavor

.NET

.NET Version

8.0.6

OS

Android

SDK Version

4.7.0

Self-Hosted Sentry Version

No response

Steps to Reproduce

options.Android.LogCatIntegration = LogCatIntegrationType.Unhandled;

I don't know how to provoke SIGSEGV Segfault.

Expected Result

It is expected that the error event has an attachment logcat.log.

Actual Result

There are no attachments to the event.

espenrl commented 6 days ago

This is one of many of these cases logged to Sentry Cloud. I've redacted it, but left the important bits.

{
  "exception": {
    "values": [
      {
        "mechanism": {
          "handled": false,
          "meta": {
            "signal": {
              "name": "SIGSEGV",
              "number": 11
            }
          },
          "synthetic": true,
          "type": "signalhandler"
        },
        "raw_stacktrace": {
          "frames": [
            {
              "data": {
                "orig_in_app": -1
              },
              "in_app": false,
              "instruction_addr": "0x7270b58418"
            }
          ],
          "registers": {
            "fp": "0x7213c09750",
            "lr": "0x7324b4c84c",
            "pc": "0x7270b58418",
            "sp": "0x7213c09750",
            "x0": "0x7242390a90",
            "x1": "0x72423908b0",
            "x10": "0x1",
            "x11": "0x1",
            "x12": "0xd61f0200",
            "x13": "0xb",
            "x14": "0xb4000074ca2cbf88",
            "x15": "0xb4000074cc6bb5d8",
            "x16": "0x7270b58418",
            "x17": "0x0",
            "x18": "0x721351c000",
            "x19": "0x0",
            "x2": "0x12",
            "x20": "0x72bc7f6bb0",
            "x21": "0x0",
            "x22": "0x0",
            "x23": "0x72bc437d78",
            "x24": "0x7242390a90",
            "x25": "0x72bc491108",
            "x26": "0x72bc437550",
            "x27": "0x7213c0a350",
            "x28": "0x7213c09c50",
            "x3": "0x10",
            "x4": "0x0",
            "x5": "0xb40000735a5785e0",
            "x6": "0xb4000074ca3ffc50",
            "x7": "0x110000",
            "x8": "0x1",
            "x9": "0x0"
          }
        },
        "stacktrace": {
          "frames": [
            {
              "data": {
                "orig_in_app": -1,
                "symbolicator_status": "unknown_image"
              },
              "in_app": false,
              "instruction_addr": "0x7270b58418"
            }
          ],
          "instruction_addr_adjustment": "none",
          "registers": {
            "fp": "0x7213c09750",
            "lr": "0x7324b4c84c",
            "pc": "0x7270b58418",
            "sp": "0x7213c09750",
            "x0": "0x7242390a90",
            "x1": "0x72423908b0",
            "x10": "0x1",
            "x11": "0x1",
            "x12": "0xd61f0200",
            "x13": "0xb",
            "x14": "0xb4000074ca2cbf88",
            "x15": "0xb4000074cc6bb5d8",
            "x16": "0x7270b58418",
            "x17": "0x0",
            "x18": "0x721351c000",
            "x19": "0x0",
            "x2": "0x12",
            "x20": "0x72bc7f6bb0",
            "x21": "0x0",
            "x22": "0x0",
            "x23": "0x72bc437d78",
            "x24": "0x7242390a90",
            "x25": "0x72bc491108",
            "x26": "0x72bc437550",
            "x27": "0x7213c0a350",
            "x28": "0x7213c09c50",
            "x3": "0x10",
            "x4": "0x0",
            "x5": "0xb40000735a5785e0",
            "x6": "0xb4000074ca3ffc50",
            "x7": "0x110000",
            "x8": "0x1",
            "x9": "0x0"
          }
        },
        "type": "SIGSEGV",
        "value": "Segfault"
      }
    ]
  },
  "level": "fatal",
  "location": null,
  "logger": "",
  "message": "",
  "metadata": {
    "display_title_with_tree_label": true,
    "in_app_frame_mix": "system-only",
    "value": "Segfault"
  },
  "platform": "native",
  "sdk": {
    "integrations": [
      "inproc"
    ],
    "name": "sentry.native.dotnet",
    "packages": [
      {
        "name": "github:getsentry/sentry-native",
        "version": "0.7.0"
      }
    ],
    "version": "0.7.0"
  },
  "tags": [
    [
      "handled",
      "no"
    ],
    [
      "installerStore",
      "com.android.vending"
    ],
    [
      "isSideLoaded",
      "false"
    ],
    [
      "level",
      "fatal"
    ],
    [
      "mechanism",
      "signalhandler"
    ],
    [
      "os",
      "Android 12"
    ],
    [
      "os.name",
      "Android"
    ],
    [
      "os.rooted",
      "no"
    ]
  ],
  "title": "<unknown>",
  "type": "error",
  "version": "7"
}
espenrl commented 6 days ago

It's important to note that some unhandled events do get logcat.log attached, so the mechanism do work. There seems to be a difference between exceptions originating from .NET and those originating from native code. The latter ones doesn't get logcat.log attached. And it's not just one event. We get lots of these.

bitsandfoxes commented 6 days ago

Interesting! thanks @espenrl for reaching out! So the logcat.log only get added as attachment within the managed code. That should be easy enough to reproduce!

espenrl commented 5 days ago

@bitsandfoxes It may simply be the fact that when Mono enters mono_handle_native_crash it prints a (rather good) crash report to stdout and then exits the program. Perhaps Sentry doesn't get a chance to process anything, and the event is actually sent at the next startup.

https://github.com/dotnet/runtime/blob/main/src/mono/mono/mini/mini-exceptions.c#L2921

On a side note: stacktraces in those native crashes aren't easily symbolicated. Only Mono has sufficient information how to unwind it. Meaning it is best to capture the crash report printed by Mono to stdout. On Android stdout is pointing to /dev/null and it is possible to redirect it and write it to file. Please see this issue https://github.com/dotnet/android/issues/8832

bitsandfoxes commented 3 days ago

Thanks for the additional context!