Skip to content

Commit cc1eac5

Browse files
committed
Merge pull request #54 from brodykenrick/master
Add a debug configuration on project creation that is suitable for use with AVR Dragon (for step-through debugging)
2 parents fdb5a96 + 8b406d5 commit cc1eac5

File tree

8 files changed

+145
-67
lines changed

8 files changed

+145
-67
lines changed

it.baeyens.arduino.common/src/it/baeyens/arduino/common/ArduinoConst.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public class ArduinoConst {
3939
public static final String KEY_LAST_USED_ARDUINO_MENU_OPTIONS = "Arduino Custom Option Selections";
4040

4141
// Serial monitor keys
42-
public static final String KEY_SERIAlRATE = "Serial monitor Last selected rate";
42+
public static final String KEY_SERIAlRATE = "Serial monitor last selected rate";
4343
public static final String KEY_SERIAlPORT = "Serial monitor last selected Port";
4444
public static final String KEY_RXTX_LAST_USED_LINE_INDES = "Serial Monitor Last Used Line Ending index";
4545
public static final String KEY_RXTX_LAST_USED_AUTOSCROLL = "Serial Monitor Last Used auto scroll setting";

it.baeyens.arduino.common/src/it/baeyens/arduino/common/Common.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,7 @@ static public String getBuildEnvironmentVariable(ICConfigurationDescription conf
673673
IEnvironmentVariableManager envManager = CCorePlugin.getDefault().getBuildEnvironmentManager();
674674
try {
675675
return envManager.getVariable(EnvName, configurationDescription, expanded).getValue();
676-
} catch (Exception e) {// ignore al errors and return the default value
676+
} catch (Exception e) {// ignore all errors and return the default value
677677
}
678678
return defaultvalue;
679679
}

it.baeyens.arduino.core/plugin.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,10 @@
396396
<projectType
397397
id="it.baeyens.arduino.core.sketch"
398398
name="%projectType.name">
399+
400+
<!-- This config and toolchain 'Release' is the standard "just like Arduino IDE" configuration. -->
401+
<!-- It is also used for the base of the Debug configuration (for use with a JTAG/DragonAVR etc). -->
402+
<!-- TODO: Consider renaming as base. -->
399403
<configuration
400404
artifactExtension="hex"
401405
cleanCommand="rm -rf"

it.baeyens.arduino.core/src/it/baeyens/arduino/toolchain/ArduinoLanguageProvider.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,9 @@ protected String getCompilerCommand(String languageId) {
155155
compilerCommand = envManager.getVariable(ArduinoConst.ENV_KEY_recipe_c_o_pattern, confDesc, true).getValue().replace(" -o ", "");
156156
} else if (languageId.equals("org.eclipse.cdt.core.g++")) {
157157
compilerCommand = envManager.getVariable(ArduinoConst.ENV_KEY_recipe_cpp_o_pattern, confDesc, true).getValue().replace(" -o ", "");
158-
} else
158+
} else {
159159
ManagedBuilderCorePlugin.error("Unable to find compiler command for language " + languageId + " in toolchain=" + getToolchainId()); //$NON-NLS-1$
160+
}
160161

161162
return compilerCommand.replaceAll("\"\"", "").replaceAll(" ", " "); // remove
162163
// ""

it.baeyens.arduino.core/src/it/baeyens/arduino/tools/ArduinoHelpers.java

Lines changed: 54 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ public static void addCodeFolder(IProject project, String PathVarName, String Su
246246
}
247247

