在 Xcode 中的选择器上添加符号断点
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8264193/
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
Add a symbolic breakpoint on a selector in Xcode
提问by Roger
There's a bug in my app which shows up with the following (partial) stacktrace:
我的应用程序中有一个错误,显示为以下(部分)堆栈跟踪:
2011-11-25 01:55:59.760 Events2[6650:403] -[Event boolValue]: unrecognized selector sent to instance 0x7fb903928670
To debug this I decided to add a symbolic breakpoint on -[Event boolValue] reasoning that when that selector is sent, the debugger would halt.
为了调试它,我决定在 -[Event boolValue] 上添加一个符号断点,因为当发送该选择器时,调试器将停止。
However, nothing happens. After setting the breakpoint the app just soldiers on and generates the same exception without halting.
然而,什么也没有发生。设置断点后,应用程序只是继续运行并生成相同的异常而不会停止。
I have defined the breakpoint as follows:
我已经定义了断点如下:
I'm using the LLDB debugger with Xcode 4.2
我在 Xcode 4.2 中使用 LLDB 调试器
回答by Martin R
Setting a breakpoint on a selector causes lldb to halt when that selector is executed, not when it is sent. In your case, there is no selector "-[Event boolValue]", therefore this breakpoint will never be hit.
在选择器上设置断点会导致 lldb 在执行该选择器时停止,而不是在发送时停止。在您的情况下,没有选择器“-[Event boolValue]”,因此永远不会命中此断点。
I would set an exception breakpoint on "All Objective-C Exceptions". This will be hit when the "unrecognized selector sent" exception is thrown and you can see where the problem occurs.
我会在“All Objective-C Exceptions”上设置一个异常断点。当抛出“unrecognized selector sent”异常时就会命中这个,可以看到问题出在哪里。
回答by Canopus
I was looking for the same answer (symbolic breakpoints) and this link helped: http://www.cocoabuilder.com/archive/cocoa/308967-symbolic-breakpoints.html#308970
我正在寻找相同的答案(符号断点),这个链接有帮助:http: //www.cocoabuilder.com/archive/cocoa/308967-symbolic-breakpoints.html#308970
You have to follow this pattern (it is also given as a placeholder in Xcode breakpoint editor):
你必须遵循这个模式(它也在 Xcode 断点编辑器中作为占位符给出):
- [name_of_the_class name_of_the_method:]
For example I was looking to see who does set my left bar item and overrides my settings, I used
-[UINavigationItem setLeftBarButtonItem:]
例如,我想看看谁设置了我的左栏项目并覆盖了我的设置,我使用了
-[UINavigationItem setLeftBarButtonItem:]
and it worked. Or this one
它奏效了。或者这个
-[UINavigationController pushViewController:animated:]
-[UINavigationController pushViewController:animated:]
回答by Bala
I would set an Symbolic breakpoint with this symbol -[NSObject doesNotRecognizeSelector:]
我会用这个符号设置一个符号断点 -[NSObject doesNotRecognizeSelector:]
which will help us to capture situations where a selector is being invoked against the wrong object.
这将帮助我们捕获针对错误对象调用选择器的情况。
回答by Duncan C
It looks to me like symbolic breakpoints don't work right in LLDB (I'm running the most recent released version of Xcode as of this writing, 4.3.3).
在我看来,符号断点在 LLDB 中不起作用(在撰写本文时,我正在运行最新发布的 Xcode 版本,4.3.3)。
I set a symbolic breakpoint at addAnimation:forKey: in LLDB, and it never gets hit. If I switch my project to GDB, the breakpoint works as expected.
我在 LLDB 中的 addAnimation:forKey: 处设置了一个符号断点,它永远不会被击中。如果我将我的项目切换到 GDB,断点会按预期工作。
回答by ancorio
Best way to find unrecognized selector call is to create this selector (as category) and put a break point in it.
查找无法识别的选择器调用的最佳方法是创建此选择器(作为类别)并在其中放置一个断点。