Skip to content

Commit ded131d

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.
1 parent 2f9bdcb commit ded131d

File tree

3 files changed

+34
-4
lines changed

3 files changed

+34
-4
lines changed

package.json

+17
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@
111111
"description": "Additional arguments to pass to GDB",
112112
"default": []
113113
},
114+
"extendedRemote": {
115+
"type": "string",
116+
"description": "gdbserver (extended-remote) to connect to (eg :2345)"
117+
},
114118
"valuesFormatting": {
115119
"type": "string",
116120
"description": "Set the way of showing variable values. 'disabled' - show value as is, 'parseText' - parse debuggers output text into structure, 'prettyPrinters' - enable debuggers custom pretty-printers if there are any",
@@ -440,6 +444,19 @@
440444
]
441445
},
442446
"valuesFormatting": "parseText"
447+
},
448+
{
449+
"label": "GDB: Debug on remote device",
450+
"description": "Transfer program to and debug it on a remote device",
451+
"body": {
452+
"type": "gdb",
453+
"request": "launch",
454+
"name": "${3:Debug remote device}",
455+
"extendedRemote": "${2:192.168.0.1:2345}",
456+
"executable": "${1:./bin/executable.elf}",
457+
"cwd": "^\"\\${workspaceRoot}\""
458+
},
459+
"valuesFormatting": "parseText"
443460
}
444461
]
445462
},

src/backend/mi2/mi2.ts

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

53-
load(cwd: string, executable: string, procArgs: string, separateConsole: string): Thenable<any> {
53+
load(cwd: string, executable: string, procArgs: string, separateConsole: string, extendedRemote?: string): Thenable<any> {
5454
if (!nativePath.isAbsolute(executable))
5555
executable = nativePath.join(cwd, executable);
5656
return new Promise((resolve, reject) => {
5757
this.isSSH = false;
58-
const args = this.preargs.concat(this.extraargs || []);
58+
const args = this.preargs.concat(this.extraargs || [], [executable]);
5959
this.process = ChildProcess.spawn(this.application, args, { cwd: cwd, env: this.procEnv });
6060
this.process.stdout.on("data", this.stdout.bind(this));
6161
this.process.stderr.on("data", this.stderr.bind(this));
6262
this.process.on("exit", (() => { this.emit("quit"); }).bind(this));
6363
this.process.on("error", ((err) => { this.emit("launcherror", err); }).bind(this));
64-
const promises = this.initCommands(executable, cwd);
64+
let promises;
65+
if (extendedRemote !== undefined) {
66+
let remoteExecutable = nativePath.basename(executable);
67+
promises = [
68+
this.sendCommand(`set target-async on`, true),
69+
this.sendCommand(`environment-directory "${escape(cwd)}"`, true),
70+
this.sendCommand(`target-select extended-remote ${extendedRemote}`),
71+
this.sendCommand(`target-file-put "${escape(executable)}" ${remoteExecutable}`),
72+
this.sendCommand(`gdb-set remote exec-file ./${remoteExecutable}`)
73+
];
74+
} else
75+
promises = this.initCommands(executable, cwd);
76+
6577
if (procArgs && procArgs.length)
6678
promises.push(this.sendCommand("exec-arguments " + procArgs));
6779
if (process.platform == "win32") {

src/gdb.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export interface LaunchRequestArguments extends DebugProtocol.LaunchRequestArgum
1313
debugger_args: string[];
1414
arguments: string;
1515
terminal: string;
16+
extendedRemote: string;
1617
autorun: string[];
1718
ssh: SSHArguments;
1819
valuesFormatting: ValuesFormattingMode;
@@ -97,7 +98,7 @@ class GDBDebugSession extends MI2DebugSession {
9798
this.sendErrorResponse(response, 102, `Failed to SSH: ${err.toString()}`);
9899
});
99100
} else {
100-
this.miDebugger.load(args.cwd, args.executable, args.arguments, args.terminal).then(() => {
101+
this.miDebugger.load(args.cwd, args.executable, args.arguments, args.terminal, args.extendedRemote).then(() => {
101102
if (args.autorun)
102103
args.autorun.forEach(command => {
103104
this.miDebugger.sendUserInput(command);

0 commit comments

Comments
 (0)