How to call class methods in the iOS simulator with lldb?

橙三吉。 提交于 2020-01-22 10:42:05

问题


I'm trying to debug an iOS app and I'm having problems with lldb in the simulator. Calling class methods doesn't seem to work. Instance methods work fine.

(lldb) po Category
<no result>
(lldb) po [Category class]
error: Couldn't prepare the expression for execution in the target
(lldb) po self
(TagsTableViewController *) $5 = 0x085585a0 <TagsTableViewController: 0x85585a0>

I've tried the 4.3 and 5.1 simulators but both exhibit the same issues.

Everything works fine when debugging on a device.


回答1:


This works. Thanks to @devioustree who answered in a comment above.

Basic command is structured like this:

po [(Class)objc_getClass("ClassName") class]

To invoke someClassMethodHere:

po [[(Class)objc_getClass("ClassName") class] someClassMethodHere]



回答2:


Adding this to expand on the accepted answer...

If you're trying to assign a new value to a variable in lldb like I was instead of just printing out the value then do something like this...

expr self.myArray = (NSArray*)[[(Class)objc_getClass("NSArray") class] arrayWithObjects:@"valueOne",@"valueTwo",@"etc",nil]


来源:https://stackoverflow.com/questions/9887740/how-to-call-class-methods-in-the-ios-simulator-with-lldb

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