Skip to content

Commit 1441b68

Browse files
committed
Improved error reporting on launch
1 parent 38ab959 commit 1441b68

File tree

4 files changed

+45
-41
lines changed

4 files changed

+45
-41
lines changed

arduino-debugger-extension/src/node/arduino-debug-adapter-contribution.ts

Lines changed: 13 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,12 @@
1-
import { injectable, inject } from 'inversify';
1+
import { injectable } from 'inversify';
22
import { DebugAdapterContribution, DebugAdapterExecutable, DebugAdapterSessionFactory } from '@theia/debug/lib/common/debug-model';
33
import { DebugConfiguration } from "@theia/debug/lib/common/debug-configuration";
44
import { MaybePromise } from "@theia/core/lib/common/types";
55
import { IJSONSchema, IJSONSchemaSnippet } from "@theia/core/lib/common/json-schema";
66
import * as path from 'path';
7-
import { BoardsService } from 'arduino-ide-extension/lib/common/protocol/boards-service';
8-
import { CoreService } from 'arduino-ide-extension/lib/common/protocol/core-service';
9-
import { FileSystem } from '@theia/filesystem/lib/common';
107

118
@injectable()
129
export class ArduinoDebugAdapterContribution implements DebugAdapterContribution {
13-
@inject(BoardsService)
14-
protected readonly boardsService: BoardsService;
15-
16-
@inject(CoreService)
17-
protected readonly coreService: CoreService;
18-
19-
@inject(FileSystem)
20-
protected readonly fileSystem: FileSystem;
2110

2211
type = "arduino";
2312

@@ -39,26 +28,25 @@ export class ArduinoDebugAdapterContribution implements DebugAdapterContribution
3928
"description": "path to the sketch root ino file",
4029
"default": "${file}",
4130
},
42-
"runToMain": {
43-
"description": "If enabled the debugger will run until the start of the main function.",
44-
"type": "boolean",
45-
"default": false
46-
},
4731
"fqbn": {
4832
"type": "string",
4933
"description": "Fully-qualified board name to debug on",
5034
"default": ""
5135
},
52-
36+
"runToMain": {
37+
"description": "If enabled the debugger will run until the start of the main function.",
38+
"type": "boolean",
39+
"default": false
40+
},
5341
"verbose": {
5442
"type": "boolean",
5543
"description": "Produce verbose log output",
56-
"default": "false"
44+
"default": false
5745
},
5846
"debugDebugAdapter": {
5947
"type": "boolean",
6048
"description": "Start the debug adapter in debug mode (with --inspect-brk)",
61-
"default": "false"
49+
"default": false
6250
},
6351
}
6452
}
@@ -74,7 +62,7 @@ export class ArduinoDebugAdapterContribution implements DebugAdapterContribution
7462
if (!!config.debugDebugAdapter) {
7563
args.push('--inspect-brk')
7664
}
77-
args = args.concat([path.join(__dirname, 'debug-adapter', 'index.js')]);
65+
args = args.concat([path.join(__dirname, 'debug-adapter', 'main')]);
7866

7967
return {
8068
command: "node",
@@ -88,25 +76,21 @@ export class ArduinoDebugAdapterContribution implements DebugAdapterContribution
8876
name: this.label,
8977
type: this.type,
9078
request: "launch",
91-
9279
sketch: "${file}",
93-
94-
verbose: true,
95-
runToMain: true,
9680
},
9781
<DebugConfiguration>{
9882
name: this.label + " (explicit)",
9983
type: this.type,
10084
request: "launch",
101-
85+
10286
program: "${sketchBinary}",
10387
objdump: "${boardTools:objdump}",
10488
gdb: "${boardTools:gdb}",
10589
gdbServer: "${boardTools:openocd}",
10690
gdbServerArguments: ["-s", "${boardTools:openocd-scripts}", "--file", "${board:openocd-debug-file}"],
107-
108-
verbose: true,
109-
runToMain: true,
91+
92+
runToMain: false,
93+
verbose: false,
11094
}
11195
];
11296
}

arduino-debugger-extension/src/node/debug-adapter/cmsis-debug-session.ts

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
import { normalize } from 'path';
2727
import { DebugProtocol } from 'vscode-debugprotocol';
28-
import { Logger, logger, InitializedEvent, OutputEvent, Scope, TerminatedEvent } from 'vscode-debugadapter';
28+
import { Logger, logger, InitializedEvent, OutputEvent, Scope, TerminatedEvent, ErrorDestination } from 'vscode-debugadapter';
2929
import { GDBDebugSession, RequestArguments, FrameVariableReference, FrameReference } from 'cdt-gdb-adapter/dist/GDBDebugSession';
3030
import { GDBBackend } from 'cdt-gdb-adapter/dist/GDBBackend';
3131
import { CmsisBackend } from './cmsis-backend';
@@ -117,7 +117,6 @@ export class CmsisDebugSession extends GDBDebugSession {
117117

118118
protected async setBreakPointsRequest(response: DebugProtocol.SetBreakpointsResponse, args: DebugProtocol.SetBreakpointsArguments): Promise<void> {
119119
await super.setBreakPointsRequest(response, args);
120-
return;
121120
}
122121

123122
protected scopesRequest(response: DebugProtocol.ScopesResponse, args: DebugProtocol.ScopesArguments): void {
@@ -224,13 +223,10 @@ export class CmsisDebugSession extends GDBDebugSession {
224223
this.gdb.on('notifyAsync', (resultClass, resultData) => this.handleGDBNotify(resultClass, resultData));
225224

226225
// gdb server has main info channel on stderr
227-
this.gdbServer.on('stderr', data => {
228-
this.sendEvent(new OutputEvent(data, 'stdout'))
229-
});
230-
this.gdbServer.on('error', message => {
231-
this.sendEvent(new TerminatedEvent());
232-
throw message;
233-
});
226+
this.gdbServer.on('stderr', data => this.sendEvent(new OutputEvent(data, 'stdout')));
227+
const gdbServerErrors: any[] = []
228+
const gdbServerErrorAccumulator = (message: any) => gdbServerErrors.push(message);
229+
this.gdbServer.on('error', gdbServerErrorAccumulator);
234230

235231
try {
236232
this.symbolTable = new SymbolTable(args.program, args.objdump);
@@ -264,12 +260,18 @@ export class CmsisDebugSession extends GDBDebugSession {
264260
this.sendEvent(new OutputEvent(`Starting debugger: ${JSON.stringify(args)}`));
265261
await this.gdbServer.spawn(args);
266262
await this.spawn(args);
263+
if (gdbServerErrors.length > 0) {
264+
throw new Error(gdbServerErrors.join('\n'));
265+
}
267266

268267
// Send commands
269268
await mi.sendTargetAsyncOn(this.gdb);
270269
await mi.sendTargetSelectRemote(this.gdb, remote);
271270
await mi.sendMonitorResetHalt(this.gdb);
272271
this.sendEvent(new OutputEvent(`Attached to debugger on port ${port}`));
272+
if (gdbServerErrors.length > 0) {
273+
throw new Error(gdbServerErrors.join('\n'));
274+
}
273275

274276
// Download image
275277
const progressListener = (percent: number) => this.progressEvent(percent, 'Loading Image');
@@ -287,8 +289,17 @@ export class CmsisDebugSession extends GDBDebugSession {
287289
await mi.sendBreakOnFunction(this.gdb);
288290
}
289291

292+
if (gdbServerErrors.length > 0) {
293+
throw new Error(gdbServerErrors.join('\n'));
294+
}
290295
this.sendEvent(new OutputEvent(`Image loaded: ${args.program}`));
291296
this.sendEvent(new InitializedEvent());
297+
298+
this.gdbServer.removeListener('error', gdbServerErrorAccumulator);
299+
this.gdbServer.on('error', message => {
300+
logger.error(JSON.stringify(message));
301+
this.sendEvent(new TerminatedEvent());
302+
});
292303
}
293304

294305
private async getGlobalVariables(frameHandle: number): Promise<DebugProtocol.Variable[]> {
@@ -378,6 +389,15 @@ export class CmsisDebugSession extends GDBDebugSession {
378389
}));
379390
}
380391

392+
protected sendErrorResponse(response: DebugProtocol.Response,
393+
codeOrMessage: number | DebugProtocol.Message, format?: string,
394+
variables?: any, dest?: ErrorDestination): void {
395+
if (!!format && (dest === undefined || dest === ErrorDestination.User)) {
396+
format = format.replace('\n', '<br>');
397+
}
398+
super.sendErrorResponse(response, codeOrMessage, format, variables, dest);
399+
}
400+
381401
protected async stopSession() {
382402
// Pause debugging
383403
if (this.isRunning) {

arduino-debugger-extension/src/node/debug-adapter/openocd-server.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import * as path from 'path';
66
import * as os from 'os';
77

88
const LAUNCH_REGEX = /GDB server started/;
9-
const ERROR_REGEX = /:ERROR:gdbserver:/;
9+
const ERROR_REGEX = /^error:/mi;
1010
const PERCENT_MULTIPLIER = 100 / 40; // pyOCD outputs 40 markers for progress
1111

1212
export class OpenocdServer extends AbstractServer {
@@ -20,14 +20,14 @@ export class OpenocdServer extends AbstractServer {
2020
sessionConfigFile += `telnet_port ${telnetPort}${"\n"}`
2121
}
2222
sessionConfigFile += `echo "GDB server started"${"\n"}`
23-
23+
2424
const tmpdir = await fs.mkdtemp(path.join(os.tmpdir(), "arduino-debugger"));
2525
const sessionCfgPath = path.join(tmpdir, "gdb.cfg");
2626
await fs.writeFile(sessionCfgPath, sessionConfigFile);
2727

2828
let serverArguments = req.gdbServerArguments || [];
2929
serverArguments.push("--file", sessionCfgPath);
30-
30+
3131
return serverArguments;
3232
}
3333

0 commit comments

Comments
 (0)