写了一个小程序学习!heap使用,但是出现栈显示不完整的问题,代码如下:
void HeapTest() { PTSTR pszbuf = NULL;
for (int i = 0; i < 5; ++i) { pszbuf = (PTSTR)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, 1025); }
for (int i = 0; i < 5; ++i) { pszbuf = (PTSTR)malloc(2049); }
for (int i = 0; i < 5; ++i) { pszbuf = new TCHAR[4097]; } }
在执行完此函数后执行如下操作,找到新申请的堆块,再执行!heap -p -a 用户地址,显示栈,但是发现只有从默认堆中声申请的块可以显示完整的栈,使用malloc与new申请的都不能完整显示,效果如下:
0> !heap -p -a 053cdbf8 address 053cdbf8 found in _DPH_HEAP_ROOT @ 3c11000 in busy allocation ( DPH_HEAP_BLOCK: UserAddr UserSize - VirtAddr VirtSize) 3c13c30: 53cdbf8 401 - 53cd000 2000 5bf18e89 verifier!AVrfDebugPageHeapAllocate+0x00000229 77100d96 ntdll!RtlDebugAllocateHeap+0x00000030 770baf0d ntdll!RtlpAllocateHeap+0x000000c4 77063cfe ntdll!RtlAllocateHeap+0x0000023a 00401819 demo!HeapTest+0x00000039 00401888 demo!wmain+0x00000008 00401170 demo!__tmainCRTStartup+0x0000010f 758d338a kernel32!BaseThreadInitThunk+0x0000000e 77069f72 ntdll!__RtlUserThreadStart+0x00000070 77069f45 ntdll!_RtlUserThreadStart+0x0000001b
使用malloc与new申请的块显示如下: 0> !heap -p -a 052ca7f8 address 052ca7f8 found in _DPH_HEAP_ROOT @ 51d1000 in busy allocation ( DPH_HEAP_BLOCK: UserAddr UserSize - VirtAddr VirtSize) 51d3f70: 52ca7f8 801 - 52ca000 2000 5bf18e89 verifier!AVrfDebugPageHeapAllocate+0x00000229 77100d96 ntdll!RtlDebugAllocateHeap+0x00000030 770baf0d ntdll!RtlpAllocateHeap+0x000000c4 77063cfe ntdll!RtlAllocateHeap+0x0000023a 我使用debug版本不存在问题都是正常的,但是如果使用禁止优化的release就会出现这个问题,不知道是什么原因,请大家忙看看。
具体的环境是:程序编译为x86运行于win7 x64系统中,调试器为x86版本
另外我也看了一下运行时库中的其它堆块问题,栈也是不能完整显示的,都是类似如下的栈(列出如下三个),明显是少了msvcr80之前的栈信息: 0:000> !heap -p -a 051c2fd0 address 051c2fd0 found in _DPH_HEAP_ROOT @ 50d1000 in busy allocation ( DPH_HEAP_BLOCK: UserAddr UserSize - VirtAddr VirtSize) 50d2068: 51c2fd0 30 - 51c2000 2000 73458e89 verifier!AVrfDebugPageHeapAllocate+0x00000229 77180d96 ntdll!RtlDebugAllocateHeap+0x00000030 7713af0d ntdll!RtlpAllocateHeap+0x000000c4 770e3cfe ntdll!RtlAllocateHeap+0x0000023a 74744efe MSVCR80!_calloc_impl+0x00000125 0:000> !heap -p -a 051c0fd8 address 051c0fd8 found in _DPH_HEAP_ROOT @ 50d1000 in busy allocation ( DPH_HEAP_BLOCK: UserAddr UserSize - VirtAddr VirtSize) 50d209c: 51c0fd8 24 - 51c0000 2000 73458e89 verifier!AVrfDebugPageHeapAllocate+0x00000229 77180d96 ntdll!RtlDebugAllocateHeap+0x00000030 7713af0d ntdll!RtlpAllocateHeap+0x000000c4 770e3cfe ntdll!RtlAllocateHeap+0x0000023a 74744efe MSVCR80!_calloc_impl+0x00000125 0:000> !heap -p -a 051acfd8 address 051acfd8 found in _DPH_HEAP_ROOT @ 50d1000 in busy allocation ( DPH_HEAP_BLOCK: UserAddr UserSize - VirtAddr VirtSize) 50d22a4: 51acfd8 28 - 51ac000 2000 73458e89 verifier!AVrfDebugPageHeapAllocate+0x00000229 77180d96 ntdll!RtlDebugAllocateHeap+0x00000030 7713af0d ntdll!RtlpAllocateHeap+0x000000c4 770e3cfe ntdll!RtlAllocateHeap+0x0000023a 74744efe MSVCR80!_calloc_impl+0x00000125
|