[Python] How to programmatically auto-detach WinDbg from a process after it exits (in headless...

Discussão em 'Python' iniciado por Stack, Maio 13, 2025.

  1. Stack

    Stack Membro Participativo

    We have an internal test automation tool that runs tests on VMs. For each test: -A new process is spawned. -After execution, it ends with sys.exit(return_code) to trigger the next test.

    Recently, I integrated WinDbg to attach automatically to the test process at start, in order to catch crashes during regressions and this helped identify some issues. However, I'm facing a blocker: When the test process exits gracefully, WinDbg remains attached. Since the next test is triggered via sys.exit(...), it won't start until WinDbg detaches manually. This means I need to log into the VM and run .detach manually every time which defeats the purpose of automation.

    What I’ve Tried: pywin32, pyautogui, and pywinauto to send .detach to the WinDbg GUI.

    Problem: These tools require an active desktop session and do not work on headless VMs.

    I also attempted scripting through .scriptload and .shell inside WinDbg, but found no reliable hook to auto-detach on process exit.

    Goal: We want to permanently integrate WinDbg for crash capture in our automation flow. So we need a headless-compatible method to ensure WinDbg: -Attaches to the test process automatically at start (this already works). -Detaches automatically once the test process exits (this is the missing piece).

    Key Constraints: -No UI automation (no RDP access or active user session). -Must work on isolated VMs in CI/test infrastructure.

    Continue reading...

Compartilhe esta Página