runtime: Debugging not working with XCode 12 selected

Description

In VSMac, we are using vsdbg(same as Omnisharp) to debug .NET Core applications… We have unit tests, but ever since bumping XCode from 11 to 12, debugging started failing… So here are repro steps:

  1. sudo xcode-select -s /Applications/Xcode_12.app
  2. mkdir xcodeTestProj
  3. cd xcodeTestProj
  4. dotnet new console
  5. dotnet publish --runtime osx-x64
  6. code .
  7. create launch.json via VSCode, and change:
  • "program": "${workspaceFolder}/bin/Debug/net5.0/xcodeTestProj.dll",
  • to
  • "program": "${workspaceFolder}/bin/Debug/net5.0/osx-x64/publish/xcodeTestProj.dll",
  1. Start debugging
  2. Observe Debug Console print Unable to attach to CoreCLR. Unknown Error: 0x80131c3c

Now try all steps, but change step 1 to sudo xcode-select -s /Applications/Xcode_11.app(notice change of Xcode version), it will work fine.

I tried to change to not use published version… But when tests are executing they fail either wrong variables values are reported or “Unable to evaluate expression because the code is optimized o…”.(Only when using XCode 12, fine with XCode 11). I believe underlining problem is same, hence I suggest trying debugging published app since its easier repro…

Im not sure how is selecting XCode 12 vs 11 effecting debugging of CoreCLR, but it does, I suspect its something related to lldb or some libraries used…

Configuration

  • Which version of .NET is the code running on? 3.1, but also tried with 5.0
  • What OS and version, and what distro if applicable? macOs
  • What is the architecture (x64, x86, ARM, ARM64)? x64
  • Do you know whether it is specific to that configuration? Yes(macOs)
  • If you’re using Blazor, which web browser(s) do you see this issue in? N/A

Regression?

No.

Other information

We have to disable .NET Core unit tests for until this is resolved, but I also believe this will effect users when doing some complex debugging.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 6
  • Comments: 38 (15 by maintainers)

Most upvoted comments

Re workaround:

It seems that downloading and installing the “Command Line Developer Tools for Xcode 11.5” (*.dmg, contains an installer package (*.pkg), about 260MB) from https://developer.apple.com/download/more/ is sufficient (no need for Xcode 11 as a whole).

Once installed, switch to this version of the tools with sudo xcode-select -s /Library/Developer/CommandLineTools

I can confirm this workaround.

  1. Download Xcode 11: https://download.developer.apple.com/Developer_Tools/Xcode_11.7/Xcode_11.7.xip
  2. Unzip and rename to Xcode_11
  3. Move it to your Applications folder
  4. Open terminal
  5. Go to root: cd /
  6. Run: sudo xcode-select -s /Applications/Xcode_11.app

Now everything works for me.

The fix had been merged in time to make it into our next official build. After that it needs to be picked up by the different debuggers in the ecosystem. VS for mac and VSCode use the same debugger engine and the owners expressed interest in including the fix as soon as possible.

Thanks!

Download Xcode

The direct link to the Xcode 11.7 file didn’t work for me.

In case anyone else is having trouble, go to Apple’s More Downloads for Apple Developers page and search Xcode 11.7 👍

image

I am assuming there will be a more official debugger zip at some point with this updated libdbgshim.dylib that can be bundled with OmniSharp and VS Mac?

Yes, soon after 5.0.1 ships the VS debugger team expects to put out a new release of vsdbg-ui which can be included into the VS Code C# extension and VS For Mac.

Ran a test of this fix and it looks good to me with Xcode 12.2.

  • Installed .NET 5.0.1
  • Ran David’s repro steps.
  • Debugger fails
  • Copied the dylib from .net 5.0.1 from /usr/local/share/dotnet/shared/Microsoft.NETCore.App/5.0.1/libdbgshim.dylib to ~/.vscode/extensions/ms-dotnettools.csharp-1.23.6/.debugger
  • Restarted VS Code and then debugged the project again
    • the debugger runs and breakpoints can be hit in the console project.

I am assuming there will be a more official debugger zip at some point with this updated libdbgshim.dylib that can be bundled with OmniSharp and VS Mac?

VS4M version 8.8.4.30 which contains a fix for this issue is available by now: https://docs.microsoft.com/en-us/visualstudio/releasenotes/vs2019-mac-relnotes#884

Issue can probably get closed.

@kuromukira There should be a new VS Mac 8.8.4 release with the updated debugger at some point - I do not have a specific date as yet.

For a workaround you can probably copy the libdbgshim.dylib from /usr/local/share/dotnet/shared/Microsoft.NETCore.App/5.0.1/libdbgshim.dylib into VS Mac’s app bundle /Applications/Visual\ Studio.app/Contents/Resources/lib/monodevelop/AddIns/DotNetCore.Debugger/Adapter/libdbgshim.dylib - making a backup copy of this file in the Adapter directory so you can rollback if it breaks something.

@wingchunninja Sorry, I was testing an internal 5.0.1 build. Not sure if this change has made it into the 5.0.200 preview builds from https://github.com/dotnet/installer yet.

@mrward Thank you for the hint. This did the work for me 🙂

@sdmaclea Because this is a dbgshim fix - it doesn’t need to be. Any debugger that wants this fix can use the .NET 5 dbgshim.

@kuromukira you can use the workarounds posted above to debug normally. Using an older copy of Xcode. Its pretty easy to switch back and forth if you also do other things with Xcode 12.

Hi @tommcdon @hoyosjs,

Im wonder how could priority on this be increased so someone takes a look at this since more and more developers will start switching to XCode 12 since it was released last week, and milestone .NET 6 feels too far away… At first I though this would only be problem for unit tests but looks like its effecting also developers…

Regards, David