是否有Valgrind Memcheck喜欢的工具为Windowsdebugging免费错误后使用?

为了达到我的工作,我经常面对相当常见的编程错误 – 使用一些已经释放的对象。 这在C ++中调用UB。 在Linux上 ,通常使用Valgrind工具Memcheck来解决这类问题。 从Memcheck手册 :

Memcheck试图确定非法地址可能涉及到什么,因为这通常是有用的。 所以,如果它指向已经被释放的内存块,你会被告知这个,并且块被释放。

Memcheck为我提供了调用堆栈,在这里对象被释放,我可以继续debugging问题。 有相同的function的Windows相似的工具,最好是免费的吗?

正如陈来林在回答这个问题时指出的,其中一个:

记忆博士: https : //github.com/dynamorio/drmemory

UMDH: http : //support.microsoft.com/kb/268343

AppVerifier: http : //msdn.microsoft.com/en-us/library/dd371695%28v=vs.85%29.aspx

为我工作的方法是编写自定义内存管理器,提供全局运算符“新建”和“删除”,并锁定每个释放/用户内存块的VirtualProtect。 这样,任何使用释放的内存的尝试都会立即触发您可以捕获和调试的访问冲突。 然而,为了做到这一点,你必须使用类似VirtualAlloc “抓取”所有可用的内存(或3/4),并且你返回的每个内存块(从这个最初分配的块)必须被PAGE_SIZE对齐(参见GetSystemInfo文档),否则你将无法可靠地锁定它。 这意味着即使是微不足道的应用程序也可能需要大量的内存来使用这种方法。

至于“valgrind替代windows” – 我还没有听说过。 有人在某处张贴,可能编译/使用cygwin valgrind,但我不知道这是否是真实的。

这是勇敢的Valgring尝试,我祝他们最好:

http://sourceforge.net/p/valgrind4win/wiki/Home/

但是,我担心,为了实现一个合适的“Windows版Valgrind”,需要访问Windows源代码。

IOW:当猪飞。

根据Dr. Memory的文档,有-delay_frees_stack选项,Valgrind的功能完全相同。 从选项参考 :

 -delay_frees_stack default: false Record callstacks on free to use when reporting use-after-free or other errors that overlap with freed objects. There is a slight performance hit incurred by this feature for malloc-intensive applications. 

这里还有一个Dr. Memory提供的错误的例子:

 Here is another example, using the -delay_frees_stack option to obtain the callstack of the freed memory: Error #8: UNADDRESSABLE ACCESS: reading 0x001338a8-0x001338ac 4 byte(s) # 0 unaddr_test1 [e:\derek\drmemory\git\src\tests\suppress.c:110] # 1 test [e:\derek\drmemory\git\src\tests\suppress.c:269] # 2 main [e:\derek\drmemory\git\src\tests\suppress.c:297] Note: @0:00:02.141 in thread 3024 Note: next higher malloc: 0x001338e8-0x00133938 Note: prev lower malloc: 0x001337e8-0x00133820 Note: 0x001338a8-0x001338ac overlaps memory 0x001338a8-0x001338c4 that was freed here: Note: # 0 test [e:\derek\drmemory\git\src\tests\suppress.c:269] Note: # 1 main [e:\derek\drmemory\git\src\tests\suppress.c:297] Note: instruction: mov (%eax) -> %eax 

最适合我的是使用可视化检漏仪 ,我所需要做的就是包括:

 #include <vld.h> 

在我想要测试的可执行文件的开头。 然后从Windows内运行一个调试可执行文件,将提供有关所有泄漏内存的详细信息。 从输出中你可以直接到达分配内存的行,所以你可以保重