dotnet / vscode-csharp

Official C# support for Visual Studio Code
MIT License
2.85k stars 667 forks source link

Bizarre breakpoint behaviour in VSCode #4544

Open m-brooks opened 3 years ago

m-brooks commented 3 years ago

Issue Description

Code window behaviour does not match actual runtime behaviour whilst debugging.

Steps to Reproduce

I have just installed dotnet-script on my W10 system and used the command "dotnet-script init" to create a basic "Hello World" CSX project. I replaced the default with a simple 3-line script that creates two integer variables and then outputs their sum, set a breakpoint on the 1st line and hit F5. What I get is really weird - the code window appears as though execution has stopped on my breakpoint, but the debug window shows that the code has already run through to completion and output the result. If I hit F10 or use the mouse to click the "step over" button, the code window then immediately reflects the fact that the code has completed (i.e. it goes back to basic editor mode).

Expected Behavior

Execution pauses at breakpoint.

Actual Behavior

Code window gives the appearance that execution has paused at the breakpoint, but in reality the code has run all the way from start to finish. See scereenshot. CSX breakpoint

Logs

OmniSharp log

Starting OmniSharp server at 09/05/2021, 14:38:41 Target: c:\Dev\CSX\play1 OmniSharp server started. Path: c:\Users\micha\.vscode\extensions\ms-dotnettools.csharp-1.23.11\.omnisharp\1.37.8\OmniSharp.exe PID: 21320 [info]: OmniSharp.Stdio.Host Starting OmniSharp on Windows 6.2.9200.0 (x64) [info]: OmniSharp.Services.DotNetCliService DotNetPath set to dotnet [info]: OmniSharp.MSBuild.Discovery.MSBuildLocator Located 2 MSBuild instance(s) 1: Visual Studio Community 2019 16.8.30907.101 - "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin" 2: StandAlone 16.9.0 - "c:\Users\micha\.vscode\extensions\ms-dotnettools.csharp-1.23.11\.omnisharp\1.37.8\.msbuild\Current\Bin" [info]: OmniSharp.MSBuild.Discovery.MSBuildLocator Registered MSBuild instance: Visual Studio Community 2019 16.8.30907.101 - "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin" [info]: OmniSharp.WorkspaceInitializer Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.CSharpFormattingWorkspaceOptionsProvider, Order: 0 [info]: OmniSharp.WorkspaceInitializer Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.Completion.CompletionOptionsProvider, Order: 0 [info]: OmniSharp.WorkspaceInitializer Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.RenameWorkspaceOptionsProvider, Order: 100 [info]: OmniSharp.WorkspaceInitializer Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.ImplementTypeWorkspaceOptionsProvider, Order: 110 [info]: OmniSharp.WorkspaceInitializer Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.BlockStructureWorkspaceOptionsProvider, Order: 140 [info]: OmniSharp.Cake.CakeProjectSystem Detecting Cake files in 'c:\Dev\CSX\play1'. [info]: OmniSharp.Cake.CakeProjectSystem Could not find any Cake files [info]: OmniSharp.MSBuild.ProjectSystem No solution files found in 'c:\Dev\CSX\play1' [info]: OmniSharp.Script.ScriptProjectSystem Detecting CSX files in 'c:\Dev\CSX\play1'. [info]: OmniSharp.Script.ScriptProjectSystem Found 1 CSX files. [info]: OmniSharp.Script.ScriptContextProvider Searching for compilation dependencies with the fallback framework of 'net5.0'. [info]: OmniSharp.Script.ScriptProjectSystem Added CSX project 'c:\Dev\CSX\play1\main.csx' to the workspace. [info]: OmniSharp.WorkspaceInitializer Configuration finished. [info]: OmniSharp.Stdio.Host Omnisharp server running using Stdio at location 'c:\Dev\CSX\play1' on host 14484. Received response for /findusages but could not find request. Received response for /findusages but could not find request.

C# log

N/A - there is none

Environment information

VSCode version: 1.56.0 C# Extension: 1.23.11

Dotnet Information .NET SDK (reflecting any global.json): Version: 5.0.104 Commit: ca6b6acadb Runtime Environment: OS Name: Windows OS Version: 10.0.19042 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\5.0.104\ Host (useful for support): Version: 5.0.5 Commit: 2f740adc14 .NET SDKs installed: 2.1.523 [C:\Program Files\dotnet\sdk] 3.1.301 [C:\Program Files\dotnet\sdk] 3.1.408 [C:\Program Files\dotnet\sdk] 5.0.102 [C:\Program Files\dotnet\sdk] 5.0.104 [C:\Program Files\dotnet\sdk] .NET runtimes installed: Microsoft.AspNetCore.All 2.1.27 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.App 2.1.27 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.14 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 5.0.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 5.0.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 5.0.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 2.1.27 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.14 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 3.1.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 3.1.11 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 3.1.14 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 5.0.2 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 5.0.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 5.0.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] To install additional .NET runtimes or SDKs: https://aka.ms/dotnet-download
Visual Studio Code Extensions |Extension|Author|Version| |---|---|---| |csharp|ms-dotnettools|1.23.11|;
m-brooks commented 3 years ago

I've just realised a major part of what's wrong here, and that bit is my own stupid fault. However, there is still an issue to be addressed. The mistake I made was to set a breakpoint on a variable definition with implicit initialisation. This does not compile to any executable instructions, but instead merely reserves and initialises memory. Consequently it is not an appropriate target for a breakpoint - I'm way too old to be making mistakes like that, or so I'd have thought... However, this has exposed an issue. What should have happened in this scenario is that omnisharp should have automatically corrected my mistake by moving the breakpoint to the next appropriate line of source code (as I've seen in the past when working in Visual Studio), and then stopped at that breakpoint. What actually happened was confusion - one part of the debugging environment stopped and another part didn't (which indicates to me that we have at least two concurrent threads sharing the debugging load). So there's still something that needs to be fixed - it just isn't exactly as I first thought.

Regards, Michael