เหตุใด DebugActiveProcessStop จึงขัดข้องแอปแก้ไขข้อบกพร่องของฉัน

ฉันมีโปรแกรมแก้ไขข้อบกพร่องที่ฉันเขียนเพื่อแนบไปกับกระบวนการและสร้างไฟล์ดัมพ์ที่ขัดข้อง ส่วนนั้นทำงานได้ดี

ปัญหาที่ฉันมีคือเมื่อโปรแกรมดีบักเกอร์หยุดทำงาน โปรแกรมที่กำลังทำการดีบั๊กก็เช่นกัน

ฉันทำ Googling และพบการเรียก DebugActiveProcessStop() API สิ่งนี้ไม่แสดงในเอกสาร MSDN รุ่นเก่าของฉันเนื่องจากเปิดตัวใน Windows XP เท่านั้น ดังนั้นฉันจึงลองโหลดมัน dynamicall จาก 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 );
}

person SparkyNZ    schedule 22.03.2012    source แหล่งที่มา


คำตอบ (1)


สาเหตุที่มันขัดข้องก็เพราะฉันพลาดคีย์เวิร์ด WINAPI ในคำจำกัดความของตัวชี้ฟังก์ชันของฉัน

วิธีนี้ได้ผล:

typedef BOOL (WINAPI * DEBUGSETPROCESSKILLONEXIT) (BOOL);

person SparkyNZ    schedule 22.03.2012