debuggercdi/com.nokia.cdt.debug.cw.symbian/src/com/nokia/cdt/debug/cw/symbian/SettingsData.java
changeset 0 fb279309251b
child 200 08d645f6399f
equal deleted inserted replaced
-1:000000000000 0:fb279309251b
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 
       
    18 package com.nokia.cdt.debug.cw.symbian;
       
    19 
       
    20 import java.io.File;
       
    21 import java.io.IOException;
       
    22 import java.util.ArrayList;
       
    23 import java.util.HashMap;
       
    24 import java.util.List;
       
    25 
       
    26 import org.eclipse.cdt.core.CCorePlugin;
       
    27 import org.eclipse.cdt.core.IBinaryParser;
       
    28 import org.eclipse.cdt.core.ICExtensionReference;
       
    29 import org.eclipse.cdt.core.IBinaryParser.IBinaryObject;
       
    30 import org.eclipse.cdt.core.model.CModelException;
       
    31 import org.eclipse.cdt.core.model.CoreModel;
       
    32 import org.eclipse.cdt.core.model.IBinary;
       
    33 import org.eclipse.cdt.core.model.ICProject;
       
    34 import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants;
       
    35 import org.eclipse.core.resources.IProject;
       
    36 import org.eclipse.core.resources.IResource;
       
    37 import org.eclipse.core.runtime.CoreException;
       
    38 import org.eclipse.core.runtime.IPath;
       
    39 import org.eclipse.core.runtime.Path;
       
    40 import org.eclipse.debug.core.DebugPlugin;
       
    41 import org.eclipse.debug.core.ILaunchConfiguration;
       
    42 import org.eclipse.debug.core.ILaunchConfigurationType;
       
    43 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
       
    44 import org.eclipse.jface.dialogs.MessageDialog;
       
    45 import org.eclipse.swt.widgets.Shell;
       
    46 import org.eclipse.ui.IWorkbenchWindow;
       
    47 import org.eclipse.ui.PlatformUI;
       
    48 import org.osgi.framework.Version;
       
    49 
       
    50 import com.freescale.cdt.debug.cw.core.ProcessFactory;
       
    51 import com.freescale.cdt.debug.cw.core.RemoteConnectionsTRKHelper;
       
    52 import com.freescale.cdt.debug.cw.core.settings.ConnectionTypeInfo;
       
    53 import com.freescale.cdt.debug.cw.core.settings.DebuggerCommonData;
       
    54 import com.freescale.cdt.debug.cw.core.settings.Utils;
       
    55 import com.nokia.carbide.cdt.builder.CarbideBuilderPlugin;
       
    56 import com.nokia.carbide.cdt.builder.EpocEngineHelper;
       
    57 import com.nokia.carbide.cdt.builder.project.ICarbideBuildConfiguration;
       
    58 import com.nokia.carbide.cdt.builder.project.ICarbideProjectInfo;
       
    59 import com.nokia.carbide.cdt.builder.project.ISISBuilderInfo;
       
    60 import com.nokia.carbide.cpp.sdk.core.ISymbianBuildContext;
       
    61 import com.nokia.carbide.cpp.sdk.core.ISymbianSDK;
       
    62 import com.nokia.carbide.cpp.sdk.core.SDKCorePlugin;
       
    63 import com.nokia.carbide.remoteconnections.interfaces.IConnection;
       
    64 
       
    65 import cwdbg.PreferenceConstants;
       
    66 
       
    67 public class SettingsData {
       
    68 
       
    69 	// NOTE: Many of these constants are mirrored in 
       
    70 	// com.freescale.cdt.debug.cw.core.RemoteConnectionsTRKHelper
       
    71 	// Due to dependency ordering, they can't be used directly
       
    72 	// If you change any of these, please be sure to change them there, as well.
       
    73 	
       
    74 	public static final String PREFIX = "com.nokia.cdt.debug.cw.symbian.SettingsData"; //$NON-NLS-1$
       
    75 	public static final String LaunchConfig_Context= PREFIX + ".LaunchConfig_Context"; //$NON-NLS-1$
       
    76 	public static final String LaunchConfig_Emulator = PREFIX + ".LaunchConfig_Emulator"; //$NON-NLS-1$
       
    77 	public static final String LaunchConfig_AppTRK = PREFIX + ".LaunchConfig_AppTRK"; //$NON-NLS-1$
       
    78 	public static final String LaunchConfig_SysTRK = PREFIX + ".LaunchConfig_SysTRK"; //$NON-NLS-1$
       
    79 	public static final String LaunchConfig_CrashDebugger = PREFIX + ".LaunchConfig_CrashDebugger"; //$NON-NLS-1$
       
    80 	public static final String LaunchConfig_Trace32 = PREFIX + ".LaunchConfig_Trace32"; //$NON-NLS-1$
       
    81 	public static final String LaunchConfig_SophiaSTI = PREFIX + ".LaunchConfig_SophiaSTI"; //$NON-NLS-1$
       
    82 
       
    83 	public static final String ATTR_originalName = "originalName"; //$NON-NLS-1$
       
    84 
       
    85 	// Executable targeting
       
    86 	public static final int LCS_ExeTargetingRule_AllInSDK = 0;
       
    87 	public static final int LCS_ExeTargetingRule_AllInProject = 1;
       
    88 	public static final int LCS_ExeTargetingRule_ExeList = 2;
       
    89 	public static final int LCS_ExeTargetingRule_All = 3;
       
    90 	public static final String LCS_ExecutableTargetingRule = PREFIX + ".LCS_ExecutableTargetingRule";
       
    91 
       
    92 	// Launch Type IDs
       
    93 	private static final String LAUNCH_TYPE_PREFIX = "com.nokia.cdt.debug.launch."; //$NON-NLS-1$
       
    94 	public static final String CONTEXT_LAUNCH_TYPE_ID = LAUNCH_TYPE_PREFIX + "contextLaunch"; //$NON-NLS-1$
       
    95 	public static final String EMULATION_LAUNCH_TYPE_ID = LAUNCH_TYPE_PREFIX + "emulationLaunch"; //$NON-NLS-1$
       
    96 	public static final String APP_TRK_LAUNCH_TYPE_ID = LAUNCH_TYPE_PREFIX + "appTRKLaunch"; //$NON-NLS-1$
       
    97 	public static final String SYS_TRK_LAUNCH_TYPE_ID = LAUNCH_TYPE_PREFIX + "systemTRKLaunch"; //$NON-NLS-1$
       
    98 	public static final String ATTACH_LAUNCH_TYPE_ID = LAUNCH_TYPE_PREFIX + "attachLaunch"; //$NON-NLS-1$
       
    99 	public static final String STI_LAUNCH_TYPE_ID = LAUNCH_TYPE_PREFIX + "stiLaunch"; //$NON-NLS-1$
       
   100 	public static final String T32_LAUNCH_TYPE_ID = LAUNCH_TYPE_PREFIX + "t32Launch"; //$NON-NLS-1$
       
   101 
       
   102 	//================ Shadowed CW Preference Panels =================================
       
   103 	// These match prefs in a pref panel that exist in the CodeWarrior IDE. The names
       
   104 	// have to match exactly the name of the fields in the C++ pref struct.
       
   105 
       
   106 	// Utility method: forms Shadowed Pref panel Name (the panel name shared with backend).
       
   107 	private static String SPN(String cwPanelName, String cwPrefName)
       
   108 	{
       
   109 		return Utils.formShadowedPrefName(cwPanelName, cwPrefName);
       
   110 	}
       
   111 
       
   112 	//---< Serial Communication Panel> -------------------
       
   113 	
       
   114 	public static final String spn_SerialComm = "Serial Communications"; //$NON-NLS-1$
       
   115 
       
   116 	public static final String spn_SerialComm_port= SPN(spn_SerialComm, "port"); //$NON-NLS-1$
       
   117 	public static final String spn_SerialComm_rate= SPN(spn_SerialComm, "rate"); //$NON-NLS-1$
       
   118 	public static final String spn_SerialComm_databits= SPN(spn_SerialComm, "databits"); //$NON-NLS-1$
       
   119 	public static final String spn_SerialComm_stopbits= SPN(spn_SerialComm, "stopbits"); //$NON-NLS-1$
       
   120 	public static final String spn_SerialComm_parity= SPN(spn_SerialComm, "parity"); //$NON-NLS-1$
       
   121 	public static final String spn_SerialComm_flowcontrol= SPN(spn_SerialComm, "flowcontrol"); //$NON-NLS-1$
       
   122 	public static final String spn_SerialComm_logdata= SPN(spn_SerialComm, "logdata"); //$NON-NLS-1$
       
   123 	public static final String spn_SerialComm_serialConn= SPN(spn_SerialComm, "serial"); //$NON-NLS-1$
       
   124 	public static final String spn_SerialComm_xtiConn= SPN(spn_SerialComm, "tcpip"); //$NON-NLS-1$
       
   125 
       
   126 	//---< T32 Connection Panel> -------------------
       
   127 	
       
   128 	public static final String spn_Trace32Conn= "Trace32 Connection"; //$NON-NLS-1$
       
   129 	
       
   130 	public static final String spn_Trace32Conn_ExePath= SPN(spn_Trace32Conn, "LauterbachTrace32ExePath"); //$NON-NLS-1$
       
   131 	public static final String spn_Trace32Conn_ConfigFilePath= SPN(spn_Trace32Conn, "Trace32ConfigFilePath"); //$NON-NLS-1$
       
   132 	public static final String spn_Trace32Conn_BootScriptFile= SPN(spn_Trace32Conn, "Trace32BootConfigFilePath"); //$NON-NLS-1$
       
   133 	public static final String spn_Trace32Conn_UdpPort= SPN(spn_Trace32Conn, "LauterbachTrace32UDPPort"); //$NON-NLS-1$
       
   134 	public static final String spn_Trace32Conn_LogOption= SPN(spn_Trace32Conn, "Trace32LogOption"); //$NON-NLS-1$	
       
   135 	public static final String spn_Trace32Conn_BootConfigArgs= SPN(spn_Trace32Conn, "Trace32BootConfigArgs"); //$NON-NLS-1$
       
   136 	
       
   137 	//	---< STI Connection Panel> -------------------
       
   138 	public static final String spn_SophiaSTIConn= "Sophia Target Interface Connection"; //$NON-NLS-1$
       
   139 	
       
   140 	public static final String spn_SophiaSTIConn_DllPath= SPN(spn_SophiaSTIConn, "SophiaTargetInterfaceDllPath"); //$NON-NLS-1$
       
   141 	public static final String spn_SophiaSTIConn_LogOption= SPN(spn_SophiaSTIConn, "STILogOption"); //$NON-NLS-1
       
   142 	public static final String spn_SophiaSTIConn_JtagClock= SPN(spn_SophiaSTIConn,	"STIJTAGClock"); //$NON-NLS-1
       
   143 	public static final String spn_SophiaSTIConn_StiEmulatorType= SPN(spn_SophiaSTIConn,	"STIJTAGType"); //$NON-NLS-1
       
   144 
       
   145 	//================= End of Shadowed panels ===========================================
       
   146 
       
   147 	public static final int J_PN_TrkTimeout_Default = 2000;
       
   148 	
       
   149 	private static String[] exceptionPropertyNames = null;
       
   150 	private static IPath mainExeTargetPath = null;
       
   151 	private static IPath mainExeHostPath = null;
       
   152 	private static IPath mainExeWorkspaceRelativeMMPPath = null;
       
   153 	
       
   154 	public static String[] getExceptionPropertyNames()
       
   155 	{
       
   156 		if (exceptionPropertyNames == null)
       
   157 		{
       
   158 			final String[] exceptionPrefNames = { "exc_CONTROL_C", //$NON-NLS-1$
       
   159 				"exc_FLT_INEXACT_RESULT", "exc_CONTROL_BREAK", //$NON-NLS-1$ //$NON-NLS-2$
       
   160 				"exc_FLT_INVALID_OPERATION", "exc_DATATYPE_MISALIGNMENT", //$NON-NLS-1$ //$NON-NLS-2$
       
   161 				"exc_FLT_STACK_CHECK", "exc_ACCESS_VIOLATION", "exc_FLT_OVERFLOW", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
       
   162 				"exc_IN_PAGE_ERROR", "exc_FLT_UNDERFLOW", "exc_NO_MEMORY", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
       
   163 				"exc_INT_DIVIDE_BY_ZERO", "exc_ILLEGAL_INSTRUCTION", //$NON-NLS-1$ //$NON-NLS-2$
       
   164 				"exc_INT_OVERFLOW", "exc_NONCONTINUABLE_EXCEPTION", //$NON-NLS-1$ //$NON-NLS-2$
       
   165 				"exc_PRIV_INSTRUCTION", "exc_INVALID_DISPOSITION", //$NON-NLS-1$ //$NON-NLS-2$
       
   166 				"exc_STACK_OVERFLOW", "exc_ARRAY_BOUNDS_EXCEEDED", //$NON-NLS-1$ //$NON-NLS-2$
       
   167 				"exc_DLL_NOT_FOUND", "exc_FLT_DENORMAL_OPERAND", //$NON-NLS-1$ //$NON-NLS-2$
       
   168 				"exc_DLL_INIT_FAIL", "exc_FLT_DIVIDE_BY_ZERO", "exc_MS_CPLUS" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
       
   169 
       
   170 		};
       
   171 			
       
   172 			exceptionPropertyNames = new String[exceptionPrefNames.length];
       
   173 			for (int i = 0; i < exceptionPrefNames.length; i++) {
       
   174 				final String cwPanelName = "x86 Exceptions Panel"; //$NON-NLS-1$
       
   175 				exceptionPropertyNames[i] = Utils.formShadowedPrefName(cwPanelName, exceptionPrefNames[i]);
       
   176 			}
       
   177 		}
       
   178 		return exceptionPropertyNames;
       
   179 	}
       
   180 
       
   181 
       
   182 	static private void addSymbianSDKMapping(String epocRoot, ILaunchConfigurationWorkingCopy configuration) {
       
   183 		if (epocRoot.length() > 0 && new File(epocRoot).exists())
       
   184 			configuration.setAttribute(SymbianPlugin.Epoc_Root, epocRoot);
       
   185 }
       
   186 
       
   187 	static public void addSymbianSDKMapping(Path executable, ILaunchConfigurationWorkingCopy configuration) {
       
   188 		
       
   189 		String epocRoot = "";
       
   190 		String[] segs = executable.segments();
       
   191 		for (int i = 0; i < segs.length; i++) {
       
   192 			if (segs[i].equalsIgnoreCase("epoc32"))
       
   193 				epocRoot = executable.removeLastSegments(segs.length - i).toOSString();				
       
   194 		}
       
   195 		addSymbianSDKMapping(epocRoot, configuration);
       
   196 	}
       
   197 
       
   198 	static public void addSymbianSDKMapping(IProject project, ILaunchConfigurationWorkingCopy configuration) {
       
   199 		if (project != null) {
       
   200 	        ICarbideProjectInfo cpi = CarbideBuilderPlugin.getBuildManager().getProjectInfo(project);
       
   201 			if (cpi == null){
       
   202 				try {
       
   203 					String exeLocation = configuration.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, "");
       
   204 					Path exePath = new Path(exeLocation);
       
   205 					addSymbianSDKMapping(exePath, configuration);
       
   206 				} catch (CoreException e) {
       
   207 					e.printStackTrace();
       
   208 				}
       
   209 			}else{
       
   210 				String epocRoot = cpi.getDefaultConfiguration().getSDK().getEPOCROOT();
       
   211 				addSymbianSDKMapping(epocRoot, configuration);
       
   212 			}
       
   213 		}
       
   214 	}
       
   215 	
       
   216 	private static IBinary setProgramNameToFirstBinary(ILaunchConfigurationWorkingCopy configuration, IProject project) {
       
   217     	List<IBinary> applicableBinaries = getApplicableBinaries(configuration, project);
       
   218 		IBinary binaryToUse = null;
       
   219 		// try to find an exe to use
       
   220 		for (IBinary binary : applicableBinaries) {
       
   221 			if (binary.isExecutable()) {
       
   222 				binaryToUse = binary;
       
   223 				break;
       
   224 			}
       
   225 		}
       
   226 		// if none, use the first in the list
       
   227 		if (binaryToUse == null && !applicableBinaries.isEmpty())
       
   228 			binaryToUse = applicableBinaries.get(0);
       
   229 		if (binaryToUse != null) {
       
   230 			IPath location = binaryToUse.getResource().getLocation();
       
   231 			configuration.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, location.toOSString());
       
   232 		}
       
   233 		return binaryToUse;
       
   234 	}
       
   235 
       
   236 	private static List<IBinary> getApplicableBinaries(ILaunchConfiguration configuration, IProject project) {
       
   237 		List<IBinary> applicableBinaries = new ArrayList<IBinary>();
       
   238 		boolean isEmulatorConfig = isEmulatorConfiguration(configuration);
       
   239 		try {
       
   240 			ICProject cProject = CoreModel.getDefault().create(project);
       
   241 			if (cProject != null) {
       
   242 				IBinary[] binaries = cProject.getBinaryContainer().getBinaries();
       
   243 				for (int i = 0; i < binaries.length; i++) {
       
   244 					IPath path = getCanonicalPath(binaries[i].getResource().getLocation());
       
   245 					int numSegs = path.segmentCount();
       
   246 					if (numSegs >= 3) {
       
   247 						if (isEmulatorConfig == "WINSCW".equalsIgnoreCase(path.segment(numSegs - 3)))
       
   248 							applicableBinaries.add(binaries[i]);
       
   249 					}
       
   250 				}
       
   251 			}
       
   252 		} catch (CModelException e) {
       
   253 			e.printStackTrace();
       
   254 			displayWarningDialog(Messages.getString("SettingsData.38")); //$NON-NLS-1$
       
   255 		}
       
   256 		return applicableBinaries;
       
   257 	}
       
   258 
       
   259 
       
   260 	public static void setEmulationMainTab(ILaunchConfigurationWorkingCopy configuration, IProject project) {
       
   261 		//======== Emulator: main tab ======================================
       
   262 		//
       
   263 		if (project != null) {
       
   264 			String projectName = project.getName();
       
   265 			configuration.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, projectName);
       
   266 			configuration.setMappedResources( new IResource[] { project });
       
   267 			
       
   268 	        ICarbideProjectInfo cpi = CarbideBuilderPlugin.getBuildManager().getProjectInfo(project);
       
   269 			if (cpi != null) {
       
   270 				ICarbideBuildConfiguration buildConfig = cpi.getDefaultConfiguration();
       
   271 				String configName = projectName + " " + buildConfig.getDisplayString(); //$NON-NLS-1$
       
   272 				configuration.rename(DebugPlugin.getDefault().getLaunchManager().generateUniqueLaunchConfigurationNameFrom(configName));
       
   273 
       
   274 				// make sure the selected build configuration of the current project
       
   275 				// is an emulator build, otherwise warn them that we can't set default values.
       
   276 				if (buildConfig.getPlatformString().compareTo(ISymbianBuildContext.EMULATOR_PLATFORM) == 0) {
       
   277 					configuration.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, mainExeHostPath == null ? "" : mainExeHostPath.toOSString());
       
   278 
       
   279 					if (isEmulatorRequired(buildConfig, mainExeHostPath, mainExeWorkspaceRelativeMMPPath)) {
       
   280 						IPath releaseRoot = buildConfig.getSDK().getReleaseRoot();
       
   281 						String winscwudeb = releaseRoot.toOSString() + File.separator + "WINSCW" + File.separator + "UDEB"; //$NON-NLS-1$ //$NON-NLS-2$
       
   282 
       
   283 						String emulatorPath = winscwudeb + File.separator + "epoc.exe"; //$NON-NLS-1$
       
   284 						configuration.setAttribute(DebuggerCommonData.Host_App_Path, getCanonicalPath(emulatorPath));			
       
   285 					}
       
   286 					else if (mainExeHostPath != null) {
       
   287 						configuration.setAttribute(DebuggerCommonData.Host_App_Path, getCanonicalPath(mainExeHostPath.toOSString()));			
       
   288 					}
       
   289 				} else {
       
   290 					displayWarningDialog(Messages.getString("SettingsData.37")); //$NON-NLS-1$
       
   291 				}
       
   292 			}
       
   293 			else {
       
   294 				if (mainExeHostPath != null && !mainExeHostPath.isEmpty()) {
       
   295 					configuration.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, mainExeHostPath.toOSString()); 				 					
       
   296 
       
   297 					// launch the emulator for non-"exe" files
       
   298 					if ("exe".equalsIgnoreCase(mainExeHostPath.getFileExtension())) {
       
   299 	 					configuration.setAttribute(DebuggerCommonData.Host_App_Path, mainExeHostPath.toOSString());			
       
   300 					} else {
       
   301 	   					String emulatorPath = mainExeHostPath.removeLastSegments(1).append("epoc.exe").toOSString();//$NON-NLS-1$
       
   302 	 					configuration.setAttribute(DebuggerCommonData.Host_App_Path, getCanonicalPath(emulatorPath));			
       
   303 					}
       
   304 				} else {
       
   305 					IBinary binary = setProgramNameToFirstBinary(configuration, project);
       
   306 					if (binary.isExecutable()) {
       
   307 						configuration.setAttribute(DebuggerCommonData.Host_App_Path, 
       
   308 								getCanonicalPath(binary.getResource().getLocation()).toOSString());
       
   309 					}
       
   310 				}
       
   311 			}
       
   312 		}
       
   313 	}
       
   314 	
       
   315 	private static String getCanonicalPath(String path) {
       
   316 		try {
       
   317 			return new File(path).getCanonicalPath();
       
   318 		} catch (IOException e) {
       
   319 			e.printStackTrace();
       
   320 		}
       
   321 		return path;
       
   322 	}
       
   323 
       
   324 	private static IPath getCanonicalPath(IPath path) {
       
   325 		try {
       
   326 			if (path == null)
       
   327 				return null;
       
   328 			return new Path(path.toFile().getCanonicalPath());
       
   329 		} catch (IOException e) {
       
   330 			e.printStackTrace();
       
   331 		}
       
   332 		return path;
       
   333 	}
       
   334 
       
   335 	public static void setEmulationDebuggerTab(ILaunchConfigurationWorkingCopy configuration, IProject project) {
       
   336 		//============= Emulator debugger tab ============================================
       
   337 		//
       
   338 		configuration.setAttribute( DebugPlugin.ATTR_PROCESS_FACTORY_ID, ProcessFactory.ID );
       
   339 		configuration.setAttribute( ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_START_MODE, ICDTLaunchConfigurationConstants.DEBUGGER_MODE_RUN );
       
   340 		configuration.setAttribute( PreferenceConstants.J_PN_StopAtMainSymbol, "E32Main" ); //$NON-NLS-1$
       
   341 		configuration.setAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_STOP_AT_MAIN, false);
       
   342 		configuration.setAttribute( ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_ENABLE_VARIABLE_BOOKKEEPING, false );
       
   343 		configuration.setAttribute( ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_ENABLE_REGISTER_BOOKKEEPING, false );
       
   344 		configuration.setAttribute( PreferenceConstants.J_PN_SymbolLoadingRule, PreferenceConstants.J_PV_SymbolLoadingRule_Auto);
       
   345 		configuration.setAttribute( PreferenceConstants.J_PN_ViewProcessOutput, true);
       
   346 		configuration.setAttribute( PreferenceConstants.J_PN_ViewSystemMessage, false);
       
   347 		configuration.setAttribute( SymbianPlugin.DebugTraceLaunchSetting, true);
       
   348 	}
       
   349 	
       
   350 	public static void setX86ExceptionsTab(ILaunchConfigurationWorkingCopy configuration, IProject project) {
       
   351 		//======= Emulator: x86 Exceptions tab ===================================
       
   352 		// 
       
   353 		String[] exceptionPropertyNames = getExceptionPropertyNames();
       
   354 		// turn off all exceptions by default as the new emulators hit
       
   355 		// a bunch of recoverable exceptions while starting up
       
   356 		for (int i = 0; i < exceptionPropertyNames.length; i++) {
       
   357 			configuration.setAttribute(exceptionPropertyNames[i], false);
       
   358 		}
       
   359 	}
       
   360 	
       
   361 	public static void setTrkMainTab(ILaunchConfigurationWorkingCopy configuration, IProject project) {
       
   362 		//===== TRK :  main tab =================================================== 
       
   363 		//
       
   364 		configuration.setAttribute(PreferenceConstants.J_PN_RemoteProcessToLaunch, ""); //$NON-NLS-1$
       
   365 		configuration.setAttribute(PreferenceConstants.J_PN_ProgramArguments, ""); //$NON-NLS-1$
       
   366 
       
   367 		if (project != null) {
       
   368 			String projectName = project.getName();
       
   369 			configuration.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, projectName);
       
   370 			configuration.setMappedResources( new IResource[] { project });
       
   371 
       
   372 	        ICarbideProjectInfo cpi = CarbideBuilderPlugin.getBuildManager().getProjectInfo(project);
       
   373 			if (cpi != null) {
       
   374 				ICarbideBuildConfiguration buildConfig = cpi.getDefaultConfiguration();
       
   375 				String configName = projectName + " " + buildConfig.getDisplayString(); //$NON-NLS-1$
       
   376 				configuration.rename(DebugPlugin.getDefault().getLaunchManager().generateUniqueLaunchConfigurationNameFrom(configName));
       
   377 
       
   378 				// make sure the selected build configuration of the current project is not an emulator build
       
   379 				// otherwise warn them that we can't set default values.
       
   380 				if (buildConfig.getPlatformString().compareTo(ISymbianBuildContext.EMULATOR_PLATFORM) != 0) {
       
   381 					configuration.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, mainExeHostPath == null ? "" : mainExeHostPath.toOSString());
       
   382 					configuration.setAttribute(PreferenceConstants.J_PN_RemoteProcessToLaunch, mainExeTargetPath == null ? "" : mainExeTargetPath.toOSString());
       
   383 				} else {
       
   384 					displayWarningDialog(Messages.getString("SettingsData.37")); //$NON-NLS-1$
       
   385 				}
       
   386 			} else {
       
   387 				IBinary binary = setProgramNameToFirstBinary(configuration, project);
       
   388 				String exeName = null;
       
   389 				if (mainExeHostPath != null)
       
   390 					exeName = mainExeHostPath.lastSegment();
       
   391 				else if (binary.isExecutable())
       
   392 					exeName = binary.getResource().getLocation().lastSegment();
       
   393 				if (exeName != null)	
       
   394 					configuration.setAttribute(PreferenceConstants.J_PN_RemoteProcessToLaunch, "C:\\sys\\bin\\" + exeName); //$NON-NLS-1$
       
   395 			}
       
   396 		}	
       
   397 	}
       
   398 	
       
   399 	public static void setStopModeMainTab(ILaunchConfigurationWorkingCopy configuration, IProject project) {
       
   400 		//===== StopMode :  main tab =================================================== 
       
   401 		//		
       
   402 		if (project != null) {
       
   403 			String projectName = project.getName();
       
   404 			configuration.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, projectName);
       
   405 			configuration.setMappedResources( new IResource[] { project });
       
   406 
       
   407 	        ICarbideProjectInfo cpi = CarbideBuilderPlugin.getBuildManager().getProjectInfo(project);
       
   408 			if (cpi != null) {
       
   409 				ICarbideBuildConfiguration buildConfig = cpi.getDefaultConfiguration();
       
   410 				String configName = projectName + " " + buildConfig.getDisplayString(); //$NON-NLS-1$
       
   411 				configuration.rename(DebugPlugin.getDefault().getLaunchManager().generateUniqueLaunchConfigurationNameFrom(configName));
       
   412 
       
   413 				// make sure the selected build configuration of the current project is not an emulator build
       
   414 				// otherwise warn them that we can't set default values.
       
   415 				if (buildConfig.getPlatformString().compareTo(ISymbianBuildContext.EMULATOR_PLATFORM) != 0) {
       
   416 					configuration.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, mainExeHostPath == null ? "" : mainExeHostPath.toOSString());					
       
   417 				} else {
       
   418 					displayWarningDialog(Messages.getString("SettingsData.37")); //$NON-NLS-1$
       
   419 				}
       
   420 			} else {
       
   421 				setProgramNameToFirstBinary(configuration, project);
       
   422 			}
       
   423 		}	
       
   424 	}
       
   425 	
       
   426 	public static void setRomImgTab(ILaunchConfigurationWorkingCopy configuration, IProject project) {
       
   427 		if (project != null) {
       
   428 	        ICarbideProjectInfo cpi = CarbideBuilderPlugin.getBuildManager().getProjectInfo(project.getProject());
       
   429 	        
       
   430 	        if (cpi != null) {
       
   431 	        	final ICarbideBuildConfiguration buildConfig = cpi.getDefaultConfiguration();
       
   432 	    		if (buildConfig != null){
       
   433 	    			if (buildConfig.getPlatformString().compareTo(ISymbianBuildContext.EMULATOR_PLATFORM) != 0) {
       
   434 	    				String epoc32Dir = buildConfig.getSDK().getEPOCROOT()+ "epoc32";
       
   435 	    				if (new File(epoc32Dir).exists())
       
   436 	    					configuration.setAttribute(PreferenceConstants.J_PN_SymbianKitEpoc32Dir, epoc32Dir);
       
   437 	    			} else {
       
   438 	    				displayWarningDialog(Messages.getString("SettingsData.37")); //$NON-NLS-1$
       
   439 	    			}
       
   440 	    		}
       
   441 	        }
       
   442 		}	        
       
   443 	}
       
   444 
       
   445 	public static void setTrkDebuggerTab(ILaunchConfigurationWorkingCopy configuration, IProject project) {
       
   446 		//======  TRK:  debugger tab ================================================================
       
   447 		//
       
   448 		configuration.setAttribute( DebugPlugin.ATTR_PROCESS_FACTORY_ID, ProcessFactory.ID );			
       
   449 		configuration.setAttribute( ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_START_MODE, ICDTLaunchConfigurationConstants.DEBUGGER_MODE_RUN );
       
   450 		configuration.setAttribute( PreferenceConstants.J_PN_StopAtMainSymbol, "E32Main" ); //$NON-NLS-1$
       
   451 		configuration.setAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_STOP_AT_MAIN, false);
       
   452 		configuration.setAttribute( ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_ENABLE_VARIABLE_BOOKKEEPING, false );
       
   453 		configuration.setAttribute( ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_ENABLE_REGISTER_BOOKKEEPING, false );
       
   454 		configuration.setAttribute( PreferenceConstants.J_PN_ViewUnframedData, true);
       
   455 		configuration.setAttribute( PreferenceConstants.J_PN_ViewCommMessages, false);
       
   456 		configuration.setAttribute( PreferenceConstants.J_PN_DefaultInstructionSet, PreferenceConstants.J_PV_DefaultInstructionSet_Auto);
       
   457 		configuration.setAttribute( PreferenceConstants.J_PN_TRKMessageTimeout, J_PN_TrkTimeout_Default);
       
   458 	}
       
   459 	
       
   460 	public static void setStopModeDebuggerTab(ILaunchConfigurationWorkingCopy configuration, IProject project) {
       
   461 		//======  Stop Mode:  debugger tab ================================================================
       
   462 		//
       
   463 		configuration.setAttribute( DebugPlugin.ATTR_PROCESS_FACTORY_ID, ProcessFactory.ID );
       
   464 		configuration.setAttribute( ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_START_MODE, ICDTLaunchConfigurationConstants.DEBUGGER_MODE_RUN );
       
   465 		configuration.setAttribute( PreferenceConstants.J_PN_StopAtMainSymbol, "E32Main" ); //$NON-NLS-1$
       
   466 		configuration.setAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_STOP_AT_MAIN, false);
       
   467 		configuration.setAttribute( ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_ENABLE_VARIABLE_BOOKKEEPING, false );
       
   468 		configuration.setAttribute( ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_ENABLE_REGISTER_BOOKKEEPING, false );
       
   469 		configuration.setAttribute( PreferenceConstants.J_PN_DefaultInstructionSet, PreferenceConstants.J_PV_DefaultInstructionSet_Auto);
       
   470 	}
       
   471 	public static void setSerialConnTab(ILaunchConfigurationWorkingCopy configuration, IProject project) {
       
   472 		//======== Serial Connection Tab =====================================
       
   473 		//
       
   474 		configuration.setAttribute(PreferenceConstants.J_PN_TrkConnectionType, PreferenceConstants.J_PV_TrkConnectionType_Serial);
       
   475 		configuration.setAttribute(RemoteConnectionsTRKHelper.USES_REMOTE_CONNECTIONS_ATTRIBUTE, true);
       
   476 		IConnection defaultConnection = RemoteConnectionsTRKHelper.getFirstCompatibleConnection();
       
   477 		if (defaultConnection != null)
       
   478 			configuration.setAttribute(RemoteConnectionsTRKHelper.CONNECTION_ATTRIBUTE, defaultConnection.getIdentifier());
       
   479 	}
       
   480 	
       
   481 	public static void setFileTransferTab(ILaunchConfigurationWorkingCopy configuration, IProject project) {
       
   482 
       
   483 		//======== File Transfer tab ============================================
       
   484 		//
       
   485 		configuration.setAttribute( PreferenceConstants.J_PN_FilesToTransfer, "" ); //$NON-NLS-1$
       
   486 		
       
   487 		// only do this for system TRK configurations
       
   488 		try {
       
   489 			if (configuration.getType().getIdentifier().compareTo(SYS_TRK_LAUNCH_TYPE_ID) == 0 ) {
       
   490 				if (project != null) {
       
   491 					
       
   492 			        ICarbideProjectInfo cpi = CarbideBuilderPlugin.getBuildManager().getProjectInfo(project);
       
   493 					if (cpi != null) {
       
   494 						ICarbideBuildConfiguration buildConfig = cpi.getDefaultConfiguration();
       
   495 						
       
   496 						String defaultTargetPath = "C:\\"; //$NON-NLS-1$
       
   497 						if (buildConfig.getSDK().isEKA2()) {
       
   498 							// C:\\sys\bin for eka2
       
   499 							defaultTargetPath += "sys\\bin\\"; //$NON-NLS-1$
       
   500 						}
       
   501 						String prefsData = "";
       
   502 						
       
   503 						// we'll add all binaries that could be built by the config, but will only enabled those
       
   504 						// that are actually being built.
       
   505 						List<IPath> builtComponents = EpocEngineHelper.getComponentsBuiltByConifguration(buildConfig);
       
   506 						
       
   507 						// add the binaries and any resource-type files generated by all mmp files in the project
       
   508 						for (IPath mmp : EpocEngineHelper.getMMPFilesForBuildConfiguration(buildConfig)) {
       
   509 							String enabled = builtComponents.contains(mmp) ? ",1," : ",0,";
       
   510 							IPath hp = EpocEngineHelper.getHostPathForExecutable(buildConfig, mmp);
       
   511 							if (hp != null) {
       
   512 								IPath tp = EpocEngineHelper.getTargetPathForExecutable(buildConfig, mmp);
       
   513 								if (tp == null) {
       
   514 									tp = new Path(defaultTargetPath).append(hp.lastSegment());
       
   515 								}
       
   516 								prefsData += hp.toOSString() + "," + tp.toOSString() + enabled; //$NON-NLS-1$
       
   517 							}
       
   518 							
       
   519 							HashMap<String, String> hostTargetRSRCMap = EpocEngineHelper.getHostAndTargetResources(buildConfig, mmp);
       
   520 							// Add resource files...
       
   521 							for (String currHostRSRC : hostTargetRSRCMap.keySet()) {
       
   522 								prefsData += currHostRSRC + "," + hostTargetRSRCMap.get(currHostRSRC) + new Path(currHostRSRC).lastSegment() + enabled; //$NON-NLS-1$
       
   523 							}
       
   524 						}
       
   525 						
       
   526 						// check the project for image makefiles
       
   527 						HashMap<String, String> hostTargetImagesMap = EpocEngineHelper.getHostAndTargetImages(buildConfig);
       
   528 						for (String currHostImg : hostTargetImagesMap.keySet()) {
       
   529 							prefsData += currHostImg + "," + hostTargetImagesMap.get(currHostImg) + ",1,"; //$NON-NLS-1$ //$NON-NLS-2$
       
   530 						}
       
   531 						
       
   532 						// Add the files to transfer to the pref
       
   533 						configuration.setAttribute( PreferenceConstants.J_PN_FilesToTransfer, prefsData );
       
   534 					}
       
   535 				}
       
   536 			}
       
   537 		} catch (CoreException e) {
       
   538 			SymbianPlugin.log(e);
       
   539 		}
       
   540 	}
       
   541 	
       
   542 	public static void setInstallationTab(ILaunchConfigurationWorkingCopy configuration, IProject project) {
       
   543 
       
   544 		//=========== AppTRK Installation tab ==========================================
       
   545 		//
       
   546 		configuration.setAttribute( PreferenceConstants.J_PN_SisFileHostPath, "" ); //$NON-NLS-1$
       
   547 		configuration.setAttribute( PreferenceConstants.J_PN_SisFileTargetPath, "C:\\data\\" ); //$NON-NLS-1$
       
   548 		configuration.setAttribute( PreferenceConstants.J_PN_AlwaysInstallSisFile, false );
       
   549 		configuration.setAttribute( PreferenceConstants.J_PN_HideInstallerUI, true );
       
   550 		configuration.setAttribute( PreferenceConstants.J_PN_InstallToDrive, 2 ); // C:
       
   551 
       
   552 		if (project != null) {
       
   553 
       
   554 	        ICarbideProjectInfo cpi = CarbideBuilderPlugin.getBuildManager().getProjectInfo(project);
       
   555 			if (cpi != null) {
       
   556 				List<ISISBuilderInfo> sisInfoList = cpi.getDefaultConfiguration().getSISBuilderInfoList();
       
   557 				if (sisInfoList != null && sisInfoList.size() > 0) {
       
   558 					// grab the last one in case they are embedded earlier built sis files
       
   559 					// in later built ones
       
   560 					configuration.setAttribute(PreferenceConstants.J_PN_SisFileHostPath, sisInfoList.get(sisInfoList.size() - 1).getFinalSISFullPath().toOSString());
       
   561 				}
       
   562 			}
       
   563 		}
       
   564 	
       
   565 	}
       
   566 
       
   567 	public static void setExecutablesTab(ILaunchConfigurationWorkingCopy configuration, String settingsGroup, IProject project) {
       
   568 		
       
   569 		//======== Executables Tab =====================================
       
   570 		// Defaults to all executables from the same SDK
       
   571 		configuration.setAttribute( LCS_ExecutableTargetingRule, LCS_ExeTargetingRule_AllInSDK ); //$NON-NLS-1$
       
   572 		configuration.setAttribute( PreferenceConstants.J_PN_ExecutablesToDebug, "" ); //$NON-NLS-1$
       
   573 		configuration.setAttribute(	PreferenceConstants.J_PN_SymbolLoadingRule,	PreferenceConstants.J_PV_SymbolLoadingRule_Auto);
       
   574 	}
       
   575 
       
   576 	/**
       
   577 	 * There are "internal preferences" that are not visible to (hence not changeable by) users. 
       
   578 	 * We set the values for them for different launch configurations. But when we change any 
       
   579 	 * of the values by re-coding, the change won't be picked up by existing launch configurations.
       
   580 	 *      
       
   581 	 * This function is supposed to fix that problem. It should be called on every debugger start.
       
   582 	 * 
       
   583 	 * Any internal preferences should be set here.
       
   584 	 * 
       
   585 	 */ 
       
   586 	public static void setInternalPreferences(ILaunchConfigurationWorkingCopy configuration, String settingsGroup)
       
   587 	{
       
   588 		// All but emulator debugger support OS Data View (kernel aware view) at present.
       
   589 		// 
       
   590 		if (settingsGroup.equals(LaunchConfig_Emulator)) 
       
   591 			configuration.setAttribute( PreferenceConstants.J_PN_SupportOSView, false);
       
   592 		else
       
   593 			configuration.setAttribute( PreferenceConstants.J_PN_SupportOSView, true);
       
   594 		
       
   595 		if (settingsGroup.equals(LaunchConfig_AppTRK) || 
       
   596 			    settingsGroup.equals(LaunchConfig_SysTRK) ||
       
   597 			    settingsGroup.equals(LaunchConfig_Emulator))
       
   598 		{
       
   599 			configuration.setAttribute( PreferenceConstants.J_PN_IsSystemModeDebug, false);
       
   600 		}
       
   601 		else // others like T32, Sophia and crash debugger.
       
   602 			configuration.setAttribute( PreferenceConstants.J_PN_IsSystemModeDebug, true);	
       
   603 	}
       
   604 
       
   605 	// a convenience function.
       
   606 	public static void setInternalPreferences(ILaunchConfiguration originalConfig, String settingsGroup)
       
   607 	{
       
   608 		ILaunchConfigurationWorkingCopy wc = null;
       
   609 		try {
       
   610 			wc = originalConfig.getWorkingCopy();
       
   611 			
       
   612 			if (wc == null)
       
   613 				return;
       
   614 			
       
   615 			setInternalPreferences(wc, settingsGroup);
       
   616 			
       
   617 			wc.doSave();
       
   618 		} catch (CoreException e) {
       
   619 			e.printStackTrace();
       
   620 		}
       
   621 	}
       
   622 
       
   623 	public static void setDefaults(ILaunchConfigurationWorkingCopy configuration, String settingsGroup, IProject project)
       
   624 	{
       
   625 		if (project != null) {
       
   626 	        ICarbideProjectInfo cpi = CarbideBuilderPlugin.getBuildManager().getProjectInfo(project);
       
   627 			if (cpi != null) {
       
   628 				ICarbideBuildConfiguration buildConfig = cpi.getDefaultConfiguration();
       
   629 				// get the list of binaries that are being built for the build config and their corresponding mmp's
       
   630 				List<IPath> exePaths = new ArrayList<IPath>(0);
       
   631 				List<IPath> mmpPaths = new ArrayList<IPath>(0);
       
   632 				EpocEngineHelper.getPathToAllExecutables(buildConfig, new ArrayList<IPath>(), exePaths, new ArrayList<IPath>(), mmpPaths);
       
   633 				if (exePaths.size() > 0) {
       
   634 					// pick the first exe in the list, otherwise the first binary in the list
       
   635 					IPath exePath = exePaths.get(0);
       
   636 					IPath mmpPath = mmpPaths.get(0);
       
   637 					for (int i=0; i<exePaths.size(); i++) {
       
   638 						String fileExt = exePaths.get(i).getFileExtension();
       
   639 						if (fileExt != null && fileExt.compareToIgnoreCase("exe") == 0) {
       
   640 							exePath = exePaths.get(i);
       
   641 							mmpPath = mmpPaths.get(i);
       
   642 							break;
       
   643 						}
       
   644 					}
       
   645 					
       
   646 					setDefaults(configuration, settingsGroup, project, mmpPath, exePath);
       
   647 					return;
       
   648 				}
       
   649 			}
       
   650 		}
       
   651 
       
   652 		setDefaults(configuration, settingsGroup, project, null, null);
       
   653 	}
       
   654 	
       
   655 	/**
       
   656 	 * Sets the default values for the launch configuration.
       
   657 	 * @param configuration
       
   658 	 * @param settingsGroup
       
   659 	 * @param project
       
   660 	 * @param workspaceRelativeMMPPath should not be null for Carbide project (but can be for debug only projects)
       
   661 	 * @param mainExePath should be null for Carbide projects but should not be null for debug projects
       
   662 	 */
       
   663 	public static void setDefaults(ILaunchConfigurationWorkingCopy configuration, String settingsGroup, IProject project, IPath workspaceRelativeMMPPath, IPath mainExePath)
       
   664 	{
       
   665 		// set the main executable target and host path here, so that we don't have to call into the EPOC engine every time.
       
   666 		// calling into EPOC engine every time could be expensive for large projects..
       
   667 		mainExeHostPath = getCanonicalPath(mainExePath);
       
   668 		mainExeTargetPath = null;
       
   669 		mainExeWorkspaceRelativeMMPPath = workspaceRelativeMMPPath;
       
   670 		
       
   671 		if (workspaceRelativeMMPPath != null) {
       
   672 			if (project != null) {
       
   673 				ICarbideProjectInfo cpi = CarbideBuilderPlugin.getBuildManager().getProjectInfo(project);
       
   674 				if (cpi != null) {			
       
   675 					ICarbideBuildConfiguration buildConfig = cpi.getDefaultConfiguration();
       
   676 
       
   677 					mainExeTargetPath = getCanonicalPath(EpocEngineHelper.getTargetPathForExecutable(buildConfig, workspaceRelativeMMPPath));
       
   678 				}
       
   679 			}
       
   680 		}
       
   681 		
       
   682 		// this can be called from various places.  launch configurations can be created by clicking
       
   683 		// the New button on the Eclipse launch configuration dialog, from our launch wizard, or from
       
   684 		// the import executable wizard.  the import executable wizard creates a non-managed make project
       
   685 		// and hence most of the logic below will not work.
       
   686 
       
   687 		// ==== common to all =======================================================================
       
   688 		//
       
   689 		
       
   690 		// Specify which debugger plugin to use.
       
   691 		configuration.setAttribute(DebuggerCommonData.Host_App_Path, ""); //$NON-NLS-1$
       
   692 		configuration.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, ""); //$NON-NLS-1$
       
   693 		configuration.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, ""); //$NON-NLS-1$
       
   694 		if (project != null)
       
   695 		{
       
   696 			configuration.setMappedResources( new IResource[] { project });
       
   697 		    ICarbideProjectInfo cpi = CarbideBuilderPlugin.getBuildManager().getProjectInfo(project);
       
   698 			if (cpi != null) {
       
   699 				configuration.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_BUILD_CONFIG_ID, cpi.getDefaultBuildConfigName());
       
   700 				}
       
   701 			
       
   702 		}
       
   703 		
       
   704 		// For all but crash debugger, use our "SymbianDebugger".
       
   705 		// Crash debugger will set its own debugger (see CrashDebugConfigurationTabGroup.setDefaults()).
       
   706 		// 
       
   707 		if (! settingsGroup.equals(LaunchConfig_CrashDebugger)) {
       
   708 			configuration.setAttribute( ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_ID, SymbianDebugger.DEBUGGER_ID);
       
   709 			// Executables tab is not shown for crash debugger launch configuration.
       
   710 			setExecutablesTab(configuration, settingsGroup, project);
       
   711 		}
       
   712 		
       
   713 		setInternalPreferences(configuration, settingsGroup);
       
   714 
       
   715 		if (settingsGroup.equals(LaunchConfig_Context)) {
       
   716 			setContextMainTab(configuration, project);
       
   717 		}
       
   718 	
       
   719 		if (settingsGroup.equals(LaunchConfig_Emulator)) {
       
   720 			setEmulationMainTab(configuration, project);
       
   721 			setEmulationDebuggerTab(configuration, project);
       
   722 			setX86ExceptionsTab(configuration, project);			
       
   723 		}
       
   724 		
       
   725 		if (settingsGroup.equals(LaunchConfig_AppTRK) || 
       
   726 			    settingsGroup.equals(LaunchConfig_SysTRK) ||
       
   727 				settingsGroup.equals(LaunchConfig_CrashDebugger))
       
   728 		{
       
   729 			setSerialConnTab(configuration, project);
       
   730 		}
       
   731 
       
   732 		if (settingsGroup.equals(LaunchConfig_AppTRK)) {
       
   733 				setInstallationTab(configuration, project);
       
   734 		}
       
   735 		
       
   736 		if (settingsGroup.equals(LaunchConfig_Trace32) ||
       
   737 				settingsGroup.equals(LaunchConfig_SophiaSTI))
       
   738 		{
       
   739 			setStopModeMainTab(configuration, project);
       
   740 			setStopModeDebuggerTab(configuration, project);
       
   741 			setRomImgTab(configuration, project);
       
   742 		}
       
   743 
       
   744 		if (settingsGroup.equals(LaunchConfig_AppTRK) || settingsGroup.equals(LaunchConfig_SysTRK)) {
       
   745 			setTrkMainTab(configuration, project);
       
   746 			setTrkDebuggerTab(configuration, project);
       
   747 			setFileTransferTab(configuration, project);
       
   748 			
       
   749 			
       
   750 			// TRK Debugging: specify TRK protocol plugin.
       
   751 			//
       
   752 			ConnectionTypeInfo connTI = new ConnectionTypeInfo(
       
   753 					"Carbide TRK", // Internal ID //$NON-NLS-1$
       
   754 					"Symbian MetroTRK", // Display name //$NON-NLS-1$
       
   755 					spn_SerialComm); // Pref panel name
       
   756 
       
   757 			DebuggerCommonData.setLaunchConfigConnSettings(
       
   758 					configuration,
       
   759 					connTI, 
       
   760 					"Symbian MetroTRK Protocol", //$NON-NLS-1$
       
   761 					""); // Protocol plugin name //$NON-NLS-1$
       
   762 		}
       
   763 
       
   764 		if (settingsGroup.equals(LaunchConfig_CrashDebugger)) {
       
   765 			// Crash debugger: specify crash debugger protocol plugin.
       
   766 			//
       
   767 			// For crash debugger, we don't need a project. But don't set the name to "" as it would 
       
   768 			// cause crasher in CDT if we tries to create CDebugTarget without a project.
       
   769 			configuration.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, "Any"); //$NON-NLS-1$
       
   770 			
       
   771 			ConnectionTypeInfo connTI = new ConnectionTypeInfo(
       
   772 					"Carbide CrashDebugger", // Internal ID //$NON-NLS-1$
       
   773 					"SymbianCrashDebuggerProtocol", // Display name. see SymbianCrashDebuggerPrefix.h on DE side. //$NON-NLS-1$
       
   774 					spn_SerialComm); // Pref panel name
       
   775 
       
   776 			DebuggerCommonData.setLaunchConfigConnSettings(
       
   777 					configuration,
       
   778 					connTI, 
       
   779 					"SymbianCrashDebuggerProtocol", //$NON-NLS-1$
       
   780 					""); // see SymbianCrashDebuggerPrefix.h on DE side //$NON-NLS-1$
       
   781 		}
       
   782 		
       
   783 		if (settingsGroup.equals(LaunchConfig_Trace32))//$NON-NLS-1$
       
   784 			{
       
   785 			// Stop mode debugging using Trace32 : specify Trace32 debugger protocol plugin.
       
   786 			//
       
   787 			ConnectionTypeInfo connTI = new ConnectionTypeInfo(
       
   788 					"Carbide Trace32", // Internal ID //$NON-NLS-1$
       
   789 					"Trace32 Configuration", // Display name. //$NON-NLS-1$
       
   790 					"Trace32 Connection"); // Pref panel name
       
   791 
       
   792 			DebuggerCommonData.setLaunchConfigConnSettings(
       
   793 					configuration,
       
   794 					connTI, 
       
   795 					"LAUTERBACH TRACE32 Plugin", //$NON-NLS-1$
       
   796 					""); //$NON-NLS-1$
       
   797 		}
       
   798 	
       
   799 		if (settingsGroup.equals(LaunchConfig_SophiaSTI)) {
       
   800 			// Stop mode debugging using STI : specify Sophia STI debugger protocol plugin.
       
   801 			//
       
   802 			ConnectionTypeInfo connTI = new ConnectionTypeInfo(
       
   803 					"Carbide Sophia STI", // Internal ID //$NON-NLS-1$
       
   804 					"Sophia STI Configuration", // Display name. //$NON-NLS-1$
       
   805 					"Sophia Target Interface Connection"); // Pref panel name
       
   806 
       
   807 			DebuggerCommonData.setLaunchConfigConnSettings(
       
   808 					configuration,
       
   809 					connTI, 
       
   810 					"Sophia Target Interface Plugin", //$NON-NLS-1$
       
   811 					""); //$NON-NLS-1$
       
   812 		}
       
   813 		
       
   814 		// Add the Symbian OS SDK Mapping.
       
   815 		addSymbianSDKMapping(project, configuration);
       
   816 
       
   817 		configuration.setAttribute(ATTR_originalName, configuration.getName());
       
   818 
       
   819 	}
       
   820 
       
   821 	private static void setContextMainTab(
       
   822 			ILaunchConfigurationWorkingCopy configuration, IProject project) {
       
   823 		if (project != null) {
       
   824 			String projectName = project.getName();
       
   825 			configuration.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, projectName);
       
   826 			configuration.setMappedResources( new IResource[] { project });
       
   827 			configuration.rename(DebugPlugin.getDefault().getLaunchManager().generateUniqueLaunchConfigurationNameFrom(projectName));
       
   828 		}
       
   829 	}
       
   830 
       
   831 
       
   832 	/**
       
   833 	 * Should the debugger launch the Symbian emulator (epoc.exe) as the debug process?
       
   834 	 * This should be true in all cases except when the executable is an '.exe'.
       
   835 	 * These can be launched directly. However there is a problem doing this with OS9.1
       
   836 	 * (it will fail after the first launch) so we still require the emulator in this case.	
       
   837 	 * @param buildConfig - current build config
       
   838 	 * @return - true if we should launch epoc.exe as the debug process
       
   839 	 */
       
   840 	public static boolean isEmulatorRequired(ICarbideBuildConfiguration buildConfig, IPath mainExeHostPath, IPath mainExeWorkspaceRelativeMMPPath) {
       
   841 		
       
   842         ICarbideProjectInfo cpi = buildConfig.getCarbideProject();
       
   843         
       
   844 		if (cpi != null && mainExeHostPath != null) {
       
   845 			if ("exe".equalsIgnoreCase(mainExeHostPath.getFileExtension()) && !isSharedLib(cpi.getProject(), mainExeHostPath)) { //$NON-NLS-1$
       
   846 				Version version = cpi.getDefaultConfiguration().getSDK().getOSVersion();
       
   847 				if (!(version.getMajor() == 9 && version.getMinor() == 1)) {
       
   848 					return false;
       
   849 				}
       
   850 
       
   851 				// for 9.1 only and exe extension, check the UID2 and if it's 0x100039CE then
       
   852 				// it needs the emulator, otherwise it doesn't.  see bugzilla #1822 for details.  this
       
   853 				// is basically to work around an issue in the 9.1 emulator.
       
   854 				if (mainExeWorkspaceRelativeMMPPath != null) {
       
   855 					String uid2 = EpocEngineHelper.getUID2(buildConfig, mainExeWorkspaceRelativeMMPPath);
       
   856 					if (uid2 != null) {
       
   857 						if (uid2.compareToIgnoreCase("0x100039CE") != 0) { //$NON-NLS-1$
       
   858 							return false;
       
   859 						}
       
   860 					}
       
   861 				}
       
   862 			}
       
   863 		}
       
   864 		return true;
       
   865 	}
       
   866 
       
   867 	public static boolean isEmulatorRequired(IPath mainExeHostPath)
       
   868 	{
       
   869 		List<ISymbianSDK> sdkList = new ArrayList<ISymbianSDK>();
       
   870 		sdkList = SDKCorePlugin.getSDKManager().getSDKList();
       
   871 		
       
   872 		for (ISymbianSDK currSDK : sdkList){
       
   873 			if (new Path(currSDK.getEPOCROOT()).isPrefixOf(mainExeHostPath))
       
   874 			{
       
   875 			       // Apparently this only works correctly with the S60 emulator.
       
   876 		        if (!currSDK.isS60() &&
       
   877 		        		!currSDK.getFamily().equalsIgnoreCase(ISymbianSDK.TECHVIEW_FAMILY_ID))
       
   878 		        	return true;
       
   879 		        
       
   880 				if ("exe".equalsIgnoreCase(mainExeHostPath.getFileExtension())) { //$NON-NLS-1$
       
   881 					Version version = currSDK.getOSVersion();
       
   882 					if (!(version.getMajor() == 9 && version.getMinor() == 1)) {
       
   883 						return false;
       
   884 					}
       
   885 				}
       
   886 				
       
   887 			}
       
   888 		}
       
   889 		
       
   890 		return true;
       
   891 	}
       
   892 		
       
   893 	// Check if the given file is a shared library (DLL or APP in Symbian ).
       
   894 	//
       
   895 	static public boolean isSharedLib(IProject project, IPath exePath) {
       
   896 		int fileType;
       
   897 		ICExtensionReference[] parserRef;
       
   898 		
       
   899 		try {
       
   900 			parserRef = CCorePlugin.getDefault().getBinaryParserExtensions(project);
       
   901 		} catch (Exception e) {
       
   902 			return false;
       
   903 		};
       
   904 		
       
   905 		for (int i = 0; i < parserRef.length; i++) {
       
   906 			try {
       
   907 				IBinaryParser parser = (IBinaryParser)parserRef[i].createExtension();
       
   908 				IBinaryObject exe = (IBinaryObject)parser.getBinary(exePath);
       
   909 				if (exe != null) {
       
   910 					fileType = exe.getType();
       
   911 					return fileType == IBinaryParser.IBinaryFile.SHARED;
       
   912 				}
       
   913 			} catch (Exception e) {
       
   914 			}
       
   915 		}
       
   916 
       
   917 		try {
       
   918 			IBinaryParser parser = CCorePlugin.getDefault().getDefaultBinaryParser();
       
   919 
       
   920 			IBinaryObject exe = (IBinaryObject)parser.getBinary(exePath);
       
   921 			if (exe != null) {
       
   922 				fileType = exe.getType();
       
   923 				return fileType == IBinaryParser.IBinaryFile.SHARED;
       
   924 			}
       
   925 		} catch (Exception e) {
       
   926 		}
       
   927 		return false;
       
   928 	}
       
   929 
       
   930 	private static void displayWarningDialog(final String msg) {
       
   931 		//  Display warning dialog
       
   932 		IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
       
   933 		if(window == null){
       
   934 			IWorkbenchWindow windows[] = PlatformUI.getWorkbench().getWorkbenchWindows();
       
   935 			window = windows[0];
       
   936 		}
       
   937 
       
   938 		final Shell shell = window.getShell();
       
   939 		//using syncExec could cause a dead-lock
       
   940 		//that is why asyncExec is used
       
   941 		shell.getDisplay().asyncExec( new Runnable() {
       
   942 			public void run() {
       
   943 				MessageDialog.openWarning(shell, Messages.getString("SettingsData.70"), msg); //$NON-NLS-1$
       
   944 			}
       
   945 		} );
       
   946 	}
       
   947 	
       
   948 	
       
   949 	public static boolean isStopModeConfiguration(ILaunchConfiguration configuration) {
       
   950 		try {
       
   951 			ILaunchConfigurationType configurationType = configuration.getType();
       
   952 			String id = configurationType.getIdentifier();
       
   953 			return id.equals(T32_LAUNCH_TYPE_ID) ||
       
   954 			id.endsWith("T32Launch")||//$NON-NLS-1$
       
   955 			id.equals(STI_LAUNCH_TYPE_ID);
       
   956 		} catch (CoreException e) {
       
   957 		}
       
   958 		
       
   959 		return false;
       
   960 	}
       
   961 
       
   962 
       
   963 	public static boolean isAppTRKConfiguration(ILaunchConfiguration configuration) {
       
   964 		try {
       
   965 			ILaunchConfigurationType configurationType = configuration.getType();
       
   966 			String id = configurationType.getIdentifier();
       
   967 			return id.equals(APP_TRK_LAUNCH_TYPE_ID);
       
   968 		} catch (CoreException e) {
       
   969 		}
       
   970 		
       
   971 		return false;
       
   972 	}
       
   973 	
       
   974 	public static boolean isEmulatorConfiguration(ILaunchConfiguration configuration) {
       
   975 		try {
       
   976 			ILaunchConfigurationType configurationType = configuration.getType();
       
   977 			String id = configurationType.getIdentifier();
       
   978 			return id.equals(EMULATION_LAUNCH_TYPE_ID);
       
   979 		} catch (CoreException e) {
       
   980 		}
       
   981 		
       
   982 		return false;
       
   983 	}
       
   984 	
       
   985 	public static void setProcessToLaunch(ILaunchConfigurationWorkingCopy configuration, IPath path) {
       
   986 		configuration.setAttribute(PreferenceConstants.J_PN_RemoteProcessToLaunch, path.toOSString());
       
   987 	}
       
   988 	
       
   989 }