|
1 | 1 | import * as ChildProcess from 'child_process'; |
2 | 2 | import * as os from 'os'; |
3 | 3 | import * as net from 'net'; |
| 4 | +import * as fs from 'fs'; |
4 | 5 | import { EventEmitter } from 'events'; |
5 | 6 | import { setTimeout } from 'timers'; |
6 | | -import { TcpPortScanner } from '../tcpportscanner'; |
7 | 7 |
|
| 8 | +const tmpDirName = os.platform() === 'win32' ? process.env.TEMP || process.env.TMP || '.' : '/tmp'; |
| 9 | +export function ServerConsoleLog(str: string) { |
| 10 | + console.log(str); |
| 11 | + try { |
| 12 | + if (false) { |
| 13 | + if (!str.endsWith('\n')) { |
| 14 | + str += '\n'; |
| 15 | + } |
| 16 | + fs.appendFileSync(`${tmpDirName}/cortex-debug-server-exiting-${process.pid}`, str); |
| 17 | + } |
| 18 | + } |
| 19 | + catch (e) { |
| 20 | + console.log(e.toString()); |
| 21 | + } |
| 22 | +} |
8 | 23 | export class GDBServer extends EventEmitter { |
9 | 24 | private process: ChildProcess.ChildProcess; |
10 | 25 | private outBuffer: string = ''; |
@@ -67,25 +82,17 @@ export class GDBServer extends EventEmitter { |
67 | 82 | public exit(): void { |
68 | 83 | if (this.process) { |
69 | 84 | try { |
70 | | - // Some of gdb-servers want to recieve an Control-C equivalent first, so try that for |
71 | | - // a bit more graceful exit |
72 | | - console.log('GDBServer: requesting an exit with SIGINT'); |
73 | | - this.process.kill('SIGINT'); |
74 | | - setTimeout(() => { |
75 | | - if (this.process != null) { // Still not dead? |
76 | | - console.log('GDBServer: forcing an exit with kill()'); |
77 | | - this.process.kill(); |
78 | | - } |
79 | | - }, 100); |
| 85 | + ServerConsoleLog('GDBServer: forcing an exit with kill()'); |
| 86 | + this.process.kill(); |
80 | 87 | } |
81 | 88 | catch (e) { |
82 | | - console.log(`Tring to force and exit failed ${e}`); |
| 89 | + ServerConsoleLog(`Tring to force and exit failed ${e}`); |
83 | 90 | } |
84 | 91 | } |
85 | 92 | } |
86 | 93 |
|
87 | 94 | private onExit(code, signal) { |
88 | | - console.log(`GDBServer: exited ${code} ${signal}`); |
| 95 | + ServerConsoleLog(`GDBServer: exited ${code} ${signal}`); |
89 | 96 | this.process = null; |
90 | 97 | if (this.exitTimeout) { |
91 | 98 | clearTimeout(this.exitTimeout); |
|
0 commit comments