Method with a function pointer local breaks variables view and debug console
Closed this issue · 6 comments
Issue Description
When the debugger is stopped in a method that contains a local typed as a function pointer, all state related debug LSP requests seem to break.
Steps to Reproduce
- Download repro project (MethodPointerDebugRepro.zip or do
dotnet new console
and paste the code below) - Set breakpoint on
Program.cs:L10
- Launch debug
Program.cs
using System;
namespace MethodPointerDebugRepro
{
internal static class Program
{
private static unsafe void Main(string[] args)
{
// Set breakpoint here.
delegate*<void> messageWriter = &WriteMessage;
messageWriter();
}
private static void WriteMessage()
{
Console.WriteLine("testing");
}
}
}
MethodPointerDebugRepro.csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
</Project>
Expected Behavior
Variables view shows locals and does not display an error. Debug console works.
Actual Behavior
Variables view shows error Error processing 'variables' request. Unknown Error: 0x80135100
. Evaluating anything in the debug repl returns Internal error in the C# compiler
.
Logs
OmniSharp log
Starting OmniSharp server at 9/10/2020, 8:25:57 AM
Target: c:\MethodPointerDebugRepro
OmniSharp server started.
Path: c:\Users\seeminglyscience\.vscode\extensions\ms-dotnettools.csharp-1.23.2\.omnisharp\1.37.1\OmniSharp.exe
PID: 26668
[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 1 MSBuild instance(s)
1: StandAlone 16.8.0 - "c:\Users\seeminglyscience\.vscode\extensions\ms-dotnettools.csharp-1.23.2\.omnisharp\1.37.1\.msbuild\Current\Bin"
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
MSBUILD_EXE_PATH environment variable set to 'c:\Users\seeminglyscience\.vscode\extensions\ms-dotnettools.csharp-1.23.2\.omnisharp\1.37.1\.msbuild\Current\Bin\MSBuild.exe'
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
Registered MSBuild instance: StandAlone 16.8.0 - "c:\Users\seeminglyscience\.vscode\extensions\ms-dotnettools.csharp-1.23.2\.omnisharp\1.37.1\.msbuild\Current\Bin"
CscToolExe = csc.exe
CscToolPath = c:\Users\seeminglyscience\.vscode\extensions\ms-dotnettools.csharp-1.23.2\.omnisharp\1.37.1\.msbuild\Current\Bin\Roslyn
MSBuildExtensionsPath = c:\Users\seeminglyscience\.vscode\extensions\ms-dotnettools.csharp-1.23.2\.omnisharp\1.37.1\.msbuild
MSBuildToolsPath = c:\Users\seeminglyscience\.vscode\extensions\ms-dotnettools.csharp-1.23.2\.omnisharp\1.37.1\.msbuild\Current\Bin
[info]: OmniSharp.WorkspaceInitializer
Project system 'OmniSharp.Cake.CakeProjectSystem' is disabled in the configuration.
[info]: OmniSharp.MSBuild.ProjectSystem
No solution files found in 'c:\MethodPointerDebugRepro'
[info]: OmniSharp.MSBuild.ProjectManager
Queue project update for 'c:\MethodPointerDebugRepro\MethodPointerDebugRepro.csproj'
[info]: OmniSharp.Script.ScriptProjectSystem
Detecting CSX files in 'c:\MethodPointerDebugRepro'.
[info]: OmniSharp.Script.ScriptProjectSystem
Could not find any CSX files
[info]: OmniSharp.WorkspaceInitializer
Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.CSharpFormattingWorkspaceOptionsProvider, Order: 0
[info]: OmniSharp.MSBuild.ProjectManager
Loading project: c:\MethodPointerDebugRepro\MethodPointerDebugRepro.csproj
[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.WorkspaceInitializer
Configuration finished.
[info]: OmniSharp.Stdio.Host
Omnisharp server running using Stdio at location 'c:\MethodPointerDebugRepro' on host 2524.
[info]: OmniSharp.MSBuild.ProjectManager
Successfully loaded project file 'c:\MethodPointerDebugRepro\MethodPointerDebugRepro.csproj'.
[info]: OmniSharp.MSBuild.ProjectManager
Adding project 'c:\MethodPointerDebugRepro\MethodPointerDebugRepro.csproj'
[info]: OmniSharp.MSBuild.ProjectManager
Update project: MethodPointerDebugRepro
[info]: OmniSharp.Roslyn.CSharp.Services.Diagnostics.CSharpDiagnosticWorkerWithAnalyzers
Solution initialized -> queue all documents for code analysis. Initial document count: 3.
C# log
Environment information
VSCode version: 1.48.2
C# Extension: 1.23.2
Dotnet Information
.NET SDK (reflecting any global.json): Version: 5.0.100-rc.2.20459.10 Commit: 2815f3cae1Runtime Environment:
OS Name: Windows
OS Version: 10.0.18362
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\5.0.100-rc.2.20459.10\
Host (useful for support):
Version: 5.0.0-rc.2.20458.14
Commit: 482494f9ec
.NET SDKs installed:
1.0.4 [C:\Program Files\dotnet\sdk]
3.0.100 [C:\Program Files\dotnet\sdk]
3.1.100 [C:\Program Files\dotnet\sdk]
3.1.102 [C:\Program Files\dotnet\sdk]
3.1.300 [C:\Program Files\dotnet\sdk]
5.0.100-rc.2.20459.10 [C:\Program Files\dotnet\sdk]
.NET runtimes installed:
Microsoft.AspNetCore.All 2.1.18 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.18 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 5.0.0-rc.2.20458.16 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 1.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 1.1.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.18 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.0-alpha.1.19564.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.0-rc.2.20458.14 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.1.2 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 3.1.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 5.0.0-rc.2.20454.1 [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 |
---|---|---|
Align | steve8708 | 0.2.0 |
better-powershell-syntax-highlighting | justin-grote | 0.0.2 |
bracket-pair-colorizer-2 | CoenraadS | 0.2.0 |
csharp | ms-dotnettools | 1.23.2 |
docomment | k--kato | 0.1.18 |
EditorConfig | EditorConfig | 0.15.1 |
github-markdown-preview | bierner | 0.0.2 |
gitlens | eamodio | 10.2.2 |
keyboard-quickfix | pascalsenn | 0.0.5 |
language-x86-64-assembly | 13xforever | 2.3.0 |
markdown-all-in-one | yzhang | 3.3.0 |
markdown-checkbox | bierner | 0.1.3 |
markdown-emoji | bierner | 0.0.9 |
markdown-preview-github-styles | bierner | 0.1.6 |
markdown-yaml-preamble | bierner | 0.0.4 |
midl-webidl-syntax | dave-deletethis | 0.0.1 |
msbuild-project-tools | tintoy | 0.3.8 |
pascal | alefragnani | 9.1.0 |
pascal-formatter | alefragnani | 2.4.0 |
powershell | ms-vscode | 2020.6.0 |
project-manager | alefragnani | 11.3.0 |
reg | ionutvmi | 1.0.1 |
roslynator | josefpihrt-vscode | 3.0.0 |
terminal-input | SeeminglyScience | 1.0.0 |
vim | vscodevim | 1.16.0 |
vscode-antlr4 | mike-lischke | 2.2.4 |
vscode-cil-complete | wk-j | 0.0.5 |
vscode-custom-snippets | NgekNgok | 1.1.4 |
vscode-markdownlint | DavidAnson | 0.36.3 |
vscode-pull-request-github | GitHub | 0.19.0 |
vscode-xml | redhat | 0.13.0 |
vscode-yaml | redhat | 0.10.1 |
xml | DotJoshJohnson | 2.5.1 |
I have a fix. Should go in shortly.
Fixed by #4091
I am not sure if this is two separate issues I am contending with but... All combinations were tried with NET6 and NET7 using omnisharp 1.25 and 1.25.1 (beta - to see if the issue was resolved). Latest VSCode, etc..
Apologies for the super sloppy code, but I tend to do that when I am fiddling. Just create a quick project, slap code in it, test, then delete it.
Anyhow, I have a scenario where I have a collection and a GetEnumerator method. Inside the GetEnumerator method, I call into a Native DLL. The code uses the most basic pinvoke just to eliminate that as a factor. Additionally, I started with the standard pinvoke using dllimport and evolved to trying other stuff like what the code currently shows. It all produces the same issue. The debugger view can not expand the result view of a collection that has a native call in its GetEnumerator method. Interestingly, I kept trying different combinations of code & pinvoke to see if I could get the debugger results view to expand with the internal native call. If I use the marshall class to convert the IntPtr from the function symbol to a delegate and then call the managed delegate within the GetEnumerator, that seems to work fine.
The second issue is more apparent directly in the code I have zipped. If there is a C#9 function pointer as a field of a class (in this case), the debugger refuses to elaborate anything within the class in the view. It gives the error shown.
One other thing to note is that I tried this within VS community 2022. It appears that the VS community debugger can somewhat handle the GetEnumerator issue, but still fails due to the function pointer. It won't let me expand the list variable, but let's me open another view where you can view the IEnumerable. VS community is fully updated.
I zipped the project so that simple things can be fiddled with to see if there are any changes.
Is #4091 available yet to test or is it already in 1.25.1 beta? Perhaps it may fix the second issue.
@LostTime76 please open a new issue instead of commenting on a closed issue.
Ok. Should I open 2 issues or just one? I am pretty sure these are two separate things. However, I am not sure if the fields one may already be fixed in a pending release and I don't want to open a ticket if I just have to wait for that one.
I would probably open two issues, but either way is fine.