问题
I have a breakpoint that looks like this
-[UITableViewCell setSelected:]
and it works, but I cannot figure out how to get the value that is being passed in.
I have tried -[UITableViewCell setSelected:(BOOL)what]
and -[UITableViewCell setSelected:what]
which do not work at all.
How can I access the parameters?
If this doesn't work, I'll have to make a DebugUITableViewCell
just to see what's going on, which is a hassle and touches a lot of code.
回答1:
If you debug your code on the device the parameters when you hit your breakpoint will consistently be in registers r0, r1, and r2. If you use po $r0
you'll see the object receiving setSelected. If you use po $r1
you'll get "no Objective-C description available" because that's the selector. Inspect $r2 to see if selected is being set to YES or NO. It's a similar story on i386, but I can't remember off hand which registers are used.
回答2:
In LLDB on Simulator use
p $arg3
for the first parameter.
回答3:
You could replace -[UITableViewCell setSelected:]
with your own implementation for debugging purposes. Below, UITableViewCellSetSelected
will be called instead of UIKit's method.
static void (*__originalUITableViewCellSetSelected)( UITableViewCell *, SEL, BOOL ) ;
static void UITableViewCellSetSelected( UITableViewCell * self, SEL _cmd, BOOL b )
{
// your code here... (or set a breakpoint here)
NSLog(@"%@<%p> b=%s\n", [ self class ], self, b ? "YES" : "NO" ) ;
(*__originalUITableViewCellSetSelected)( self, _cmd, b ) ; // call original implementation:
}
@implementation UITableViewCell (DebugIt)
+(void)load
{
Method m = class_getInstanceMethod( [ self class ], @selector( setSelected: ) ) ;
__originalUITableViewCellSetSelected = (void(*)(id, SEL, BOOL))method_getImplementation( m ) ;
method_setImplementation( m, (IMP)UITableViewCellSetSelected ) ;
}
@end
回答4:
Based on -[UIApplication sendAction:toTarget:fromSender:forEvent:]
symbol we can add symbolic breakpoint to check which sender has sent an action to which target.
We create symbolic breakpoint with:
- symbol:
-[UIApplication sendAction:toTarget:fromSender:forEvent:]
- debugger command line actions:
po "Target"
po $arg4
po "Sender"
po $arg5
The output would be:
"Target"
<project.TargetViewController: 0x14ddb1470>
"Sender"
<UIButton: 0x14de86000; frame = (331 7; 49 30); opaque = NO; layer = <CALayer: 0x174237020>>
So as @Dan said, method parameters start with argument 3 (po $arg3
).
回答5:
For the methods without source code, the following works: Put a symbolic breakpoint in so that the debugger stops at the first line of the method. Make sure the top stack frame in selected. Then:
In Objectice-C methods
po $arg1
prints selfpo $arg3
prints the first argument, remaining arguments in$arg4
,$arg5
, etc.
In C functions the arguments start at $arg1
This works both on IOS device and simulator.
来源:https://stackoverflow.com/questions/15513045/how-to-get-parameters-using-symbolic-breakpoints-in-objective-c