我有一个看起来像这样的断点
-[UITableViewCell setSelected:]
它有效,但我无法弄清楚如何获取正在传递的值。
我已经尝试过-[UITableViewCell setSelected:(BOOL)what],-[UITableViewCell setSelected:what]但它根本不起作用。
如何访问参数?
如果这不起作用,我将不得不做一个DebugUITableViewCell只是为了看看发生了什么,这很麻烦并且涉及很多代码。
我有一个看起来像这样的断点
-[UITableViewCell setSelected:]
它有效,但我无法弄清楚如何获取正在传递的值。
我已经尝试过-[UITableViewCell setSelected:(BOOL)what],-[UITableViewCell setSelected:what]但它根本不起作用。
如何访问参数?
如果这不起作用,我将不得不做一个DebugUITableViewCell只是为了看看发生了什么,这很麻烦并且涉及很多代码。
如果您在设备上调试代码,当您遇到断点时,参数将始终位于寄存器 r0、r1 和 r2 中。如果您使用po $r0,您将看到对象接收 setSelected。如果你使用po $r1,你会得到“没有可用的 Objective-C 描述”,因为那是选择器。检查 $r2 以查看 selected 是否设置为 YES 或 NO。这是 i386 上的类似故事,但我不记得使用了哪些寄存器。
在模拟器上使用 LLDB
p $arg3
对于第一个参数。
您可以-[UITableViewCell setSelected:]用自己的实现替换以进行调试。下面,UITableViewCellSetSelected将被调用而不是 UIKit 的方法。
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
对于没有源代码的方法,以下工作: 放置一个符号断点,以便调试器在方法的第一行停止。确保选择了顶部堆栈帧。然后:
在 Objectice-C 方法中
po $arg1打印自我po $arg3打印第一个参数,在 , 等中的剩余$arg4参数$arg5。在 C 函数中,参数开始于$arg1
这适用于 IOS 设备和模拟器。
基于-[UIApplication sendAction:toTarget:fromSender:forEvent:]符号,我们可以添加符号断点来检查哪个发送者向哪个目标发送了一个动作。
我们使用以下命令创建符号断点:
-[UIApplication sendAction:toTarget:fromSender:forEvent:]po "Target"po $arg4po "Sender"po $arg5输出将是:
"Target"
<project.TargetViewController: 0x14ddb1470>
"Sender"
<UIButton: 0x14de86000; frame = (331 7; 49 30); opaque = NO; layer = <CALayer: 0x174237020>>
正如@Dan 所说,方法参数从参数 3 ( po $arg3) 开始。
你可以使用 lldb 命令:
“图像查找 -rn 关键字”
关键字等于您要搜索的功能,例如,显示
然后,您将看到如下输出,
总结:ApplSlate`closure #2 (__C.UIBarButtonItem) -> () in ApplSlate.BaseTableViewController.showLoading(includeTabBar: Swift.Bool) -> () at BaseTableViewController.swift:98 地址:FullSlate[0x0000000100154a60] (FullSlate.__TEXT. __文本 + 1378752)
你得到的符号名称是:closure #2 (__C.UIBarButtonItem) -> () in ApplSlate.BaseTableViewController.showLoading(includeTabBar: Swift.Bool) -> ()
XCode的lldb获取ObjC第一个参数是:$arg3
->
$arg4, $arg5, ...$arg0不存在
(lldb) po $arg0
error: <user expression 3>:1:1: use of undeclared identifier '$arg0'
$arg0
^
$arg1是函数类型
-方法Instance
(lldb) po $arg1
_
+方法Class$arg2是函数指针self,使用SEL可以解析为函数名
(lldb) po $arg2
8203662366
(lldb) po (SEL)$arg2
"stringByAppendingString:"