我想知道是否可以使用 WinDbg 来了解导致分配句柄的调用堆栈。
例如:
#include <windows.h>
#include <conio.h>
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
cout << "Press ENTER to leak handles." << endl;
_getch();
cout << "Leaking handles" << endl;
for (int i = 0; i < 100; ++i)
{
HANDLE h = CreateEvent(NULL, FALSE, FALSE, NULL);
if (h != NULL)
{
cout << ".";
}
}
cout << "Handles leaked. Press ENTER to exit." << endl;
_getch();
return 0;
}
在构建此示例并在 WinDbg 中启动它之后,是否可以在行上方的示例中获取分配句柄的调用堆栈:
HANDLE h = CreateEvent(NULL, FALSE, FALSE, NULL);
我正在用!handle
命令四处寻找,但到目前为止没有任何进展。
这与处理泄漏分析有关。我知道,!htrace -enable
但这!htrace -diff
是一个不同的使用场景(除非有某种组合方式或其他使用向量,请提供信息)。