调试堆/ STL调试等效GCC? [英] Debug heap/STL debugging equivalent for GCC?

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

问题描述

我计划使用GCC更多(Linux和Windows),我想知道是否有一个等价的MSVC 调试堆 STL检查可用于GCC CRT和STL。

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.

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

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

推荐答案

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

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)):


最近版本的Linux libc GNU libc(2.x)包括一个
malloc实现,它通过环境变量是可调的。当设置
MALLOC_CHECK_时,使用一个特殊的(效率较低的)实现,它是
设计为容忍简单错误,例如具有相同参数的double()
的double调用,或者超过一个字节(一个错误)。但并不是所有的
这样的错误都可以防止,并且可能导致内存泄漏。如果
MALLOC_CHECK_设置为0,任何检测到的堆损坏都会被静默忽略;如果
设置为1,诊断打印在stderr上;如果设置为2,abort()立即调用
。这可能是有用的,因为否则碰撞可能会发生很多
以后,然后很难跟踪问题的真正原因。

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.

还有电篱笆,它可以帮助抓住缓冲区溢出,一旦超限/欠载发生,中止。有关详情,请参见 libefence(3)

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天全站免登陆