Cannot debug Swift module/framework embedded in Ob

2019-03-09 18:18发布

Alternative titles (to aid searching)

  • Cannot debug Swift 2.3 framework linked to an Objective-C app in Xcode 8
  • error in auto-import: failed to get module 'XYZ' from AST context Xcode 8
  • Xcode 8 cannot debug Swift framework
  • warning: Swift error in module <XYZ>
  • Workaround for; Xcode Debugger cannot debug apps written in Objective-C only but that link against frameworks written in Swift only. (28312362)

I have an app written in Objective-C that links against some modules (frameworks) written in Swift 2.x.

Question

Everything (debugging etc.) works fine in , however when moving to and updating the modules to use I was unable to debug the modules.

LLDB reported these errors:

warning: Swift error in module XYZ.
Debug info from this module will be unavailable in the debugger.

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

This does not happen if I link the modules to an app built in Swift 2.3.

11条回答
小情绪 Triste *
2楼-- · 2019-03-09 18:27

use fr v instead po for debugging

For more debugging https://www.codeproject.com/Articles/1181358/Debugging-with-Xcode

查看更多
女痞
3楼-- · 2019-03-09 18:27

In my case there was a compiler error in the "C" code which was reported in LLDB, after fixing the error LLDB started working again.

查看更多
Summer. ? 凉城
4楼-- · 2019-03-09 18:29

I ran into the error in auto-import: failed to get module 'XYZ' from AST context message while attempting to debug in an 9.3 simulator. Switching to a 10.2 simulator resolved the issue.

查看更多
Juvenile、少年°
5楼-- · 2019-03-09 18:35

tl:dr

Add a user defined setting under "Build Settings" for your app target.

SWIFT_VERSION = 2.3

SWIFT_VERSION = 2.3 — Build Settings

More Info

I'm unsure if this is an Xcode 8 bug or if it's Apple policy (to try an force developers to Swift 3.0?). But... by default Xcode 8 installs the Swift 3.0 versions of the standard Swift runtime libraries.

When it comes to debugging with LLDM the Swift 2.3 modules fail to load (in to the Swift 3.0 runtime).

Forcing the app to use Swift 2.3 (or legacy Swift as Apple call it), fixes the issue.

Swift apps have this setting exposed by Xcode but you have to manually add it for an Objective-C app.

Further Advice

Port your Swift 2.3 code to Swift 3.0 as soon as possible, Apple won't support 2.x for very long.

查看更多
手持菜刀,她持情操
6楼-- · 2019-03-09 18:36

As suggested by Tim https://stackoverflow.com/a/41876400/1840269 the root cause to our problem was a matter of duplicates.

We had a obj-c wrapper category for SDWebImage that was used from both obj-c and Swift. When Importing the category from Swift everything blew up because of redefinition/duplicate import since the SDWebImage pod already exposed it self as a Swift module.

The solution? We re-implemented the obj-c category as a Swift extension - and kept using it from both Swift and obj-c by adding @objc in front of the extension and importing the #import "product-Swift.h" file from obj-c.

And maybe start with checking: https://developer.apple.com/library/content/qa/qa1947/_index.html.

查看更多
贪生不怕死
7楼-- · 2019-03-09 18:38

I discussed this issue with an Apple engineer named Sean at WWDC 2017.

My team spent weeks trying to figure this out, and it ended up being a bug on Apple's compiler, which we could never have figured out by ourselves. Also, it has a VERY easy workaround.

There happens to be a bug with the way the compiling flags get aggregated from the frameworks and the project, and the "pure Objective-C" project "activates" it.

Solution: add one single, empty Swift file ("Whatever.swift", or whatever) in your Objective-C project, making it not-pure-objective-c anymore (new->file->Swift file, don't create the bridging header. The file will only contain the import of Foundation).

And that's it. Problem solved.

查看更多
登录 后发表回答