LLDB po complain error: expression failed to parse: error: Couldn't realize type of self
Asked Answered
M

2

5

It's a iOS application using cocoapods. Xcode 14 and Xcode 13.4.1 behavior same. I am using a static lib.

With Xcode 14 new lldb cmd swift-healthcheck, print

"SwiftASTContextForExpressions::LoadOneModule() -- Missing Swift module or Clang module found for "shortvideo", "imported" via SwiftDWARFImporterDelegate. Hint: Register Swift modules with the linker using -add_ast_path."

How can I register Swift modules with the linker using -add_ast_path.

refer: WWDC 2022 Video Debug Swift debugging with LLDB

Mroz answered 14/6, 2022 at 12:3 Comment(4)
You don't say what kind of library "short video" is. The most common failure with swift debug info is with static libraries, and many iOS pods favor static libraries. If that's what this library is, the solution is described at around the 15:50 mark in the video you cited. You have to find the library(s) shortvideo gets linked into, and add --add_ast_path <path_to_shortvideo swift module> to that link line.Chipboard
@JimIngham Thanks for your reply . “shortvideo” is a static libraries written with objc and swift, imported as development pod. I search on Google, and do not know how to add --add_ast_path <path_to_shortvideo swift module> to that link line. Is it a Linking setting for shortvideo target in Xcode or something in shortvideo.podspecMroz
Sorry, other than to build examples sent to me as part of bug reports, I haven't actually used CocoaPods, so I don't know how you specify linker flags in a pod. But I bet if you ask that question specifically here, somebody will know.Chipboard
Thank you @JimIngham . I give up with static library, and trying to use dynamic library.Mroz
A
2

from xcode -> Preferences -> Locations : try to delete the contents of derived data file and it should work fine after that

Akimbo answered 28/12, 2022 at 10:34 Comment(1)
Thank you for your reply. It does not help to this issue.Mroz
M
0

If you are debugging a Swift class inside a dependent child project or framework, that class must have an @objc annotation, otherwise you will get this error if you try to inspect variables from a breakpoint inside that class.

BAD:

public class Logger: NSObject {
    public static func debug(_ message: String, file:NSString = #file, function:NSString = #function, line:Int = #line) {
        log(message: message, file: file, function: function, line: line)
    }
(lldb) po message
error: Couldn't realize type of self

GOOD:

@objc public class Logger: NSObject {
    public static func debug(_ message: String, file:NSString = #file, function:NSString = #function, line:Int = #line) {
        log(message: message, file: file, function: function, line: line)
    }
(lldb) po message
"This is the line I am logging"
Mckinzie answered 1/7, 2022 at 14:48 Comment(1)
What if it's a swiftUI view class. I cannot apply @objcCheap

© 2022 - 2024 — McMap. All rights reserved.