如何使用windbg调试子进程和父进程?

时间:2014-05-09 08:46:05

标签: debugging command windbg createprocess child-process

我有一个使用CreateProcess函数创建子进程的程序。在调试时,我通过 childdbg 1 进入子进程。但是在执行完整的子进程步骤之后。它没有返回到父进程。

当我使用.childdbg 1

  

0:000> .childdbg 1
  将调试当前进程创建的进程

然后我用了2次g, 第一次,它加载模块并来到,低于位置,

  

0:000>摹
  
  。
  。
  。
  
  1:002>

第二次,它再次加载了一些其他模块,并且到了下面的位置,

  

1:002>摹
  
  。
  。
  。
  
  2:005>

从这一点开始,我将开始调试我的子进程。它的工作性很好。之后,运行子进程,直接执行它的父进程。那么,任何人都可以给我调试命令或命令从第二个进程到第一个进程。请,我需要调试级解决方案。不是来自我的代码。

2 个答案:

答案 0 :(得分:8)

您可以使用|命令验证当前连接的进程。类似于在线程之间切换(~0s,~1s,~2s),您可以使用|0s |1s |2s等在附加进程之间切换。

答案 1 :(得分:2)

.childdbg 1只能调试第一个孩子而不是孙子 在你的例子中2.002是孙子 调试它,然后回到孩子,你需要在每一代发出.childdbg 1

childdbg:\>dir /b
childdbg.cpp

childdbg:\>type childdbg.cpp
#include <stdio.h>
#include <windows.h>
int main (void)
{
    STARTUPINFO si;
    PROCESS_INFORMATION pi;
    ZeroMemory( &si, sizeof(si) );
    si.cb = sizeof(si);
    ZeroMemory( &pi, sizeof(pi) );
    if( !CreateProcess( NULL, "childdbg.exe", NULL, NULL, 
    FALSE,0,NULL,NULL,&si, &pi ) )
    {
        printf( "CreateProcess failed (%d).\n", GetLastError() );
        return 0;
    }
    WaitForSingleObject( pi.hProcess, INFINITE );
    CloseHandle( pi.hProcess );
    CloseHandle( pi.hThread );
    return 0;
}
childdbg:\>cl /Zi /nologo childdbg.cpp
childdbg.cpp

childdbg:\>dir /b *.exe
childdbg.exe

do not run the exe it will spawn zillion childs
use debugger and when done subvert flow to skip child creation


childdbg:\>cdb childdbg.exe

0:000> .childdbg 1
Processes created by the current process will be debugged
0:000> g

1:001> .childdbg 1
Processes created by the current process will be debugged
1:001> g

2:002> .childdbg 1
Processes created by the current process will be debugged
2:002> g

3:003> .childdbg 1
Processes created by the current process will be debugged
3:003> g

4:004> lsf childdbg.cpp
childdbg.cpp
4:004> bp childdbg!main
*** WARNING: Unable to verify checksum for childdbg.exe
4:004> g

Breakpoint 0 hit

childdbg!main:
00401010 55              push    ebp

4:004> ls 10
    10:     if( !CreateProcess( NULL, "childdbg.exe", NULL, NULL,
                FALSE,0,NULL,NULL,&si,&pi ) )
    11:     {
    12:         printf( "CreateProcess failed (%d).\n", GetLastError() );
    13:         return 0;
    14:     }
    15:     WaitForSingleObject( pi.hProcess, INFINITE );
    16:     CloseHandle( pi.hProcess );
    17:     CloseHandle( pi.hThread );
    18:     return 0;
    19: }
4:004> r eip = `:18`
WARNING: Line information loading disabled
4:004> .lines
Line number information will be loaded
4:004> r eip = `:18`
4:004> r
childdbg!main+0x8a:
0040109a 33c0            xor     eax,eax
4:004> g
4:004> g
3:003> g
2:002> g
1:001> g
0:000> g
       ^ No runnable debuggees error in 'g'
0:000> q
quit:
childdbg:\>