找到因覆盖vtable而导致崩溃的地方 [英] Find the place for crash due to overwrite of the vtable

查看:73
本文介绍了找到因覆盖vtable而导致崩溃的地方的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



我有A类,有虚拟方法。 (并实现它)

B类继承自A类,但没有实现虚拟方法。



我有一个对象图B级。



我有一个很长的程序,它会在地图上添加很多次物体。



我随机运行程序,在大约4-5次运行中,它崩溃了一条消息:

::`vftable'(NULL:0)。



这是一个无法解决的例外,我不能回到它发生的地方。



我猜是因为虚拟表已经被某种方式覆盖了,但我发现它什么时候发现(正如我所说,它只发生在4-5次运行中)。



有没有办法找到,使用调试器,虚拟表被覆盖的点和时刻?



谢谢

解决方案

Quote:

有没有办法找到,使用调试器,点a虚拟表被覆盖的那一刻?

很可能你的代码覆盖了 vtable。如果yoyu正在使用Visual Studio 数据断点 [ ^ ]可以您感兴趣。


首先,使用具有未实现的虚函数的类是没有意义的。如果这个类是抽象的,只用作其他类的基类,这很好,但你不应该实例化它。



现在,没有这样的作为覆盖虚拟表的概念。您覆盖一个函数。每个使用虚函数的类通常都与其各自的虚拟表相关联,这就是全部。 因此,您无法找到虚拟表被覆盖的点和时刻,因为这一点不存在。虚拟表是在编译,链接和最终加载项目期间形成的(实际上, loading - 因为虚拟表是驻留在RAM中的对象。它在您的应用程序开始执行时始终存在。虚拟表本身是一个静态对象,即使它用于实现调用的动态调度。



相反,你需要在调试器下运行应用程序,找出异常抛出的行,然后在该行放置一个断点并在执行该行之前检查上下文以找出错误。在100%的情况下无法重现相同的问题可能是令人讨厌的,但这个调试问题应该是可以解决的。



-SA

Hello,

I have Class A, that has a virtual method. (and implements it)
Class B inherits from Class A, but does not implement the virtual method.

I have a map of objects of class B.

I have a very long program, and it adds a lot of times objects to the map.

I run the program randomly, and once in about 4-5 runs, it crashed with a message of:
"::`vftable' (NULL:0)".

It is an unhandeled exception and I can't go back to the place it happened.

My guess is that the virtual table has been overwritten somehow, but I can't find when it happens (and as I said, it happens just once in 4-5 runs).

Is there a way I can find, using the debugger, the point and moment the virtual table is overridden?

Thanks

解决方案

Quote:

Is there a way I can find, using the debugger, the point and moment the virtual table is overridden?

Most likely your code overwrites the vtable. If yoyu are using Visual Studio the Data Breakpoints[^] could interest you.


First of all, it makes no sense to use a class with non-implemented virtual function. If this class is abstract, used only as a base class for some other classes, this is fine, but you should not instantiate it.

Now, there is no such concept as overriding of a virtual table. You override a function. Each class using virtual function, generally is associated with its individual virtual table, that's all. So, you cannot find "the point and moment the virtual table is overridden" because such point does not exist. Virtual table is formed during the compilation, linking and, ultimately, loading of the project (essentially, loading — because the virtual table is the object residing in your RAM). It always exists when your application is started to execute. A virtual table itself is a static object, even though it is used to achieve dynamic dispatching of the calls.

Instead, you need to run the application under the debugger, find out in what line the exception is throwing, then put a break point on that line and inspect the context before executing this line to find what's wrong. Not being able to reproduce the same problem in 100% of cases can be nasty, but this debugging problem should be solvable.

—SA


这篇关于找到因覆盖vtable而导致崩溃的地方的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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