如何跟踪"libc ++ abi.dylib:称为纯虚拟函数!".在Xcode中 [英] How to track down "libc++abi.dylib: Pure virtual function called!" in Xcode

查看:328
本文介绍了如何跟踪"libc ++ abi.dylib:称为纯虚拟函数!".在Xcode中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个多线程OS X应用程序,它混合使用了C ++,Objective-C和Swift.

I have a multithreaded OS X application that uses a mixture of C++, Objective-C, and Swift.

当我的应用程序关闭时,我在Xcode调试器窗口中看到了这一点:

When my application shuts down, I see this in the Xcode debugger window:

libc++abi.dylib: Pure virtual function called!

我知道此错误通常是由对C ++类构造函数或析构函数中的虚函数的调用引起的.

I know that this error is typically caused by a call to a virtual function in a C++ class constructor or destructor.

有一种简单的方法可以找到它的位置吗? 轻松"的意思是不对具有虚拟函数的每个类的每个构造函数和析构函数的每一行都分析调用树".

Is there an easy way to find where it is? By "Easy", I mean "not analyzing call trees for every line of every constructor and destructor of every class that has a virtual function".

我没有看到堆栈跟踪.打印此消息时,调试器不会停止程序.我的应用程序委托的applicationDidTerminate方法记录的消息位于此消息之前.

I don't see a stack trace. The debugger does not halt the program when this message is printed. A message logged from my app delegate's applicationDidTerminate method precedes this message.

我尝试在所有异常"上设置断点,但是不幸的是,使用大量异常的代码经常会碰到断点.还有其他可以放置断点的符号吗?

I tried setting a breakpoint on "All exceptions" but unfortunately that breakpoint is hit often by code that uses lots of exceptions. Is there some other symbol where I can put a breakpoint?

推荐答案

C ++标准库定义了一些实现底层语言/库功能的"ABI"功能. libc++有一个很好的文档,描述了它们此处.

C++ standard libraries define a few "ABI" functions that implement low-level language/library features. libc++ has a nice document that describes them here.

其中之一是__cxa_pure_virtual,当程序以某种方式调用纯虚函数时会调用它.因此,如果您在此处设置一个断点,则应该能够找出发生这种情况的地方.

One of them is __cxa_pure_virtual, which is called when a program somehow invokes a pure-virtual function. So if you set a breakpoint there, you should be able to find out where that's happening.

通常,当vtable处于中间状态时,当您从构造函数或析构函数内调用虚拟函数时,就会发生纯虚拟函数调用.有关更多详细信息,请参见此答案.

Usually, pure virtual function calls happen when you call a virtual function from within a constructor or destructor, while the vtable is in an intermediate state. See this answer for more details.

这篇关于如何跟踪"libc ++ abi.dylib:称为纯虚拟函数!".在Xcode中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