Skip to content
This repository has been archived by the owner on Oct 1, 2024. It is now read-only.

Commit

Permalink
Adopt the new VSCode Debug API.
Browse files Browse the repository at this point in the history
  • Loading branch information
yaohaizh committed Oct 25, 2017
1 parent 9c0a8e8 commit 1987bdc
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 156 deletions.
47 changes: 5 additions & 42 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"aiKey": "83dd2c27-6594-41d3-85a9-bdb22070eb42",
"preview": true,
"engines": {
"vscode": "^1.13.0"
"vscode": "^1.17.0"
},
"icon": "images/arduino.png",
"license": "SEE LICENSE IN LICENSE.txt",
Expand All @@ -34,7 +34,6 @@
],
"activationEvents": [
"*",
"onCommand:arduino.debug.startSession",
"onCommand:arduino.verify",
"onCommand:arduino.upload",
"onCommand:arduino.selectSerialPort",
Expand All @@ -48,7 +47,8 @@
"onCommand:arduino.showBoardManager",
"onCommand:arduino.showLibraryManager",
"onCommand:arduino.showExamples",
"onCommand:arduino.initialize"
"onCommand:arduino.initialize",
"onDebug"
],
"main": "./out/src/extension",
"contributes": {
Expand Down Expand Up @@ -129,7 +129,6 @@
{
"type": "arduino",
"label": "Arduino",
"startSessionCommand": "arduino.debug.startSession",
"enableBreakpointsFor": {
"languageIds": [
"c",
Expand All @@ -145,7 +144,7 @@
"type": "arduino",
"request": "launch",
"program": "$${{file}}",
"cwd": "$${{workspaceRoot}}",
"cwd": "$${{workspaceFolder}}",
"MIMode": "gdb",
"targetArchitecture": "arm",
"miDebuggerPath": "",
Expand Down Expand Up @@ -176,42 +175,6 @@
}
}
],
"initialConfigurations": [
{
"name": "Arduino",
"type": "arduino",
"request": "launch",
"program": "${file}",
"cwd": "${workspaceRoot}",
"MIMode": "gdb",
"targetArchitecture": "arm",
"miDebuggerPath": "",
"debugServerPath": "",
"debugServerArgs": "",
"customLaunchSetupCommands": [
{
"text": "target remote localhost:3333"
},
{
"text": "file ${file}"
},
{
"text": "load"
},
{
"text": "monitor reset halt"
},
{
"text": "monitor reset init"
}
],
"stopAtEntry": true,
"serverStarted": "Info\\ :\\ [\\w\\d\\.]*:\\ hardware",
"launchCompleteCommand": "exec-continue",
"filterStderr": true,
"args": []
}
],
"configurationAttributes": {
"launch": {
"required": [
Expand All @@ -221,7 +184,7 @@
"program": {
"type": "string",
"description": "Full path to program executable.",
"default": "${workspaceRoot}/arduino.elf"
"default": "${workspaceFolder}/arduino.elf"
},
"args": {
"type": "array",
Expand Down
20 changes: 6 additions & 14 deletions src/arduinoContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import { ArduinoApp } from "./arduino/arduino";
import { BoardManager } from "./arduino/boardManager";
import { DebugConfigurator } from "./debug/configurator";
import { DebuggerManager } from "./debug/debuggerManager";
import { DeviceContext } from "./deviceContext";

Expand All @@ -28,26 +27,19 @@ class ArduinoContext {
this._boardManager = value;
}

public get arduinoConfigurator(): DebugConfigurator {
if (this._arduinoConfigurator === null) {
const debuggerManager = new DebuggerManager(
public get debuggerManager(): DebuggerManager {
if (this._debuggerManager === null) {
this._debuggerManager = new DebuggerManager(
DeviceContext.getInstance().extensionPath,
this.arduinoApp.settings,
this.boardManager);
debuggerManager.initialize();
this._arduinoConfigurator = new DebugConfigurator(
this.arduinoApp, this.arduinoApp.settings
, this.boardManager, debuggerManager);
this._debuggerManager.initialize();
}
return this._arduinoConfigurator;
}

public set arduinoConfigurator(value: DebugConfigurator) {
this._arduinoConfigurator = value;
return this._debuggerManager;
}

private _arduinoApp: ArduinoApp = null;
private _arduinoConfigurator: DebugConfigurator = null;
private _debuggerManager: DebuggerManager = null;
private _boardManager: BoardManager = null;
}

Expand Down
133 changes: 68 additions & 65 deletions src/debug/configurator.ts → src/debug/configurationProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,62 +5,66 @@ import * as path from "path";
import * as vscode from "vscode";

import { ArduinoApp } from "../arduino/arduino";
import { IArduinoSettings } from "../arduino/arduinoSettings";
import { BoardManager } from "../arduino/boardManager";
import ArduinoActivator from "../arduinoActivator";
import ArduinoContext from "../arduinoContext";

import { VscodeSettings } from "../arduino/vscodeSettings";
import * as platform from "../common/platform";
import * as util from "../common/util";
import { DeviceContext } from "../deviceContext";
import * as Logger from "../logger/logger";
import { DebuggerManager } from "./debuggerManager";

/**
* Automatically generate the Arduino board's debug settings.
*/
export class DebugConfigurator {
constructor(
private _arduinoApp: ArduinoApp,
private _arduinoSettings: IArduinoSettings,
private _boardManager: BoardManager,
private _debuggerManager: DebuggerManager,
) {

export class ArduinoDebugConfigurationProvider implements vscode.DebugConfigurationProvider {

constructor() { }

public provideDebugConfigurations(folder: vscode.WorkspaceFolder | undefined, token?: vscode.CancellationToken):
vscode.ProviderResult<vscode.DebugConfiguration[]> {
return [{
name: "Arduino",
type: "arduino",
request: "launch",
program: "${file}",
cwd: "${workspaceFolder}",
MIMode: "gdb",
targetArchitecture: "arm",
miDebuggerPath: "",
debugServerPath: "",
debugServerArgs: "",
customLaunchSetupCommands: [
{
text: "target remote localhost:3333",
},
{
text: "file ${file}",
},
{
text: "load",
},
{
text: "monitor reset halt",
},
{
text: "monitor reset init",
},
],
stopAtEntry: true,
serverStarted: "Info\\ :\\ [\\w\\d\\.]*:\\ hardware",
launchCompleteCommand: "exec-continue",
filterStderr: true,
args: [],
}];
}

public async run(config) {
// Default settings:
if (!config.request) {
config = {
name: "Arduino",
type: "arduino",
request: "launch",
program: "${file}",
cwd: "${workspaceRoot}",
MIMode: "gdb",

targetArchitecture: "arm",
customLaunchSetupCommands: [
{
text: "target remote localhost:3333",
},
{
text: "file ${file}",
},
{
text: "load",
},
{
text: "monitor reset halt",
},
{
text: "monitor reset init",
},
],
stopAtEntry: true,
serverStarted: "Info\\ :\\ [\\w\\d\\.]*:\\ hardware",
launchCompleteCommand: "exec-continue",
filterStderr: true,
args: [],
};
// Try to add all missing attributes to the debug configuration being launched.
public resolveDebugConfiguration(folder: vscode.WorkspaceFolder | undefined, config: vscode.DebugConfiguration, token?: vscode.CancellationToken):
vscode.ProviderResult<vscode.DebugConfiguration> {
return this.resolveDebugConfigurationAsync(config);
}

private async resolveDebugConfigurationAsync(config: vscode.DebugConfiguration) {
if (!ArduinoContext.initialized) {
await ArduinoActivator.activate();
}

if (VscodeSettings.getInstance().logLevel === "verbose" && !config.logging) {
Expand All @@ -71,40 +75,40 @@ export class DebugConfigurator {
};
}

if (!this._boardManager.currentBoard) {
if (!ArduinoContext.boardManager.currentBoard) {
vscode.window.showErrorMessage("Please select a board.");
return;
return undefined;
}

if (!this.resolveOpenOcd(config)) {
return;
return undefined;
}

if (!await this.resolveOpenOcdOptions(config)) {
return;
return undefined;
}

if (!this.resolveDebuggerPath(config)) {
return;
return undefined;
}

if (!await this.resolveProgramPath(config)) {
return;
return undefined;
}

// Use the C++ debugger MIEngine as the real internal debugger
config.type = "cppdbg";
vscode.commands.executeCommand("vscode.startDebug", config);
const dc = DeviceContext.getInstance();
Logger.traceUserData("start-cppdbg", { board: dc.board });
return config;
}

private async resolveProgramPath(config) {
const dc = DeviceContext.getInstance();

if (!config.program || config.program === "${file}") {
// make a unique temp folder because keeping same temp folder will corrupt the build when board is changed
const outputFolder = path.join(dc.output || `.build`, this._boardManager.currentBoard.board);
const outputFolder = path.join(dc.output || `.build`, ArduinoContext.boardManager.currentBoard.board);
util.mkdirRecursivelySync(path.join(vscode.workspace.rootPath, outputFolder));
if (!dc.sketch || !util.fileExistsSync(path.join(vscode.workspace.rootPath, dc.sketch))) {
await dc.resolveMainSketch();
Expand All @@ -122,7 +126,7 @@ export class DebugConfigurator {
config.program = path.join(vscode.workspace.rootPath, outputFolder, `${path.basename(dc.sketch)}.elf`);

// always compile elf to make sure debug the right elf
if (!await this._arduinoApp.verify(outputFolder)) {
if (!await ArduinoContext.arduinoApp.verify(outputFolder)) {
vscode.window.showErrorMessage("Failure to verify the program, please check output for details.");
return false;
}
Expand All @@ -145,10 +149,10 @@ export class DebugConfigurator {
private resolveDebuggerPath(config) {
if (!config.miDebuggerPath) {
config.miDebuggerPath = platform.findFile(platform.getExecutableFileName("arm-none-eabi-gdb"),
path.join(this._arduinoSettings.packagePath, "packages", this._boardManager.currentBoard.getPackageName()));
path.join(ArduinoContext.arduinoApp.settings.packagePath, "packages", ArduinoContext.boardManager.currentBoard.getPackageName()));
}
if (!util.fileExistsSync(config.miDebuggerPath)) {
config.miDebuggerPath = this._debuggerManager.miDebuggerPath;
config.miDebuggerPath = ArduinoContext.debuggerManager.miDebuggerPath;
}
if (!util.fileExistsSync(config.miDebuggerPath)) {
vscode.window.showErrorMessage("Cannot find the debugger path.");
Expand All @@ -160,11 +164,11 @@ export class DebugConfigurator {
private resolveOpenOcd(config) {
if (!config.debugServerPath) {
config.debugServerPath = platform.findFile(platform.getExecutableFileName("openocd"),
path.join(this._arduinoSettings.packagePath, "packages",
this._boardManager.currentBoard.getPackageName()));
path.join(ArduinoContext.arduinoApp.settings.packagePath, "packages",
ArduinoContext.boardManager.currentBoard.getPackageName()));
}
if (!util.fileExistsSync(config.debugServerPath)) {
config.debugServerPath = this._debuggerManager.debugServerPath;
config.debugServerPath = ArduinoContext.debuggerManager.debugServerPath;
}
if (!util.fileExistsSync(config.debugServerPath)) {
vscode.window.showErrorMessage("Cannot find the OpenOCD from the launch.json debugServerPath property." +
Expand All @@ -176,10 +180,9 @@ export class DebugConfigurator {
}

private async resolveOpenOcdOptions(config) {

if (config.debugServerPath && !config.debugServerArgs) {
try {
config.debugServerArgs = await this._debuggerManager.resolveOpenOcdOptions(config);
config.debugServerArgs = await ArduinoContext.debuggerManager.resolveOpenOcdOptions(config);
if (!config.debugServerArgs) {
return false;
}
Expand Down
Loading

0 comments on commit 1987bdc

Please sign in to comment.