Stack Walking a debugged process

寵の児 提交于 2020-01-13 09:52:06

问题


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 :)


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/4224307/stack-walking-a-debugged-process

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!