in src/debug/configurationProvider.ts [117:158]
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`, ArduinoContext.boardManager.currentBoard.board);
util.mkdirRecursivelySync(path.join(ArduinoWorkspace.rootPath, outputFolder));
if (!dc.sketch || !util.fileExistsSync(path.join(ArduinoWorkspace.rootPath, dc.sketch))) {
await dc.resolveMainSketch();
}
if (!dc.sketch) {
vscode.window.showErrorMessage("No sketch file was found. Please specify the sketch in the arduino.json file");
return false;
}
if (!util.fileExistsSync(path.join(ArduinoWorkspace.rootPath, dc.sketch))) {
vscode.window.showErrorMessage(`Cannot find ${dc.sketch}, Please specify the sketch in the arduino.json file`);
return false;
}
config.program = path.join(ArduinoWorkspace.rootPath, outputFolder, `${path.basename(dc.sketch)}.elf`);
// always compile elf to make sure debug the right elf
if (!await ArduinoContext.arduinoApp.build(BuildMode.Verify, outputFolder)) {
vscode.window.showErrorMessage("Failed to verify the program, please check the output for details.");
return false;
}
config.program = config.program.replace(/\\/g, "/");
config.customLaunchSetupCommands.forEach((obj) => {
if (obj.text && obj.text.indexOf("${file}") > 0) {
obj.text = obj.text.replace(/\$\{file\}/, config.program);
}
});
}
if (!util.fileExistsSync(config.program)) {
vscode.window.showErrorMessage("Cannot find the elf file.");
return false;
}
return true;
}