Uploaded image for project: 'Swift'
  1. Swift
  2. SR-11543

lldb doesn't work in tests: error: warning: failed to get module "NIO" from AST context

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Medium
    • Resolution: Duplicate
    • Component/s: LLDB for Swift
    • Labels:
      None

      Description

      Very often, when I try to use lldb on Linux (with Swift 5.0.x or 5.1) I get

      (lldb) po ev
      error: warning: failed to get module "NIO" from AST context
      
      error: in auto-import:
      failed to get module "NIO" from AST context
      

      here's a very straightforward repro without having any dependencies (but Docker):

      cd /tmp && git clone https://github.com/apple/swift-nio && cd swift-nio && git reset --hard f548a29a27d7e533f1714d2d282ca0d79f6086dd && docker run -it --rm -v "$PWD:$PWD" -w "$PWD" swift:5.1 swift build --build-tests && docker run -it --rm -v "$PWD:$PWD" -w "$PWD" --privileged swift:5.1 lldb .build/debug/swift-nioPackageTests.xctest
      

      which will compile the NIO test suite and run LLDB on the test suite. Once you're in lldb:

      (lldb) break set -f EventLoop.swift -l 857
      (lldb) run NIOTests.ChannelTests/testHalfClosure
      

      and once you hit the breakpoint do

      po ev
      

      Expected: prints ev

      Actual:

      (lldb) po ev
      error: warning: failed to get module "NIO" from AST context
      
      error: in auto-import:
      failed to get module "NIO" from AST context
      

      macOS

      This also doesn't work in macOS. The setup is similar:

      cd /tmp && git clone https://github.com/apple/swift-nio && cd swift-nio && git reset --hard f548a29a27d7e533f1714d2d282ca0d79f6086dd && swift build --build-tests
      

      after this, the tests are built. Now, open a new terminal window and type

      lldb -w -n xctest
      

      and in your first window type

      swift test --filter NIOTests.ChannelTests/testHalfClosure
      

      now, lldb should've attached and in lldb you type

      (lldb) break set -f EventLoop.swift -l 857     # ignore the warning
      (lldb) cont
      

      Soon after, the breakpoint should be hit and then you type

      (lldb) po ev
      

      which leads to

      (lldb) po ev
      Cannot create Swift scratch context (couldn't load the Swift stdlib)Cannot create Swift scratch context (couldn't load the Swift stdlib)Shared Swift state for xctest could not be initialized.
      The REPL and expressions are unavailable.
      (lldb) 
      

      versions:

      $ swift --version && sw_vers
      Apple Swift version 5.1 (swiftlang-1100.0.270.13 clang-1100.0.33.7)
      Target: x86_64-apple-darwin19.0.0
      ProductName:	Mac OS X
      ProductVersion:	10.15
      BuildVersion:	19A558d
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              aprantl Adrian Prantl
              Reporter:
              jw Johannes Weiss
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: