Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Fix #438 #765

Merged
merged 2 commits into from
Feb 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions scripts/terminateProcess.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

terminateTree() {
for cpid in $(/usr/bin/pgrep -P $1); do
terminateTree $cpid
done
kill -9 $1 > /dev/null 2>&1
}

for pid in $*; do
terminateTree $pid
done
24 changes: 22 additions & 2 deletions src/debugAdapter/goDebug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { DebugProtocol } from 'vscode-debugprotocol';
import { DebugSession, InitializedEvent, TerminatedEvent, ThreadEvent, StoppedEvent, OutputEvent, Thread, StackFrame, Scope, Source, Handles } from 'vscode-debugadapter';
import { readFileSync, existsSync, lstatSync } from 'fs';
import { basename, dirname } from 'path';
import { spawn, ChildProcess } from 'child_process';
import { spawn, ChildProcess, execSync, spawnSync } from 'child_process';
import { Client, RPCConnection } from 'json-rpc2';
import { getBinPathWithPreferredGopath } from '../goPath';
import * as logger from 'vscode-debug-logger';
Expand Down Expand Up @@ -305,7 +305,7 @@ class Delve {
});
});
} else {
this.debugProcess.kill();
killTree(this.debugProcess.pid);
}
}
}
Expand Down Expand Up @@ -757,4 +757,24 @@ function random(low: number, high: number): number {
return Math.floor(Math.random() * (high - low) + low);
}

function killTree(processId: number): void {
if (process.platform === 'win32') {
const TASK_KILL = 'C:\\Windows\\System32\\taskkill.exe';

// when killing a process in Windows its child processes are *not* killed but become root processes.
// Therefore we use TASKKILL.EXE
try {
execSync(`${TASK_KILL} /F /T /PID ${processId}`);
} catch (err) {
}
} else {
// on linux and OS X we kill all direct and indirect child processes as well
try {
const cmd = path.join(__dirname, '../../../scripts/terminateProcess.sh');
spawnSync(cmd, [ processId.toString() ]);
} catch (err) {
}
}
}

DebugSession.run(GoDebugSession);