为什么 WinDbg 在测试内存泄漏程序时总是返回相同的"!heap -s"信息?
Why the WinDbg always return the same information of "!heap -s" when I test a memory leak program?
我编写了一个程序来学习使用WinDbg进行内存泄漏检测。但是当我使用"!heap -s"命令时,在我长时间运行内存泄漏程序后,它总是返回相同的信息(见下文)。
Microsoft (R) Windows Debugger Version 6.12.0002.633 AMD64
Copyright (c) Microsoft Corporation. All rights reserved.
*** wait with pending attach
Symbol search path is: srv*c:symbols*http://msdl.microsoft.com/download/symbols;C:image
Executable search path is: srv*c:symbols*http://msdl.microsoft.com/download/symbols;C:image
ModLoad: 00000000`00400000 00000000`0041a000 C:imagememory.exe
ModLoad: 00000000`76d40000 00000000`76ee9000 C:WindowsSYSTEM32ntdll.dll
ModLoad: 00000000`76f20000 00000000`770a0000 ntdll.dll
ModLoad: 00000000`001c0000 00000000`0022e000 C:Windowssystem32verifier.dll
ModLoad: 00000000`731c0000 00000000`731ff000 C:WindowsSYSTEM32wow64.dll
ModLoad: 00000000`73160000 00000000`731bc000 C:WindowsSYSTEM32wow64win.dll
ModLoad: 00000000`74850000 00000000`74858000 C:WindowsSYSTEM32wow64cpu.dll
ModLoad: 00000000`6f7f0000 00000000`6f850000 VERIFIER.dll
ModLoad: 00000000`72a20000 00000000`72a49000 vrfcore.dll
ModLoad: 00000000`6f870000 00000000`6f8ac000 VFBASICS.dll
ModLoad: 00000000`76380000 00000000`76490000 KERNEL32.dll
ModLoad: 00000000`76490000 00000000`764d7000 KERNELBASE.dll
ModLoad: 00000000`10200000 00000000`10320000 MSVCR80D.dll
ModLoad: 00000000`74e20000 00000000`74ecc000 msvcrt.dll
(44e0.4748): Break instruction exception - code 80000003 (first chance)
ntdll!DbgBreakPoint:
00000000`76d90590 cc int 3
0:001> !heap -s
LFH Key : 0x0000008a68294636
Termination on corruption : ENABLED
Heap Flags Reserv Commit Virt Free List UCR Virt Lock Fast
(k) (k) (k) (k) length blocks cont. heap
-------------------------------------------------------------------------------------
0000000000320000 00000002 512 8 512 3 1 1 0 0
0000000003d80000 00001002 512 8 512 3 1 1 0 0
0000000000310000 00008000 64 4 64 1 1 1 0 0
00000000003a0000 00008000 64 64 64 61 1 1 0 0
-------------------------------------------------------------------------------------
0:001> g
(44e0.1550): Break instruction exception - code 80000003 (first chance)
ntdll!DbgBreakPoint:
00000000`76d90590 cc int 3
0:001> g
(44e0.3b04): Break instruction exception - code 80000003 (first chance)
ntdll!DbgBreakPoint:
00000000`76d90590 cc int 3
0:001> !heap -s
LFH Key : 0x0000008a68294636
Termination on corruption : ENABLED
Heap Flags Reserv Commit Virt Free List UCR Virt Lock Fast
(k) (k) (k) (k) length blocks cont. heap
-------------------------------------------------------------------------------------
0000000000320000 00000002 512 8 512 3 1 1 0 0
0000000003d80000 00001002 512 8 512 3 1 1 0 0
0000000000310000 00008000 64 4 64 1 1 1 0 0
00000000003a0000 00008000 64 64 64 61 1 1 0 0
-------------------------------------------------------------------------------------
程序代码如下所示:
#include <windows.h>
void AllocateMemory()
{
int* a = new int[2000];
ZeroMemory(a, 8000);
Sleep(1);
}
int main(int argc, char* argv[])
{
while(1)
{
AllocateMemory();
}
return 0;
}
gflag 命令如下所示:
C:Program FilesDebugging Tools for Windows (x64)>gflags.exe -i memory.exe +ust
我只是稍微修改了代码以帮助我计算迭代次数并在 6.12 中运行它并使用 !heap -l 来检测泄漏 windbg 似乎正确报告 查看 BusyBlock 的计数
#include <windows.h>
int count =0;
void AllocateMemory() {
int* a = new int[2000];
ZeroMemory(a, 8000);
Sleep(1);
count++;
}
int main(void) {
while(1) {
AllocateMemory();
}
return 0;
}
来自windbg的输出
0:000> .printf "%yn" ,@eip
leakmem!main (00401050)
0:000> ?? count ; !heap -l
int 0n0
Scanning references from 97 busy blocks (0 MBytes) ...No potential unreachable blocks were detected.
0:000> bp @eip+3 0n5
0:000> g
Breakpoint 0 hit
0:000> ?? count ; !heap -l
int 0n4
Scanning references from 101 busy blocks (0 MBytes) ...No potential unreachable blocks were detected.
0:000> bp 401053 0n15
breakpoint 0 redefined
0:000> bl
0 e 00401053 000f (000f) 0:**** leakmem!main+0x3
0:000> g
Breakpoint 0 hit
0:000> ?? count ; !heap -l
int 0n19
Scanning references from 117 busy blocks (0 MBytes) ...
Entry User Heap Segment Size PrevSize Unused Flags
-----------------------------------------------------------------------------
00421f98 00421fa0 00030000 00410000 1f58 1f58 18 busy extra
fill
00425e48 00425e50 00030000 00410000 1f58 1f58 18 busy extra
fill
00435908 00435910 00030000 00420000 1f58 1f58 18 busy extra
fill
00437860 00437868 00030000 00420000 1f58 1f58 18 busy extra
fill
004397b8 004397c0 00030000 00420000 1f58 1f58 18 busy extra
fill
5 potential unreachable blocks were detected.
0:000>
相关文章:
- 正在查找文档以获得PS4平台的C++中的设备信息
- 为什么在运行时没有向我们提供有关分段错误的更多信息?
- 奇怪的(对我来说)返回声明 - 在谷歌上找不到任何关于它的信息
- 如何设置一个范围来提取我想要获得的信息
- 系统参数信息A 与 SPI_GETMOUSE 返回 0
- 为什么 gcovr 会生成空覆盖率统计信息?
- 为什么我的 heap.h 文件给我一个LNK2001错误?
- 我已经阅读了很多关于 2d 数组的信息,但我在作业中使用它时遇到了麻烦
- 将信息输入到下面显示的结构向量中的正确语法/格式是什么
- 调试符号中缺少 QObject 类信息(编辑但存在其他 Qt 类)
- 当为可变性配置时,boost::heap::d_ary_heap 保留的额外 std::list 的目的是什么?
- 为什么数组大小信息可用于"sizeof"运算符和 delete[] 运算符,但在将数组作为参数传递到
- Pisarze - 来自波兰奥林匹克信息学的数据分析任务
- 将数组信息存储到 c++ 向量中有一个"Access violation reading location"
- C++20 个模块在 clang (Windows):在最简单的示例中键入信息错误
- C++ 如何暂停控制台输出,以便用户可以在继续之前阅读信息
- 如何从WebAssembly模块检测浏览器信息?
- Visual Studio 2017 C++,不能使用 typeid() 获取信息对象,缺少指针?;
- 为什么 WinDbg 在测试内存泄漏程序时总是返回相同的"!heap -s"信息?
- malloc和heap:用于存储大小和链表信息的额外内存