Skip to content

Commit 0445700

Browse files
committed
Added 'optimize for debug' option
1 parent 486f110 commit 0445700

24 files changed

+2441
-424
lines changed

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ export interface ArduinoLaunchRequestArguments extends DebugProtocol.LaunchReque
1313

1414
export class ArduinoDebugSession extends GDBDebugSession {
1515

16+
protected get arduinoBackend(): ArduinoGDBBackend {
17+
return this.gdb as ArduinoGDBBackend;
18+
}
19+
1620
protected createBackend(): GDBBackend {
1721
return new ArduinoGDBBackend();
1822
}
@@ -38,4 +42,24 @@ export class ArduinoDebugSession extends GDBDebugSession {
3842
}
3943
}
4044

45+
protected async disconnectRequest(response: DebugProtocol.DisconnectResponse): Promise<void> {
46+
try {
47+
if (this.isRunning) {
48+
// Need to pause first
49+
const waitPromise = new Promise(resolve => this.waitPaused = resolve);
50+
this.gdb.pause();
51+
await waitPromise;
52+
}
53+
try {
54+
await this.arduinoBackend.sendTargetDetach();
55+
} catch (e) {
56+
// Need to catch here as the command result being returned will never exist as it's detached
57+
}
58+
await this.gdb.sendGDBExit();
59+
this.sendResponse(response);
60+
} catch (err) {
61+
this.sendErrorResponse(response, 1, err.message);
62+
}
63+
}
64+
4165
}

arduino-debugger-extension/src/node/debug-adapter/arduino-gdb-backend.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { ArduinoLaunchRequestArguments } from './arduino-debug-session';
66

77
export class ArduinoGDBBackend extends GDBBackend {
88

9-
public spawn(requestArgs: ArduinoLaunchRequestArguments): Promise<void> {
9+
spawn(requestArgs: ArduinoLaunchRequestArguments): Promise<void> {
1010
if (!requestArgs.sketch) {
1111
throw new Error('Missing argument: sketch');
1212
}
@@ -28,14 +28,18 @@ export class ArduinoGDBBackend extends GDBBackend {
2828
return this.parser.parse(proc.stdout);
2929
}
3030

31-
public sendFileExecAndSymbols(): Promise<void> {
31+
sendFileExecAndSymbols(): Promise<void> {
3232
// The program file is already sent by `arduino-cli`
3333
return Promise.resolve();
3434
}
3535

36-
public pause(): boolean {
36+
pause(): boolean {
3737
this.sendCommand('-exec-interrupt');
3838
return true;
3939
}
4040

41+
sendTargetDetach(): Promise<void> {
42+
return this.sendCommand('-target-detach');
43+
}
44+
4145
}

arduino-ide-extension/src/browser/arduino-commands.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ export namespace ArduinoCommands {
1212
label: 'Upload Sketch'
1313
}
1414

15+
export const TOGGLE_COMPILE_FOR_DEBUG: Command = {
16+
id: "arduino-toggle-compile-for-debug"
17+
}
18+
1519
export const SHOW_OPEN_CONTEXT_MENU: Command = {
1620
id: 'arduino-show-open-context-menu',
1721
label: 'Open Sketch'

arduino-ide-extension/src/browser/arduino-frontend-contribution.tsx

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -289,13 +289,22 @@ export class ArduinoFrontendContribution implements FrontendApplicationContribut
289289
}
290290
// Reveal the Output view asynchronously (don't await it)
291291
this.outputContribution.openView({ reveal: true });
292-
await this.coreService.compile({ uri: uri.toString(), board: boardsConfig.selectedBoard });
292+
await this.coreService.compile({
293+
uri: uri.toString(),
294+
board: boardsConfig.selectedBoard,
295+
optimizeForDebug: this.editorMode.compileForDebug
296+
});
293297
} catch (e) {
294298
await this.messageService.error(e.toString());
295299
}
296300
}
297301
});
298302

