xcode 如何在Objective-C中使用符号断点获取参数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15513045/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to get parameters using symbolic breakpoints in Objective-C
提问by Dan Rosenstark
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.
我已经尝试过-[UITableViewCell setSelected:(BOOL)what]
,-[UITableViewCell setSelected:what]
但根本不起作用。
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.
如果这不起作用,我将不得不做一个DebugUITableViewCell
只是看看发生了什么,这很麻烦并且涉及很多代码。
采纳答案by Aaron Golden
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.
如果您在设备上调试您的代码,那么在您遇到断点时的参数将始终位于寄存器 r0、r1 和 r2 中。如果您使用,po $r0
您将看到接收 setSelected 的对象。如果你使用po $r1
你会得到“没有可用的 Objective-C 描述”,因为那是选择器。检查 $r2 以查看 selected 是否设置为 YES 或 NO。i386 上有类似的故事,但我不记得使用了哪些寄存器。
回答by Dan Rosenstark
In LLDB on Simulator use
在模拟器上的 LLDB 中使用
p $arg3
p $arg3
for the first parameter.
对于第一个参数。
回答by nielsbot
You could replace -[UITableViewCell setSelected:]
with your own implementation for debugging purposes. Below, UITableViewCellSetSelected
will be called instead of UIKit's method.
-[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
回答by Bartosz Olszanowski
Based on -[UIApplication sendAction:toTarget:fromSender:forEvent:]
symbol we can add symbolic breakpoint to check which sender has sent an action to which target.
基于-[UIApplication sendAction:toTarget:fromSender:forEvent:]
符号,我们可以添加符号断点来检查哪个发送者向哪个目标发送了一个动作。
We create symbolic breakpoint with:
我们创建符号断点:
- symbol:
-[UIApplication sendAction:toTarget:fromSender:forEvent:]
- debugger command line actions:
po "Target"
po $arg4
po "Sender"
po $arg5
- 象征:
-[UIApplication sendAction:toTarget:fromSender:forEvent:]
- 调试器命令行操作:
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>>
输出将是:
"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
).
正如@Dan 所说,方法参数以参数 3 ( po $arg3
)开头。
回答by Jacob Wallstr?m
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
在 Objectice-C 方法中
po $arg1
prints selfpo $arg3
prints the first argument, remaining arguments in$arg4
,$arg5
, etc.
po $arg1
打印自己po $arg3
打印的第一个参数,其余的参数中$arg4
,$arg5
等等。
In C functions the arguments start at $arg1
在 C 函数中,参数从 $arg1
This works both on IOS device and simulator.
这适用于 IOS 设备和模拟器。