$ErrorActionPreference = "Stop" $targetExe = "D:\ae\proj\Renderive\cmake-build-vs2022_debug\web_server\Renderive_Web_Server.exe" $cdb = "D:\ae\ewdk\EWDK_22621_230929-1800\Program Files\Windows Kits\10\Debuggers\x64\cdb.exe" $outputRoot = "D:\ae\proj\Renderive\deadlock_capture" if (-not (Test-Path -LiteralPath $cdb)) { throw "CDB not found: $cdb" } if (-not (Test-Path -LiteralPath $targetExe)) { throw "Target executable not found: $targetExe" } $processes = @( Get-CimInstance Win32_Process | Where-Object { $_.ExecutablePath -eq $targetExe } ) if ($processes.Count -eq 0) { throw "Renderive_Web_Server.exe is not running: $targetExe" } if ($processes.Count -ne 1) { $processes | Select-Object ProcessId, Name, ExecutablePath | Format-Table -AutoSize throw "Multiple matching processes found. Stop the extra processes first." } $pidValue = [int]$processes[0].ProcessId $timestamp = Get-Date -Format "yyyyMMdd_HHmmss" $outputDir = Join-Path $outputRoot $timestamp $logPath = Join-Path $outputDir "Renderive_deadlock_$timestamp.txt" $dumpPath = Join-Path $outputDir "Renderive_deadlock_$timestamp.dmp" $commandPath = Join-Path $outputDir "cdb_commands.txt" New-Item -ItemType Directory -Force -Path $outputDir | Out-Null $cdbCommands = @" .echo ============================================================ .echo Renderive deadlock capture .echo ============================================================ .echo === PROCESS === | .echo === ALL THREAD STACKS === ~* kb .echo === THREAD CPU TIME === !runaway 3 .echo === LOCKS === !locks .echo === HANG ANALYSIS === !analyze -hang .echo === FULL MEMORY DUMP === .dump /ma $dumpPath .echo === CAPTURE FINISHED === q "@ Set-Content -LiteralPath $commandPath -Value $cdbCommands -Encoding ASCII Write-Host "" Write-Host "Target:" Write-Host " $targetExe" Write-Host "" Write-Host "PID:" Write-Host " $pidValue" Write-Host "" Write-Host "Output:" Write-Host " $outputDir" Write-Host "" Write-Host "Attaching CDB non-invasively..." Write-Host "" $cdbArgs = @( "-pv" "-p" $pidValue.ToString() "-logo" $logPath "-cf" $commandPath ) & $cdb @cdbArgs $cdbExitCode = $LASTEXITCODE Write-Host "" Write-Host "CDB exit code: $cdbExitCode" Write-Host "" if (Test-Path -LiteralPath $logPath) { Write-Host "Log:" Write-Host " $logPath" } if (Test-Path -LiteralPath $dumpPath) { $dump = Get-Item -LiteralPath $dumpPath Write-Host "" Write-Host "Dump:" Write-Host " $dumpPath" Write-Host " Size: $([math]::Round($dump.Length / 1MB, 2) ) MB" } Write-Host "" Write-Host "Capture complete."