303+
registry.registerCommand(ArduinoCommands.TOGGLE_COMPILE_FOR_DEBUG, {
304+
execute: () => this.editorMode.toggleCompileForDebug(),
305+
isToggled: () => this.editorMode.compileForDebug
306+
});
307+
299308
registry.registerCommand(ArduinoCommands.UPLOAD, {
300309
isVisible: widget => ArduinoToolbar.is(widget) && widget.side === 'left',
301310
isEnabled: widget => true,
@@ -326,7 +335,12 @@ export class ArduinoFrontendContribution implements FrontendApplicationContribut
326335
}
327336
// Reveal the Output view asynchronously (don't await it)
328337
this.outputContribution.openView({ reveal: true });
329-
await this.coreService.upload({ uri: uri.toString(), board: boardsConfig.selectedBoard, port: selectedPort.address });
338+
await this.coreService.upload({
339+
uri: uri.toString(),
340+
board: boardsConfig.selectedBoard,
341+
port: selectedPort.address,
342+
optimizeForDebug: this.editorMode.compileForDebug
343+
});
330344
} catch (e) {
331345
await this.messageService.error(e.toString());
332346
} finally {
@@ -402,7 +416,7 @@ export class ArduinoFrontendContribution implements FrontendApplicationContribut
402416
});
403417

