Sometime it happens when you got project with very unmanaged code so you can't figure out how to solve a simple issue. In most of the case debugger helps us to reach the root point to start with, I just want to know how strong is xcode debugger is. As I used some asm debugger like OllyDbg these provide us a no. of option to for breakpoint the most I used is breakpoint on click event or tap event. So is there any way to put a similar breakpoint on xcode project ?
问题:
回答1:
Sounds like you are looking for a way to trap any time a UIButton gets tapped. To do this, I would set a symbolic breakpoint. In the Breakpoint Navigator (⌘7), click the plus sign at the bottom of the screen and choose Add Symbolic Breakpoint
In the dialogue, add the following to the Symbol field:
-[UIControl sendAction:to:forEvent:]
This is a little more than you are asking for. It will actually capture all events from lots of things besides just UIButtons. However, I'll bet you can make it work for your needs. Now run the app and tap a button. When it hits the breakpoint, the debugger will look a little differently than the normal stack trace you might be used to seeing, since you will be hitting a breakpoint at a spot where you do not have source to match the symbols. With a few commands, you can decipher a fair amount. For instance, see the screenshot below.
Here's what I did, and what some of this means. The first thing is to step over (F6) to the beginning of the next command (e.g. line 12), to make sure all the registers for your incoming variables are correctly populated. From there, I just start digging around in the registers for interesting information. In this example, register r15 is the calling object (the button!), and r14, r12, and rbx are the arguments (lines 4 - 7). When the value in a register is a pointer to an object, you can 'print object' it like when you are in a 'normal' stackframe. e.g.:
(lldb) register read r15
r15 = 0x00007fc6f4a24510
(lldb) po 0x00007fc6f4a24510
<UIButton: 0x7fc6f4a24510; frame = (0 0; 414 100); opaque = NO; autoresize = RM+BM; layer = <CALayer: 0x7fc6f4a247b0>>
(lldb) po [[(UIButton *)0x00007fc6f4a24510 titleLabel] text]
Done