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

5.8k views Asked by At

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

2

There are 2 answers

1
davidgyoung On

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"
1
Mutasm On

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