404418
registry.registerCommand(ArduinoCommands.TOGGLE_ADVANCED_MODE, {
405-
execute: () => this.editorMode.toggle(),
419+
execute: () => this.editorMode.toggleProMode(),
406420
isVisible: widget => ArduinoToolbar.is(widget) && widget.side === 'right',
407421
isToggled: () => this.editorMode.proMode
408422
});
@@ -445,10 +459,15 @@ export class ArduinoFrontendContribution implements FrontendApplicationContribut
445459
label: 'Verify/Compile',
446460
order: '1'
447461
});
462+
registry.registerMenuAction(ArduinoMenus.SKETCH, {
463+
commandId: ArduinoCommands.TOGGLE_COMPILE_FOR_DEBUG.id,
464+
label: 'Optimize for Debug',
465+
order: '2'
466+
});
448467
registry.registerMenuAction(ArduinoMenus.SKETCH, {
449468
commandId: ArduinoCommands.UPLOAD.id,
450469
label: 'Upload',
451-
order: '2'
470+
order: '3'
452471
});
453472
registry.registerMenuAction(ArduinoToolbarContextMenu.OPEN_GROUP, {
454473
commandId: ArduinoCommands.OPEN_FILE_NAVIGATOR.id,

arduino-ide-extension/src/browser/editor-mode.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export class EditorMode implements FrontendApplicationContribution {
2222
return value === 'true';
2323
}
2424

25-
async toggle(): Promise<void> {
25+
async toggleProMode(): Promise<void> {
2626
const oldState = this.proMode;
2727
const inAdvancedMode = !oldState;
2828
window.localStorage.setItem(EditorMode.PRO_MODE_KEY, String(inAdvancedMode));
@@ -41,8 +41,20 @@ export class EditorMode implements FrontendApplicationContribution {
4141
window.location.reload(true);
4242
}
4343

44+
get compileForDebug(): boolean {
45+
const value = window.localStorage.getItem(EditorMode.COMPILE_FOR_DEBUG_KEY);
46+
return value === 'true';
47+
}
48+
49+
async toggleCompileForDebug(): Promise<void> {
50+
const oldState = this.compileForDebug;
51+
const newState = !oldState;
52+
window.localStorage.setItem(EditorMode.COMPILE_FOR_DEBUG_KEY, String(newState));
53+
}
54+
4455
}
4556

4657
export namespace EditorMode {
4758
export const PRO_MODE_KEY = 'arduino-advanced-mode';
59+
export const COMPILE_FOR_DEBUG_KEY = 'arduino-compile-for-debug';
4860
}

arduino-ide-extension/src/common/protocol/boards-service.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -186,22 +186,12 @@ export interface BoardDetails extends Board {
186186
fqbn: string;
187187

188188
requiredTools: Tool[];
189-
locations?: BoardDetailLocations;
190-
}
191-
192-
export interface BoardDetailLocations {
193-
debugScript: string;
194189
}
195190

196191
export interface Tool {
197192
readonly packager: string;
198193
readonly name: string;
199194
readonly version: string;
200-
readonly locations?: ToolLocations;
201-
}
202-
export interface ToolLocations {
203-
main: string
204-
[key: string]: string
205195
}
206196

207197
export namespace Board {

arduino-ide-extension/src/common/protocol/core-service.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@ export namespace CoreService {
1414
readonly uri: string;
1515
readonly board: Board;
1616
readonly port: string;
17+
readonly optimizeForDebug: boolean;
1718
}
1819
}
1920

2021
export namespace Compile {
2122
export interface Options {
2223
readonly uri: string;
2324
readonly board: Board;
25+
readonly optimizeForDebug: boolean;
2426
}
2527
}
26-
}
28+
}

arduino-ide-extension/src/node/boards-service-impl.ts

Lines changed: 4 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,17 @@ import { Deferred } from '@theia/core/lib/common/promise-util';
55
import { FileSystem } from '@theia/filesystem/lib/common';
66
import {
77
BoardsService, AttachedSerialBoard, BoardPackage, Board, AttachedNetworkBoard, BoardsServiceClient,
8-
Port, BoardDetails, Tool, ToolLocations, BoardDetailLocations
8+
Port, BoardDetails, Tool
99
} from '../common/protocol/boards-service';
1010
import {
1111
PlatformSearchReq, PlatformSearchResp, PlatformInstallReq, PlatformInstallResp, PlatformListReq,
1212
PlatformListResp, Platform, PlatformUninstallResp, PlatformUninstallReq
1313
} from './cli-protocol/commands/core_pb';
1414
import { CoreClientProvider } from './core-client-provider';
15-
import { BoardListReq, BoardListResp, BoardDetailsReq, BoardDetailsResp, RequiredTool } from './cli-protocol/commands/board_pb';
15+
import { BoardListReq, BoardListResp, BoardDetailsReq, BoardDetailsResp } from './cli-protocol/commands/board_pb';
1616
import { ToolOutputServiceServer } from '../common/protocol/tool-output-service';
1717
import { Installable } from '../common/protocol/installable';
1818
import { ConfigService } from '../common/protocol/config-service';
19-
import * as path from 'path';
2019

2120
@injectable()
2221
export class BoardsServiceImpl implements BoardsService {
@@ -237,59 +236,18 @@ export class BoardsServiceImpl implements BoardsService {
237236
const tools = await Promise.all(resp.getRequiredToolsList().map(async t => <Tool>{
238237
name: t.getName(),
239238
packager: t.getPackager(),
240-
version: t.getVersion(),
241-
locations: await this.getToolLocations(t),
239+
version: t.getVersion()
242240
}));
243241

244242
return {
245243
item: {
246244
name: resp.getName(),
247245
fqbn: options.id,
248-
requiredTools: tools,
249-
locations: await this.getBoardLocations(resp)
246+
requiredTools: tools
250247
}
251248
};
252249
}
253250

254-
// TODO: these location should come from the CLI/daemon rather than us botching them together
255-
protected async getBoardLocations(details: BoardDetailsResp): Promise<BoardDetailLocations | undefined> {
256-
const config = await this.configService.getConfiguration();
257-
const datadir = await this.fileSystem.getFsPath(config.dataDirUri);
258-
if (!datadir) {
259-
return undefined;
260-
}
261-
262-
return {
263-
debugScript: path.join(datadir, "packages", "arduino", "hardware", "samd", "1.8.4", "variants", "arduino_zero", "openocd_scripts", "arduino_zero.cfg")
264-
}
265-
}
266-
267-
// TODO: these location should come from the CLI/daemon rather than us botching them together
268-
protected async getToolLocations(t: RequiredTool): Promise<ToolLocations | undefined> {
269-
const config = await this.configService.getConfiguration();
270-
const datadir = await this.fileSystem.getFsPath(config.dataDirUri);
271-
if (!datadir) {
272-
return undefined;
273-
}
274-
275-
const toolBasePath = path.join(datadir, "packages", "arduino", "tools");
276-
let loc: ToolLocations = {
277-
main: path.join(toolBasePath, t.getName(), t.getVersion())
278-
};
279-
280-
switch (t.getName()) {
281-
case "openocd":
282-
loc.scripts = path.join(loc.main, "share", "openocd", "scripts");
283-
loc.main = path.join(loc.main, "bin", "openocd");
284-
break;
285-
case "arm-none-eabi-gcc":
286-
["gdb", "objdump"].forEach(s => loc[s] = path.join(loc.main, "bin", `arm-none-eabi-${s}`));
287-
break;
288-
}
289-
290-
return loc;
291-
}
292-
293251
async search(options: { query?: string }): Promise<{ items: BoardPackage[] }> {
294252
const coreClient = await this.coreClientProvider.getClient();
295253
if (!coreClient) {

arduino-ide-extension/src/node/cli-protocol/commands/commands_grpc_pb.js

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
11
// GENERATED CODE -- DO NOT EDIT!
22

33
// Original file comments:
4-
//
54
// This file is part of arduino-cli.
65
//
7-
// Copyright 2018 ARDUINO SA (http://www.arduino.cc/)
6+
// Copyright 2020 ARDUINO SA (http://www.arduino.cc/)
87
//
98
// This software is released under the GNU General Public License version 3,
109
// which covers the main part of arduino-cli.
1110
// The terms of this license can be found at:
1211
// https://www.gnu.org/licenses/gpl-3.0.en.html
1312
//
1413
// You can be released from the requirements of the above licenses by purchasing
15-
// a commercial license. Buying such a license is mandatory if you want to modify or
16-
// otherwise use the software for commercial activities involving the Arduino
17-
// software without disclosing the source code of your own applications. To purchase
18-
// a commercial license, send an email to license@arduino.cc.
19-
//
14+
// a commercial license. Buying such a license is mandatory if you want to
15+
// modify or otherwise use the software for commercial activities involving the
16+
// Arduino software without disclosing the source code of your own applications.
17+
// To purchase a commercial license, send an email to license@arduino.cc.
2018
//
2119
'use strict';
2220
var grpc = require('@grpc/grpc-js');
@@ -582,7 +580,7 @@ function deserialize_cc_arduino_cli_commands_VersionResp(buffer_arg) {
582580
// The main Arduino Platform Service
583581
var ArduinoCoreService = exports.ArduinoCoreService = {
584582
// Start a new instance of the Arduino Core Service
585-
init: {
583+
init: {
586584
path: '/cc.arduino.cli.commands.ArduinoCore/Init',
587585
requestStream: false,
588586
responseStream: true,
@@ -594,7 +592,7 @@ var ArduinoCoreService = exports.ArduinoCoreService = {
594592
responseDeserialize: deserialize_cc_arduino_cli_commands_InitResp,
595593
},
596594
// Destroy an instance of the Arduino Core Service
597-
destroy: {
595+
destroy: {
598596
path: '/cc.arduino.cli.commands.ArduinoCore/Destroy',
599597
requestStream: false,
600598
responseStream: false,
@@ -606,7 +604,7 @@ var ArduinoCoreService = exports.ArduinoCoreService = {
606604
responseDeserialize: deserialize_cc_arduino_cli_commands_DestroyResp,
607605
},
608606
// Rescan instance of the Arduino Core Service
609-
rescan: {
607+
rescan: {
610608
path: '/cc.arduino.cli.commands.ArduinoCore/Rescan',
611609
requestStream: false,
612610
responseStream: false,
@@ -618,7 +616,7 @@ var ArduinoCoreService = exports.ArduinoCoreService = {
618616
responseDeserialize: deserialize_cc_arduino_cli_commands_RescanResp,
619617
},
620618
// Update package index of the Arduino Core Service
621-
updateIndex: {
619+
updateIndex: {
622620
path: '/cc.arduino.cli.commands.ArduinoCore/UpdateIndex',
623621
requestStream: false,
624622
responseStream: true,
@@ -630,7 +628,7 @@ var ArduinoCoreService = exports.ArduinoCoreService = {
630628
responseDeserialize: deserialize_cc_arduino_cli_commands_UpdateIndexResp,
631629
},
632630
// Update libraries index
633-
updateLibrariesIndex: {
631+
updateLibrariesIndex: {
634632
path: '/cc.arduino.cli.commands.ArduinoCore/UpdateLibrariesIndex',
635633
requestStream: false,
636634
responseStream: true,
@@ -653,10 +651,10 @@ var ArduinoCoreService = exports.ArduinoCoreService = {
653651
responseDeserialize: deserialize_cc_arduino_cli_commands_VersionResp,
654652
},
655653
// BOARD COMMANDS
656-
// --------------
657-
//
658-
// Requests details about a board
659-
boardDetails: {
654+
// --------------
655+
//
656+
// Requests details about a board
657+
boardDetails: {
660658
path: '/cc.arduino.cli.commands.ArduinoCore/BoardDetails',
661659
requestStream: false,
662660
responseStream: false,

0 commit comments

Comments
 (0)