Skip to content
This repository has been archived by the owner on Jan 13, 2021. It is now read-only.

Commit

Permalink
fix: remote debugging
Browse files Browse the repository at this point in the history
Remote debugging is still flaky
* we need to figure out a better handler of db output and application output
* relative paths eg. might be different when remote debugging
  • Loading branch information
Morten Henriksen committed Feb 10, 2018
1 parent d4855a5 commit 12e03a9
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 8 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@
"name": "Perl-Debug remote",
"program": "${workspaceFolder}/${relativeFile}",
"root": "${workspaceRoot}/",
"stopOnEntry": true,
"port": 5000
}
]
Expand Down
10 changes: 10 additions & 0 deletions src/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,11 @@ export class perlDebuggerConnection {
}
});

if (res.exception || res.finished) {
// Close the connection to perl debugger
this.perlDebugger.kill();
}

if (res.exception) {
if (typeof this.onException === 'function') {
try {
Expand Down Expand Up @@ -339,6 +344,11 @@ export class perlDebuggerConnection {

// Depend on the data dumper for the watcher
// await this.streamCatcher.request('use Data::Dumper');
await this.streamCatcher.request('$DB::single = 1;');
if (options.port) {
//
await this.streamCatcher.request('select($DB::OUT);');
}

// Listen for a ready signal
const data = await this.streamCatcher.isReady()
Expand Down
2 changes: 1 addition & 1 deletion src/localSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class LocalSession implements DebugSession {
...options.env,
},
};

// print $DB::OUT eval { require PadWalker; PadWalker->VERSION(0.08) }
const session = spawn(perlCommand, commandArgs, spawnOptions);
this.stdin = session.stdin;
this.stdout = session.stdout;
Expand Down
4 changes: 3 additions & 1 deletion src/regExp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,6 @@ export const codeErrorSyntax = /^syntax error at (\S+) line ([0-9]+), near ([\S|
export const codeErrorRuntime = /([\S|\s]+) at (\S+) line ([0-9]+)\.$/;

// EG. PadWalker for scope investigation
export const codeErrorMissingModule = /^(\S+) module not found - please install$/;
export const codeErrorMissingModule = /^(\S+) module not found - please install$/;

export const debuggerSignature = /^ DB<[0-9]+> $/;
35 changes: 29 additions & 6 deletions src/remoteSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {spawn} from 'child_process';
import { Readable, Writable } from 'stream';
import { EventEmitter } from 'events';
import { DebugSession, LaunchOptions } from './session';
import { debuggerSignature } from './regExp';

export class RemoteSession implements DebugSession {
public stdin: Writable;
Expand Down Expand Up @@ -43,30 +44,52 @@ export class RemoteSession implements DebugSession {
} else {
// Already have a client connected, lets close and notify user
this.stdout.push(`Warning: Additional remote client tried to connect "${name}".`);
socket.end('Remote debugger already connected!');
socket.destroy('Remote debugger already connected!');
}

socket.on('data', data => this.stderr.push(data));
socket.on('data', data => {
const str = data.toString('utf8');
const signature = str.split('\n').pop();
// xxx: We should figure out a more stable way of differentiating between
// command result and application output
if (debuggerSignature.test(signature)) {
this.stderr.push(data);
} else {
this.stdout.push(data);
}
});

socket.on('end', data => {
client = null;
this.stdout.push(`Connection closed by "${name}"`);
this.event.emit('close', data);
this.kill();
});

socket.on('error', data => this.event.emit('error', data));
socket.on('error', data => {
this.event.emit('error', data);
});
});

server.listen(port, '0.0.0.0'); // Listen to port make it remotely available
server.on('error', data => this.event.emit('error', data));
server.on('error', data => {
this.event.emit('error', data);
this.kill();
});

this.on = (type, callback) => this.event.on(type, callback);
this.kill = () => {
server.close();
server.removeAllListeners();
this.event.removeAllListeners();
this.stdin.removeAllListeners();
this.stdout.removeAllListeners();
this.stderr.removeAllListeners();

if (client) {
client.destroy();
client = null;
}

server.close();
};
this.title = () => `Running debug server for remote session to connect on port "${port}"`;
this.dump = () => `debug server port ${port}`;
Expand Down

0 comments on commit 12e03a9

Please sign in to comment.