Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing support for remote GDB via intermediate remote server #192 #223

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
65 changes: 64 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

80 changes: 78 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,24 @@
"bootstrap": {
"type": "string",
"description": "Content will be executed on the SSH host before the debugger call."
},
"proxyPort": {
"type": "number",
"description": "Port of the proxy server to connect to; (by default port = display + 6000)",
"default": 22
},
"proxyHost": {
"type": "string",
"description": "Hostname/ip of the proxy server",
"default": "localhost"
},
"proxyUser": {
"type": "string",
"description": "Username to connect as"
},
"proxyPassword": {
"type": "string",
"description": "Plain text password (unsafe; if possible use keyfile instead)"
}
}
}
Expand Down Expand Up @@ -338,6 +356,24 @@
"bootstrap": {
"type": "string",
"description": "Content will be executed on the SSH host before the debugger call."
},
"proxyPort": {
"type": "number",
"description": "Port of the proxy server to connect to; (by default port = display + 6000)",
"default": 22
},
"proxyHost": {
"type": "string",
"description": "Hostname/ip of the proxy server",
"default": "localhost"
},
"proxyUser": {
"type": "string",
"description": "Username to connect as"
},
"proxyPassword": {
"type": "string",
"description": "Plain text password (unsafe; if possible use keyfile instead)"
}
}
}
Expand Down Expand Up @@ -411,6 +447,27 @@
"valuesFormatting": "parseText"
}
},
{
"label": "GDB: Launch over SSH throw a proxy server",
"description": "Remotely starts the program using gdb",
"body": {
"type": "gdb",
"request": "launch",
"name": "${6:Launch Program (SSH)}",
"target": "${1:./bin/executable}",
"cwd": "^\"\\${workspaceRoot}\"",
"ssh": {
"host": "${2:127.0.0.1}",
"cwd": "${3:/home/remote_user/project/}",
"keyfile": "${4:/home/my_user/.ssh/id_rsa}",
"user": "${5:remote_user}",
"proxyHost": "${7:proxy_host}",
"proxyUser": "${8:proxy_user}",
"proxyPassword": "${9:proxy_password}"
},
"valuesFormatting": "parseText"
}
},
{
"label": "GDB: Launch GUI over SSH with X11 forwarding",
"description": "Remotely starts the program using gdb with X11 forwarding",
Expand Down Expand Up @@ -623,6 +680,24 @@
"bootstrap": {
"type": "string",
"description": "Content will be executed on the SSH host before the debugger call."
},
"proxyPort": {
"type": "number",
"description": "Port of the proxy server to connect to; (by default port = display + 6000)",
"default": 22
},
"proxyHost": {
"type": "string",
"description": "Hostname/ip of the proxy server",
"default": "localhost"
},
"proxyUser": {
"type": "string",
"description": "Username to connect as"
},
"proxyPassword": {
"type": "string",
"description": "Plain text password (unsafe; if possible use keyfile instead)"
}
}
}
Expand Down Expand Up @@ -953,9 +1028,10 @@
"postinstall": "node ./node_modules/vscode/bin/install"
},
"dependencies": {
"ssh2": "^0.8.2",
"ssh2-promise": "^0.1.7",
"vscode-debugadapter": "^1.16.0",
"vscode-debugprotocol": "^1.16.0",
"ssh2": "^0.8.2"
"vscode-debugprotocol": "^1.16.0"
},
"devDependencies": {
"@types/mocha": "^5.2.6",
Expand Down
4 changes: 4 additions & 0 deletions src/backend/backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ export interface SSHArguments {
x11port: number;
x11host: string;
bootstrap: string;
proxyPort: number;
proxyHost: string;
proxyUser: string;
proxyPassword: string;
}

export interface IBackend {
Expand Down
57 changes: 35 additions & 22 deletions src/backend/mi2/mi2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import * as fs from "fs";
import { posix } from "path";
import * as nativePath from "path";
const path = posix;
import { Client } from "ssh2";
import ssh2_promise = require('ssh2-promise');

export function escape(str: string) {
return str.replace(/\\/g, "\\\\").replace(/"/g, "\\\"");
Expand Down Expand Up @@ -94,47 +94,60 @@ export class MI2 extends EventEmitter implements IBackend {
return new Promise((resolve, reject) => {
this.isSSH = true;
this.sshReady = false;
this.sshConn = new Client();

if (separateConsole !== undefined)
this.log("stderr", "WARNING: Output to terminal emulators are not supported over SSH");

if (args.forwardX11) {
this.sshConn.on("x11", (info, accept, reject) => {
const xserversock = new net.Socket();
xserversock.on("error", (err) => {
this.log("stderr", "Could not connect to local X11 server! Did you enable it in your display manager?\n" + err);
});
xserversock.on("connect", () => {
const xclientsock = accept();
xclientsock.pipe(xserversock).pipe(xclientsock);
});
xserversock.connect(args.x11port, args.x11host);
});
}

const connectionArgs: any = {
host: args.host,
port: args.port,
username: args.user
};

const proxyConnection: any = {
host: args.proxyHost,
port: args.proxyPort,
username: args.proxyUser
};

if (args.useAgent) {
connectionArgs.agent = process.env.SSH_AUTH_SOCK;
} else if (args.keyfile) {
if (require("fs").existsSync(args.keyfile))
connectionArgs.privateKey = require("fs").readFileSync(args.keyfile);
else {
if (require("fs").existsSync(args.keyfile)) {
connectionArgs.identity = args.keyfile;
proxyConnection.identity = args.keyfile;
} else {
this.log("stderr", "SSH key file does not exist!");
this.emit("quit");
reject();
return;
}
} else {
connectionArgs.password = args.password;
proxyConnection.password = args.proxyPassword;
}

this.sshConn.on("ready", () => {
if (proxyConnection.host !== undefined) {
this.sshConn = new ssh2_promise([proxyConnection, connectionArgs]);
} else {
this.sshConn = new ssh2_promise(connectionArgs);
}

if (args.forwardX11) {
this.sshConn.on("x11", (info, accept, reject) => {
const xserversock = new net.Socket();
xserversock.on("error", (err) => {
this.log("stderr", "Could not connect to local X11 server! Did you enable it in your display manager?\n" + err);
});
xserversock.on("connect", () => {
const xclientsock = accept();
xclientsock.pipe(xserversock).pipe(xclientsock);
});
xserversock.connect(args.x11port, args.x11host);
});
}

this.sshConn.connect().then(() => {
this.log("stdout", "Running " + this.application + " over ssh...");
const execArgs: any = {};
if (args.forwardX11) {
Expand Down Expand Up @@ -172,12 +185,12 @@ export class MI2 extends EventEmitter implements IBackend {
resolve();
}, reject);
});
}).on("error", (err) => {
}).catch("error", (err) => {
this.log("stderr", "Could not run " + this.application + " over ssh!");
this.log("stderr", err.toString());
this.emit("quit");
reject();
}).connect(connectionArgs);
});
});
}

Expand Down