Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Debugging 为什么DebugActiveProcessStop使我的调试应用程序崩溃?_Debugging - Fatal编程技术网

Debugging 为什么DebugActiveProcessStop使我的调试应用程序崩溃?

Debugging 为什么DebugActiveProcessStop使我的调试应用程序崩溃?,debugging,Debugging,我有一个调试程序,我写了附加到一个进程,并创建一个崩溃转储文件。那部分很好用 我遇到的问题是,当调试器程序终止时,它正在调试的程序也会终止 我在谷歌上搜索了一下,找到了DebugActiveProcessStop API调用。这没有出现在我以前的MSDN文档中,因为它只在Windows XP中引入,所以我尝试在运行时从Kernel32.dll动态调用加载它 现在我的问题是,我的调试器程序在发出_DebugActiveProcessStop调用后立即崩溃。谁能告诉我我做错了什么 typedef B

我有一个调试程序,我写了附加到一个进程,并创建一个崩溃转储文件。那部分很好用

我遇到的问题是,当调试器程序终止时,它正在调试的程序也会终止

我在谷歌上搜索了一下,找到了DebugActiveProcessStop API调用。这没有出现在我以前的MSDN文档中,因为它只在Windows XP中引入,所以我尝试在运行时从Kernel32.dll动态调用加载它

现在我的问题是,我的调试器程序在发出_DebugActiveProcessStop调用后立即崩溃。谁能告诉我我做错了什么

typedef BOOL (*DEBUGACTIVEPROCESSSTOP)(DWORD);

DEBUGACTIVEPROCESSSTOP _DebugActiveProcessStop;

HMODULE hK32 = LoadLibrary( "kernel32.dll" );

if( hK32 )
  _DebugActiveProcessStop = (DEBUGACTIVEPROCESSSTOP) GetProcAddress( hK32,"DebugActiveProcessStop" );
else
{
  printf( "Can't load Kernel32.dll\n" );
  return;
}

if( ! _DebugActiveProcessStop )
{
  printf( "Can't find DebugActiveProcessStop\n" );
  return;
}

...

void DebugLoop( void )
{
  DEBUG_EVENT de;

  while( 1 )
  {
    WaitForDebugEvent( &de, INFINITE ); 

    switch( de.dwDebugEventCode )
    {
      case CREATE_PROCESS_DEBUG_EVENT:
        hProcess = de.u.CreateProcessInfo.hProcess;
        break;

      case EXCEPTION_DEBUG_EVENT: 

        // PDS: I want a crash dump immediately!
        dwProcessId = de.dwProcessId;
        dwThreadId  = de.dwThreadId;

        WriteCrashDump( &de.u.Exception );
        return;

      case CREATE_THREAD_DEBUG_EVENT:
      case OUTPUT_DEBUG_STRING_EVENT:
      case EXIT_THREAD_DEBUG_EVENT:
      case EXIT_PROCESS_DEBUG_EVENT :
      case LOAD_DLL_DEBUG_EVENT:
      case UNLOAD_DLL_DEBUG_EVENT:
      case RIP_EVENT:
      default:
        break;
    }

    ContinueDebugEvent( de.dwProcessId, de.dwThreadId, DBG_CONTINUE );
  }
}

...
void main( void )
{
...
  BOOL bo = DebugActiveProcess( dwProcessId );

  if( bo == 0 )
    printf( "DebugActiveProcess failed, GetLastError: %u \n",GetLastError() );

  hProcess = OpenProcess( PROCESS_ALL_ACCESS, TRUE, dwProcessId );

  if( hProcess == NULL )
    printf( "OpenProcess failed, GetLastError: %u \n",GetLastError() );

  DebugLoop();

  _DebugActiveProcessStop( dwProcessId );

  CloseHandle( hProcess );
}

它崩溃的原因是我错过了函数指针定义中的WINAPI关键字

这项工作:

typedef BOOL WINAPI*DEBUGSETPROCESSKILLONEXITBOOL