@@ -8,7 +8,7 @@ import * as childProcess from 'child_process'
88import * as path from 'path'
99import * as util from 'util'
1010import * as fs from 'fs'
11- import { Terminal , IProgram , ProgramPidWrapper } from './terminal'
11+ import { Terminal , IProgram , ProgramPidWrapper , isProcessAlive } from './terminal'
1212import { convertClientPathToDebugger , convertDebuggerPathToClient , isPositiveMatchInGlobs } from './paths'
1313import minimatch from 'minimatch'
1414import { BreakpointManager , BreakpointAdapter } from './breakpoints'
@@ -514,6 +514,21 @@ class PhpDebugSession extends vscode.DebugSession {
514514 private async initializeConnection ( connection : xdebug . Connection ) : Promise < void > {
515515 const initPacket = await connection . waitForInitPacket ( )
516516
517+ // track the process, if we asked the IDE to spawn it
518+ if (
519+ ! this . _phpProcess &&
520+ ( this . _args . program || this . _args . runtimeArgs ) &&
521+ initPacket . appid &&
522+ isProcessAlive ( parseInt ( initPacket . appid ) )
523+ ) {
524+ this . _phpProcess = new ProgramPidWrapper ( parseInt ( initPacket . appid ) )
525+ // we only do this for CLI mode. In normal listen mode, only a thread exited event is send.
526+ this . _phpProcess . on ( 'exit' , ( code : number | null ) => {
527+ this . sendEvent ( new vscode . ExitedEvent ( code ?? 0 ) )
528+ this . sendEvent ( new vscode . TerminatedEvent ( ) )
529+ } )
530+ }
531+
517532 // check if this connection should be skipped
518533 if (
519534 this . _args . skipEntryPaths &&
@@ -1448,10 +1463,8 @@ class PhpDebugSession extends vscode.DebugSession {
14481463 }
14491464 }
14501465 // If launched as CLI, kill process
1451- if ( this . _phpProcess ?. pid ) {
1452- Terminal . killTree ( this . _phpProcess . pid ) . catch ( err =>
1453- this . sendEvent ( new vscode . OutputEvent ( `killTree: ${ err as string } \n` ) )
1454- )
1466+ if ( this . _phpProcess ) {
1467+ this . _phpProcess . kill ( )
14551468 }
14561469 } catch ( error ) {
14571470 this . sendErrorResponse ( response , error as Error )
0 commit comments