Resolved: Can't get debugging to work in VSCode on Windows ARM

Hello,

I can't get debugging to work in VScode on a Windows 11 ARM VM.

I am not sure if that's simply because ARM is not yet supported (although building and everything except debugging seems to work), or if there's some problem with my setup.

The behavior I see is that everything (i.e., package resolution, building) works fine, except for debugging, where nothing happens after the build step has completed.

I tried with and without the "Use Debug Adapter From Toolchain" setting, but saw no difference. The debugging session simply would not start in either case.

I tried different toolchains, both the official Swift.org one, as well as builds by The Browser Company. I provided some diagnostics for the different toolchains below.

Environment & Test App

  • VSCode 1.96.2
  • Swift extension 1.11.4
  • Windows 11 Home 24H2
  • on a 2021 Mac Book Pro with M1 Pro

My test app is a minimal console app created with SPM.

Test app
@main
struct HelloConsole {
  static func main() {
    print("hello, console")
  }
}
// swift-tools-version: 6.0
import PackageDescription

let package = Package(
    name: "helloconsole",
    targets: [
        .executableTarget(
            name: "helloconsole"),
    ]
)
launch.json
{
    "configurations": [
        {
            "type": "swift-lldb",
            "request": "launch",
            "args": [],
            "cwd": "${workspaceFolder:helloconsole}",
            "name": "Debug helloconsole",
            "program": "${workspaceFolder:helloconsole}/.build/debug/helloconsole",
            "preLaunchTask": "swift: Build Debug helloconsole"
        },
        {
            "type": "swift-lldb",
            "request": "launch",
            "args": [],
            "cwd": "${workspaceFolder:helloconsole}",
            "name": "Release helloconsole",
            "program": "${workspaceFolder:helloconsole}/.build/release/helloconsole",
            "preLaunchTask": "swift: Build Release helloconsole"
        }
    ]
}

Swift.org latest 6.0 release, installed via winget

Following the installation instructions, this toolchain doesn't work:

PS E:\sandbox\compositorapp\helloconsole> swift build
error: toolchain is invalid: could not find CLI tool `link` at any of these directories: [<AbsolutePath:"C:\WINDOWS\system32">, 
<AbsolutePath:"C:\WINDOWS">, <AbsolutePath:"C:\WINDOWS\System32\Wbem">, <AbsolutePath:"C:\WINDOWS\System32\WindowsPowerShell\v1.0\">, 
<AbsolutePath:"C:\WINDOWS\System32\OpenSSH\">, <AbsolutePath:"C:\Program Files\Git\cmd">, <AbsolutePath:"C:\Program Files\dotnet\">, 
<AbsolutePath:"C:\Users\karl\AppData\Local\Programs\Python\Python39\Scripts\">, <AbsolutePath:"C:\Users\karl\AppData\Local\Programs\Python\Python39\">, 
<AbsolutePath:"C:\Users\karl\AppData\Local\Microsoft\WindowsApps">, <AbsolutePath:"C:\Users\karl\AppData\Local\Programs\Visual Studio Code\bin">, 
<AbsolutePath:"C:\Users\karl\bin">, <AbsolutePath:"C:\Users\karl\.dotnet\tools">, <AbsolutePath:"E:\Swift\Runtimes\6.0.2\usr\bin\">, 
<AbsolutePath:"E:\Swift\Toolchains\6.0.2+Asserts\usr\bin\">]
Diagnostics
> swift -version
Swift version 6.0.2 (swift-6.0.2-RELEASE)
Target: aarch64-unknown-windows-msvc

Settings captured by VScode Swift diagnostics:

Swift version 6.0.2 (swift-6.0.2-RELEASE)
Platform: win32
Swift Path: E:\Swift\Toolchains\6.0.2+Asserts\usr\bin
Toolchain Path: E:\Swift\Toolchains\6.0.2+Asserts\usr
Runtime Library Path: E:\Swift\Runtimes\6.0.2\usr\bin
Default Target: aarch64-unknown-windows-msvc
Settings:
{
  "path": "e:\\Swift\\Toolchains\\6.0.2+Asserts\\usr\\bin",
  "buildArguments": [],
  "additionalTestArguments": [],
  "testEnvironmentVariables": {},
  "sanitizer": "off",
  "searchSubfoldersForPackages": false,
  "autoGenerateLaunchConfigurations": true,
  "disableAutoResolve": false,
  "diagnosticsCollection": "keepSourceKit",
  "diagnosticsStyle": "llvm",
  "backgroundCompilation": false,
  "actionAfterBuildError": "Focus Terminal",
  "buildPath": "",
  "disableSwiftPackageManagerIntegration": false,
  "warnAboutSymlinkCreation": true,
  "enableTerminalEnvironment": true,
  "excludeFromCodeCoverage": [],
  "excludePathsFromPackageDependencies": [
    ".git",
    ".github"
  ],
  "showBuildStatus": "swiftStatus",
  "showCreateSwiftProjectInWelcomePage": true,
  "openAfterCreateNewProject": "prompt",
  "sourcekit-lsp": {
    "serverPath": "",
    "serverArguments": [],
    "supported-languages": [
      "swift",
      "objective-c",
      "objective-cpp",
      "c",
      "cpp"
    ],
    "backgroundIndexing": "auto",
    "trace": {
      "server": "off"
    },
    "disable": false
  },
  "debugger": {
    "useDebugAdapterFromToolchain": true,
    "path": ""
  },
  "swiftEnvironmentVariables": {
    "DEVELOPER_DIR": "public"
  },
  "runtimePath": "",
  "SDK": "",
  "diagnostics": false
}

Swift.org latest 6.0 release, manual installer

Using this installer, the toolchain works fine, except for debugging.

Diagnostics
> swift -version
Swift version 6.0.3 (swift-6.0.3-RELEASE)
Target: aarch64-unknown-windows-msvc

Settings captured by VScode Swift diagnostics:

Swift version 6.0.3 (swift-6.0.3-RELEASE)
Platform: win32
Swift Path: E:\Swift\Toolchains\6.0.3+Asserts\usr\bin
Toolchain Path: E:\Swift\Toolchains\6.0.3+Asserts\usr
Runtime Library Path: E:\Swift\Runtimes\6.0.3\usr\bin
Default Target: aarch64-unknown-windows-msvc
Default SDK: E:\Swift\Platforms\6.0.3\Windows.platform\Developer\SDKs\Windows.sdk\
XCTest Path: E:\Swift\Platforms\6.0.3\Windows.platform\Developer\Library\XCTest-development\usr\bin64a
Settings:
{
  "path": "",
  "buildArguments": [],
  "additionalTestArguments": [],
  "testEnvironmentVariables": {},
  "sanitizer": "off",
  "searchSubfoldersForPackages": false,
  "autoGenerateLaunchConfigurations": true,
  "disableAutoResolve": false,
  "diagnosticsCollection": "keepSourceKit",
  "diagnosticsStyle": "llvm",
  "backgroundCompilation": false,
  "actionAfterBuildError": "Focus Terminal",
  "buildPath": "",
  "disableSwiftPackageManagerIntegration": false,
  "warnAboutSymlinkCreation": true,
  "enableTerminalEnvironment": true,
  "excludeFromCodeCoverage": [],
  "excludePathsFromPackageDependencies": [
    ".git",
    ".github"
  ],
  "showBuildStatus": "swiftStatus",
  "showCreateSwiftProjectInWelcomePage": true,
  "openAfterCreateNewProject": "prompt",
  "sourcekit-lsp": {
    "serverPath": "",
    "serverArguments": [],
    "supported-languages": [
      "swift",
      "objective-c",
      "objective-cpp",
      "c",
      "cpp"
    ],
    "backgroundIndexing": "auto",
    "trace": {
      "server": "off"
    },
    "disable": false
  },
  "debugger": {
    "useDebugAdapterFromToolchain": true,
    "path": ""
  },
  "swiftEnvironmentVariables": {},
  "runtimePath": "",
  "SDK": "",
  "diagnostics": false
}

The Browser Company's latest dev release 20241227.3

This toolchain also works fine, except for debugging.

Diagnostics
> swift -version
compnerd.org Swift version 6.2-dev (LLVM 9f6c3d784782c34, Swift 55189bae8e55169)
Target: aarch64-unknown-windows-msvc

Settings captured by VScode Swift diagnostics:

compnerd.org Swift version 6.2-dev (LLVM 9f6c3d784782c34, Swift 55189bae8e55169)
Platform: win32
Swift Path: E:\Swift\Toolchains\0.0.0+Asserts\usr\bin
Toolchain Path: E:\Swift\Toolchains\0.0.0+Asserts\usr
Runtime Library Path: E:\Swift\Runtimes\0.0.0\usr\bin
Default Target: aarch64-unknown-windows-msvc
Default SDK: E:\Swift\Platforms\0.0.0\Windows.platform\Developer\SDKs\Windows.sdk\
XCTest Path: E:\Swift\Platforms\0.0.0\Windows.platform\Developer\Library\XCTest-development\usr\bin64a
Settings:
{
  "path": "",
  "buildArguments": [],
  "additionalTestArguments": [],
  "testEnvironmentVariables": {},
  "sanitizer": "off",
  "searchSubfoldersForPackages": false,
  "autoGenerateLaunchConfigurations": true,
  "disableAutoResolve": false,
  "diagnosticsCollection": "keepSourceKit",
  "diagnosticsStyle": "llvm",
  "backgroundCompilation": false,
  "actionAfterBuildError": "Focus Terminal",
  "buildPath": "",
  "disableSwiftPackageManagerIntegration": false,
  "warnAboutSymlinkCreation": true,
  "enableTerminalEnvironment": true,
  "excludeFromCodeCoverage": [],
  "excludePathsFromPackageDependencies": [
    ".git",
    ".github"
  ],
  "showBuildStatus": "swiftStatus",
  "showCreateSwiftProjectInWelcomePage": true,
  "openAfterCreateNewProject": "prompt",
  "sourcekit-lsp": {
    "serverPath": "",
    "serverArguments": [],
    "supported-languages": [
      "swift",
      "objective-c",
      "objective-cpp",
      "c",
      "cpp"
    ],
    "backgroundIndexing": "auto",
    "trace": {
      "server": "off"
    },
    "disable": false
  },
  "debugger": {
    "useDebugAdapterFromToolchain": true,
    "path": "E:\\Swift\\Toolchains\\0.0.0+Asserts\\usr\\bin\\lldb-dap.exe"
  },
  "swiftEnvironmentVariables": {
    "DEVELOPER_DIR": "public"
  },
  "runtimePath": "",
  "SDK": "",
  "diagnostics": false
}

Thanks in advance,
Karl

Did you install the right version of python? You need to have Python 3.9.x for ARM64 that is installed and setup properly for debugging to function. Currently, I'd recommend using The Browser Company developer snapshot as there is a bug in the 6.0 released ARM64 toolchain (the compiler is miscompiled due to a bug in MSVC that has been fixed but we need to update the MSVC release).

1 Like

The winget step has skipped over Python, so I think the right version is installed:

> winget install --id Swift.Toolchain -e -i
Found Swift [Swift.Toolchain] Version 6.0.2
This application is licensed to you by its owner.
Microsoft is not responsible for, nor does it grant any licenses to, third-party packages.
This package requires the following dependencies:
  - Packages
      Git.Git
      Microsoft.VCRedist.2015+.x64 [>= 14.28.29913.0]
      Python.Python.3.9
Downloading https://download.swift.org/swift-6.0.2-release/windows10-arm64/swift-6.0.2-RELEASE/swift-6.0.2-RELEASE-windows10-arm64.exe
  ██████████████████████████████   440 MB /  440 MB
Successfully verified installer hash
Starting package install...
Successfully installed

Here's what I have installed:

Can you verify that the Python that is installed is arm64 and not x64? Windows does have a built-in emulator that allows you to run x64 software on ARM64 but that would not be sufficient for this purpose as we link against the DLL and this is not built for ARM64EC.

Ah, it says AMD64:

> python
Python 3.9.13 (tags/v3.9.13:6de2ca5, May 17 2022, 16:36:42) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.

But after uninstalling that version and installing the latest Python 3.12.8 ARM64, as well as The Browser Company's developer snapshot Swift toolchain, the debug session still doesn't start.

Hmm.

Can you launch lldb from the command line at this point? Until that functions, it is unlikely that the debugging in VSCode will function.

Sorry, just re-read this - this will not work. You must have Python 3.9.x for ARM64 for this to work.

I couldn't find a Python 3.9 ARM64 installer, so I tried building it from source. But it appears the Python 3.9 msi (installer) subsystem only supports x86 and x64 build targets, so I wasn't able to produce an installer for ARM64.

Please have a look at this post Swift Installer for Windows on ARM? - #15 by compnerd

1 Like

That did the trick, debugging now works! Thank you so much!

(I had to add the path to python.exe to my PATH)

1 Like

UPDATE:
/cc @compnerd

Had to also set PYTHONHOME, now it works-ish.

So now it does trigger the breakpoint but when I try and use the console to do something like po foo I get the error below. Interestingly this is only when I try and print something in a dependent package. If I store a local variable, I can print that just fine.

Given this code:

import MyLib

let rect = Rect(x: 0, y: 0, width: 100, height: 100) // defined in MyLib
print(rect) // causes error below

let foo = "foo"
let bar = "bar"
let result = foo + bar
print(result) // prints "foobar" as expected

FYI if I let that print statement execute, I do see the result as expected in the console. I just can't do po from a debugger session :frowning:

Error while parsing SDK path from debug info: class llvm::Expected<class lldb_private::XcodeSDK> __cdecl lldb_private::Platform::GetSDKPathFromDebugInfo(class lldb_private::CompileUnit &) not implemented for 'host' platform.error: Error while parsing SDK path from debug info: class llvm::Expected<class lldb_private::XcodeSDK> __cdecl lldb_private::Platform::GetSDKPathFromDebugInfo(class lldb_private::CompileUnit &) not implemented for 'host' platform.
Summary

Can you clarify more specifically because if I check in Terminal I can see I have Python 3.9.13 however when I try and run Debug Tests for example I still get this output "Error: "Debugger not started"

I have added it to my PATH and also system environment variables for PYTHONPATH but I still am unable to Debug builds or tests :frowning:

Everything else appears to work well tbh, especially with the latest 6.1 release.

I think that the issue about the SDK path might be something related to recent changes around this path? CC: @JDevlieghere