我不能得到这个简单的LLDB别名工作

我想创build一个LLDB别名ps,这样的

ps foo 

  print [self foo] 

我一直在观看LLDB讨论(在iTunes上的WWDC会话321),基于此,看起来应该是这样的别名:

 command alias ps print [ self %1 ] 

但它不起作用。 在这里,我已经给我的应用程序委托一个简单的“计数”方法返回一个整数:

 (lldb) command alias ps print [ self %1 ] (lldb) ps count error: invalid operands to binary expression ('AppDelegate *' and 'int') error: 1 errors parsing expression (lldb) print [ self count ] (int) $6 = 2 (lldb) 

我错过了什么?

看来参数(%1,%2等)不能用于expression式的别名。 有一个解决方法是使用正则expression式来代替:

 command regex ps 's/(.+)/print [self %1]/' 

它为上面的正则expression式创build了一个别名ps:

 (lldb) ps firstName print [self firstName] (NSString *) $1 = 0x06e64e20 @"John" 

然而,这将持续到debugging会话结束。 您将不得不再次input下一个debugging会话。 如果你想让你的ps命令通过debugging会话保持,你必须把它保存在〜/ .lldbinit文件中(如果不存在,创build一个)。

请参阅llvm博客 ,了解有关regex命令的更多信息。

Interesting Posts