Repository navigation
[typemap] Mark generated JNI debugger boundaries - #13154
Conversation
There was a problem hiding this comment.
🔵 Needs a closer look
Attached-debugger stopping, handled-event suppression, Continue, and Java evaluation remain unverified and require human acceptance review.
0 open findings
What changed in this PR
Marks generated JNI constructor and export exception boundaries so debugger handling follows runtime policy, without changing method-body IL.
Changes:
- Caches and emits the debugger attribute on generated boundaries.
- Adds metadata/IL tests and strengthens device exception-policy coverage.
- Documents test selection and attached-debugger validation limitations.
| File | Description |
|---|---|
| tests/Mono.Android-Tests/Mono.Android-Tests/Java.Interop/TrimmableTypeMapExportTests.cs | Tests handled export failures and default returns. |
| tests/Mono.Android-Tests/Mono.Android-Tests/Java.Interop/ExportTests.cs | Adds the debugger-boundary test category. |
| tests/Mono.Android-Tests/Mono.Android-Tests/Java.Interop/ConstructorActivationTests.cs | Tests exception identity, policy delivery, and recovery. |
| src/Microsoft.Android.Sdk.TrimmableTypeMap/Generator/TypeMapAssemblyEmitter.cs | Annotates generated constructor boundaries. |
| src/Microsoft.Android.Sdk.TrimmableTypeMap/Generator/PEAssemblyBuilder.cs | Caches and emits debugger attribute metadata. |
| src/Microsoft.Android.Sdk.TrimmableTypeMap/Generator/ExportMethodDispatchEmitter.cs | Annotates generated export boundaries. |
| src/Microsoft.Android.Build.Tasks/Tests/Microsoft.Android.Build.Tasks.Tests/GeneratedJniDebuggerBoundaryTests.cs | Adds 19 metadata and IL test cases. |
| .github/skills/tests/references/test-catalog.md | Documents coverage and acceptance-test limitations. |
🧠 Review effort: Balanced
83c13f6 to
0645475
Compare
|
/review |
|
✅ Android PR Reviewer completed successfully!
|
There was a problem hiding this comment.
⚠️ Needs Changes — debugger acceptance evidence remains outstanding
0 errors · 1 warning · 1 suggestion, posted inline. I found no concrete implementation defect: the parameterless attribute constructor/blob are cached per PE builder, all constructor branches reach the annotated shared emitter, and export dispatch receives the same annotation without changing method-body IL. The existing managed activation and legacy forwarding paths remain unannotated. The new tests provide substantial metadata/IL and transport coverage, including original exception identity and handled-policy delivery.
The remaining warning is specifically about validating the debugger-facing behavior: as the description correctly acknowledges, neither attached-client attempt reached a constructor/export test. Successful no-debugger runs do not establish stop suppression, runtime-directed stopping, Continue, or Java evaluation at the stop. This verdict reflects that acceptance gap, not an observed runtime regression.
CI: All 41 GitHub checks on head bff9ca60f810c08e961c93877d82d40dafb45484 report completed/success, including the aggregate dotnet-android check for Azure build 1650661. Direct Azure build-result verification was blocked by the CLI requiring authentication, so I cannot independently confirm the Azure result. The host/device execution results in the description are author-reported; I did not rerun them in this review.
Generated by Android PR Reviewer for #13154 · copilot · gpt61 · 41.8 AIC · ⌖ 4.75 AIC · ⊞ 20K
Comment /review to run again
Generated constructor and export UCOs already catch managed exceptions and delegate the user-unhandled decision to JniRuntime. Annotate those boundary-owning methods so their catches do not override that policy. Keep activation, marshalling, transitions, ABI defaults, and runtime notification/publication behavior unchanged. Cover emitted attribute identity and constructor, all constructor paths, static/instance export dispatch, exception regions, and ABI defaults. Exercise original exception identity, subsequent successful JNI calls, and exactly-once handled CoreCLR application policy on device. Keep NativeAOT application-event parity outside this independent change. Co-authored-by: Copilot App <[email protected]>
NativeAOT now honors Android application exception policy on main. Remove the two exclusions that existed only until that parity landed, and cover handled constructor and export failures on both runtimes. Verify original exception identity, exactly-once application events, default ABI returns, and subsequent successful JNI calls against the rebuilt SDK after rebasing onto the merged policy fix. Co-authored-by: Copilot App <[email protected]>
Keep representative constructor/export exception handlers in user code instead of NUnit Assert.Catch. This separates the generated JNI boundary notification from a later managed rethrow into external test code, allowing exactly-once attached-debugger acceptance without changing runtime policy or generated IL. Document the representative stop/Continue probes and keep Java evaluation as a separate acceptance check. Co-authored-by: Copilot App <[email protected]>
e0b8cdd to
dd88d1e
Compare
|
/review |
|
✅ Android PR Reviewer completed successfully!
|
There was a problem hiding this comment.
Code assessment: no blocking findings. 0 ❌ errors, 0
Reviewed all eight changed files at dd88d1efba0f86f2c044a4ee7310eb3ca970973b, including their full source and the shared runtime-policy implementations. The cached parameterless attribute reference/blob is correctly scoped to the PE builder, and both emission sites annotate the boundary-owning methods without changing their IL, ABI signatures, or transition ordering. Constructor variants and static/instance exports have substantial metadata/IL coverage. Keeping the two representative JNI-rethrow catches in user code makes the documented debugger acceptance cases clearer.
The description now reports successful constructor/export stop-and-Continue and handled-policy suppression, while explicitly separating the remaining function-evaluation limitation and the absence of a clean-main A/B comparison. I found no demonstrated production defect warranting expanding this attribute-only change into a runtime-policy fix. Those attached-debugger observations were not independently reproduced here.
CI: All 41 GitHub check runs report success, including the aggregate dotnet-android check for Azure build 1654454. Independent Azure build/timeline confirmation was unavailable because the CLI required authentication and public HTTP access was denied; I therefore cannot independently certify the underlying Azure result.
Local validation: Attempted dotnet test src/Microsoft.Android.Build.Tasks/Tests/Microsoft.Android.Build.Tasks.Tests/Microsoft.Android.Build.Tasks.Tests.csproj --no-restore -v minimal --filter 'FullyQualifiedName~GeneratedJniDebuggerBoundaryTests|FullyQualifiedName~GenerateTrimmableTypeMapTests'. The CLI failed during first-run configuration with a NuGet-Migrations mutex IOException, before build or test discovery. No local test results are claimed. No repository files were changed by this review.
Generated by Android PR Reviewer for #13154 · copilot · gpt61 · 53.2 AIC · ⌖ 7.91 AIC · ⊞ 19.3K
Comment /review to run again
Check the cumulative notification count immediately after each throwing export so duplicate and missing policy events cannot cancel out across ABI return kinds. Co-authored-by: Copilot App <[email protected]>
|
/review |
|
✅ Android PR Reviewer completed successfully!
|
There was a problem hiding this comment.
✅ LGTM on code — CI verification limited
Findings: 0 errors, 0 warnings, 1 optional inline testing suggestion. Reviewed all eight changed files in full, the emitted metadata/exception regions, generator invalidation, and the CoreCLR/NativeAOT policy implementations. The attribute is correctly scoped to constructor and export/direct-dispatch boundaries, its constructor/blob cache is emitter-local, and the production diff changes no method-body IL, ABI, transition ordering, or legacy forwarding. The constructor branch matrix and per-call notification assertions provide useful regression coverage.
The earlier feedback is reflected in the current code and documented evidence. The description reports successful attached CoreCLR original-throw stops, Continue, and handled-policy suppression; I did not independently reproduce those runs. Exception-stop function evaluation remains explicitly unverified, and the documented controls do not establish this attribute change as its cause. I found no basis to require a broader runtime/debugger fix in this PR.
CI: GitHub reports all 41 head-commit checks successful, including the aggregate dotnet-android check for Azure build 1655619. Independent Azure build/timeline confirmation was unavailable because the CLI encountered tooling/authentication errors and the public REST read was not permitted. Thus this review does not independently certify the underlying Azure result. The focused dotnet test src/Microsoft.Android.Build.Tasks/Tests/Microsoft.Android.Build.Tasks.Tests/Microsoft.Android.Build.Tasks.Tests.csproj -v minimal --filter 'FullyQualifiedName~GeneratedJniDebuggerBoundaryTests|FullyQualifiedName~GenerateTrimmableTypeMapTests' attempt failed during NuGet first-use initialization, before compilation or test execution. No local test pass is claimed.
Generated by Android PR Reviewer for #13154 · copilot · gpt61 · 55.7 AIC · ⌖ 7.49 AIC · ⊞ 19.4K
Comment /review to run again
| { | ||
| [Test] | ||
| public void HandledExportExceptionsReturnAbiDefaultsAndDeliverPolicyOnce () | ||
| { |
There was a problem hiding this comment.
🤖 💡 Testing — Consider adding a throwing static [Export] case alongside this instance-only handled-policy test. The host matrix verifies the annotation and IL for both static and instance dispatch, but the existing static device test only exercises successful dispatch. Calling a throwing static export through JNIEnv.CallStaticIntMethod and checking the zero return plus exactly one notification containing the original exception would extend the runtime-policy coverage to the static JNI entry path on CoreCLR and NativeAOT. This is optional additional coverage, not a demonstrated defect.
{Rule: Test edge cases across supported dispatch variants}
|
@dalexsoto review |
dalexsoto
left a comment
There was a problem hiding this comment.
Reviewed all eight changed files and the generator fingerprint/emitter, CoreCLR/NativeAOT policy, JNI transition/pending-exception, and device-filter integration at this head against the pinned current target. The debugger annotation stays on the boundary-owning constructor/export methods without changing the boundary IL/ABI or policy contract, and the per-call notification assertions cover counts 1 through 6. No actionable blocking issue remained after a separate final pass.
This is a static source review. The documented attached-debugger observations remain author-reported; the accepted exception-stop function-evaluation limitation is not claimed resolved. No builds, tests, generators or devices were executed for this review.
Generated constructor and export/direct-dispatch UCOs already own inline JNI exception boundaries. Their catches delegate the user-unhandled decision to
JniRuntime, but the boundary methods do not carryDebuggerDisableUserUnhandledExceptionsAttribute. Add the attribute so the debugger does not infer user-unhandled behavior from those generated catches instead of the runtime's policy decision.Cache the parameterless
System.Diagnostics.DebuggerDisableUserUnhandledExceptionsAttributeconstructor and attribute blob, and emit one attribute on each boundary-owning constructor/export method. Cover matching managed constructors, invokers, leaf/inherited handle and Java.Interop activation, and open-generic rejection. No method-body IL, activation/marshalling, ABI defaults, runtime policy, transition ordering, legacyn_*forwarding, bridge waits, or exception publication behavior changes. This does not addDebugger.Breakor duplicateBreakForUserUnhandledExceptionnotifications.Add 19 emitted-metadata/IL cases covering attribute identity/constructor/blob, all constructor branches, static/instance export dispatch, the existing
System.Exceptioncatch/finally shape, marshalling/copy-back placement, and ABI defaults. Extend the existing device fixtures with the distinctiveGeneratedJniDebuggerBoundarycategory, original exception identity, successful calls after failures, and exactly-once handled policy/default-return checks on CoreCLR and NativeAOT. Document the category and acceptance limitations in the test catalog.The review follow-up keeps the exception handlers in two representative device tests in user code instead of NUnit's external
Assert.Catch. This preserves their original identity/message assertions while separating the generated boundary's debugger notification from the later managed JNI rethrow into external test code. It changes no production code.Local validation
Tested source:
e0b8cddb0034fab75565683563f5635a8eaec734, including the existing main mergebff9ca60f810c08e961c93877d82d40dafb45484. The merged NativeAOT application-event policy fix from #13153 is included; the two obsoleteNativeAOTIgnoreexclusions have been removed, without adding a runtime override here. The PR remains independently based onmain, with no stack or retargeting.Commands below ran in this worktree on October 29 using its freshly rebuilt Release SDK (
12.0.100-alpha.1.26523.103). Device projects targetnet11.0-android; ARM64 runtime packages are11.0.0-preview.7.26381.103. Runs use this session's dedicated API 35 ARM64 emulator,emulator-5580.SDK preparation/build — both passed, 0 errors.
Focused and adjacent host tests — 56 passed, 0 failed/skipped. This builds the affected host projects before testing.
ARM64 CoreCLR Release — rebuild/install passed; 66 device tests passed, 0 failed/skipped.
ARM64 NativeAOT Release — rebuild/install passed; 66 device tests passed, 0 failed/skipped. Both commands explicitly use
PublishAot=true. The installed ARM64 split APK containslibMono.Android.NET-Tests.soand nolibcoreclr.so. Coverage includes both handled-policy cases, original exception identity, exactly-once events, six export ABI defaults, and subsequent successful JNI calls.Existing trim/AOT analysis and duplicate debugger-library warnings remain visible. Intermediate fixture AARs contain unused scratch profiler libraries; the ordinary CoreCLR/NativeAOT builds used no scratch debugger import, their generated
__environment__.txtis empty, anddebug.coreclr.enabledwas reset to0. No SDK, runtime-policy, or callback-forwarder changes were added for the review follow-up.Attached-debugger evidence and evaluation limitation
Supported-client CoreCLR stop/Continue and handled-policy suppression are observed for this PR's own constructor/export cases. Successful Java evaluation at their user-unhandled stops is not claimed. Additional controls reproduce function-evaluation failure on the pre-existing non-ctor/export
JniMarshal.SafeInvokeFuncpath, including a pure-managed expression. These controls use unchanged main-sourced methods within the PR build, not a separately built unchanged-main baseline. Static assertions and ordinary device runs are not substituted for attached-debugger evidence.The main attached runs used isolated VS Code Insiders
1.144.0-insider, C#11.7.18/ vsdbg18.13.11021.6, and MAUI11.0.114's paired ARM64 host/target profiler resources. The installed target profiler's SHA-256 matched the extension's binary. The supported C#coreclr_mobileclient was used through VS Code's normal debug API/handshake, withrequest=launch,justMyCode=true, and theuser-unhandledfilter confirmed before execution. The MAUI auto-build launch provider was disabled for the prebuilt non-MAUI test app. The adapter sent its launch request before instrumentation; earlier startup crashes are not evidence of general debugger/runtime incompatibility.The debugger app was rebuilt/installed successfully with:
./dotnet-local.sh build -t:Rebuild,Install -m:1 -c Release \ -p:RuntimeIdentifier=android-arm64 '-p:AdbTarget=-s emulator-5580' \ -p:IncludeCategories=GeneratedJniDebuggerBoundary -p:PublishAot=false \ -p:Optimize=false -p:AndroidDebuggable=true -p:AndroidIncludeDebugSymbols=true \ -p:DebuggerSupport=true -p:AndroidAttachDebugger=true -p:AndroidSdbTargetPort=56121 \ -p:NdkBuildPath=/Users/simon/android-toolchain/ndk/ndk-build \ -p:CustomAfterMicrosoftCSharpTargets=/Users/simon/.copilot/session-state/def21f4f-fd5a-456e-a083-1cb6507976b4/files/review-debugger-build.targets \ tests/Mono.Android-Tests/Mono.Android-Tests/Mono.Android.NET-Tests.csprojThe scratch targets import MAUI's
Custom.After.Microsoft.CSharp.targetsand add its ARM64 target profiler, both conditioned onMSBuildProjectName == Mono.Android.NET-Tests. The launch configuration uses the own-worktreeobj/Release/net11.0-android/android-arm64/linked/Mono.Android.NET-Tests.dll, TCP127.0.0.1:56121, platformandroid;arm64,isServer=false, and an assets path containing the linked directory and pairedVsdbgRemoteCoreclrHost/osx-arm64directory. The linked-directory entry must end in/, matching MAUI's provider: adding that separator fixed the earlier host metadataFileNotFoundException. Constants now evaluate successfully, superseding the earlier claim that even1 + 1fails.Instrumentation was started after the adapter's launch request:
Complete stop/Continue run: 66 passed, 0 failed/skipped, target exit 0. Complete DAP logs, per-test instrumentation/logcat, and device TRX were retained. No sibling results are used as constructor/export acceptance evidence.
JavaSideThrowingConstructorPropagatesExceptionuserUnhandledstop at the original constructor throw,ConstructorActivationTests.cs:722; Continue succeeded and original-exception assertions passed.Export_Method_Throws_PrimitiveReturn_SurfacesAsManagedExceptionuserUnhandledstop at the original export throw,ExportTests.cs:400; Continue succeeded and original-exception assertions passed.JavaSideHandledConstructorExceptionDeliversPolicyOnceHandledExportExceptionsReturnAbiDefaultsAndDeliverPolicyOnceThat complete run recorded 11 stops and 11 successful Continue responses (
review-debugger-user-catch-probe.jsonl). Other tests exercise nested JNI boundaries or rethrows caught by external NUnit code; their traces distinguish later rethrows from generated-boundary notifications. Only the two representative catch sites changed to make the one-stop acceptance result unambiguous.Constructor/export evaluation probes: the debugger build command was repeated with additional
-p:PublishReadyToRun=false— rebuild/install passed, 0 errors.expressionEvaluationOptions.allowFastEvaluate=falseensured actual invocation instead of debugger simulation. At the ordinary source breakpoint before the constructor JNI call (ConstructorActivationTests.cs:146),1 + 1returned2andJava.Lang.JavaSystem.CurrentTimeMillis()returned a timestamp (for example1793279952877), followed by successful Continue. At its user-unhandled stop, constants still worked but Java func-eval did not complete: the engine started eval, later aborted it, and reported target exit 0 while evaluation remained pending. The response was canceled/process-terminated. Selecting the live user caller, generated UCO catch frame, or physicalDebugger.BreakForUserUnhandledExceptionframe did not fix it. A separate export-only probe reproduced this after successful normal-breakpoint Java evaluation in the same process. Each instrumentation run passed 66/66, but the incomplete eval is not successful final Continue. Disabling ReadyToRun did not fix it. The other installed supported C# client,11.5.15/ vsdbg18.12.10930.3, also reproduced the constructor-stop failure with the unchanged app.Pre-existing-path comparison within the PR build:
JniRuntimeExceptionPolicyTests.FailedFunctionReturnsDefault(false)callsJniMarshal.SafeInvokeFunc<int>directly, with no generated constructor/export UCO in its failing stack. Both fixture andJniMarshal.SafeInvoke.csare byte-identical to the incorporated main base9d70f2f9934ccf67e277ca4fd55f159e988818b9. The same installed PR-built app and supported current client were used—not an independently built main app:Result: 76 passed, 0 failed/skipped, exit 0 (the instrumentation category is combined with the app's configured 66-case category). At the ordinary breakpoint before
InvokeManagedInt(JniRuntimeExceptionPolicyTests.cs:59), Java evaluation succeeded. At the laterBreakForUserUnhandledExceptionstop in SafeInvoke, Java func-eval again did not complete. In a separate control, pure-managedSystem.GC.GetTotalMemory(false)returned1982736at the ordinary breakpoint but did not complete at that SafeInvoke exception stop; target exit 0 canceled it. That run also passed 76/76. Its stack contains the callback throw,JniMarshal.SafeInvokeFunc, runtime policy, and the direct managed test caller—not the constructor/export emitter's UCOs. Thus the failure also occurs on a pre-existing non-ctor/export path and with managed-only func-eval. This is not a clean-main A/B comparison and establishes no specific debugger/runtime/JNI cause.One pure-managed-control attempt ended before NUnit with an Android process-startup ANR; its logs were retained and no test success is attributed to it. Declaring the owned app with
adb -s emulator-5580 shell am set-debug-app Mono.Android.NET_Testsbefore retry avoided that startup termination. The debug-app setting was subsequently cleared withadb -s emulator-5580 shell am clear-debug-app.Review disposition: original-throw stops, Continue, and handled-policy behavior are verified. Both review threads are addressed: the optional legacy-forwarder assertion was declined because it would freeze behavior owned by #13155; requiring an additional general function-evaluation fix is declined as outside this attribute-only PR, based on the bounded controls above. Successful exception-stop Java evaluation remains explicitly unverified, not silently counted as passing. No speculative runtime-policy or exception-publication changes were added, and no NativeAOT managed-debugger acceptance result is claimed.
Evidence is retained in
review-debugger-{jit,leaf,export-eval,csharp115-ready,safeinvoke-control,managed-eval-ready}-probe.jsonl, corresponding instrumentation logs, and the final control TRX/logcat. These diagnostic runs are separate from the complete 11-stop/11-Continue acceptance run. Debugger property, debug-app setting, and forwarding were reset; only this session's IDE/emulator processes were stopped.Pull Request
title and
description
should follow the
commit-messages.mdworkflow documentation, and in particular should include: