vscode-csharp icon indicating copy to clipboard operation
vscode-csharp copied to clipboard

Linux Debugging fails with 'Unknown Error: 0x80131c3c' if LD_LIBRARY_PATH includes '.' or empty entries

Open gchiaia opened this issue 3 years ago • 19 comments

NOTE: This description was edited by this repo's maintainers to clarify when this happens and the work around.

Issue Description

C# debugging stopped working after installing dotnet-sdk-7 on different Linux setups (Ubuntu 22.0, OpenSuse 15.4)

Steps to Reproduce

Modify LD_LIBRARY_PATH in VS Code's environment to either include . or an empty entry Install dotnet SDK 7 debug (F5) simple "Hello World " console application.

Actual Behavior

Debugging fails with: 'Unable to attach to CoreCLR. Unknown Error: 0x80131c3c'

Work around

There are two possible work arounds if you run into this --

Option 1

Modify LD_LIBRARY_PATH to remove those entries

Option 2

# NOTE1: replace '.vscode' with whatever version of Code you have installed (ex: .vscode-server for VS Code remote scenarios)
# NOTE2: replace '1.25.2' with whatever version of the C# extension you have
cd ~/.vscode/extensions/ms-dotnettools.csharp-1.25.2-linux-x64/.debugger
mv libmscordbi.so libmscordbi.so.bak
mv libmscordaccore.so libmscordaccore.so.bak

Logs

-> (C) {"command":"initialize","arguments":{"clientID":"vscode","clientName":"Visual Studio Code","adapterID":"coreclr","pathFormat":"path","linesStartAt1":true,"columnsStartAt1":true,"supportsVariableType":true,"supportsVariablePaging":true,"supportsRunInTerminalRequest":true,"locale":"en-gb","supportsProgressReporting":true,"supportsInvalidatedEvent":true,"supportsMemoryReferences":true,"supportsArgsCanBeInterpretedByShell":true,"supportsMemoryEvent":true},"type":"request","seq":1} -> (C) {"command":"launch","arguments":{"name":".NET Core Launch (console)","type":"coreclr","request":"launch","preLaunchTask":"build","program":"/mars/proj/csharp/Snippet/snippet/bin/Debug/net7.0/snippet.dll","args":[],"cwd":"/mars/proj/csharp/Snippet/snippet","console":"internalConsole","stopAtEntry":false,"logging":{"engineLogging":false},"__configurationTarget":6,"internalConsoleOptions":"openOnSessionStart","__sessionId":"2b9a69c7-bec6-4550-b942-b8b7adcd87b2"},"type":"request","seq":2} <- (E) {"seq":4,"type":"event","event":"output","body":{"category":"console","output":"-------------------------------------------------------------------\nYou may only use the Microsoft .NET Core Debugger (vsdbg) with\nVisual Studio Code, Visual Studio or Visual Studio for Mac software\nto help you develop and test your applications.\n-------------------------------------------------------------------\n","severity":"ok"}} ------------------------------------------------------------------- You may only use the Microsoft .NET Core Debugger (vsdbg) with Visual Studio Code, Visual Studio or Visual Studio for Mac software to help you develop and test your applications. ------------------------------------------------------------------- <- (R) {"seq":5,"type":"response","request_seq":2,"success":true,"command":"launch"} <- (E) {"seq":6,"type":"event","event":"initialized","body":{}} -> (C) {"command":"setBreakpoints","arguments":{"source":{"name":"Program.cs","path":"/mars/proj/csharp/Snippet/snippet/Program.cs","checksums":[{"algorithm":"SHA1","checksum":"abc75ff2f0684e0dbec4466653c5264070ddfa03"},{"algorithm":"SHA256","checksum":"eb41b513b31a491535ac06bc677df96b4b9b831a5f3fe982423034e0a6d2463b"},{"algorithm":"SHA1","checksum":"0bc6f1e91c1a85fca0c65e5c667392058989f774"},{"algorithm":"SHA256","checksum":"0acfd5307a189a90ed1d453645f6b2dbc59de964bad81292ce03eb305f18702e"}]},"lines":[5],"breakpoints":[{"line":5}],"sourceModified":false},"type":"request","seq":3} -> (C) {"command":"setFunctionBreakpoints","arguments":{"breakpoints":[]},"type":"request","seq":4} -> (C) {"command":"setExceptionBreakpoints","arguments":{"filters":[],"filterOptions":[{"filterId":"user-unhandled"}]},"type":"request","seq":5} <- (R) {"seq":7,"type":"response","request_seq":3,"success":true,"command":"setBreakpoints","body":{"breakpoints":[{"id":1,"verified":false,"message":"The breakpoint is pending and will be resolved when debugging starts.","line":5}]}} <- (R) {"seq":8,"type":"response","request_seq":4,"success":true,"command":"setFunctionBreakpoints","body":{"breakpoints":[]}} <- (R) {"seq":9,"type":"response","request_seq":5,"success":true,"command":"setExceptionBreakpoints","body":{"breakpoints":[{"verified":true}]}} -> (C) {"command":"configurationDone","type":"request","seq":6} <- (E) {"seq":10,"type":"event","event":"output","body":{"category":"telemetry","output":"VS/Diagnostics/Debugger/vsdbg/ProcessCreate","data":{"VS.Diagnostics.Debugger.vsdbg.Distribution.Version":"15.4","VS.Diagnostics.Debugger.vsdbg.TargetArchitecture":"AMD64","VS.Diagnostics.Debugger.vsdbg.Distribution.Name":"611d3582","VS.Diagnostics.Debugger.vsdbg.OSFamily":"Linux","VS.Diagnostics.Debugger.vsdbg.Version":"17.4.11017.1 commit:fe68eee3d38c1935f4872cebf5f8a86033673f76"}}} <- (E) {"seq":11,"type":"event","event":"process","body":{"name":"/mars/proj/csharp/Snippet/snippet/bin/Debug/net7.0/snippet.dll","systemProcessId":8719,"isLocalProcess":true,"startMethod":"launch"}} <- (E) {"seq":12,"type":"event","event":"breakpoint","body":{"reason":"changed","breakpoint":{"id":1,"verified":false,"message":"No symbols have been loaded for this document.","line":5}}} <- (E) {"seq":13,"type":"event","event":"output","body":{"category":"telemetry","output":"VS/Diagnostics/Debugger/vsdbg/Launch","data":{"VS.Diagnostics.Debugger.vsdbg.Launch.Duration":160,"VS.Diagnostics.Debugger.vsdbg.SourceFileMappings":0,"VS.Diagnostics.Debugger.vsdbg.VisualizerFileUsed":false,"VS.Diagnostics.Debugger.vsdbg.TargetType":"Live","VS.Diagnostics.Debugger.vsdbg.AdapterId":"coreclr","VS.Diagnostics.Debugger.vsdbg.Distribution.Version":"15.4","VS.Diagnostics.Debugger.vsdbg.Distribution.Name":"611d3582","VS.Diagnostics.Debugger.vsdbg.OSFamily":"Linux","VS.Diagnostics.Debugger.vsdbg.Version":"17.4.11017.1 commit:fe68eee3d38c1935f4872cebf5f8a86033673f76"}}} <- (R) {"seq":14,"type":"response","request_seq":6,"success":true,"command":"configurationDone"} -> (C) {"command":"threads","type":"request","seq":7} <- (R) {"seq":15,"type":"response","request_seq":7,"success":true,"command":"threads","body":{"threads":[]}} <- (E) {"seq":16,"type":"event","event":"output","body":{"category":"stderr","output":"Unable to attach to CoreCLR. Unknown Error: 0x80131c3c","severity":"error"}} Unable to attach to CoreCLR. Unknown Error: 0x80131c3c

OmniSharp log

Starting OmniSharp server at 22/12/2022, 21:45:20 Target: /mars/proj/csharp/Snippet/Snippet.sln

OmniSharp server started with .NET 7.0.101 . Path: /home/gualtiero/.vscode/extensions/ms-dotnettools.csharp-1.25.2-linux-x64/.omnisharp/1.39.2-net6.0/OmniSharp.dll PID: 8548

Starting OmniSharp on Unknown 0.0 (Unknown) info: OmniSharp.Services.DotNetCliService Checking the 'DOTNET_ROOT' environment variable to find a .NET SDK info: OmniSharp.Services.DotNetCliService Using the 'dotnet' on the PATH. info: OmniSharp.Services.DotNetCliService DotNetPath set to dotnet info: OmniSharp.MSBuild.Discovery.MSBuildLocator Located 2 MSBuild instance(s) 1: .NET Core SDK 7.0.101 17.4.0 - "/usr/share/dotnet/sdk/7.0.101/" 2: .NET Core SDK 6.0.402 17.3.2 - "/usr/share/dotnet/sdk/6.0.402/" info: OmniSharp.MSBuild.Discovery.MSBuildLocator Registered MSBuild instance: .NET Core SDK 7.0.101 17.4.0 - "/usr/share/dotnet/sdk/7.0.101/" info: OmniSharp.WorkspaceInitializer Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.CSharpFormattingWorkspaceOptionsProvider, Order: 0 info: OmniSharp.Cake.CakeProjectSystem Detecting Cake files in '/mars/proj/csharp/Snippet'. info: OmniSharp.Cake.CakeProjectSystem Did not find any Cake files info: OmniSharp.MSBuild.ProjectSystem Detecting projects in '/mars/proj/csharp/Snippet/Snippet.sln'. info: OmniSharp.MSBuild.ProjectManager Queue project update for '/mars/proj/csharp/Snippet/snippet/snippet.csproj' info: OmniSharp.Script.ScriptProjectSystem Detecting CSX files in '/mars/proj/csharp/Snippet'. info: OmniSharp.Script.ScriptProjectSystem Did not find any CSX files info: OmniSharp.WorkspaceInitializer Configuration finished. info: OmniSharp.Stdio.Host Omnisharp server running using Stdio at location '/mars/proj/csharp/Snippet' on host 8317. info: OmniSharp.MSBuild.ProjectManager Loading project: /mars/proj/csharp/Snippet/snippet/snippet.csproj info: OmniSharp.MSBuild.ProjectManager Successfully loaded project file '/mars/proj/csharp/Snippet/snippet/snippet.csproj'. info: OmniSharp.MSBuild.ProjectManager Adding project '/mars/proj/csharp/Snippet/snippet/snippet.csproj' info: OmniSharp.MSBuild.ProjectManager Update project: snippet Received response for /v2/codestructure but could not find request. Received response for /v2/getcodeactions but could not find request.

C# log

Environment information

VSCode version: 1.74.2 C# Extension: 1.25.2

Mono Information OmniSharp using mono: 6.12.0
Dotnet Information .NET SDK: Version: 7.0.101 Commit: bb24aafa11

Runtime Environment: OS Name: opensuse-leap OS Version: 15.4 OS Platform: Linux RID: linux-x64 Base Path: /usr/share/dotnet/sdk/7.0.101/

Host: Version: 7.0.1 Architecture: x64 Commit: 97203d38ba

.NET SDKs installed: 3.1.424 [/usr/share/dotnet/sdk] 5.0.408 [/usr/share/dotnet/sdk] 6.0.402 [/usr/share/dotnet/sdk] 7.0.101 [/usr/share/dotnet/sdk]

.NET runtimes installed: Microsoft.AspNetCore.App 3.1.30 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 5.0.17 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.10 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 7.0.1 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.NETCore.App 3.1.30 [/usr/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.17 [/usr/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.1 [/usr/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.6 [/usr/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.8 [/usr/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.10 [/usr/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 7.0.1 [/usr/share/dotnet/shared/Microsoft.NETCore.App]

Other architectures found: None

Environment variables: Not set

global.json file: Not found

Learn more: https://aka.ms/dotnet/info

Download .NET: https://aka.ms/dotnet/download

Visual Studio Code Extensions
Extension Author Version
better-cpp-syntax jeff-hykin 1.17.2
Bookmarks alefragnani 13.3.1
cmake twxs 0.0.17
cmake-tools ms-vscode 1.12.27
cpptools ms-vscode 1.13.8
cpptools-extension-pack ms-vscode 1.3.0
cpptools-themes ms-vscode 2.0.0
csharp ms-dotnettools 1.25.2
doxdocgen cschlosser 1.4.0
ilspy-vscode icsharpcode 0.13.1
remote-explorer ms-vscode 0.0.3
remote-ssh ms-vscode-remote 0.94.0
remote-wsl ms-vscode-remote 0.72.0
rust-analyzer rust-lang 0.3.1325
rust-syntax dustypomerleau 0.6.1
unity-code-snippets kleber-swf 1.3.0
vs-code-runner HarryHopkinson 2.0.1
vscode-docker ms-azuretools 1.23.3
vscode-dotnet-runtime ms-dotnettools 1.6.0
vscode-lldb vadimcn 1.8.1
vscode-solution-explorer fernandoescolar 0.7.4

gchiaia avatar Dec 22 '22 22:12 gchiaia

Finally figured it out but still need to understand why omnisharp is not doing this for me: I needed to copy a couple of shared libraries from SDK 7 to where the vdsbg is installed: In my case, the target directory is: ~/.vscode/extensions/ms-dotnettools.csharp-1.25.2-linux-x64/.debugger and the files to be copied there are: /usr/share/dotnet/shared/Microsoft.NETCore.App/7.0.1/libmscordaccore.so and /usr/share/dotnet/shared/Microsoft.NETCore.App/7.0.1/libmscordbi.so

The problem is those files were already there but for a NET6 build and not NET7. I guess this will be fixed when the debugger installed by omnisharp is NET7

gchiaia avatar Dec 23 '22 14:12 gchiaia

@gchiaia I am glad you found a work around. I am very confused why that helped, but I am glad you found something anyway.

That said, that is definitely not the "real" fix. vsdbg should be trying to load those two dlls from '/usr/share/dotnet/shared/Microsoft.NETCore.App/7.0.1'.

How did you install the .NET SDK? If instead of coping those two .so's next to vsdbg you instead delete them, what does that do?

There is a new debugger that is checked in but not released yet that does correct an issue in this area. That said, your symptoms sound different. So, I am not sure how likely whatever you are seeing is really the same as the problem that the new debugger is addressing.

gregg-miskelly avatar Jan 03 '23 18:01 gregg-miskelly

Thanks @gregg-miskelly , what I suspect is the following: the two "so" libraries, compiled against dotnet6 are in the same directory of the debugger executable and that path takes precedence against the location of the installed version for dotnet7, which is in /usr/share/dotnet/shared/Microsoft.NETCore.App/7.0.1/. Before that, I have tried everything else (including uninstalling sdK6 and re-installing sdk7 from the recipes given in the microsoft page), for two independent and different linux flavours (ubuntu and opensuse). On both systems, the dotnet executable (v7) worked, but the debugger (installed by omnisharp) did not. Or better, it started but could not attach to a dotnet7 code. The error messages 0x80131c3c told me that the issue was when loading the native shared objects. Hence how I fixed it.

You say: That said, that is definitely not the "real" fix. vsdbg should be trying to load those two dlls from '/usr/share/dotnet/shared/Microsoft.NETCore.App/7.0.1'.

But then, why does omnisharp debugger ships with its own (dotnet6) versions of those files?

gchiaia avatar Jan 03 '23 19:01 gchiaia

You also said: If instead of coping those two .so's next to vsdbg you instead delete them, what does that do?

I did not try but I guess it should work as well, as long as the system has a way to find the official ones (dlconfig) or LD_LIBRARY_PATH

gchiaia avatar Jan 03 '23 19:01 gchiaia

The way .NET debugging works is that a debugger will look at a target process, see where it is loading the .NET runtime (usually libcoreclr.so on Linux) from, and load the two libraries you referenced from next to it.

But then, why does omnisharp debugger ships with its own (dotnet6) versions of those files?

To be able to debug the debugger.

I did not try but I guess it should work as well, as long as the system has a way to find the official ones (dlconfig) or LD_LIBRARY_PATH)

When you get a chance, can you try this?

gregg-miskelly avatar Jan 03 '23 19:01 gregg-miskelly

Sure I will try and keep you posted. Thx

gchiaia avatar Jan 03 '23 19:01 gchiaia

Yes tested by renaming those two *.so to something else, so they can't be loaded, and the debugger does work. The only case when it does not is when the two original (from omnisharp) are there and I am debugging some dotnet7 code

gchiaia avatar Jan 03 '23 19:01 gchiaia

I just had a similar issue where I migrated a project from netcore3.1 to net6.0 and was getting the same unknown error. Removing those two .so files from the extension directory fixed the issue by probably making it fetch new ones from my dotnet install or something. In any case I am so lucky to to have found this issue with comments from 1 hour ago.

martinkozle avatar Jan 03 '23 21:01 martinkozle

Do either of you have any LD_ environment variables specified? I am trying to guess why you are seeing this while most folks do not.

gregg-miskelly avatar Jan 03 '23 21:01 gregg-miskelly

yes, my LD_LIBRARY_PATH contains the current directory (.)

gchiaia avatar Jan 03 '23 22:01 gchiaia

I don't know what this means but here you go:

$ printenv LD_LIBRARY_PATH
:/opt/rocm/lib:/opt/rocm/lib64:/opt/rocm/profiler/lib:/opt/rocm/profiler/lib64:/opt/rocm/opencl/lib:/opt/rocm/hip/lib:/opt/rocm/opencl/lib64:/opt/rocm/hip/lib64:/opt/rocm/lib:/opt/rocm/lib64:/opt/rocm/profiler/lib:/opt/rocm/profiler/lib64:/opt/rocm/opencl/lib:/opt/rocm/hip/lib:/opt/rocm/opencl/lib64:/opt/rocm/hip/lib64

For more context this issue for me happened when I upgraded from Fedora 36 to Fedora 37, reinstalled dotnet and ported my project to net6.0. The previous netcore3.1 .so files probably stayed around in the extension directory and caused the issue.

martinkozle avatar Jan 04 '23 01:01 martinkozle

@martinkozle you might have left out a "." at the beginning when you cut & pasted the output of printenv, since your output starts with a ":". In which case you also point to the current directory in your search for shared objects files. Also I have tested with other collegues using Linux and they have the same issue

gchiaia avatar Jan 04 '23 10:01 gchiaia

I checked again and there isn't a "." at the beginning, it starts with ":". I don't know what that would mean. But maybe when split an empty string would be evaluated as the current directory? I am not sure.

martinkozle avatar Jan 04 '23 18:01 martinkozle

I am able to repro the problem. DBI/DAC are loaded at the following call stack and they use a fully qualified path. But it looks like at least glibc (not sure about musl) will ignore the path if LD_LIBRARY_PATH is set.

Example arguments to dlopen:

Name Value Type
file 0x7fffefba24c0 "/usr/share/dotnet/shared/Microsoft.NETCore.App/7.0.0/libmscordbi.so" const char *
mode 0x1 (RTLD_LAZY) int

Call stack

libdl.so.2!__dlopen(const char * file, int mode) Line 75 at \build\glibc-SzIz7B\glibc-2.31\dlfcn\dlopen.c(75) libdbgshim.so!LOADLoadLibraryDirect(LPCSTR libraryNameOrPath) Line 1260 at __w\1\s\src\shared\pal\src\loader\module.cpp(1260) libdbgshim.so!LOADLoadLibrary(LPCSTR shortAsciiName, BOOL fDynamic) Line 1490 at __w\1\s\src\shared\pal\src\loader\module.cpp(1490) libdbgshim.so!LoadLibraryExW(LPCWSTR lpLibFileName, HANDLE hFile, DWORD dwFlags) Line 241 at __w\1\s\src\shared\pal\src\loader\module.cpp(241) libdbgshim.so!CreateCoreDbg(HMODULE hCLRModule, DWORD processId, SString & dbiModulePath, SString & dacModulePath, LPCWSTR lpApplicationGroupId, int iDebuggerVersion, IUnknown ** ppCordb) Line 172 at __w\1\s\src\dbgshim\dbgshim.cpp(172) libdbgshim.so!RuntimeStartupHelper::InvokeStartupCallback(RuntimeStartupHelper * this, const char * pszModulePath, HMODULE hModule) Line 385 at __w\1\s\src\dbgshim\dbgshim.cpp(385) libdbgshim.so!PAL_RuntimeStartupHelper::InvokeStartupCallback(PAL_RuntimeStartupHelper * this) Line 1504 at __w\1\s\src\shared\pal\src\thread\process.cpp(1504) libdbgshim.so!PAL_RuntimeStartupHelper::StartupHelperThread(PAL_RuntimeStartupHelper * this) Line 1559 at __w\1\s\src\shared\pal\src\thread\process.cpp(1559) libdbgshim.so!StartupHelperThread(LPVOID p) Line 1579 at __w\1\s\src\shared\pal\src\thread\process.cpp(1579) libdbgshim.so!CorUnix::CPalThread::ThreadEntry(void * pvParam) Line 739 at __w\1\s\src\shared\pal\src\thread\thread.cpp(739) libpthread.so.0!start_thread(void * arg) Line 477 at \build\glibc-SzIz7B\glibc-2.31\nptl\pthread_create.c(477) libc.so.6!clone() Line 95 at \build\glibc-SzIz7B\glibc-2.31\sysdeps\unix\sysv\linux\x86_64\clone.S(95)

gregg-miskelly avatar Jan 04 '23 23:01 gregg-miskelly

Thanks @gregg-miskelly for reproducing and providing solutions. Wouldn't it be better to remove those two "so" files from the debugger package all-together? After all they are part of the installed SDK package. Also, I had no problem running the debugger when my SDK was .NET6, and LD_LIBRARY_PATH was the same as it is now. Clearly the linux ld loader was picking up the shared objects in the debugger directory, but those where .NET6 and in line with my environment at the time. Only moving to the latest SDK created some incompatibility between shared objects, in my opinion.

gchiaia avatar Jan 05 '23 09:01 gchiaia

Wouldn't it be better to remove those two "so" files from the debugger package all-together?

Currently, that isn't possible. Doing so would make it impossible to debug the .NET code running in the debugger itself. Instead, vsdbg/vsdbg-ui will need some code to detect if an incompatible LD_LIBRARY_PATH is set, and if so, remove the incompatible entries, and fork itself.

Also, I had no problem running the debugger when my SDK was .NET6, and LD_LIBRARY_PATH was the same as it is now.

To some degree you were lucky -- the .NET debugger runtime is super tightly coupled to the .NET runtime. So just because vsdbg-ui might have used some 6.0.x runtime, and your test application also did, that doesn't mean the two would be close enough for things to work.

gregg-miskelly avatar Jan 05 '23 17:01 gregg-miskelly

Option 2 worked here, let's see how long it lasts

Looking forward for a fix on this

coloboxp avatar Mar 06 '23 17:03 coloboxp

This issue was fixed a few releases ago, but we forgot to resolve it.

gregg-miskelly avatar Oct 02 '23 16:10 gregg-miskelly

the error is repeated - https://github.com/dotnet/vscode-csharp/issues/7377

ShevRuslan avatar Jul 20 '24 22:07 ShevRuslan