-
Notifications
You must be signed in to change notification settings - Fork 564
[docs] Document how to debug JNI Object Reference crashes #7362
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
6b6e99e to
b13b919
Compare
| `logcat-parse` combines an API around the JNI Global Reference logs with a C# REPL. | ||
| It is included with Classic Xamarin.Android installs. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to file an issue to distribute this as a .NET global tool? On NuGet.org? Then you could do dotnet tool install --global logcat-parse.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I should do that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might also take the opportunity to rename logcat-parse, since I don't think it's parsing logcat? 😁
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It can parse adb logcat output.
I'm open to alternative names. objref-parse?
| In particular, `adb logcat` has a `MissingMethodException` mentioning that a constructor | ||
| with the signature `(IntPtr, JniHandleOwnership)` could not be found. | ||
|
|
||
| If you see a `NotSupportedException` which with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/which/d
|
|
||
| Enable JNI Global Reference log collection by setting the `debug.mono.log` system property to a value which contains `gref`: | ||
|
|
||
| adb shell setprop debug.mono.log gref |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest adding
adb logcat -G 16Mto increase the logcat buffer size, otherwise the logcat daemon will truncate messages
| Once your app crashes, `log.txt` will contain the JNI Object Reference logs. | ||
|
|
||
| *However*, the output *may* be incomplete. It is not unusual for information to be missing, because *so much* | ||
| data is written to `adb logcat`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should find out what's the maximum admissible logcat buffer size and suggest setting it here
| /* 31 */ at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_(IntPtr jnienv, IntPtr native__this, IntPtr native_savedInstanceState) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/obj/Release/net6.0/android-31/mcw/Android.App.Activity.cs:line 2781 | ||
| /* 32 */ at Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PPL_V(_JniMarshal_PPL_V callback, IntPtr jnienv, IntPtr klazz, IntPtr p0) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs:line 121 | ||
| ``` | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd "simplify" the format here - use 1. for line numbers, the asterisks introduce visual noise IMO
| csharp> var r = grefs.AllocatedPeers.Where(p => p.KeyHandle=="0x466b26f"); | ||
| csharp> r; | ||
| { PeerInfo(State='Collected' JniType='mono/java/lang/Runnable' McwType='Java.Lang.Runnable' KeyHandle=0x466b26f Handles=1) } | ||
| ``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we count on people having Mono installed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If they're on macOS, yes. Classic Xamarin.Android SDK requires msbuild, which is part of Mono.framework.
We need a better solution for "pure .NET" environments; we likely need to turn logcat-parse into a dotnet global tool.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's what I was thining, it should be a dotnet tool most likely. Not necessarily dotnet global one, enough that it is shipped with XA and can be invoked with just logcat-parse
| # run the app… | ||
|
|
||
| adb shell run-as @PACKAGE-NAME@ cat files/.__override__/grefs.txt > grefs.txt | ||
| adb shell run-as @PACKAGE-NAME@ cat files/.__override__/lrefs.txt > lrefs.txt |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps explain where @PACKAGE-NAME@ can be looked up? I wouldn't be surprised if many people wouldn't know what their package name actually is, it being hidden behind properties in the project file
46d82fa to
accefa5
Compare
|
|
||
| If you see a `NotSupportedException` with | ||
| [*anything else* as the inner exception](https://github.com/xamarin/xamarin-android/issues/7324), | ||
| then this is *not* due to JNI object references, and the rest of this guide will not help you. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A suggestion to some "next step(s)" if this guide does not help might be useful, even if it says something like "The exception message should tell you what the real error is".
accefa5 to
34052cc
Compare
* main: [docs] Document how to debug JNI Object Reference crashes (dotnet#7362) [Mono.Android] Parse cookies on redirect in AndroidClientHandler (dotnet#7373) Bump to xamarin/Java.Interop/main@fcc33ce2 (dotnet#7380) Bump to dotnet/installer@11f6b8f 7.0.100-rc.2.22459.2 (dotnet#7367) LEGO: Merge pull request 7385 Bump to xamarin/monodroid@135be73 (dotnet#7384) Bump to xamarin/xamarin-android-tools/main@0be567a9 (dotnet#7383) Bump to Tessil/robin-map@784245b4 [v1.0.1] (dotnet#7382) Bump to mono/mono@a96bde97 (dotnet#7372) [ci] Fix test categories for emu smoke tests (dotnet#7374) Bump to xamarin/monodroid@43583d02 (dotnet#7370)
Context: dotnet/java-interop#1039