c++ - GCC 的调试堆/STL 调试等价物?

标签 c++ debugging gcc

我计划更多地使用 GCC(Linux 和 Windows),我想知道是否有 MSVC debug heap 的等价物和 STL checks适用于 GCC CRT 和 STL。

我已经了解 Valgrind 等工具,但我正在寻找库中内置的东西。

最佳答案

我不太熟悉调试堆和 STL 检查,但是当我在 Linux 上的 GCC 中遇到内存问题时,我使用一个名为 MALLOC_CHECK_ 的环境变量(来自 malloc(3)):

Recent versions of Linux libc (later than 5.4.23) and GNU libc (2.x) include a malloc implementation which is tunable via environment variables. When MALLOC_CHECK_ is set, a special (less efficient) implementation is used which is designed to be tolerant against simple errors, such as double calls of free() with the same argument, or overruns of a single byte (off-by-one bugs). Not all such errors can be protected against, however, and memory leaks can result. If MALLOC_CHECK_ is set to 0, any detected heap corruption is silently ignored; if set to 1, a diagnostic is printed on stderr; if set to 2, abort() is called immediately. This can be useful because otherwise a crash may happen much later, and the true cause for the problem is then very hard to track down.

还有 Electric Fence 可以帮助捕获缓冲区溢出,一旦溢出/欠载发生就会立即中止。参见 libefence(3)获取更多信息。

关于c++ - GCC 的调试堆/STL 调试等价物?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1177457/

相关文章:

c++ - 将 vector 并行保存到文件

linux - rasm 和 ndisasm

java - 这个正弦源代码有什么问题?

Linux clock_gettime(CLOCK_MONOTONIC) 奇怪的非单调行为

不能对多个文件指定 -c

c++ - 是否允许调用参数中的typename T?

c++ - vector vector 的迭代器无法处理一维 vector

c++ - 二维矩阵的推送和弹出操作并在 C++ 中显示它们

asp.net - 弹出IE脚本调试

c++ - 如何在 gcc 中禁用尾调用优化