调试堆/ STL调试相当于GCC? [英] Debug heap/STL debugging equivalent for GCC?

查看:166
本文介绍了调试堆/ STL调试相当于GCC?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我打算更多地使用GCC(Linux和Windows),我想知道是否有相当于MSVC 调试堆 STL检查可用于GCC CRT和STL。



我已经了解了Valgrind等工具,但是我正在寻找在图书馆内建的东西。

解决方案

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


Linux libc(早于5.4.23)和GNU libc(2.x)包括一个
malloc实现,可通过环境变量进行调整。当
MALLOC_CHECK_被设置时,使用一个特殊的(效率较低的)实现,它是
,设计为容忍对简单的错误,例如具有相同参数的free()
的双调用,或超出一个字节(一个错误)。不是所有的
这样的错误可以被保护,但是,可能会导致内存泄漏。如果
MALLOC_CHECK_设置为0,任何检测到的堆损坏将被默认忽略;如果
设置为1,则在stderr上打印诊断;如果设置为2,则abort()立即被称为
。这可能是有用的,因为否则崩溃可能会发生在
以后,真正的原因是很难跟踪。


还有一个电篱笆可以帮助缓冲区溢出中止,一旦超限/欠运行发生。有关详细信息,请参阅 libefence(3)


I plan on using GCC more (Linux and Windows) and I was wondering if there's an equivalent of the MSVC debug heap and the STL checks available for the GCC CRT and STL.

I already know about tools such as Valgrind, but I'm looking for something built in the libraries.

解决方案

I'm not too familiar with the debug heap and STL checks, but when I have memory problems in GCC on linux I use an environment variable called MALLOC_CHECK_ (from 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.

There is also Electric Fence which can help catch buffer overruns aborting as soon as the overrun / underrun happens. See libefence(3) for more information.

这篇关于调试堆/ STL调试相当于GCC?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