Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
338 views
in Technique[技术] by (71.8m points)

ios - 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 ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

enter image description here

In the dialog, add the following to the Symbol field:

-[UIControl sendAction:to:forEvent:]

enter image description here

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.

enter image description here

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...