XCode / Objective C 基于调用者的条件断点
好的,我需要设置一个断点,只有当特定对象和/或选择器调用(或不)方法时才会“命中”,
我能想到的最简单的方法是如果有一些编译器宏(如 _cmd)展开堆栈并返回当前方法的直接调用者的 id 和选择器。
例如,假设 majical 宏是 _cmd_caller_id & _cmd_caller_sel) -
if ( (_cmd_caller_id == self) && (_cmd_caller_sel != @selector(some_method:signature:) ) {
NSLog(@"called by %@ - hitting breakpoint",NSStringFromSelector(_cmd_caller_sel));
}
(您可以在包含 NSLog(...); 的行上放置一个断点);
原因是我有一个被多次调用的方法,我需要能够设置比上面描述的更复杂的条件集,以设置陷阱来确定哪个方法正在调用违规方法以及何时调用。
Ok, i have a requirement to set a breakpoint that only gets "hit" when a method is (or is not) called by a specific object and/or selector
the easiest way i can think of doing that is if there were some compiler macro (like _cmd) that unwinds the stack and returns the id and selector of the immediate caller of the current method.
eg assuming the majical macros were _cmd_caller_id & _cmd_caller_sel) -
if ( (_cmd_caller_id == self) && (_cmd_caller_sel != @selector(some_method:signature:) ) {
NSLog(@"called by %@ - hitting breakpoint",NSStringFromSelector(_cmd_caller_sel));
}
(and you would put a break point on the line containing the NSLog(...); );
the reason being i have a method that is called many times, an i need to be able to set up a more complex set of conditions than i have described above to set a trap to determine what method is calling the offending method and when.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在调用站点设置断点,并在断点上设置条件(例如 self == another)
Set your breakpoint at the calling site, with a condition on the breakpoint (e.g. self == whatever)