简体   繁体   中英

Switch to Objective-C mode in lldb

When I am debugging a Swift app in Xcode, the debugger expects expressions in Swift format. How can I switch it to expect Objective-C expressions instead?

Eg, I want to be able to type expr id $foo = [[SomeClass alloc] initWithBar:@"quux"]; instead of whatever the Swift equivalent is.

Swift 3.0 or before use: You can use the following command to identify the name of all available languages in LLDB.

(lldb)帮助<语言>

Swift 4.0

(lldb)帮助<源语言>

Create an alias like "eco" to print objective-c objects:

(lldb)command alias eco expression -l objective-c -o --
(lldb)eco [[UIApplication sharedApplication] userHomeDirectory] 
/Users/...

Advanced debugging with Xcode and LLDB from WWDC 2018, shows that this can be done with the following command:

expression -l objc -O -- [doYourStuff here]

but there is an important thing to note here, switching from a Swift to an Objective C frame creates a new context . In practice this means that you will probably get an error like:

error: use of undeclared identifier 'self'

to avoid this problem you need to enclose any varables, that need to be evaluated before the context change, in backticks ` . For example:

expression -l objc -O -- [`self` class]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM