windows 获得随机 SIGTRAP 信号(在 MinGW-gdb 中)是否是内存损坏的迹象?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2307621/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 13:59:46  来源:igfitidea点击:

Does getting random SIGTRAP signals (in MinGW-gdb) is a sign of memory corruption?

c++windowsmemory-managementgdbmingw

提问by Calmarius

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.

我写了我自己的引用计数内存管理器 c++(为了好玩),我确信它并不完美 ;) 。现在当我尝试使用它时,我收到了随机的 SIGTRAP 信号。如果我注释掉与该内存管理器相关的每一行,一切运行正常。获得 SIGTRAP-s 而不是 SIGSEGV 是很奇怪的。我知道当程序遇到断点时会抛出 SIGTRAP-s,但没有设置断点。我在另一个线程中读到 exe 和 dll 的调试版本必须是最新的。他们是最新的,所以这不是原因。

Does anyone know why is this happening?

有谁知道为什么会这样?

采纳答案by Calmarius

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"...

在 Google 上搜索后,我意识到这些 sigtraps 与您在 MSVC++ 中收到的警告相同,说“Windows 已触发 xxxx.exe 中的断点。这可能是由于堆损坏,并表示存在错误 blahblahblah”...

So it seems yes, unexpected sigtraps can indicate memory corrupction (quite strange...)

所以看起来是的,意外的 sigtraps 可以表明内存损坏(很奇怪......)

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.

我也发现了我的错误。MM 位于链接到 dll 的静态库中。那个静态库和 dll 链接到我的 exe。所以有两个内存管理器,一个在我的 exe 中,一个在我的 dll 中。如果调用MM的初始化方法。它在我的 exe 中初始化了 MM,但不在 dll 中,因此 dll 没有 init。我通过不将我的 exe 链接到那个静态库来解决这个问题。

回答by VoidPointer

I'd throw in a guess that you might be calling mismatched new/delete or malloc/free implementations - So something was allocated by your memory manager but when the memory is released you end up with the default delete/free implementation.

我猜测您可能正在调用不匹配的 new/delete 或 malloc/free 实现 - 因此您的内存管理器分配了一些东西,但是当内存被释放时,您最终会得到默认的 delete/free 实现。

Set a breakpoint on the signal and see whether there is free() or operator delete on the stack and whether that is the implementation of said function which you would expect.

在信号上设置一个断点,看看堆栈上是否有 free() 或 operator delete ,以及这是否是您期望的所述函数的实现。