How to get parameters using symbolic breakpoints in Objective-C

我只是一个虾纸丫 提交于 2019-11-28 17:51:27

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.

In LLDB on Simulator use

p $arg3

for the first parameter.

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

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).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!