Why do my stack traces only include line numbers if the debugger is attached?

懵懂的女人 提交于 2019-12-01 23:53:12

问题


I have a Xamarin.Android application that reports crashes to Raygun. The stack traces reported to Raygun from Release builds do not include line numbers. If I give the Release build configuration the same settings as the Debug configuration in the .csproj file:

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
  <DebugSymbols>True</DebugSymbols>
  <DebugType>full</DebugType>
  <Optimize>false</Optimize>
  ...
</PropertyGroup>

then I still don't see line numbers in the stack traces sent to Raygun. However, if I run the app with the Visual Studio debugger attached, then the stack traces sent to Raygun do include line numbers. Note that all stack traces include class and method names in any case. This question is only concerned with line numbers.

Why do stack traces only include line numbers if the debugger is attached when an exception is thrown? More importantly, how can I get line numbers in the Release build's reported stack traces, without a debugger attached?


回答1:


You would need to symbolize the "native" Android crash report via mono-symbolicate using the symbols of the release build (the build's msym and the build app must be from the same build).

Some crash reporting services directly support Xamarin and allow you to upload the build's msym files and automatically run mono-symbolicate, others do not and thus require you to do it manually (or some support web-hooks and you can implement it yourself to run on each received crash report, I do it this way on Fabric)

mono-symbolicate
Usage: symbolicate [options] <msym dir> <input file>
       symbolicate [options] store-symbols <msym dir> [<dir>]+

Available options:
  -h, --help                 Show this help
  -q                         Quiet, warnings are not displayed
  -v                         Verbose, log debug messages
  • https://developer.xamarin.com/releases/android/xamarin.android_7/xamarin.android_7.4/ (search the release text for mono-symbolicate)

Next, grab a crash log which an unhandled exception

adb logcat -d > errors.txt

Finally, use mono-symbolicate to convert the errors to contain file and line numbers:

mono-symbolicate path-to-dll-in-.mSYM-directory path-to-errors.txt

For example, given an errors.txt with the contents:

I/MonoDroid( 1545): System.Exception: wow it broke
I/MonoDroid( 1545):   at CrashApp.MainActivity+<OnCreate>c__AnonStorey0.<>m__0 (System.Object , System.EventArgs ) [0x00030] in <filename unknown>:0
I/MonoDroid( 1545):   at Android.Views.View+IOnClickListenerImplementor.OnClick (Android.Views.View v) [0x00014] in <filename unknown>:0
I/MonoDroid( 1545):   at Android.Views.View+IOnClickListenerInvoker.n_OnClick_Landroid_view_View_ (IntPtr jnienv, IntPtr native__this, IntPtr native_v) [0x00011] in <filename unknown>:0
I/MonoDroid( 1545):   at (wrapper dynamic-method) System.Object:5616285d-461b-4005-a31b-d4637a8cdddc (intptr,intptr,intptr)

mono-symbolicate will translate the above into:

I/MonoDroid( 1545): System.Exception: wow it broke
I/MonoDroid( 1545):   at CrashApp.MainActivity+<OnCreate>c__AnonStorey0.<>m__0 (System.Object , System.EventArgs ) [0x00030] in /Users/dean/Projects/CrashApp/CrashApp/MainActivity.cs:30
I/MonoDroid( 1545):   at Android.Views.View+IOnClickListenerImplementor.OnClick (Android.Views.View v) [0x00014] in /Users/dean/Documents/Sandbox/Xamarin/dellismonodroid/src/Mono.Android/platforms/android-19/src/generated/Android.Webkit.WebBackForwardList.cs:68
I/MonoDroid( 1545):   at Android.Views.View+IOnClickListenerInvoker.n_OnClick_Landroid_view_View_ (IntPtr jnienv, IntPtr native__this, IntPtr native_v) [0x00011] in /Users/dean/Documents/Sandbox/Xamarin/dellismonodroid/src/Mono.Android/platforms/android-19/src/generated/Android.Webkit.WebBackForwardList.cs:23
I/MonoDroid( 1545):   at (wrapper dynamic-method) System.Object:5616285d-461b-4005-a31b-d4637a8cdddc (intptr,intptr,intptr)


来源:https://stackoverflow.com/questions/49639837/why-do-my-stack-traces-only-include-line-numbers-if-the-debugger-is-attached

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!