简体   繁体   中英

Is there any way to breakpoint all the button touchUpInside method?

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?

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 dialog, 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 (eg 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. eg::

(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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM