问题描述
我编写了自己的引用计数内存管理器 c++(为了好玩),我确信它并不完美;).现在,当我尝试使用它时,我得到了随机的 SIGTRAP 信号.如果我注释掉与该内存管理器相关的每一行,一切都会运行良好.获得 SIGTRAP-s 而不是 SIGSEGV 是很奇怪的.我知道当程序遇到断点时会抛出 SIGTRAP-s,但没有设置断点.我在另一个线程中读到,exe 和 dll 的调试版本必须是最新的.它们是最新的,因此不是原因.
I wrote my own reference counted memory manager c++ (for fun) and I'm sure it isn't perfect ;) . And now when I'm trying to use it I got random SIGTRAP signals. If I comment out every line which are in connection with that memory manager everything runs fine. Getting SIGTRAP-s instead of SIGSEGV is quite strange. I know that SIGTRAP-s are thrown when the program hits a breakpoint, but no breakpoint is set. I read in an other thread that debug builds of the exe's and dll's must be up to date. They are up to date and so it is not the reason.
有人知道为什么会这样吗?
Does anyone know why is this happening?
推荐答案
在 Google 上搜索后,我发现这些 sigtraps 与您在 MSVC++ 中收到的警告相同,即Windows 已在 xxxx.exe 中触发断点.这可能是由于堆损坏,并指示错误 blahblahblah"...
After searching on Google I realized that those sigtraps are same as those warnings you get in MSVC++ saying "Windows has triggered a breakpoint in xxxx.exe. This may be due to a corruption of the heap, and indicates a bug blahblahblah"...
看来是的,意外的 sigtraps 可能表明内存损坏(很奇怪...)
So it seems yes, unexpected sigtraps can indicate memory corrupction (quite strange...)
我也发现了我的错误.MM 在一个链接到 dll 的静态库中.那个静态库和dll链接到我的exe.所以有两个内存管理器,一个在我的 exe 中,一个在我的 dll 中.如果调用MM的初始化方法.它在我的 exe 中初始化了 MM,但没有在 dll 中初始化,所以 dll 没有初始化.我通过不将我的 exe 链接到那个静态库来解决这个问题.
And I found my bug too. The MM is in a static library which is linked to a dll. And that static lib and the dll is linked to my exe. So there were two memory managers, one in my exe and one in my dll. If call the initaialization method of the MM. It initialized the MM in my exe but not in the dll so the dll went without init. I solved this by not linking my exe against that static library.
这篇关于获得随机 SIGTRAP 信号(在 MinGW-gdb 中)是否是内存损坏的标志?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!