xcode 收到奇怪的调试器消息:断言失败:(cls),函数 getName:这是什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3703447/
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
Getting strange debugger message: Assertion failed: (cls), function getName: what is this?
提问by nemesys
Since I upgraded from Xcode 3.2.3 to 3.2.4 and iOS 4.0.1 to iOS 4.1 SDK, when I set a breakpoint in my code and single-step over instructions, at each step, the debugger will spit one or more of that line:
由于我从 Xcode 3.2.3 升级到 3.2.4 和 iOS 4.0.1 到 iOS 4.1 SDK,当我在我的代码中设置断点并单步执行指令时,在每一步,调试器都会吐出一个或多个线:
Assertion failed: (cls), function getName, file /SourceCache/objc4_Sim/objc4-427.1.1/runtime/objc-runtime-new.m, line 3939
Assertion failed: (cls), function getName, file /SourceCache/objc4_Sim/objc4-427.1.1/runtime/objc-runtime-new.m, line 3939
It doesn't happen on a specific line or for a specific instructions. I have a few breakpoints in my code and each time I hit one of those, the debugger starts spewing those messages. It doesn't seem to have any detrimental effect as the program works correctly. It's just very annoying to retrieve the information in the console when there are tens of those lines. I'm sure they're not displayed for nothing but I haven't found what the problem might be and what instruction might cause it. If I don't hit a breakpoint, then I don't see any of those lines. I did clean and rebuild my project multiple times to no avail.
它不会发生在特定行或特定指令上。我的代码中有几个断点,每次我点击其中一个断点时,调试器就会开始喷出这些消息。由于程序正常运行,它似乎没有任何不利影响。当有几十行时,在控制台中检索信息非常烦人。我确定它们不会无缘无故地显示,但我还没有发现问题可能是什么以及可能导致它的指令。如果我没有遇到断点,那么我就看不到任何这些行。我多次清理和重建我的项目无济于事。
Does anybody have any idea what this is?
有人知道这是什么吗?
回答by Owen Hartnett
I ran into this - and here's the reason mine happened: I had used
+localizedStringFromDate:dateStyle:timeStyle:
in my code. Worked fine on the iPhone, but it's not available pre-4.0 SDK, so it coughed on the iPad. See if you're calling some routine that's either no longer available in the SDK, or available only in later versions. Frankly, I can't wait for 4.1 on the iPad!
我遇到了这个 - 这就是我发生的原因:我+localizedStringFromDate:dateStyle:timeStyle:
在我的代码中使用
过。在 iPhone 上运行良好,但它在 4.0 SDK 之前不可用,所以它在 iPad 上咳嗽。查看您是否正在调用 SDK 中不再可用或仅在更高版本中可用的某些例程。坦白说,我已经等不及 iPad 上的 4.1 了!
-Owen
-欧文
回答by SteveCaine
I'm also having this problem, in an iPad app originally written in Xcode 3.2.4 using the iOS 3.2 SDK, now being debugged in Xcode 3.2.5 using the 4.2 SDK, but only when I set the simulator to the 3.2 iOS Deployment Target (so I can run in the 3.2 simulator). Every stop at a breakpoint in the debugger, I get this assert repeated eight times. Single-stepping over a line gets two more.
我也有这个问题,在最初使用 iOS 3.2 SDK 用 Xcode 3.2.4 编写的 iPad 应用程序中,现在正在使用 4.2 SDK 在 Xcode 3.2.5 中调试,但仅当我将模拟器设置为 3.2 iOS 部署时目标(所以我可以在 3.2 模拟器中运行)。每次在调试器的断点处停止,我都会将这个断言重复八次。单步越过一条线得到两个。
What I can't understand is I haven't added any code to the project since I last run it in Xcode 3.2.4 and iOS SDK 3.2, so I can't have added any calls that were not present in that SDK or else it wouldn't have compiled.
我不明白的是,自从我上次在 Xcode 3.2.4 和 iOS SDK 3.2 中运行它以来,我没有向项目添加任何代码,所以我无法添加该 SDK 中不存在的任何调用,否则它不会编译。
Until someone finds an answer to this, I think the only workaround (so I can continue debugging my code in a 3.2 environment) is to reinstall Xcode 3.2.4 and use the 3.2 SDK and simulator.
在有人找到答案之前,我认为唯一的解决方法(以便我可以在 3.2 环境中继续调试我的代码)是重新安装 Xcode 3.2.4 并使用 3.2 SDK 和模拟器。
回答by Saqib Saud
I had this problem when I was running on simulator "iPad 3.2 simulator". This problem disappeared when I switched the simulator to "iPad 4.3 simulator"
我在模拟器“iPad 3.2 模拟器”上运行时遇到了这个问题。当我将模拟器切换到“iPad 4.3 模拟器”时,这个问题就消失了
回答by Engin Kurutepe
I have exactly the same issue. I know it's not the complete answer but here's what I could find.
我有完全相同的问题。我知道这不是完整的答案,但这是我能找到的。
The relevant function getName looks like this:
相关函数 getName 如下所示:
/***********************************************************************
* getName
* fixme
* Locking: runtimeLock must be held by the caller
**********************************************************************/
static const char *
getName(struct class_t *cls)
{
// fixme hack rwlock_assert_writing(&runtimeLock);
assert(cls);
if (isRealized(cls)) {
return cls->data->ro->name;
} else {
return ((const struct class_ro_t *)cls->data)->name;
}
}
So gdb is complaining that the assertion assert(cls) is failing. Which means that getName somehow gets a NULL pointer as an argument.
所以 gdb 抱怨断言 assert(cls) 失败。这意味着 getName 以某种方式获取 NULL 指针作为参数。
Which is kinda funny, where could we be asking for the name of a NULL class?
这有点有趣,我们在哪里可以要求 NULL 类的名称?
Hope this helps...
希望这可以帮助...
回答by Corin
I also have the same problem; I don't have a solution but I'm able to work around it. In short, I suggest you add more breakpoints...
我也有同样的问题; 我没有解决方案,但我能够解决它。总之,我建议你添加更多的断点......
I noticed in the call stack that it's actually the debugger that is misbehaving. The function gdb_class_getClass
calls getName
, presumedly this is passing NULL instead of (say) MyClass. The code that I'm trying to debug is a method of MyClass. So, thinking that the debugger has a problem with MyClass, I set a breakpoint at a line outside of any code of MyClass (ie the line that calls the method on MyClass) and hit continue when the program breaks. This seems to resolve the problem in my case. (Note that auto-continue doesn't work.)
我在调用堆栈中注意到它实际上是调试器行为不端。函数gdb_class_getClass
调用getName
,推测这是传递NULL而不是(比如)MyClass。我试图调试的代码是 MyClass 的一个方法。因此,认为调试器对 MyClass 有问题,我在 MyClass 的任何代码之外的一行(即调用 MyClass 上的方法的行)设置了一个断点,并在程序中断时点击 continue。这似乎解决了我的问题。(请注意,自动继续不起作用。)
To be clear:
要清楚:
//Set breakpoint here
[myClassInstance buggyMethod];
My buggyMethod is actually in another file:
我的 buggyMethod 实际上在另一个文件中:
...
-(void)buggyMethod {
//This is where I set my 'real' breakpoint
Hope that helps.
希望有帮助。
回答by jowie
I'm having a similar problem, but mine is with creating a custom view with Core Text in it. As soon as my view's drawRect calls the line
我遇到了类似的问题,但我的问题是创建一个包含 Core Text 的自定义视图。只要我的视图的 drawRect 调用该行
CTFontRef titleFont = CTFontCreateWithName(CFSTR("Baskerville"), 40.0f, NULL);
It hangs the app, whether in the simulator or on the device. Bizarrely, I can rectify this by alloc-initing another UIKit text component in the View Controller's viewDidLoad method... I don't even have to add it as a subview. It's like it needs some common text elements loaded before Core Text can load in fonts.
它会挂起应用程序,无论是在模拟器中还是在设备上。奇怪的是,我可以通过在视图控制器的 viewDidLoad 方法中分配初始化另一个 UIKit 文本组件来纠正这个问题……我什至不必将它添加为子视图。就好像它需要先加载一些常用的文本元素,然后 Core Text 才能加载字体。
- (void)viewDidLoad
{
[super viewDidLoad];
UILabel *l = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
}
Weird.
奇怪的。