堆栈遍历已调试的进程

发布于 2024-10-03 12:16:30 字数 1040 浏览 4 评论 0原文

打开一个进程(使用 C++/Windows)

if( CreateProcessA( NULL,   // No module name (use command line)
   (LPSTR)path, //argv[1],        // Command line
    NULL,           // Process handle not inheritable
    NULL,           // Thread handle not inheritable
    FALSE,          // Set handle inheritance to FALSE
    creationFlags,              // No creation flags
    NULL,           // Use parent's environment block
    NULL,           // Use parent's starting directory 
    &startInfo,            // Pointer to STARTUPINFO structure
    &processInfo )           // Pointer to PROCESS_INFORMATION structure

我使用where

DWORD creationFlags = DEBUG_PROCESS | DEBUG_ONLY_THIS_PROCESS;  

,然后我尝试使用 stackwalk 来执行它,

bool ok = StackWalk64(IMAGE_FILE_MACHINE_I386,m_ps.Handle ,m_th.Handle, 
    &m_stackframe, &m_threadContext,
    0, NULL, NULL, 0); 

但是 stackwalk 只给我顶部地址,下一个是 0,而我知道堆栈中还有更多地址。

有谁知道问题出在哪里吗?
谢谢 :)

I'm opened opening a process (with C++/Windows) using

if( CreateProcessA( NULL,   // No module name (use command line)
   (LPSTR)path, //argv[1],        // Command line
    NULL,           // Process handle not inheritable
    NULL,           // Thread handle not inheritable
    FALSE,          // Set handle inheritance to FALSE
    creationFlags,              // No creation flags
    NULL,           // Use parent's environment block
    NULL,           // Use parent's starting directory 
    &startInfo,            // Pointer to STARTUPINFO structure
    &processInfo )           // Pointer to PROCESS_INFORMATION structure

where

DWORD creationFlags = DEBUG_PROCESS | DEBUG_ONLY_THIS_PROCESS;  

and then I'm trying to stackwalk it with

bool ok = StackWalk64(IMAGE_FILE_MACHINE_I386,m_ps.Handle ,m_th.Handle, 
    &m_stackframe, &m_threadContext,
    0, NULL, NULL, 0); 

but stackwalk just gives me the top address and the next one is 0, while I know there are more addresses in the stack.

Does anybody know what's the problem?
thanks :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

魄砕の薆 2024-10-10 12:16:30

根据这个片段无法判断。为了让它发挥作用,你必须正确设置很多东西。查看这篇详细的博客文章<的逻辑< /a>.

如果您可以发布更大但不是太大的示例,请发布更多代码。您如何设置 STACKFRAME 和 CONTEXT 结构?您是否在 StackWalk64 上循环?任何给定的调用仅返回一个堆栈帧。

It's impossible to tell based on this snippet. There's so much you have to set up correctly in order for this to work. Check out the logic at this detailed blog post.

Post more code if you can post a bigger but not too big sample. How are you setting up the STACKFRAME and CONTEXT structures? Are you looping on StackWalk64? Any given call only returns one stack frame.

你的他你的她 2024-10-10 12:16:30

哎呀...我忘记在收到来自调试进程的事件后调用“ContinueDebugEvent” - 所以它保持暂停状态并且 StackWalk 实际上是正确的。 :)

oops... I forget to call "ContinueDebugEvent" after receiving events from the debugged process - so it stayed paused and the StackWalk was infact correct. :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文