Skip to content

Commit bca7a61

Browse files
committed
Add support for using extended-remote with launch configurations
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.
1 parent dd1c936 commit bca7a61

File tree

3 files changed

+35
-4
lines changed

3 files changed

+35
-4
lines changed

package.json

+14
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,20 @@
436436
]
437437
},
438438
"valuesFormatting": "parseText"
439+
},
440+
{
441+
"label": "GDB: Debug on remote device",
442+
"description": "Transfer program to and debug it on a remote device",
443+
"body": {
444+
"type": "gdb",
445+
"request": "launch",
446+
"name": "${3:Debug remote device}",
447+
"target": "${2:192.168.0.1:2345}",
448+
"remote": true,
449+
"executable": "${1:./bin/executable}",
450+
"cwd": "^\"\\${workspaceRoot}\""
451+
},
452+
"valuesFormatting": "parseText"
439453
}
440454
]
441455
},

src/backend/mi2/mi2.ts

+18-3
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,33 @@ export class MI2 extends EventEmitter implements IBackend {
5050
}
5151
}
5252

53-
load(cwd: string, target: string, procArgs: string, separateConsole: string): Thenable<any> {
54-
if (!nativePath.isAbsolute(target))
53+
load(cwd: string, target: string, procArgs: string, separateConsole: string, executable?: string, remote?: boolean): Thenable<any> {
54+
if (!remote && !nativePath.isAbsolute(target))
5555
target = nativePath.join(cwd, target);
56+
if (remote && !nativePath.isAbsolute(executable))
57+
executable = nativePath.join(cwd, executable);
5658
return new Promise((resolve, reject) => {
5759
this.isSSH = false;
5860
const args = this.preargs.concat(this.extraargs || []);
61+
if (executable !== undefined)
62+
args.push(executable);
5963
this.process = ChildProcess.spawn(this.application, args, { cwd: cwd, env: this.procEnv });
6064
this.process.stdout.on("data", this.stdout.bind(this));
6165
this.process.stderr.on("data", this.stderr.bind(this));
6266
this.process.on("exit", (() => { this.emit("quit"); }).bind(this));
6367
this.process.on("error", ((err) => { this.emit("launcherror", err); }).bind(this));
64-
const promises = this.initCommands(target, cwd);
68+
let promises;
69+
if (remote) {
70+
let remoteExecutable = nativePath.basename(executable);
71+
promises = [
72+
this.sendCommand(`set target-async on`, true),
73+
this.sendCommand(`environment-directory "${escape(cwd)}"`, true),
74+
this.sendCommand(`target-select extended-remote ${target}`),
75+
this.sendCommand(`target-file-put "${escape(executable)}" ${remoteExecutable}`),
76+
this.sendCommand(`gdb-set remote exec-file ./${remoteExecutable}`),
77+
];
78+
} else
79+
promises = this.initCommands(target, cwd);
6580
if (procArgs && procArgs.length)
6681
promises.push(this.sendCommand("exec-arguments " + procArgs));
6782
if (process.platform == "win32") {

src/gdb.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ export interface LaunchRequestArguments extends DebugProtocol.LaunchRequestArgum
1212
debugger_args: string[];
1313
arguments: string;
1414
terminal: string;
15+
executable: string;
16+
remote: boolean;
1517
autorun: string[];
1618
ssh: SSHArguments;
1719
valuesFormatting: ValuesFormattingMode;
@@ -93,7 +95,7 @@ class GDBDebugSession extends MI2DebugSession {
9395
this.sendErrorResponse(response, 102, `Failed to SSH: ${err.toString()}`);
9496
});
9597
} else {
96-
this.miDebugger.load(args.cwd, args.target, args.arguments, args.terminal).then(() => {
98+
this.miDebugger.load(args.cwd, args.target, args.arguments, args.terminal, args.executable, args.remote).then(() => {
9799
if (args.autorun)
98100
args.autorun.forEach(command => {
99101
this.miDebugger.sendUserInput(command);

0 commit comments

Comments
 (0)