如何确定进程终止的原因

Yng*_*and 10 debugging winapi visual-studio-2010

我有一个问题,在调用第三方库例程期间,我的进程终止.我完全无法在调试器中捕获这个.这可能与此问题有关:如何调试意外终止的win32进程?.

当我调用此库中的调用时,正在调试的进程只会终止.如果此终止是由于未处理的异常或内存访问冲突导致的,则调试器会捕获它.所以我最好的猜测是该过程以某种方式正常终止.

我尝试过的:

  • ExitThread和上设置断点ExitProcess
  • 为未处理的异常和无效参数设置处理程序(set_terminate_set_invalid_parameter_handler)
  • 改变_set_abort_behavior_set_error_mode.
  • 指示调试器停止对所有抛出的异常执行.

但无济于事,没有一个处理程序被调用,也没有触发任何断点.

我观察到的: 当进程崩溃时,我在调试输出窗口中看到两件事:

  1. 没有关系(见下面的更新) 我看到EEFileLoadException被扔了.快速谷歌这个例外并没有给我一个明确的答案,这个例外意味着什么.

    First-chance exception at 0x7656b9bc (KernelBase.dll) in Program.exe: Microsoft C++ exception: EEFileLoadException at memory location 0x0030b5ac..
    First-chance exception at 0x7656b9bc (KernelBase.dll) in Program.exe: Microsoft C++ exception: [rethrow] at memory location 0x00000000..
    First-chance exception at 0x7656b9bc (KernelBase.dll) in Program.exe: Microsoft C++ exception: [rethrow] at memory location 0x00000000..
    First-chance exception at 0x7656b9bc (KernelBase.dll) in Program.exe: 0xE0434352: 0xe0434352.
    
    Run Code Online (Sandbox Code Playgroud)
  2. 终止时,所有线程都返回相同的错误代码(STATUS_INVALID_CRUNTIME_PARAMETER).据我所知,此错误代码意味着其中一个c运行时函数已收到无效参数,并且出于安全原因终止了应用程序.

    The thread 'Win32 Thread' (0x12c0) has exited with code -1073740777 (0xc0000417).
    The thread 'Win32 Thread' (0xe04) has exited with code -1073740777 (0xc0000417).
    The thread 'Win32 Thread' (0x53c) has exited with code -1073740777 (0xc0000417).
    The thread 'Win32 Thread' (0x116c) has exited with code -1073740777 (0xc0000417).
    The thread 'Win32 Thread' (0x16e0) has exited with code -1073740777 (0xc0000417).
    The thread 'Win32 Thread' (0x1420) has exited with code -1073740777 (0xc0000417).
    The thread 'Win32 Thread' (0x13c4) has exited with code -1073740777 (0xc0000417).
    The thread 'Win32 Thread' (0x40c) has exited with code -1073740777 (0xc0000417).
    The thread 'Win32 Thread' (0xc78) has exited with code -1073740777 (0xc0000417).
    The thread 'Win32 Thread' (0xd88) has exited with code -1073740777 (0xc0000417).
    The thread 'Win32 Thread' (0x16c8) has exited with code -1073740777 (0xc0000417).
    The thread 'Win32 Thread' (0xcb8) has exited with code -1073740777 (0xc0000417).
    The thread 'Win32 Thread' (0x584) has exited with code -1073740777 (0xc0000417).
    The thread 'Win32 Thread' (0x1164) has exited with code -1073740777 (0xc0000417).
    The thread 'Win32 Thread' (0x1550) has exited with code -1073740777 (0xc0000417).
    The thread 'Win32 Thread' (0x474) has exited with code -1073740777 (0xc0000417).
    The program '[5140] Program.exe: Native' has exited with code -1073740777 (0xc0000417).
    
    Run Code Online (Sandbox Code Playgroud)

我真正想知道的是导致这种情况的原因,也可以选择; 我怎样才能在调试器中捕获到它?

更新 关于EEFileLoadException,它实际上是在程序进行调用之前抛出的,这导致它终止,因此它与进程的终止无关.

更新 我只是读取set_terminate在调试器中不起作用,所以这是不可能的.正如我的评论中所述,处理程序是基于每个线程进行管理的,因此我无权访问相关的处理程序.

此外,程序很可能在我无法访问的工作线程中崩溃,因此很难设置任何断点/处理程序.

有没有更好的方法来弄清楚出了什么问题?

Rom*_* R. 0

运行您的应用程序裸调试器(或附加到正在运行的进程),按下Ctrl+Alt+E并选中复选框以使调试器在出现异常时停止执行。

每次发生异常时,调试器都会中断。您将能够检查线程状态/调用堆栈以可能识别问题。

应用程序意外终止的典型原因有:

  • 有些东西确实发布了WM_QUIT消息,这指示应用程序关闭
  • 发生异常,但未处理(尤其是在后台线程上);异常遍历调用堆栈直到操作系统,它不知道如何处理所有内容,只是终止进程

EEFileLoadException发生异常并且您不知道它是什么时,您可能希望首先了解它是否被处理,如果它实际上对您的应用程序来说是致命的事情。