Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-11543] lldb doesn't work in tests: error: warning: failed to get module "NIO" from AST context #4480

Closed
weissi opened this issue Sep 28, 2019 · 7 comments
Assignees
Labels
bug Something isn't working LLDB for Swift

Comments

@weissi
Copy link
Member

weissi commented Sep 28, 2019

Previous ID SR-11543
Radar rdar://problem/55807178
Original Reporter @weissi
Type Bug
Status Resolved
Resolution Duplicate
Additional Detail from JIRA
Votes 0
Component/s LLDB for Swift
Labels Bug
Assignee @adrian-prantl
Priority Medium

md5: 34d8edffa7e6295e40791aa573b01e24

duplicates:

  • SR-3280 Package manager should link main swiftmodule in executables

relates to:

  • SR-3280 Package manager should link main swiftmodule in executables

Issue 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
@weissi
Copy link
Member Author

weissi commented Sep 28, 2019

@swift-ci create

@weissi
Copy link
Member Author

weissi commented Sep 28, 2019

CC @adrian-prantl

@belkadan
Copy link

I think this was a SwiftPM problem that just just got fixed. cc @aciidb0mb3r

@adrian-prantl
Copy link
Member

@weissi did you use Swiftpm to build?

-> [SR-3280]: Package manager should link main swiftmodule in executables

@weissi
Copy link
Member Author

weissi commented Oct 1, 2019

@adrian-prantl yes, see the one-line repro that works from macOS and Linux:

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 broken into multiple lines is

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" swift:5.1 lldb --privileged .build/debug/swift-nioPackageTests.xctest

@adrian-prantl
Copy link
Member

Great! That's a dupe of the swiftpm bug then.

@weissi
Copy link
Member Author

weissi commented Nov 9, 2019

I can confirm this works much better on 5.1.2, thank you! Whilst playing with it, I filed SR-11746 and SR-11745 as follow ups.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 7, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working LLDB for Swift
Projects
None yet
Development

No branches or pull requests

3 participants