codelldb icon indicating copy to clipboard operation
codelldb copied to clipboard

Unable to debug Swift on Windows

Open svanimpe opened this issue 3 years ago • 6 comments

OS: Windows 11 VSCode version: 1.61.2 CodeLLDB version: 1.6.8 Compiler: Swift 5.5

I am unable to debug any Swift applications on Windows. I keep getting the following error after my app finishes building:

Fatal Python error: initfsencoding: unable to load the file system codec
ModuleNotFoundError: No module named 'encodings'

So far, I've:

  • set lldb.library to the liblldb.dll that comes with Swift
  • set PYTHONHOME and PYTHONPATH environment variables
  • set the same variables in my lldb.adapterEnv

but with no success. On macOS and Linux, setting lldb.library was enough to get this working.

Verbose log
 configuration: {
  type: 'lldb',
  request: 'launch',
  name: 'Debug',
  program: '${workspaceFolder}/.build/debug/Squares.exe',
  args: [],
  cwd: '${workspaceFolder}',
  preLaunchTask: 'swift build',
  __configurationTarget: 5,
  noDebug: true,
  relativePathBase: 'c:\\Users\\steve\\Projects\\Squares'
}
liblldb: C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\liblldb.dll
environment: {
  PYTHONHOME: 'C:\\Users\\steve\\AppData\\Local\\Programs\\Python\\Python37',
  PYTHONPATH: 'C:\\Users\\steve\\AppData\\Local\\Programs\\Python\\Python37'
}
params: { evaluateForHovers: true, commandCompletions: true }
Listening on port 52531
[2021-10-31T19:17:20.921Z DEBUG codelldb] New debug session
Fatal Python error: initfsencoding: unable to load the file system codec
ModuleNotFoundError: No module named 'encodings'

Current thread 0x000014b0 (most recent call first): Debug adapter exit code=3221226505, signal=null.

svanimpe avatar Oct 31 '21 19:10 svanimpe

Looks like Swft's LLDB is broken in some way. Can you debug with CLI lldb?

vadimcn avatar Oct 31 '21 19:10 vadimcn

I am unfamiliar with the CLI but if I try to follow the example on swift.org, I also get stuck. I can launch the executable in LLDB, but cannot set any breakpoints. This seems to be a known issue (https://bugs.swift.org/browse/SR-14243)

svanimpe avatar Nov 01 '21 08:11 svanimpe

I got same problem. cannot set any breakpoints, vscode showed an hollow circle

vonyu avatar Nov 14 '21 19:11 vonyu

I've noticed that when compiling in release mode, I can set breakpoints. However, without the Swift-specific LLDB, the variable names are mangled.

svanimpe avatar Dec 19 '21 10:12 svanimpe

Hi svanimpe. I am having the same error as you reported above. Has your issue been fixed yet?

Fatal Python error: initfsencoding: unable to load the file system codec
ModuleNotFoundError: No module named 'encodings'

OS: Windows 10 VSCode version: 1.65.2 Swift extension version: 0.5.0 CodeLLDB version: 1.7.0 Compiler: Swift 5.6.1

I have read the following, which all seem to be related to your issue:

https://github.com/swift-server/vscode-swift/issues/250
https://github.com/swift-server/vscode-swift/pull/275
https://github.com/swift-server/vscode-swift/issues/260
https://github.com/swift-server/vscode-swift/pull/57

It looks like it may be fixed but not yet released, but I am new to understanding github, so I cannot tell if the necessary fixes have been created, merged, and released. Or if we are looking at the next release to contain the fixes. Any thoughts would be welcome!

gandalfas avatar May 09 '22 14:05 gandalfas

Another Swift lldb and Python issue. Swift lldb Python integration on Windows basically doesn't work in swift 5.6 and earlier (unlike ubuntu where it has been broken since 5.6). This is resolved in the latest 5.7 nightly.

adam-fowler avatar May 29 '22 11:05 adam-fowler