【问题标题】:How to debug child and parent process using windbg?如何使用windbg调试子进程和父进程?
【发布时间】:2014-05-09 08:46:05
【问题描述】:

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

当我使用 .childdbg 1 时

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

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

0:000> g

.
.
.

1:002>

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

1:002> g

.
.
.

2:005>

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

【问题讨论】:

    标签: debugging command windbg createprocess child-process


    【解决方案1】:

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

    【讨论】:

    • 好的。它来到父进程。在这里,我有一个疑问。如果,我从子进程切换到父进程,那么子进程将完成它的所有步骤,或者它会挂在那个步骤上?
    • 这救了我的命!如果可以的话,我想给这个答案投票 10 次。
    【解决方案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:\>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-11-30
      • 2014-04-30
      • 2014-12-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-20
      • 2013-08-11
      相关资源
      最近更新 更多