vscode-swift: On Windows 10, at launch of LLDB, program is unable to access stdout or stdin

Issue Description

On Windows 10, at the launch of Swift’s custom LLDB by the Swift extension for VS Code (vscode-swift), the user program’s output from the ‘print()’ statement is nowhere to be seen, and the attempt to do ‘readline()’ gets an EOF result.

The issue seems most likely to be in the Swift extension for VS Code, or possibly in the CodeLLDB extension. This is based on the ‘Variations’ section, below.

This is in the global settings.json file, which correctly points to the Swift custom LLDB:

{
    "lldb.library": "C:\\Library\\Developer\\Toolchains\\unknown-Asserts-development.xctoolchain\\usr\\bin\\liblldb.dll"
}

Discovered during work on #301.

Let me know if you need me to provide any additional information.

Environment

OS: Windows 10 VSCode version: 1.67.1 Swift extension version: 0.5.2 CodeLLDB version: 1.7.0 Compiler: Swift 5/04/22 ‘latest snapshot of main’: swift-DEVELOPMENT-SNAPSHOT-2022-05-04-a-windows10.exe

  • Note: The results below differ substantially if the slightly earlier release, Swift 5.6.1, is used - see #301.

Test Case

md hello cd hello swift package init --type=executable place these lines into main.swift:

import Foundation

print("Hello, world!")
print("enter something  ->", terminator: "")

guard let answer = readLine() else {
    print("End of File was reached - aborting...")
    exit(1)
}
print("readline() did not see EOF")

open folder with VS Code compile with: Terminal > Build Debug hello hello.exe is built. set a breakpoint on ‘Hello,world’ line. click Run > Start Debugging, and then step through the program.

Expected Behavior

This expectation is based on one of the ‘Variations’ - see below. At this point you should see the following in VS Code’s lower pane > Terminal tab. When the prompt “enter something” appears, you should be able to enter text, for example “abc”. Control should skip over the ‘else’ to the print statement at the bottom of the program. At the end of execution, the Terminal tab should show:

Hello, world!
enter something  ->abc
readline() did not see EOF

Actual Behavior

A new command prompt window is created, titled with ‘hello.exe’. It remains empty throughout program execution.

The output of the print statements is nowhere to be seen - neither in the VS Code lower pane in tab ‘Terminal’, nor in the new empty command prompt window.

As you step over the ‘readline()’ statement, the program fails to wait for you to enter text, control simply falls into the ‘else’ part of the guard, where EOF is handled.

This output appears in the lower pane, tab ‘Output’, channel LLDB:

configuration: {
  type: 'lldb',
  request: 'launch',
  name: 'Debug hello',
  program: '${workspaceFolder:hello}/.build/debug/hello',
  args: [],
  cwd: '${workspaceFolder:hello}',
  preLaunchTask: 'swift: Build Debug hello',
  __configurationTarget: 5,
  relativePathBase: 'k:\\Kim Shared\\CodeLab\\SwiftTests\\hello'
}
[adapter\src\terminal.rs:104] FreeConsole() = 1
[adapter\src\terminal.rs:105] AttachConsole(pid) = 1
[adapter\src\terminal.rs:109] FreeConsole() = 1
[2022-05-17T23:49:11.082Z ERROR codelldb::debug_session] Internal debugger error: Invalid frame reference: 1001

There seems to be some variability in this error log - in another similar case, shown in #301, in the comments by me starting with “Alrighty”, I had this instead:

[adapter\src\terminal.rs:104] FreeConsole() = 1
[adapter\src\terminal.rs:105] AttachConsole(pid) = 1
[adapter\src\terminal.rs:109] FreeConsole() = 1
ERROR(Python) 20:38:54 codelldb: Traceback (most recent call last):
  File "c:\Users/Kim/.vscode/extensions/vadimcn.vscode-lldb-1.7.0/adapter\codelldb.py", line 152, in evaluate
    value = evaluate_in_context(pycode, is_simple_expr, context)
  File "c:\Users/Kim/.vscode/extensions/vadimcn.vscode-lldb-1.7.0/adapter\codelldb.py", line 288, in evaluate_in_context
    return eval(code, eval_globals, eval_locals)
  File "<input>", line 1, in <module>
  File "c:\Users/Kim/.vscode/extensions/vadimcn.vscode-lldb-1.7.0/adapter\codelldb.py", line 269, in __missing__
    raise VariableNotFound(name)
codelldb.VariableNotFound: Variable 'vars' not found

[2022-05-12T01:38:54.750Z ERROR codelldb::debug_session] Variable 'vars' not found
Debug adapter exit code=0, signal=null.

Variations

When I comment out the “lldb.library” entry in settings.json, thus forcing the standard LLDB (poorly named, I meant the LLDB packaged with the CodeLLDB extension) to be used instead of the Swift custom LLDB, then do Run > Start Debugging, the print() statement output appears in the lower pane of VS Code, in the Terminal tab; likewise, for readline(), the user enters text in the same Terminal tab. That feels like the correct behavior to me, for VSCode-based debugging. This is the basis of my expected behavior, above.

When I run the Swift LLDB from the command prompt, the program uses stdin/stdout just fine, and that occurs in a command prompt window that lldb launches for the program.

Likewise when I run the program directly from the command prompt (no LLDB), the prog uses stdin/stdout just fine in that same command prompt window.

Taking all these variations together, these indicate that the source of the problem must be in the setup done in the Swift extension as it prepares to invoke the LLDB debug adapter, or possibly the debug adapter is mishandling something when the lldb.library is set. If no objections, we propose that we begin the investigation in the Swift extension (see #301 at the bottom).

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Comments: 64 (31 by maintainers)

Most upvoted comments

I think that we should look at how the inferior is launched. I suspect that this might be a bug in lldb-server. One quick test would be to try a “remote” (it can be run on the same host) debug session with ds2 (https://github.com/compnerd/ds2).

I will try this next.