【问题标题】:Switch to Objective-C mode in lldb在 lldb 中切换到 Objective-C 模式
【发布时间】:2017-01-08 07:58:17
【问题描述】:

当我在 Xcode 中调试 Swift 应用程序时,调试器需要 Swift 格式的表达式。如何将其切换为期望 Objective-C 表达式?

例如,我希望能够键入 expr id $foo = [[SomeClass alloc] initWithBar:@"quux"]; 而不是 Swift 等效项。

【问题讨论】:

标签: ios lldb


【解决方案1】:

Swift 3.0 或之前使用: 您可以使用以下命令来识别 LLDB 中所有可用语言的名称。

Swift 4.0

创建一个像“eco”这样的别名来打印objective-c对象:

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

【讨论】:

  • 似乎不再工作(Xcode 9.3):(lldb) help <language> (linebreak) error: '<language>' is not a known command. (linebreak) Try 'help' to see a current list of commands. (换行) Try 'apropos <language>' for a list of related commands. (换行) Try 'type lookup <language>' for information on types, methods, functions, modules, etc.
【解决方案2】:

Advanced debugging with Xcode and LLDB 来自 WWDC 2018,表明这可以通过以下命令完成:

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

但这里需要注意一件重要的事情,从 Swift 切换到 Objective C 框架会创建一个新上下文。实际上,这意味着您可能会收到如下错误:

error: use of undeclared identifier 'self'

为避免此问题,您需要将任何需要在上下文更改之前评估的变量括在反引号 ` 中。例如:

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

【讨论】:

  • Xcode 12 给了我:使用未声明的标识符 'l'
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-08-03
  • 2016-01-24
  • 1970-01-01
  • 2018-07-16
  • 1970-01-01
  • 2016-05-09
相关资源
最近更新 更多