XCode / Objective C 基于调用者的条件断点

发布于 2024-12-10 04:30:03 字数 506 浏览 1 评论 0原文

好的,我需要设置一个断点,只有当特定对象和/或选择器调用(或不)方法时才会“命中”,

我能想到的最简单的方法是如果有一些编译器宏(如 _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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦魇绽荼蘼 2024-12-17 04:30:03

在调用站点设置断点,并在断点上设置条件(例如 self == another)

Set your breakpoint at the calling site, with a condition on the breakpoint (e.g. self == whatever)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文