0X40010004

DBG_TERMINATE_PROCESS (0X40010004) – Fix Debugger Crashing Your App

Programming & Dev Tools Beginner 👁 0 views 📅 Jun 10, 2026

Your debugger killed your process. Here's why and how to stop it from happening again.

You see 0X40010004 and your app just died mid-debug. Annoying, but fixable.

That error code means the debugger itself terminated your process. It's not a bug in your code — it's the debugger saying "I'm done with you." Let's fix it.

The Fix: Stop the Debugger from Killing the Process

The most common cause is you accidentally hit Stop Debugging (Shift+F5 in Visual Studio, or quit in gdb/lldb). But if you didn't, here's what to check:

  1. Visual Studio 2022 / 2019 — Go to Tools > Options > Debugging > General. Uncheck "Enable Just My Code". Yes, that sounds unrelated. But JMC can cause debugger to abort processes during async operations. Then restart your debug session.
  2. Check for exception settings — In Visual Studio, open Debug > Windows > Exception Settings. Make sure "Break When Thrown" is not checked for Win32 Exceptions > 0x40010004. If it is, uncheck it. That tells the debugger to stop the process when this code is raised — which is exactly what you're seeing.
  3. Kill zombie debugger processes — Open Task Manager, end any lingering devenv.exe or msvsmon.exe (Remote Debugger). Restart Visual Studio clean. Sometimes a stale debugger session sends a terminate signal to new processes.
  4. For GDB/LLDB — If you're using command-line debuggers, you likely sent a kill or quit command accidentally. Check your GDB script or IDE plugin. The fix is simple: don't send that signal. Or if you're debugging a child process, use set follow-fork-mode child in GDB so it doesn't terminate the parent prematurely.

Why This Worked

Let's get into what's actually happening here. The error code 0X40010004 is a DBG_TERMINATE_PROCESS status code. It's part of Windows' debugging API — specifically, the WaitForDebugEvent loop. When the debugger decides to stop debugging (for any reason), it calls TerminateProcess on the target process, and Windows raises this status code as an exit code.

The reason step 1 works (disabling Just My Code) is that JMC can cause the debugger to treat certain async operations as "not my code" and silently kill the process when an exception occurs outside your code. With JMC off, the debugger pauses on the actual exception instead of terminating.

Step 2 is even more direct: the Exception Settings dialog lets you configure which system codes cause the debugger to break (pause) vs. continue. If you told it to break on 0x40010004, that's exactly what it does — but the break action for a terminate process is a full kill, not a pause. It's a misleading option in the UI.

Step 3 addresses a real but rare issue: Visual Studio's debugger can get stuck in a bad state. The msvsmon.exe process (Microsoft Visual Studio Remote Debugging Monitor) might hold a handle to your process. When you start a new debug session, the old monitor sees the new process and terminates it — thinking it's a leftover.

Less Common Variations of the Same Issue

Here are a few edge cases where 0x40010004 shows up but the fix is different:

  • Anti-virus killing the debugger — Some AV software (I've seen this with McAfee and Bitdefender) hooks into debug events. It can generate a false DBG_TERMINATE_PROCESS. Temporarily disable real-time protection to test. If it fixes it, add exceptions for your IDE and debugger executables.
  • Remote debugging over network — If you're using Remote Debugger, a network timeout can cause the debugger to think the process is dead and terminate it. Increase the timeout in Tools > Options > Debugging > General > "Require source files to exactly match the original version" — weirdly, that setting also controls timeout behavior. Set it to false.
  • Mixed-mode debugging (managed + native) — If you're debugging a C# app that calls C++ DLLs, the debugger can kill the process when crossing boundaries. Solution: In Project Properties > Debug, enable "Enable Native Code Debugging". That tells Visual Studio to handle the cross-boundary correctly instead of terminating.
  • Windows 10/11 with Fast Startup — This sneaky one: Fast Startup can cause the debugger to retain stale process handles from a previous session. Disable Fast Startup in Power Options > Choose what the power buttons do. Reboot. The error disappears because the kernel's process table is clean.

How to Prevent This from Happening Again

You can't always stop the debugger from terminating when you tell it to — that's by design. But you can avoid accidental terminations:

  • Rebind the Stop Debugging shortcut — In Visual Studio, go to Tools > Options > Environment > Keyboard. Find Debug.StopDebugging (default is Shift+F5). Change it to something less easy to fat-finger, like Ctrl+Alt+Shift+F5. I did this after hitting it by accident during a demo. Saved my sanity.
  • Use a launch profile that attaches to a running process — Instead of launching your app from the debugger, compile it, run it separately, then attach the debugger (Debug > Attach to Process). If the debugger crashes, your app keeps running. You lose the ability to break on startup, but for most bugs that's fine.
  • Log exit codes — Add a try/catch around Main() in C# or a __try/__except in C++. Log the exit code. If 0x40010004 appears, you'll know the debugger killed it, not a crash in your code. That saves hours of misdirected debugging.
  • Keep Visual Studio updated — Microsoft fixed a bug in VS 2022 version 17.4 where debugger would randomly terminate processes during async local functions. Update to the latest patch. This is one of those rare cases where "update your tools" is actually the answer.

Bottom line: 0X40010004 is the debugger saying "I don't want to debug this anymore." Most of the time, it's a settings issue — not a bug in your app. Check the three steps above, and you'll spend less time fighting the debugger and more time fixing real problems.

Was this solution helpful?