Does getting random SIGTRAP signals (in MinGW-gdb) is a sign of memory corruption?(获得随机 SIGTRAP 信号(在 MinGW-gdb 中)是否是内存损坏的标志?)
问题描述
我编写了自己的引用计数内存管理器 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 中)是否是内存损坏的标志?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:获得随机 SIGTRAP 信号(在 MinGW-gdb 中)是否是内存损


基础教程推荐
- 我有静态或动态 boost 库吗? 2021-01-01
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
- 常量变量在标题中不起作用 2021-01-01
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- 这个宏可以转换成函数吗? 2022-01-01
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01