-
Notifications
You must be signed in to change notification settings - Fork 569
[clr-android] Add CoreCLR debugger support for Android #10889
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -198,4 +198,64 @@ This file contains targets specific for Android application projects. | |
| /> | ||
| <Message Text="Logcat output is available in $(_RunLogFilePath)" Importance="High" /> | ||
| </Target> | ||
|
|
||
| <!-- The remotemscordbitarget library runs as a CLR profiler on the device and communicates with the host via gRPC --> | ||
| <Target Name="_SetupCoreClrDebugger" | ||
| Condition=" '$(AndroidEnableCoreClrDebugger)' == 'true' "> | ||
| <Message Text="Setting up CoreCLR remote debugger on port $(CoreClrDebuggerPort)" Importance="High" /> | ||
|
|
||
| <AndroidAdb | ||
| ToolExe="$(AdbToolExe)" | ||
| ToolPath="$(AdbToolPath)" | ||
| AdbTarget="$(AdbTarget)" | ||
| Command="shell" | ||
| Arguments="setprop debug.coreclr.isserver $(CoreClrDebuggerIsServer)" | ||
| /> | ||
| <AndroidAdb | ||
| ToolExe="$(AdbToolExe)" | ||
| ToolPath="$(AdbToolPath)" | ||
| AdbTarget="$(AdbTarget)" | ||
| Command="shell" | ||
| Arguments="setprop debug.coreclr.ip 127.0.0.1" | ||
| /> | ||
| <AndroidAdb | ||
| ToolExe="$(AdbToolExe)" | ||
| ToolPath="$(AdbToolPath)" | ||
| AdbTarget="$(AdbTarget)" | ||
| Command="shell" | ||
| Arguments="setprop debug.coreclr.port $(CoreClrDebuggerPort)" | ||
| /> | ||
|
|
||
| <Message Text="Setting up adb port forwarding: tcp:$(CoreClrDebuggerPort) -> tcp:$(CoreClrDebuggerPort)" Importance="High" /> | ||
| <AndroidAdb | ||
| ToolExe="$(AdbToolExe)" | ||
| ToolPath="$(AdbToolPath)" | ||
| AdbTarget="$(AdbTarget)" | ||
| Command="forward" | ||
| Arguments="tcp:$(CoreClrDebuggerPort) tcp:$(CoreClrDebuggerPort)" | ||
| /> | ||
| </Target> | ||
|
|
||
| <Target Name="RunWithCoreClrDebugger" | ||
| DependsOnTargets="Install;_SetupCoreClrDebugger"> | ||
|
Comment on lines
+239
to
+240
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a new public target, what calls it? I think I have some general questions on how this is supposed to integrate with IDEs. |
||
| <GetAndroidActivityName | ||
| Condition=" '$(AndroidLaunchActivity)' == '' " | ||
| ManifestFile="$(IntermediateOutputPath)android\AndroidManifest.xml"> | ||
| <Output TaskParameter="ActivityName" PropertyName="AndroidLaunchActivity" /> | ||
| </GetAndroidActivityName> | ||
|
|
||
| <PropertyGroup> | ||
| <_AmStartUserArg Condition=" '$(AndroidDeviceUserId)' != '' "> --user $(AndroidDeviceUserId)</_AmStartUserArg> | ||
| </PropertyGroup> | ||
|
|
||
| <Message Text="Launching application with CoreCLR remote debugger" Importance="High" /> | ||
| <AndroidAdb | ||
| ToolExe="$(AdbToolExe)" | ||
| ToolPath="$(AdbToolPath)" | ||
| AdbTarget="$(AdbTarget)" | ||
| Command="shell" | ||
| Arguments="am start -S -W$(_AmStartUserArg) -n "$(_AndroidPackage)/$(AndroidLaunchActivity)"" | ||
| /> | ||
| <Message Text="Application started. Connect the remote debugger host to 127.0.0.1:$(CoreClrDebuggerPort)" Importance="High" /> | ||
| </Target> | ||
| </Project> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,9 +21,6 @@ | |
| <_AndroidFastDeploymentSupported Condition=" Exists ('$(MSBuildThisFileDirectory)../tools/Xamarin.Android.Common.Debugging.targets') ">true</_AndroidFastDeploymentSupported> | ||
| <_AndroidFastDeploymentSupported Condition=" '$(_AndroidFastDeploymentSupported)' == '' ">False</_AndroidFastDeploymentSupported> | ||
|
|
||
| <!-- TODO: remove when we have debugger support for CoreCLR --> | ||
| <UseMonoRuntime Condition=" '$(UseMonoRuntime)' == '' and '$(Configuration)' == 'Debug' ">true</UseMonoRuntime> | ||
|
|
||
| <!-- | ||
| Disable @(Content) from referenced projects | ||
| See: https://github.com/dotnet/sdk/blob/955c0fc7b06e2fa34bacd076ed39f61e4fb61716/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Publish.targets#L16 | ||
|
|
@@ -57,6 +54,12 @@ | |
| <AndroidEnableProfiler Condition=" '$(AndroidEnableProfiler)' == '' and ('$(DiagnosticConfiguration)' != '' or '$(DiagnosticAddress)' != '' or '$(DiagnosticPort)' != '' or '$(DiagnosticSuspend)' != '' or '$(DiagnosticListenMode)' != '') ">true</AndroidEnableProfiler> | ||
| <AndroidEnableProfiler Condition=" '$(AndroidEnableProfiler)' == '' ">false</AndroidEnableProfiler> | ||
|
|
||
| <AndroidEnableCoreClrDebugger Condition=" '$(AndroidEnableCoreClrDebugger)' == '' and '$(_AndroidRuntime)' == 'CoreCLR' and '$(Configuration)' != 'Release' ">true</AndroidEnableCoreClrDebugger> | ||
| <AndroidEnableCoreClrDebugger Condition=" '$(AndroidEnableCoreClrDebugger)' == '' ">false</AndroidEnableCoreClrDebugger> | ||
|
Comment on lines
+57
to
+58
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Question about naming: should this just be Setting a single property would be ideal, and then it would do the same thing no matter what runtime is used. |
||
| <CoreClrDebuggerPort Condition=" '$(CoreClrDebuggerPort)' == '' ">4711</CoreClrDebuggerPort> | ||
| <CoreClrDebuggerIsServer Condition=" '$(CoreClrDebuggerIsServer)' == '' ">1</CoreClrDebuggerIsServer> | ||
|
Comment on lines
+59
to
+60
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, these it seems like we should choose names that don't have |
||
| <CoreClrDebuggerNativeLibraryPath Condition=" '$(CoreClrDebuggerNativeLibraryPath)' == '' ">$(MSBuildThisFileDirectory)..\tools\libremotemscordbitarget</CoreClrDebuggerNativeLibraryPath> | ||
|
|
||
| <!-- | ||
| Android package (apt/aab) alignment, expressed as the page size in kilobytes. Two values are supported: 4 and 16. | ||
| Sometime next year 16 is going to be a Google Play store requirement for application submissions. | ||
|
|
@@ -153,6 +156,8 @@ | |
|
|
||
| <!-- profiler won't work without internet permission, we must thus force it --> | ||
| <AndroidNeedsInternetPermission Condition=" '$(AndroidEnableProfiler)' == 'true' ">True</AndroidNeedsInternetPermission> | ||
| <!-- CoreCLR debugger uses gRPC which requires network access --> | ||
| <AndroidNeedsInternetPermission Condition=" '$(AndroidEnableCoreClrDebugger)' == 'true' ">True</AndroidNeedsInternetPermission> | ||
| </PropertyGroup> | ||
| <!-- Trimmer switches that default to OFF in Release mode --> | ||
| <PropertyGroup Condition=" '$(AndroidApplication)' == 'true' and '$(Optimize)' == 'true' "> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -72,6 +72,7 @@ public class GenerateNativeApplicationConfigSources : AndroidTask | |
| public string? AndroidSequencePointsMode { get; set; } | ||
| public bool EnableSGenConcurrent { get; set; } | ||
| public string? CustomBundleConfigFile { get; set; } | ||
| public bool EnableCoreClrDebugger { get; set; } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems like this could check:
|
||
|
|
||
| bool _Debug { | ||
| get { | ||
|
|
@@ -118,13 +119,20 @@ public override bool RunTask () | |
| envBuilder.AddDefaultDebugBuildLogLevel (); | ||
| } | ||
|
|
||
| if (androidRuntime != Xamarin.Android.Tasks.AndroidRuntime.NativeAOT) { | ||
| AddDefaultEnvironmentVariables (envBuilder, HttpClientHandlerType, EnableSGenConcurrent); | ||
| } else { | ||
| if (androidRuntime == Xamarin.Android.Tasks.AndroidRuntime.NativeAOT) { | ||
| // NativeAOT sets all the environment variables from Java, we don't want to repeat that | ||
| // process in the native code. This is just a precaution, because NativeAOT builds should | ||
| // not even use this task. | ||
| envBuilder.EnvironmentVariables.Clear (); | ||
| } else if (androidRuntime == Xamarin.Android.Tasks.AndroidRuntime.CoreCLR) { | ||
| // CoreCLR needs the HTTP client handler type | ||
| envBuilder.AddHttpClientHandlerType (HttpClientHandlerType); | ||
| } else { | ||
| AddDefaultEnvironmentVariables (envBuilder, HttpClientHandlerType, EnableSGenConcurrent); | ||
| } | ||
|
|
||
| if (EnableCoreClrDebugger && TargetsCLR) { | ||
| envBuilder.AddCoreClrDebuggerEnvironment (); | ||
| } | ||
|
|
||
| global::Android.Runtime.BoundExceptionType boundExceptionType; | ||
|
|
||
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.
These are a lot of adb calls, do they all need to be system properties? We also have the ability to bake environment variables into apps, or use
dotnet run -e DOTNET_CORE_CLR_IP=127.0.0.1.