Skip to content

Commit

Permalink
Add support for using extended-remote with launch configurations
Browse files Browse the repository at this point in the history
This extends gdb launch configurations to support extended-remote.
It can be used for remote debugging where code is compiled on host, and
transferred and debugged on target using a remote gdbserver (or something
else speaking GDB/MI).

Note, this is not touching the code added in commit
318ece4 ("Added special commands for extended-remote fix #91"),
as that is only related to gdb attach configuration, although the
example in package.json is confusingly put with launch, which is
opposite of the code change.
I did not fixup that change, as I am not sure exactly what to put
instead.
  • Loading branch information
esben committed Nov 22, 2019
1 parent dd1c936 commit bca7a61
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
14 changes: 14 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,20 @@
]
},
"valuesFormatting": "parseText"
},
{
"label": "GDB: Debug on remote device",
"description": "Transfer program to and debug it on a remote device",
"body": {
"type": "gdb",
"request": "launch",
"name": "${3:Debug remote device}",
"target": "${2:192.168.0.1:2345}",
"remote": true,
"executable": "${1:./bin/executable}",
"cwd": "^\"\\${workspaceRoot}\""
},
"valuesFormatting": "parseText"
}
]
},
Expand Down
21 changes: 18 additions & 3 deletions src/backend/mi2/mi2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,33 @@ export class MI2 extends EventEmitter implements IBackend {
}
}

load(cwd: string, target: string, procArgs: string, separateConsole: string): Thenable<any> {
if (!nativePath.isAbsolute(target))
load(cwd: string, target: string, procArgs: string, separateConsole: string, executable?: string, remote?: boolean): Thenable<any> {
if (!remote && !nativePath.isAbsolute(target))
target = nativePath.join(cwd, target);
if (remote && !nativePath.isAbsolute(executable))
executable = nativePath.join(cwd, executable);
return new Promise((resolve, reject) => {
this.isSSH = false;
const args = this.preargs.concat(this.extraargs || []);
if (executable !== undefined)
args.push(executable);
this.process = ChildProcess.spawn(this.application, args, { cwd: cwd, env: this.procEnv });
this.process.stdout.on("data", this.stdout.bind(this));
this.process.stderr.on("data", this.stderr.bind(this));
this.process.on("exit", (() => { this.emit("quit"); }).bind(this));
this.process.on("error", ((err) => { this.emit("launcherror", err); }).bind(this));
const promises = this.initCommands(target, cwd);
let promises;
if (remote) {
let remoteExecutable = nativePath.basename(executable);
promises = [
this.sendCommand(`set target-async on`, true),
this.sendCommand(`environment-directory "${escape(cwd)}"`, true),
this.sendCommand(`target-select extended-remote ${target}`),
this.sendCommand(`target-file-put "${escape(executable)}" ${remoteExecutable}`),
this.sendCommand(`gdb-set remote exec-file ./${remoteExecutable}`),
];
} else
promises = this.initCommands(target, cwd);
if (procArgs && procArgs.length)
promises.push(this.sendCommand("exec-arguments " + procArgs));
if (process.platform == "win32") {
Expand Down
4 changes: 3 additions & 1 deletion src/gdb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ export interface LaunchRequestArguments extends DebugProtocol.LaunchRequestArgum
debugger_args: string[];
arguments: string;
terminal: string;
executable: string;
remote: boolean;
autorun: string[];
ssh: SSHArguments;
valuesFormatting: ValuesFormattingMode;
Expand Down Expand Up @@ -93,7 +95,7 @@ class GDBDebugSession extends MI2DebugSession {
this.sendErrorResponse(response, 102, `Failed to SSH: ${err.toString()}`);
});
} else {
this.miDebugger.load(args.cwd, args.target, args.arguments, args.terminal).then(() => {
this.miDebugger.load(args.cwd, args.target, args.arguments, args.terminal, args.executable, args.remote).then(() => {
if (args.autorun)
args.autorun.forEach(command => {
this.miDebugger.sendUserInput(command);
Expand Down

0 comments on commit bca7a61

Please sign in to comment.