句柄分配在哪里?
我想知道是否可以使用 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
但这是一个不同的使用场景(除非有某种方法来组合或其他使用向量,请提供资料)。
I am wondering if it is possible to use WinDbg to kwown the callstack that lead to the allocation of a handle.
For example:
#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;
}
After building this sample and firing it up in WinDbg is it possible to get the callstack that allocated the handles, in the sample above the line:
HANDLE h = CreateEvent(NULL, FALSE, FALSE, NULL);
I am poking around with the !handle
command but no progress so far.
This is pertinent to handle leak analysis. I am aware of !htrace -enable
and !htrace -diff
but this is a different usage scenario (unless there is some way to combine or other usage vector for it, please provide information).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
找到了似乎是解决方案:
!htrace -enable
启用跟踪!htrace
进行分析的峰值之一 操作:
要获取该地址处的代码行,我执行了以下
Found what seems to be a solution:
!htrace -enable
!htrace <handle>
And to get the line of code at that address I did: