Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 424
devioustree Avatar asked Mar 27 '12 10:03

devioustree


People also ask

How to set a breakpoint lldb?

In lldb you can set breakpoints by typing either break or b followed by information on where you want the program to pause. After the b command, you can put either: a function name (e.g., b my_subroutine ) a line number (e.g., b 12 )

How to use lldb for debugging?

Loading a Program into lldb First we need to set the program to debug. As with gdb, you can start lldb and specify the file you wish to debug on the command line: $ lldb /Projects/Sketch/build/Debug/Sketch. app Current executable set to '/Projects/Sketch/build/Debug/Sketch.

Does Xcode have an iPhone emulator?

Simulator app, available within Xcode, presents the iPhone, iPad, or Apple Watch user interface in a window on your Mac computer. You interact with Simulator by using the keyboard and the mouse to emulate taps, device rotation, and other user actions.


1 Answers

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]
like image 130
bentford Avatar answered Oct 13 '22 00:10

bentford