I can't get this simple LLDB alias to work

怎甘沉沦 提交于 2019-12-01 05:27:19

问题


I want to create an LLDB alias ps, such that

 ps foo

becomes

 print [self foo]

I've been watching the LLDB talk (WWDC session 321 on iTunes), and based on that, it looks like the alias to do that should be this one:

command alias ps print [ self %1 ]

but it doesn't work. Here I've given my app delegate a simple "count" method that returns an integer:

(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) 

What am I missing?


回答1:


It seems arguments (%1, %2, etc) doesn't work to alias an expression. There is a workaround by using a regular expression instead:

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

It makes an alias ps for the above regular expression:

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

However this will last till the debug session ends. You'll have to enter it again for the next debug session. If you want your ps command to persist through debug sessions, you'll have to save it in your ~/.lldbinit file (if it doesn't exist, create one).

See llvm blog for more deails about regex command.



来源:https://stackoverflow.com/questions/7690181/i-cant-get-this-simple-lldb-alias-to-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!