Skip to content

Commit 2921f7a

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 WebFreak001#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 53b6c34 commit 2921f7a

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed

package.json

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

src/backend/mi2/mi2.ts

+19-3
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,34 @@ 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) + "\" "
76+
+ remoteExecutable),
77+
this.sendCommand("gdb-set remote exec-file ./" + remoteExecutable),
78+
];
79+
} else
80+
promises = this.initCommands(target, cwd);
6581
if (procArgs && procArgs.length)
6682
promises.push(this.sendCommand("exec-arguments " + procArgs));
6783
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)