macos “EXC_BREAKPOINT (SIGTRAP)”异常是调试断点引起的吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2611607/
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
Are "EXC_BREAKPOINT (SIGTRAP)" exceptions caused by debugging breakpoints?
提问by Dennis
I have a multithreaded app that is very stable on all my test machines and seems to be stable for almost every one of my users (based on no complaints of crashes). The app crashes frequently for one user, though, who was kind enough to send crash reports. All the crash reports (~10 consecutive reports) look essentially identical:
我有一个多线程应用程序,它在我所有的测试机器上都非常稳定,而且似乎对我的几乎每个用户都是稳定的(基于没有崩溃的投诉)。但是,该应用程序经常崩溃,因为一位用户非常友好地发送了崩溃报告。所有崩溃报告(约 10 个连续报告)看起来基本相同:
Date/Time: 2010-04-06 11:44:56.106 -0700
OS Version: Mac OS X 10.6.3 (10D573)
Report Version: 6
Exception Type: EXC_BREAKPOINT (SIGTRAP)
Exception Codes: 0x0000000000000002, 0x0000000000000000
Crashed Thread: 0 Dispatch queue: com.apple.main-thread
Thread 0 Crashed: Dispatch queue: com.apple.main-thread
0 com.apple.CoreFoundation 0x90ab98d4 __CFBasicHashRehash + 3348
1 com.apple.CoreFoundation 0x90adf610 CFBasicHashRemoveValue + 1264
2 com.apple.CoreText 0x94e0069c TCFMutableSet::Intersect(__CFSet const*) const + 126
3 com.apple.CoreText 0x94dfe465 TDescriptorSource::CopyMandatoryMatchableRequest(__CFDictionary const*, __CFSet const*) + 115
4 com.apple.CoreText 0x94dfdda6 TDescriptorSource::CopyDescriptorsForRequest(__CFDictionary const*, __CFSet const*, long (*)(void const*, void const*, void*), void*, unsigned long) const + 40
5 com.apple.CoreText 0x94e00377 TDescriptor::CreateMatchingDescriptors(__CFSet const*, unsigned long) const + 135
6 com.apple.AppKit 0x961f5952 __NSFontFactoryWithName + 904
7 com.apple.AppKit 0x961f54f0 +[NSFont fontWithName:size:] + 39
(....more text follows)
(……更多文字如下)
First, I spent a long time investigating [NSFont fontWithName:size:]. I figured that maybe the user's fonts were screwed up somehow, so that [NSFont fontWithName:size:] was requesting something non-existent and failing for that reason. I added a bunch of code using [[NSFontManager sharedFontManager] availableFontNamesWithTraits:NSItalicFontMask] to check for font availability in advance. Sadly, these changes didn't fix the problem.
首先,我花了很长时间研究 [NSFont fontWithName:size:]。我想也许用户的字体以某种方式搞砸了,所以 [NSFont fontWithName:size:] 请求的东西不存在并且因此失败。我使用 [[NSFontManager sharedFontManager] availableFontNamesWithTraits:NSItalicFontMask] 添加了一堆代码来提前检查字体的可用性。遗憾的是,这些更改并没有解决问题。
I've now noticed that I forgot to remove some debugging breakpoints, including _NSLockError, [NSException raise], and objc_exception_throw. However, the app was definitely built using "Release" as the active build configuration. I assume that using the "Release" configuration prevents setting of any breakpoints--but then again I am not sure exactly how breakpoints work or whether the program needs to be run from within gdb for breakpoints to have any effect.
我现在注意到我忘记删除一些调试断点,包括 _NSLockError、[NSException raise] 和 objc_exception_throw。但是,该应用程序肯定是使用“Release”作为活动构建配置构建的。我假设使用“Release”配置可以防止设置任何断点——但是我又不确定断点是如何工作的,或者程序是否需要从 gdb 中运行才能使断点产生任何效果。
My questions are: could my having left the breakpoints set be the cause of the crashes observed by the user? If so, why would the breakpoints cause a problem only for this one user? If not, has anybody else had similar problems with [NSFont fontWithName:size:]?
我的问题是:我离开断点集是否会导致用户观察到崩溃?如果是这样,为什么断点只会对这个用户造成问题?如果没有,有没有其他人对 [NSFont fontWithName:size:] 有类似的问题?
I will probably just try removing the breakpoints and sending back to the user, but I'm not sure how much currency I have left with that user. And I'd like to understand more generally whether leaving the breakpoints set could possibly cause a problem (when the app is built using "Release" configuration).
我可能会尝试删除断点并将其发送回用户,但我不确定我给该用户留下了多少货币。而且我想更广泛地了解保留断点设置是否可能会导致问题(当应用程序是使用“发布”配置构建时)。
回答by Peter Hosey
Are “EXC_BREAKPOINT (SIGTRAP)” exceptions caused by debugging breakpoints?
“EXC_BREAKPOINT (SIGTRAP)”异常是调试断点引起的吗?
No. Other way around, actually: A SIGTRAP (trace trap) will cause the debugger to break (interrupt) your program, the same way an actual breakpoint would. But that's because the debugger always breaks on a crash, and a SIGTRAP (like several other signals) is one type of crash.
不。实际上,反过来说:SIGTRAP(跟踪陷阱)将导致调试器中断(中断)您的程序,就像实际断点一样。但那是因为调试器总是在崩溃时中断,而 SIGTRAP(像其他几个信号一样)是一种类型的崩溃。
SIGTRAPs are generally caused by NSExceptions being thrown, but not always—it's even possible to directly raiseone yourself.
SIGTRAPs 通常是由抛出 NSExceptions 引起的,但并非总是如此——甚至可以自己直接引发一个。
I've now noticed that I forgot to remove some debugging breakpoints, including _NSLockError, [NSException raise], and objc_exception_throw.
我现在注意到我忘记删除一些调试断点,包括 _NSLockError、[NSException raise] 和 objc_exception_throw。
Those are not breakpoints. Two of them are functions and -[NSException raise]
is a method.
这些不是断点。其中两个是函数,-[NSException raise]
是方法。
Did you mean you set breakpoints onthose functions and that method?
你的意思是你在这些函数和方法上设置了断点?
I assume that using the "Release" configuration prevents setting of any breakpoints--
我假设使用“发布”配置可以防止设置任何断点——
No.
不。
The configurations are buildconfigurations. They affect how Xcode builds your applications.
这些配置是构建配置。它们会影响 Xcode 构建应用程序的方式。
Breakpoints are not part of the build; you set them in the debugger. They only exist, only get hit, and only stop your program when you run your program under the debugger.
断点不是构建的一部分;你在调试器中设置它们。它们只存在,只会被击中,并且只会在您在调试器下运行程序时停止您的程序。
Since they aren't part of the build, it's not possible to pass your breakpoints to a user simply by giving them the app bundle.
由于它们不是构建的一部分,因此不可能通过向用户提供应用程序包来将断点传递给用户。
I am not sure exactly how breakpoints work …
我不确定断点究竟是如何工作的……
When your program hits the breakpoint, the debugger breaks (interrupts) your program, whereupon you can examine the program's state and step carefully forward to see how the program goes wrong.
当您的程序遇到断点时,调试器会中断(中断)您的程序,因此您可以检查程序的状态并小心地向前看程序是如何出错的。
Since it's the debugger that stops your program, breakpoints have no effect when you're not running your program under the debugger.
由于它是停止程序的调试器,因此当您不在调试器下运行程序时,断点不起作用。
… or whether the program needs to be run from within gdb for breakpoints to have any effect.
... 或者程序是否需要从 gdb 中运行才能使断点产生任何效果。
It does. Debugger breakpoints only work within the debugger.
确实如此。调试器断点仅在调试器内工作。
My questions are: could my having left the breakpoints set be the cause of the crashes observed by the user?
我的问题是:我离开断点集是否会导致用户观察到崩溃?
No.
不。
First, as noted, even if these breakpoints did somehow get carried over to the user's system, breakpoints are only effective in the debugger. The debugger can't stop on a breakpoint if your program isn't running under the debugger. The user almost certainly isn't running your app under the debugger, especially since they got a crash log out of it.
首先,如前所述,即使这些断点确实以某种方式转移到用户系统中,断点也仅在调试器中有效。如果您的程序不在调试器下运行,则调试器无法在断点处停止。用户几乎肯定不会在调试器下运行您的应用程序,尤其是因为他们从中获得了崩溃日志。
Even if they did run your app under the debugger with all of these breakpoints set, a breakpoint is only hit when your program reaches that point, so one of these breakpoints could only fire if you or Cocoa called _NSLockError
, -[NSException raise]
, or objc_exception_throw
. Getting to that point wouldn't be the cause of the problem, it'd be a symptom of the problem.
即使他们确实在设置了所有这些断点的情况下在调试器下运行了您的应用程序,也只有在您的程序到达该点时才会触发断点,因此这些断点之一只能在您或 Cocoa 调用_NSLockError
、-[NSException raise]
、 或 时触发objc_exception_throw
。达到这一点不会是问题的原因,而是问题的征兆。
And if you did crash as a result of one of those being called, your crash log would have at least one of them named in it. It doesn't.
如果你确实因为其中一个被调用而崩溃,你的崩溃日志中至少会有一个被命名。它没有。
So, this wasn't related to your breakpoints (different machine, debugger not involved), and it wasn't a Cocoa exception—as I mentioned, Cocoa exceptions are one cause of SIGTRAPs, but they are not the only one. You encountered a different one.
所以,这与您的断点无关(不同的机器,不涉及调试器),也不是 Cocoa 异常——正如我提到的,Cocoa 异常是 SIGTRAP 的一个原因,但它们不是唯一的原因。你遇到了另一种情况。
If not, has anybody else had similar problems with [NSFont fontWithName:size:]?
如果没有,有没有其他人对 [NSFont fontWithName:size:] 有类似的问题?
There's no way we can tell whether any problems we've had are similar because you cut off the crash log. We know nothing about what context the crash happened in.
由于您切断了崩溃日志,我们无法判断我们遇到的任何问题是否相似。我们对崩溃发生的背景一无所知。
The only thing that's good to cut out is the “Binary images” section, since we don't have your dSYM bundles, which means we can't use that section to symbolicate the crash log.
唯一可以剪掉的是“二进制图像”部分,因为我们没有您的 dSYM 包,这意味着我们不能使用该部分来表示崩溃日志。
You, on the other hand, can. I wrote an appfor this purpose; feed the crash log to it, and it should detect the dSYM bundle automatically (you are keeping the dSYM bundle for every Release build you distribute, right?) and restore your function and method names into the stack trace wherever your functions and methods appear.
另一方面,你可以。我为此编写了一个应用程序;将崩溃日志提供给它,它应该自动检测 dSYM 包(您为分发的每个 Release 构建保留 dSYM 包,对吗?)并将您的函数和方法名称恢复到堆栈跟踪中,无论您的函数和方法出现在哪里。
For further information, see the Xcode Debugging Guide.
有关更多信息,请参阅Xcode 调试指南。
回答by Rob Keniger
It is extremely likely that this user has a corrupt font installed. The stack trace definitely supports that hypothesis, as does the fact that it's only affecting one user.
此用户极有可能安装了损坏的字体。堆栈跟踪绝对支持该假设,因为它只影响一个用户的事实也是如此。
There's not much you can do in that case except get the user to remove the offending font, as the crashes that occur take place deep down in Apple's code.
在这种情况下,除了让用户删除有问题的字体之外,您无能为力,因为发生的崩溃发生在 Apple 代码的深处。
Try getting the user to run a font validation in Font Book. To do this, launch Font Book, click All Fontsin the source list and then select all the listed fonts. You can then select Validate Fontsfrom the Filemenu.
尝试让用户在 Font Book 中运行字体验证。为此,请启动字体簿,单击源列表中的所有字体,然后选择所有列出的字体。然后您可以从文件菜单中选择验证字体。
回答by Azeem.Butt
Breakpoints aren't written to the binary. Odds are good that this person has a broken OS installation. Check the console logs for dyld messages.
断点不会写入二进制文件。这个人的操作系统安装有问题的可能性很大。检查控制台日志中的 dyld 消息。
回答by veladan
I had the same error. For an unexplainable reason the breakpoint was the responsible of the throwing the EXC_BREAKPOINTexception. The solution was to remove the breakpoint, and then code works.
我有同样的错误。由于无法解释的原因,断点是引发 EXC_BREAKPOINT异常的原因。解决方案是删除断点,然后代码工作。
EXC_BREAKPOINTis a type of exception that debuggers use. When you set a breakpoint in your code, the compiler inserts an exception of this type in the executable code. When the execution reaches that point, the exception is thrown and the debugger catches it. Then the debugger shows your code in the "breakpointed" line. This is how debuggers work. But in this case the debugger does not handle the exception correctly and is presented as a regular exception error.
EXC_BREAKPOINT是调试器使用的一种异常类型。当您在代码中设置断点时,编译器会在可执行代码中插入这种类型的异常。当执行到达那个点时,抛出异常并且调试器捕获它。然后调试器在“断点”行中显示您的代码。这就是调试器的工作方式。但在这种情况下,调试器没有正确处理异常并显示为常规异常错误。
I have found this error two times in my life:
我一生中发现过两次这个错误:
- one using Xcode about a year ago.
- the other using Visual C++ about 15 years ago.
- 大约一年前使用 Xcode。
- 另一个使用 Visual C++ 大约 15 年前。