不会执行的行的更改会破坏构建!
我的工作是实现一个提供文件共享功能的库。
这种情况已经发生过两次:
首先,在 if-else 路径中的字符串中,仅执行 if 路径,但是当我更改 else 路径中的拼写时,几分钟后软件在 std 库中崩溃。我通过附加的调试验证了线路变化从未被触及。当我撤销更改时,它又可以正常工作了。
其次,我的软件在对标准 basic_string 析构函数进行数组外
检查时再次在 std 库上崩溃。
我做了一切,所有库都匹配_HAS_ITERATOR_DEBUGGING
。
4 小时后我发现有问题的文件是 TorrentFile.cpp/h
。
如果我添加一个函数(即使它从未被调用),程序会在该文件末尾崩溃,但如果它不存在,则没有错误。导致问题的代码:
std::vector<TorrentFileListPacket> TorrentFile::GetFileMap()
{
std::vector<TorrentFileListPacket> vFiles;
return vFiles;
};
如果我注释掉这段代码,崩溃就会消失。
这实在是让我抓狂了!
我做了 8 年开发人员,以前从未见过这样的事情!
其他信息
我的记忆没问题,我在 Windows 7 中使用带有 SP1 的 Visual Studio 2010。该库是来自 RasterBar 的 libTorrent
,它链接到 boost。该软件采用MFC。
I have this job of implementing a library that provides a file-sharing feature.
This has already happened twice:
First, in a string in an if-else path, only the if path is being executed, but when i change a spelling in the else path, the software after a few minutes crashes in an std library. I verified with a debug attached that the lined changed was never being touched. When i reversed the change, it works nicely again.
Second, my software crashes on a std library again with the out-of-array
check into a standard basic_string destructor.
I did everything, all library matched the _HAS_ITERATOR_DEBUGGING
.
After 4 hours I discovered that the problematic file is TorrentFile.cpp/h
.
If i add a function ( even though it is never called ), the program crashes at the end of that file, but if its not there, there's no bug. The code causing the problem:
std::vector<TorrentFileListPacket> TorrentFile::GetFileMap()
{
std::vector<TorrentFileListPacket> vFiles;
return vFiles;
};
If i comment this code out, the crash is gone.
This is really driving me crazy!
I've been a developer for 8 years, and I've never seen something like this before!
Additional Information
My memory is OK, I'm using Visual Studio 2010 with SP1 in Windows 7. The library is libTorrent
from RasterBar and it links to boost. The software is using MFC.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这在与您预期崩溃的位置完全不同的位置闻到了强烈的内存损坏气味。最有可能的添加和删除功能是更改内存布局,从而导致内存损坏的影响立即可见或不可见。
你最好的希望是像 Purify 或 Valgrind 这样的东西来追捕它。
This smells strongly of memory corruption in a totally different location from where you would expect from the crashes. Most likely adding and removing functions is changing the memory layout in such a way that causes the memory corruption's effects to be immediately visible or not.
Your best hope is something like Purify or Valgrind to hunt it down.
您可能希望确保所有目标文件和库都 ABI 彼此兼容。
许多编译器设置都会更改 ABI。特别是调试和发布构建以及迭代器调试。当您启用迭代器调试时,标准容器的结构布局通常会发生变化(我相信默认情况下,对于 msvc 中的所有调试版本都是打开的,对于发布版本是关闭的)。
因此,如果您链接的单个目标文件、静态库或 DLL 是使用不兼容的配置构建的,您通常会看到非常奇怪的行为。使用 libtorrent,您需要确保使用与链接库相同的配置来构建库。许多 TORRENT_* 定义实际上会改变某些结构布局或函数调用的某些方面。确保您在客户端中定义的一组与构建库时完全相同。处理此问题的一种简单方法是将所有源文件放入项目中并一起构建所有内容。
You probably want to make sure that all your object files and libraries are ABI compatible with each other.
Numerous compiler settings will change the ABI. Especially debug and release builds and iterator debugging. The struct layout for standard containers typically change when you enable iterator debugging (which I believe is on by default for all debug builds in msvc, and off for release builds).
So, if a single object file, static library or DLL that you link against is built with an incompatible configuration, you typically see very odd behaviors. With libtorrent you need to make sure you build the library with the same configuration as you link against it with. Many of the TORRENT_* defines will actually change some aspect of some struct layout or function call. Make sure you define the exact same set of those in your client as when building the library. One simple way of dealing with this problem is to simply pull all source files into your project and build everything together.
如果您使用 libtorrent 作为 DLL(或 boost),它们是否针对相同的 C 运行时进行编译?
通常,当我遇到此类问题时,是因为我调用了使用 MinGW(使用 VS6.0 中的 CRT)或旧版本 Visual Studio 编译的库。如果内存由库分配,然后由应用程序释放,则析构函数中通常会出现这些类型的错误。
如果您不确定,可以在 Dependency Walker 等工具中打开相关 DLL。查找依赖项 MSVCRT.DLL、MSVCR100.DLL 等。
If you are using libtorrent as a DLL (or boost for that matter), are they compiled against the same C Run-Time?
Often when I run into this type of issue it is because I make a call into a library that was compiled with MinGW (which uses the CRT from VS6.0) or an older version of Visual Studio. If memory is allocated by the library and then free'd by your application, you will often get these types of errors in the destructor.
If you aren't sure, you can open the DLL in question in a tool like the Dependency Walker. Look for the dependency MSVCRT.DLL, MSVCR100.DLL, etc.