dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.06k stars 4.69k forks source link

Dotnet Android broken debugging (and runtime?) #104265

Closed arivoir closed 2 months ago

arivoir commented 3 months ago

Description

For some months we've been having issues to debug native Android libraries, if I set a breakpoint in the application it works, but if I set a breakpoint in a library it is completely ignored.

Additionally, I see the following in the Debug console

System.IndexOutOfRangeException: Index was outside the bounds of the array. at Mono.Debugger.Soft.Connection.decode_int(Byte[] packet, Int32& offset) in D:\a_work\1\s\External\debugger-libs\Mono.Debugger.Soft\Mono.Debugger.Soft\Connection.cs:line 732 at Mono.Debugger.Soft.Connection.Method_GetLocalsInfo(Int64 id) in D:\a_work\1\s\External\debugger-libs\Mono.Debugger.Soft\Mono.Debugger.Soft\Connection.cs:line 2308 at Mono.Debugger.Soft.MethodMirror.GetLocals() in D:\a_work\1\s\External\debugger-libs\Mono.Debugger.Soft\Mono.Debugger.Soft\MethodMirror.cs:line 276 at Mono.Debugger.Soft.StackFrame.GetVisibleVariableByName(String name) in D:\a_work\1\s\External\debugger-libs\Mono.Debugger.Soft\Mono.Debugger.Soft\StackFrame.cs:line 246 at Mono.Debugging.Soft.SoftDebuggerAdaptor.OnGetLocalVariable(EvaluationContext ctx, String name) in D:\a_work\1\s\External\debugger-libs\Mono.Debugging.Soft\SoftDebuggerAdaptor.cs:line 1072 at Mono.Debugging.Evaluation.NRefactoryExpressionEvaluatorVisitor.VisitIdentifierName(IdentifierNameSyntax node) in D:\a_work\1\s\External\debugger-libs\Mono.Debugging\Mono.Debugging.Evaluation\NRefactoryExpressionEvaluatorVisitor.cs:line 660 at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxVisitor1.Visit(SyntaxNode node) at Mono.Debugging.Evaluation.NRefactoryExpressionEvaluatorVisitor.VisitMemberAccessExpression(MemberAccessExpressionSyntax node) in D:\a\_work\1\s\External\debugger-libs\Mono.Debugging\Mono.Debugging.Evaluation\NRefactoryExpressionEvaluatorVisitor.cs:line 979 at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxVisitor1.Visit(SyntaxNode node) at Mono.Debugging.Evaluation.NRefactoryExpressionEvaluatorVisitor.VisitBinaryExpression(BinaryExpressionSyntax node) in D:\a_work\1\s\External\debugger-libs\Mono.Debugging\Mono.Debugging.Evaluation\NRefactoryExpressionEvaluatorVisitor.cs:line 578 at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxVisitor`1.Visit(SyntaxNode node) at Mono.Debugging.Evaluation.ObjectValueAdaptor.GetExpressionValue(EvaluationContext ctx, String exp) in D:\a_work\1\s\External\debugger-libs\Mono.Debugging\Mono.Debugging.Evaluation\ObjectValueAdaptor.cs:line 1418

And the crash show some exception that I can not understand how it happens image The debugging shows nothing for the local field "thickness" but three dots, and I can not comprehend how something can be null here, when there is an if before that to avoid it, and the properties are of type double.

We're in a critical situation where we can not continue developing, because the debugger doesn't work, and the runtime exceptions are incomprehensible.

Steps to Reproduce

I don't have a reproduction steps for now

Link to public reproduction project repository

No response

Version with bug

8.0.3 GA

Is this a regression from previous behavior?

Yes, this used to work in .NET MAUI

Last version that worked well

6.0

Affected platforms

Android

Affected platform versions

No response

Did you find any workaround?

No

Relevant log output

System.IndexOutOfRangeException: Index was outside the bounds of the array.
   at Mono.Debugger.Soft.Connection.decode_int(Byte[] packet, Int32& offset) in D:\a\_work\1\s\External\debugger-libs\Mono.Debugger.Soft\Mono.Debugger.Soft\Connection.cs:line 732
   at Mono.Debugger.Soft.Connection.Method_GetLocalsInfo(Int64 id) in D:\a\_work\1\s\External\debugger-libs\Mono.Debugger.Soft\Mono.Debugger.Soft\Connection.cs:line 2308
   at Mono.Debugger.Soft.MethodMirror.GetLocals() in D:\a\_work\1\s\External\debugger-libs\Mono.Debugger.Soft\Mono.Debugger.Soft\MethodMirror.cs:line 276
   at Mono.Debugger.Soft.StackFrame.GetVisibleVariableByName(String name) in D:\a\_work\1\s\External\debugger-libs\Mono.Debugger.Soft\Mono.Debugger.Soft\StackFrame.cs:line 246
   at Mono.Debugging.Soft.SoftDebuggerAdaptor.OnGetLocalVariable(EvaluationContext ctx, String name) in D:\a\_work\1\s\External\debugger-libs\Mono.Debugging.Soft\SoftDebuggerAdaptor.cs:line 1072
   at Mono.Debugging.Evaluation.NRefactoryExpressionEvaluatorVisitor.VisitIdentifierName(IdentifierNameSyntax node) in D:\a\_work\1\s\External\debugger-libs\Mono.Debugging\Mono.Debugging.Evaluation\NRefactoryExpressionEvaluatorVisitor.cs:line 660
   at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxVisitor`1.Visit(SyntaxNode node)
   at Mono.Debugging.Evaluation.ObjectValueAdaptor.GetExpressionValue(EvaluationContext ctx, String exp) in D:\a\_work\1\s\External\debugger-libs\Mono.Debugging\Mono.Debugging.Evaluation\ObjectValueAdaptor.cs:line 1418
github-actions[bot] commented 3 months ago

Hi I'm an AI powered bot that finds similar issues based off the issue title.

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you!

Open similar issues:

Closed similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

arivoir commented 3 months ago

I also reported here https://developercommunity.visualstudio.com/t/Debugging-an-native-Android-library-is-b/10694337?

I found a repro case AndroidDebuggerIssue.zip

The bug regarding debugger appears when library target net7 and application net8

dotnet-policy-service[bot] commented 3 months ago

Tagging subscribers to this area: @thaystg See info in area-owners.md if you want to be subscribed.