248248
/**
249-
* This method creates a link folder in the project and add the folder as a source path to the project it also adds the path to the include folder
249+
* This method creates a link folder in the project and adds the folder as a source path to the project it also adds the path to the include folder
250250
* if the includepath parameter points to a path that contains a subfolder named "utility" this subfolder will be added to the include path as
251251
* well <br/>
252252
* <br/>
@@ -486,7 +486,7 @@ private static void setTheEnvironmentVariablesSetTheDefaults(IContributedEnviron
486486
IEnvironmentVariable var = new EnvironmentVariable(ENV_KEY_ARDUINO_PATH, getArduinoPath().toString());
487487
contribEnv.addVariable(var, confDesc);
488488

489-
// from 1.5.3 onwards 2 more enviroment variables need to be added
489+
// from 1.5.3 onwards 2 more environment variables need to be added
490490
var = new EnvironmentVariable(ENV_KEY_ARCHITECTURE, platformFile.removeLastSegments(1).lastSegment());
491491
contribEnv.addVariable(var, confDesc);
492492
var = new EnvironmentVariable(ENV_KEY_BUILD_ARCH, platformFile.removeLastSegments(1).lastSegment().toUpperCase());
@@ -702,15 +702,18 @@ private static boolean isThisMenuItemSelected(ArduinoBoards boardsFile, ICConfig
702702
/**
703703
* This method creates environment variables based on the platform.txt and boards.txt platform.txt is processed first and then boards.txt. This
704704
* way boards.txt settings can overwrite common settings in platform.txt The environment variables are only valid for the project given as
705-
* parameter The projectproperties are used to identify the boards.txt and platform.txt as well as the board id to select the settings in the
705+
* parameter The project properties are used to identify the boards.txt and platform.txt as well as the board id to select the settings in the
706706
* board.txt file At the end also the path variable is set
707707
*
708708
* @param project
709709
* the project for which the environment variables are set
710710
* @param arduinoProperties
711711
* the info of the selected board to set the variables for
712712
*/
713-
public static void setTheEnvironmentVariables(IProject project, ICConfigurationDescription confDesc) {
713+
714+
715+
public static void setTheEnvironmentVariables(IProject project, ICConfigurationDescription confDesc, boolean debugConfig) {
716+
714717
IEnvironmentVariableManager envManager = CCorePlugin.getDefault().getBuildEnvironmentManager();
715718
IContributedEnvironment contribEnv = envManager.getContributedEnvironment();
716719

@@ -735,6 +738,11 @@ public static void setTheEnvironmentVariables(IProject project, ICConfigurationD
735738
setTheEnvironmentVariablesAddtheBoardsTxt(contribEnv, confDesc, boardFileName, boardName);
736739
// Do some post processing
737740
setTheEnvironmentVariablesPostProcessing(contribEnv, confDesc);
741+
742+
//If this is a debug config we modify the environment variables for compilation
743+
if(debugConfig) {
744+
setTheEnvironmentVariablesModifyDebugCompilerSettings(confDesc, envManager, contribEnv);
745+
}
738746

739747
} catch (Exception e) {// Catch exception if any
740748
Common.log(new Status(IStatus.ERROR, ArduinoConst.CORE_PLUGIN_ID, "Error parsing " + platformFilename + " or " + boardFileName, e));
@@ -797,6 +805,48 @@ private static void setTheEnvironmentVariablesPostProcessing(IContributedEnviron
797805

798806
}
799807

808+
/**
809+
* Converts the CPP and C compiler flags to not optimise for space/size and to leave symbols in.
810+
* These changes allow step through debugging with JTAG and Dragon AVR
811+
* @param confDesc
812+
* @param envManager
813+
* @param contribEnv
814+
*/
815+
816+
private static void setTheEnvironmentVariablesModifyDebugCompilerSettings(
817+
ICConfigurationDescription confDesc,
818+
IEnvironmentVariableManager envManager,
819+
IContributedEnvironment contribEnv) {
820+
821+
//Modify the compiler flags for the debug configuration
822+
//Replace "-g" with "-g2"
823+
//Replace "-Os" with ""
824+
//TODO: This should move to another location eventually -- a bit hacky here (considering other env vars come from other -- a little bit magical -- places).
825+
//I couldn't easily determine where that magic happened :(
826+
IEnvironmentVariable original = null;
827+
IEnvironmentVariable replacement = null;
828+
829+
original = envManager.getVariable( ENV_KEY_ARDUINO_START + "COMPILER.C.FLAGS" , confDesc, true);
830+
if(original != null)
831+
{
832+
replacement = new EnvironmentVariable(original.getName(),
833+
original.getValue().replace("-g", "-g2").replace("-Os", ""),
834+
original.getOperation(), original.getDelimiter() );
835+
contribEnv.addVariable(replacement, confDesc);
836+
}
837+
838+
original = envManager.getVariable( ENV_KEY_ARDUINO_START + "COMPILER.CPP.FLAGS" , confDesc, true);
839+
if(original != null)
840+
{
841+
replacement = new EnvironmentVariable(original.getName(),
842+
original.getValue().replace("-g", "-g2").replace("-Os", ""),
843+
original.getOperation(), original.getDelimiter() );
844+
contribEnv.addVariable(replacement, confDesc);
845+
}
846+
}
847+
848+
849+
800850
/**
801851
* When parsing boards.txt and platform.txt some processing needs to be done to get "acceptable environment variable values" This method does the
802852
* parsing

it.baeyens.arduino.core/src/it/baeyens/arduino/tools/ShouldHaveBeenInCDT.java

Lines changed: 44 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@
1919
// TOFIX Get this code in CDT so I should not have to do this
2020
public class ShouldHaveBeenInCDT {
2121
/*
22-
* copied from wizard STDWizardHandler package package org.eclipse.cdt.managedbuilder.ui.wizards;; This method creates the .cProject file in your
22+
* Copied from wizard STDWizardHandler package package org.eclipse.cdt.managedbuilder.ui.wizards;; This method creates the .cProject file in your
2323
* project.
24+
*
25+
* BK: modified this and made it work for multiple configs.
2426
*/
2527
/**
2628
* This method creates the .cProject file in your project. it is intended to be used with newly created projects. Using this method with project
@@ -29,56 +31,57 @@ public class ShouldHaveBeenInCDT {
2931
*
3032
* @param project
3133
* The newly created project that needs a .cproject file.
32-
* @param toolChain
33-
* The toolchain to be used with this project
34+
* @param sTCIds
35+
* An array of toolchain IDs to be used with this project
3436
* @param configuration
35-
* The configuration you want to use with this project ("release", "debug", ...)
37+
* An array of configuration strings you want to use with this project ["release", "debug", ...]
3638
* @param isManagedBuild
3739
* When true the project is managed build. Else the project is not (read you have to maintain the makefiles yourself)
3840
* @param monitor
3941
* The monitor to follow the process
4042
* @throws CoreException
4143
*/
42-
public static void setCProjectDescription(IProject project, IToolChain toolChain, String configuration, boolean isManagedBuild,
44+
public static void setCProjectDescription(IProject project,
45+
String sTCIds[], //sTCIds and sCfgs -- Need to be ordered the same and the same length
46+
String sCfgs[],
47+
boolean isManagedBuild,
4348
IProgressMonitor monitor) throws CoreException {
4449

45-
ICProjectDescriptionManager mngr = CoreModel.getDefault().getProjectDescriptionManager();
46-
ICProjectDescription des = mngr.createProjectDescription(project, false, false);
47-
ManagedBuildInfo info = ManagedBuildManager.createBuildInfo(project);
48-
ManagedProject mProj = new ManagedProject(des);
49-
info.setManagedProject(mProj);
50-
monitor.worked(20);
51-
52-
String s = "it.baeyens.arduino.core.toolChain.release";
53-
IToolChain tcs = ManagedBuildManager.getExtensionToolChain(s);
54-
55-
Configuration cfg = new Configuration(mProj, (ToolChain) tcs, ManagedBuildManager.calculateChildId(s, null), configuration);
56-
IBuilder bld = cfg.getEditableBuilder();
57-
if (bld != null) {
58-
if (bld.isInternalBuilder()) {
59-
IConfiguration prefCfg = ManagedBuildManager.getPreferenceConfiguration(false);
60-
IBuilder prefBuilder = prefCfg.getBuilder();
61-
cfg.changeBuilder(prefBuilder, ManagedBuildManager.calculateChildId(cfg.getId(), null), prefBuilder.getName());
62-
bld = cfg.getEditableBuilder();
63-
bld.setBuildPath(null);
64-
}
65-
bld.setManagedBuildOn(isManagedBuild);
66-
} else {
67-
System.out.println("Messages.StdProjectTypeHandler_3");
68-
}
69-
cfg.setArtifactName(mProj.getDefaultArtifactName());
70-
// CConfigurationData data = cfg.getConfigurationData();
71-
// ICConfigurationDescription cfgDes = des.createConfiguration(ManagedBuildManager.CFG_DATA_PROVIDER_ID, data);
72-
73-
// ConfigurationDataProvider.setDefaultLanguageSettingsProviders(project, cfg, cfgDes);
74-
75-
//BK - 2013.10.18
76-
// creates/add the configuration to the project description
77-
des.createConfiguration(ManagedBuildManager.CFG_DATA_PROVIDER_ID, cfg.getConfigurationData());
50+
ICProjectDescriptionManager mngr = CoreModel.getDefault().getProjectDescriptionManager();
51+
ICProjectDescription des = mngr.createProjectDescription(project, false, false);
52+
ManagedBuildInfo info = ManagedBuildManager.createBuildInfo(project);
53+
ManagedProject mProj = new ManagedProject(des);
54+
info.setManagedProject(mProj);
55+
monitor.worked(20);
7856

79-
monitor.worked(50);
80-
mngr.setProjectDescription(project, des);
81-
57+
//Iterate across the configurations
58+
for(int i = 0; i < Math.min(sTCIds.length, sCfgs.length); i++)
59+
{
60+
IToolChain tcs = ManagedBuildManager.getExtensionToolChain( sTCIds[i] );
61+
62+
Configuration cfg = new Configuration(mProj, (ToolChain) tcs, ManagedBuildManager.calculateChildId(sTCIds[i], null), sCfgs[i]);
63+
IBuilder bld = cfg.getEditableBuilder();
64+
if (bld != null) {
65+
if (bld.isInternalBuilder()) {
66+
IConfiguration prefCfg = ManagedBuildManager.getPreferenceConfiguration(false);
67+
IBuilder prefBuilder = prefCfg.getBuilder();
68+
cfg.changeBuilder(prefBuilder, ManagedBuildManager.calculateChildId(cfg.getId(), null), prefBuilder.getName());
69+
bld = cfg.getEditableBuilder();
70+
bld.setBuildPath(null);
71+
}
72+
bld.setManagedBuildOn(isManagedBuild);
73+
} else {
74+
System.out.println("Messages.StdProjectTypeHandler_3");
75+
}
76+
77+
cfg.setArtifactName(mProj.getDefaultArtifactName());
78+
79+
//BK - 2013.10.18
80+
// creates/add the configuration to the project description
81+
des.createConfiguration(ManagedBuildManager.CFG_DATA_PROVIDER_ID, cfg.getConfigurationData());
82+
}
83+
monitor.worked(50);
84+
mngr.setProjectDescription(project, des);
8285
}
8386

8487
}

it.baeyens.arduino.core/src/it/baeyens/arduino/ui/ArduinoSelectionPage.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,8 @@ public void saveAllSelections(ICConfigurationDescription confdesc) {
370370
contribEnv.addVariable(var, confdesc);
371371

372372
ArduinoHelpers.setProjectPathVariables(project, platformPath.removeLastSegments(1));
373-
ArduinoHelpers.setTheEnvironmentVariables(project, confdesc);
373+
ArduinoHelpers.setTheEnvironmentVariables(project, confdesc, false);
374+
374375

375376
try {
376377
ArduinoHelpers.addArduinoCodeToProject(project, confdesc);

it.baeyens.arduino.core/src/it/baeyens/arduino/ui/NewArduinoSketchWizard.java

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public void addPages() {
7272
mWizardPage.setTitle("New Arduino sketch");
7373

7474
mArduinoPage = new ArduinoSettingsPage("Arduino information");
75-
mArduinoPage.setTitle("Provide the Arduino informtion.");
75+
mArduinoPage.setTitle("Provide the Arduino information.");
7676
mArduinoPage.setDescription("These settings can be changed later.");
7777
addPage(mWizardPage);
7878
addPage(mArduinoPage);
@@ -151,45 +151,63 @@ void createProject(IProjectDescription description, IProject project, IProgressM
151151

152152
project.open(IResource.BACKGROUND_REFRESH, new SubProgressMonitor(monitor, 1000));
153153
IContainer container = project;
154-
String s = "it.baeyens.arduino.core.toolChain.release";
155-
ShouldHaveBeenInCDT.setCProjectDescription(project, ManagedBuildManager.getExtensionToolChain(s), "Release", true, monitor); // this
156-
// creates
157-
// the
158-
// .cproject
159-
// file
154+
155+
//TODO: Consider renaming Release to ArduinoIDEConfig
156+
//TODO: Consider renaming Debug to DragonAVR
157+
//Debug has same toolchain as release
158+
String sCfgs[] = {"Release", "Debug"};
159+
String sTCIds[] = {"it.baeyens.arduino.core.toolChain.release",
160+
"it.baeyens.arduino.core.toolChain.release"};
161+
162+
// Creates the .cproject file with the configurations
163+
ShouldHaveBeenInCDT.setCProjectDescription(project, sTCIds, sCfgs, true, monitor);
160164

161165
// Add the C C++ AVR and other needed Natures to the project
162166
ArduinoHelpers.addTheNatures(project);
163167

164-
// Add the arduino folder
168+
// Add the Arduino folder
165169
ArduinoHelpers.createNewFolder(project, "arduino", null);
166170

167171
// Set the environment variables
168172
ICProjectDescription prjDesc = CoreModel.getDefault().getProjectDescription(project);
169-
ICConfigurationDescription configurationDescription = prjDesc.getConfigurationByName("Release");
170-
mArduinoPage.saveAllSelections(configurationDescription);
171173

172-
ArduinoHelpers.setTheEnvironmentVariables(project, configurationDescription);
174+
//We don't iterate on the configs. Behaviour is a little custom for each.
175+
//Release
176+
ICConfigurationDescription configurationDescriptionRel = prjDesc
177+
.getConfigurationByName( sCfgs[0] );
178+
mArduinoPage.saveAllSelections(configurationDescriptionRel);
179+
ArduinoHelpers.setTheEnvironmentVariables(project,
180+
configurationDescriptionRel, false);
181+
182+
//Debug
183+
ICConfigurationDescription configurationDescriptionDbg = prjDesc
184+
.getConfigurationByName( sCfgs[1] );
185+
mArduinoPage.saveAllSelections(configurationDescriptionDbg);
186+
//The last boolean indicates to set debug settings in the compilation
187+
ArduinoHelpers.setTheEnvironmentVariables(project,
188+
configurationDescriptionDbg, true);
173189

174190
// Set the path variables
175191
IPath platformPath = new Path(new File(mArduinoPage.mPageLayout.mControlBoardsTxtFile.getText().trim()).getParent())
176192
.append(ArduinoConst.PLATFORM_FILE_NAME);
177193
ArduinoHelpers.setProjectPathVariables(project, platformPath.removeLastSegments(1));
178194

179-
// intermediately save or the adding code will fail
180-
prjDesc.setActiveConfiguration(configurationDescription);
195+
//Intermediately save or the adding code will fail
196+
//Release is the active config (as that is the "IDE" Arduino type....)
197+
prjDesc.setActiveConfiguration(configurationDescriptionRel);
181198

182199
// Insert The Arduino Code
183-
ArduinoHelpers.addArduinoCodeToProject(project, configurationDescription);
200+
//NOTE: Not duplicated for debug (the release reference is just to get at some environment variables)
201+
ArduinoHelpers.addArduinoCodeToProject(project, configurationDescriptionRel);
202+
184203

185204
/* Add the sketch source code file */
186205
ArduinoHelpers.addFileToProject(container, new Path(project.getName() + ".cpp"),
187206
Stream.openContentStream(project.getName(), "", "templates/sketch.cpp"), monitor);
188207

189208
/* Add the sketch header file */
190209
String Include = "WProgram.h";
191-
if (ArduinoInstancePreferences.isArduinoIdeOne()) // this is Arduino
192-
// version 1.0
210+
if (ArduinoInstancePreferences.isArduinoIdeOne()) //Arduino v1.0+
193211
{
194212
Include = "Arduino.h";
195213
}
@@ -214,7 +232,8 @@ void createProject(IProjectDescription description, IProject project, IProgressM
214232
// .createResourceConfiguration(file);
215233
// ResConfig.setExclude(true);
216234

217-
ICResourceDescription cfgd = configurationDescription.getResourceDescription(new Path(""), true);
235+
236+
ICResourceDescription cfgd = configurationDescriptionRel.getResourceDescription(new Path(""), true);
218237
ICExclusionPatternPathEntry[] entries = cfgd.getConfiguration().getSourceEntries();
219238
if (entries.length == 1) {
220239
Path exclusionPath[] = new Path[1];
@@ -250,7 +269,7 @@ void createProject(IProjectDescription description, IProject project, IProgressM
250269
// }
251270
// }
252271

253-
prjDesc.setActiveConfiguration(configurationDescription);
272+
prjDesc.setActiveConfiguration(configurationDescriptionRel);
254273
prjDesc.setCdtProjectCreated();
255274
CoreModel.getDefault().getProjectDescriptionManager().setProjectDescription(project, prjDesc, true, null);
256275
monitor.done();

0 commit comments

Comments
 (0)