Skip to content
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

iOS: Breakpoint not hit in classes containing static fields that are initialized inline #100243

Closed
rolfbjarne opened this issue Mar 25, 2024 · 13 comments · Fixed by #100841
Closed

Comments

@rolfbjarne
Copy link
Member

From @prollin on Fri, 15 Mar 2024 17:21:43 GMT

Steps to Reproduce

  1. create a new ios project: dotnet new iOS
  2. in AppDelegate.cs add a new field: private static int foo = 42;
  3. add a breakpoint in FinishedLaunching()
  4. launch app

Expected Behavior

Breakpoint is hit

Actual Behavior

Breakpoint not hit

Environment

Visual Studio Code 1.87.2 + .NET MAUI 0.9.7 + C# Dev Kit 1.4.29

Version information
Version: 1.87.2 (Universal)
Commit: 863d2581ecda6849923a2118d93a088b0745d9d6
Date: 2024-03-08T15:21:31.043Z
Electron: 27.3.2
ElectronBuildId: 26836302
Chromium: 118.0.5993.159
Node.js: 18.17.1
V8: 11.8.172.18-electron.0
OS: Darwin arm64 23.1.0
dotnet --info ```

.NET SDK:
Version: 8.0.202
Commit: 25674bb2f4
Workload version: 8.0.200-manifests.a7f084b6

Runtime Environment:
OS Name: Mac OS X
OS Version: 14.1
OS Platform: Darwin
RID: osx-arm64
Base Path: /usr/local/share/dotnet/sdk/8.0.202/

.NET workloads installed:
[ios]
Installation Source: SDK 8.0.200
Manifest Version: 17.2.8043/8.0.100
Manifest Path: /usr/local/share/dotnet/sdk-manifests/8.0.100/microsoft.net.sdk.ios/17.2.8043/WorkloadManifest.json
Install Type: FileBased

[maui]
Installation Source: SDK 8.0.200
Manifest Version: 8.0.7/8.0.100
Manifest Path: /usr/local/share/dotnet/sdk-manifests/8.0.100/microsoft.net.sdk.maui/8.0.7/WorkloadManifest.json
Install Type: FileBased

[android]
Installation Source: SDK 8.0.200
Manifest Version: 34.0.85/8.0.100
Manifest Path: /usr/local/share/dotnet/sdk-manifests/8.0.100/microsoft.net.sdk.android/34.0.85/WorkloadManifest.json
Install Type: FileBased

Host:
Version: 8.0.3
Architecture: arm64
Commit: 9f4b1f5

.NET SDKs installed:
8.0.202 [/usr/local/share/dotnet/sdk]

.NET runtimes installed:
Microsoft.AspNetCore.App 8.0.3 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 8.0.3 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]

Other architectures found:
x64 [/usr/local/share/dotnet/x64]
registered at [/etc/dotnet/install_location_x64]

Environment variables:
Not set

global.json file:
Not found

</details>

### Build Logs

<!--
1. How to get a build log: https://github.com/xamarin/xamarin-macios/wiki/Diagnosis#build-logs
2. Place the cursor below this comment block.
3. Drag and drop the build log.
-->

### Example Project (If Possible)

<!--
1. Place cursor below this comment block.
2. Drag and drop the compressed project or files needed to reproduce.
-->

<!--
Switch to the "Preview" tab to ensure your issue renders correctly.
-->


_Copied from original issue xamarin/xamarin-macios#20315_
@rolfbjarne

This comment was marked as outdated.

@rolfbjarne
Copy link
Member Author

From @prollin on Sun, 24 Mar 2024 00:10:34 GMT

@rolfbjarne just had a chance to confirm that this also happens in Visual Studio Professional (tested on 17.9.4 as well as 17.10.0 Preview 2.0) with a mac build host so it is not exclusive to VSCode.

This problem seem to be at the core of our inability to properly debug our app on iOS (both simulator and device) since we use static classes/variables extensively. With such a simple repro case, could this be escalated? AFAIK this has been an issue since at least net8 release for us (we only were able to narrow it down to this clear repro case recently)

@rolfbjarne
Copy link
Member Author

From @rolfbjarne on Mon, 25 Mar 2024 17:39:33 GMT

I can reproduce, and since it's happening in VS as well, I believe dotnet/runtime is probably a more correct place for this issue.

@rolfbjarne
Copy link
Member Author

From @rolfbjarne on Mon, 25 Mar 2024 17:39:45 GMT

FWIW I can reproduce the problem.

@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Mar 25, 2024
@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label Mar 25, 2024
@vcsjones vcsjones added area-Debugger-mono os-ios Apple iOS and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Mar 25, 2024
@mdh1418
Copy link
Member

mdh1418 commented Apr 2, 2024

It looks like this is a regression. .NET 7.0.408 iOS app can still hit the breakpoint with a static field initialized inline.

@mdh1418 mdh1418 added this to the 9.0.0 milestone Apr 2, 2024
@dotnet-policy-service dotnet-policy-service bot removed the untriaged New issue has not been triaged by the area owner label Apr 2, 2024
@prollin
Copy link

prollin commented Apr 9, 2024

Is there any known workaround to this issue? (aside from avoiding inline statics which would require a lot of refactoring on our end)
This is a pretty strong showstopper for us.

@thaystg
Copy link
Member

thaystg commented Apr 9, 2024

Not yet. My goal is to work on it tomorrow. I will let you know when I have any news.

@thaystg
Copy link
Member

thaystg commented Apr 10, 2024

@rolfbjarne a possible workaround should be enable running with interpreter, but I don't know how to do it and if this is possible in the ios template.
Can you help us with that?

@rolfbjarne
Copy link
Member Author

@rolfbjarne a possible workaround should be enable running with interpreter, but I don't know how to do it and if this is possible in the ios template. Can you help us with that?

Add this to the project to run with the interpreter:

<PropertyGroup>
    <UseInterpreter>true</UseInterpreter>
</PropertyGroup>

@prollin
Copy link

prollin commented Apr 10, 2024

I can confirm that explicitely enabling the interpreter allows the breakpoint to be hit in the sample project.
I thought <UseInterpreter> was enabled by default in net8-ios project since afaik it is for maui projects (for debug configuration)

Regardless, we prefer to force disable <UseInterpreter> since we measured significant performance issues in our use cases, and we prefer our debug build to be as close to the release builds as possible.

Is a fix possible without having to enable <UseInterpreter>?

@thaystg
Copy link
Member

thaystg commented Apr 11, 2024

The PR is already opened to fix it. this is only a workaround while the fix is not shipped.

@prollin
Copy link

prollin commented Apr 23, 2024

Will this be included in the next 8.0.X release? 8.0.5?

@thaystg
Copy link
Member

thaystg commented Apr 23, 2024

Will this be included in the next 8.0.X release? 8.0.5?

Yes

@github-actions github-actions bot locked and limited conversation to collaborators May 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.