尝试从 Xcode 控制台打印内容时出现“执行被中断,原因:断点”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17987132/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 03:38:46  来源:igfitidea点击:

"Execution was interrupted, reason: breakpoint" when trying to print something from the Xcode console

xcodellvm

提问by Senseful

I paused my app and tried printing something to the console. (e.g. po foo()). After doing so, I got the following message:

我暂停了我的应用程序并尝试将一些内容打印到控制台。(例如po foo())。这样做后,我收到以下消息:

error: Execution was interrupted, reason: breakpoint 2.1.
The process has been returned to the state before execution.

错误:执行被中断,原因:断点 2.1。
流程已经恢复到执行前的状态。

However, there are no breakpoints in that function. Why is it showing me this error and not executing the function?

但是,该函数中没有断点。为什么它向我显示此错误而不执行该功能?

This is on Xcode 4.6.

这是在 Xcode 4.6 上。

采纳答案by Senseful

It turns out that the breakpoint in question (2.1) was the All Exceptions breakpoint. The method I was calling raised an exception, which caused the All Exceptions breakpoint to be hit. powill stop execution once a breakpoint is reached (see this answerfor more info).

事实证明,有问题的断点 (2.1) 是 All Exceptions 断点。我调用的方法引发了一个异常,导致命中所有异常断点。po到达断点后将停止执行(有关更多信息,请参阅此答案)。

If you disable the All Exceptions breakpoint and run it again, it is more clear that there was an exception:

如果禁用了 All Exceptions 断点并再次运行它,则更清楚地出现了异常:

error: Execution was interrupted, reason: signal SIGSTOP.
The process has been returned to the state before execution.

If you always leave the All Exceptions breakpoint enabled, then the message can be ambiguous: did it reach a breakpoint because there really was a breakpoint somewhere along the execution path, or was an exception raised?

如果始终启用 All Exceptions 断点,则消息可能不明确:它到达断点是因为执行路径上的某处确实存在断点,还是引发了异常?

An alternative solution (which doesn't require disabling the All Exceptions breakpoint) is to use exprinstead of po(see the link above for a description of the following flags).

另一种解决方案(不需要禁用所有异常断点)是使用expr代替po(有关以下标志的描述,请参见上面的链接)。

Running expr -u 0 -o -- foo()produces the following output:

运行expr -u 0 -o -- foo()产生以下输出:

error: Execution was interrupted, reason: breakpoint 2.1 -2.1.
The process has been left at the point where it was interrupted.  
* thread #1: tid = [...] libobjc.A.dylib`objc_exception_throw, stop reason = breakpoint 2.1 -2.1  
    frame #0: [...] libobjc.A.dylib`objc_exception_throw

The objc_exception_throwstring is a hint that an exception was raised.

objc_exception_throw字符串是引发异常的提示。