Navigation Menu

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-3169] lldb stops working when C module includes a header outside of module's include/ dir #4577

Closed
swift-ci opened this issue Nov 9, 2016 · 2 comments
Labels
bug Something isn't working LLDB for Swift

Comments

@swift-ci
Copy link

swift-ci commented Nov 9, 2016

Previous ID SR-3169
Radar None
Original Reporter zmeyc (JIRA User)
Type Bug
Status Closed
Resolution Invalid
Environment

OS X, Xcode 8.2 beta (8C23)

Additional Detail from JIRA
Votes 0
Component/s LLDB for Swift
Labels Bug
Assignee None
Priority Medium

md5: ff8ca5b36378a02cd00801a6b06efbbc

relates to:

  • SR-2192 Swift's LLDB cannot import system modules and prevents debugging
  • SR-2764 LLDB fails to to import a Clang module imported into Swift

Issue Description:

When C module references a header outside of module's include/ directory, lldb stops showing variable
values for the entire application.

UPDATE debugging works if C module is in a separate repository. So, this problem is only present if there are two modules in same repo's Sources/ dir.

I reproduced this with a minimal example. Steps to reproduce:

git clone https://github.com/zmeyc/lldbtest
open lldbtest.xcodeproj

Choose Main target, put the breakpoint at print() in main.swift.
Run the app.

In Debugger, choose "Show all variables".
Value of variable "i" won't be printed.
In lldb, type "p i", which will produce:

(lldb) p i
warning: Swift error in module Main.
Debug info from this module will be unavailable in the debugger.

error: in auto-import:
failed to get module 'Main' from AST context:

Detailed description:

I created a Swift app with the following structure:

lldbtest
  ThirdParty
    thirdpartylib.h - a header file from some third-party library.
  Source
    CLib - a C module which includes <thirdpartylib.h> and exposes it to Swift code.
    Main - main.swift which calls a function from thirdpartylib

The app compiles and works fine from console:

swift build -Xcc -I"$(shell pwd)/ThirdParty"

If you want to regenerate the xcodeproj:

rm -rf lldbtest.xcodeproj
swift package generate-xcodeproj
open lldbtest.xcodeproj
Select "Main" target -> Build Settings.
Add "$(SRCROOT)/ThirdParty" to Header Search Paths.
Add "$(SRCROOT)/Sources/CLib" to Import Paths.

The app will now compile and run, but debugging won't work.

@swift-ci
Copy link
Author

Comment by Andrey Fidrya (JIRA)

UPDATE: debugging works if C module is in a separate repository. So, this problem is only present if there are two modules in Sources/ dir of the same repo.

@belkadan
Copy link

Jim I and I looked into this a bit today and discovered that LLDB is (rightfully) refusing to import 'CLib' because it contains references to thirdpartylib.h, which is not part of any module. The compiler would reject this too, except for the module map stuck inside the Sources/CLib/ directory, which would normally be ignored if it weren't for an extra, possibly-mistaken search path to that directory.

We do see that this is a stripped-down test case attempting to reproduce a real issue, but the general principle here is "all C headers you import must belong to a module", and the "System Modules" feature of SwiftPM is the supported way to do that for externally-available sources.

@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

2 participants