[Esbox-commits] r131 - in trunk/org.indt.esbox.debug: . META-INF src/org/indt/esbox/debug/internal src/org/indt/esbox/debug/ui

raul at garage.maemo.org raul at garage.maemo.org
Mon Oct 15 20:45:06 EEST 2007


Author: raul
Date: 2007-10-15 20:45:05 +0300 (Mon, 15 Oct 2007)
New Revision: 131

Added:
   trunk/org.indt.esbox.debug/src/org/indt/esbox/debug/internal/ESboxGDBRemoteCDIDebugger.java
   trunk/org.indt.esbox.debug/src/org/indt/esbox/debug/ui/GDBRemoteDebuggerPage.java
Modified:
   trunk/org.indt.esbox.debug/META-INF/MANIFEST.MF
   trunk/org.indt.esbox.debug/plugin.xml
   trunk/org.indt.esbox.debug/src/org/indt/esbox/debug/ui/GDBServerDebuggerPage.java
Log:


Modified: trunk/org.indt.esbox.debug/META-INF/MANIFEST.MF
===================================================================
--- trunk/org.indt.esbox.debug/META-INF/MANIFEST.MF	2007-10-15 15:14:40 UTC (rev 130)
+++ trunk/org.indt.esbox.debug/META-INF/MANIFEST.MF	2007-10-15 17:45:05 UTC (rev 131)
@@ -14,5 +14,7 @@
  org.eclipse.debug.ui,
  org.indt.esbox.core,
  org.eclipse.cdt.ui,
- org.eclipse.cdt.debug.ui
+ org.eclipse.cdt.debug.ui,
+ org.indt.esbox.ui,
+ com.jcraft.jsch
 Eclipse-LazyStart: true

Modified: trunk/org.indt.esbox.debug/plugin.xml
===================================================================
--- trunk/org.indt.esbox.debug/plugin.xml	2007-10-15 15:14:40 UTC (rev 130)
+++ trunk/org.indt.esbox.debug/plugin.xml	2007-10-15 17:45:05 UTC (rev 131)
@@ -16,13 +16,16 @@
             cpu="*"
             id="esboxGDBServerDebugger"
             modes="run"
-            name="ESbox GDB Server Debugger"
+            name="ESbox gdbserver Local Debugger"
             platform="*">
       </debugger>
       <debugger
             class="org.indt.esbox.debug.CDIDebugger21"
+            cpu="*"
             id="esboxGDBRemoteDebugger"
-            name="ESbox GDB Remote Debugger">
+            modes="run"
+            name="ESbox gdbserver Debugger on Device"
+            platform="*">
       </debugger>
    </extension>
    <extension

Added: trunk/org.indt.esbox.debug/src/org/indt/esbox/debug/internal/ESboxGDBRemoteCDIDebugger.java
===================================================================
--- trunk/org.indt.esbox.debug/src/org/indt/esbox/debug/internal/ESboxGDBRemoteCDIDebugger.java	                        (rev 0)
+++ trunk/org.indt.esbox.debug/src/org/indt/esbox/debug/internal/ESboxGDBRemoteCDIDebugger.java	2007-10-15 17:45:05 UTC (rev 131)
@@ -0,0 +1,228 @@
+/*******************************************************************************
+ * Copyright (c) 2007 INdT.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Raul Herbster (raul at embedded.ufcg.edu.br) (UFCG) - initial API and implementation
+ *******************************************************************************/
+
+package org.indt.esbox.debug.internal;
+
+import java.io.File;
+
+import org.eclipse.cdt.core.IBinaryParser.IBinaryObject;
+import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants;
+import org.eclipse.cdt.debug.core.cdi.model.ICDITarget;
+import org.eclipse.cdt.debug.mi.core.IGDBServerMILaunchConfigurationConstants;
+import org.eclipse.cdt.debug.mi.core.IMIConstants;
+import org.eclipse.cdt.debug.mi.core.IMILaunchConfigurationConstants;
+import org.eclipse.cdt.debug.mi.core.MIException;
+import org.eclipse.cdt.debug.mi.core.MIPlugin;
+import org.eclipse.cdt.debug.mi.core.MISession;
+import org.eclipse.cdt.debug.mi.core.cdi.Session;
+import org.eclipse.cdt.debug.mi.core.cdi.model.Target;
+import org.eclipse.cdt.debug.mi.core.command.CommandFactory;
+import org.eclipse.cdt.debug.mi.core.command.MIGDBSet;
+import org.eclipse.cdt.debug.mi.core.command.MITargetSelect;
+import org.eclipse.cdt.debug.mi.core.output.MIInfo;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Preferences;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.indt.esbox.core.CoreActivator;
+import org.indt.esbox.core.ESboxPreferenceConstants;
+import org.indt.esbox.core.ErrorLogger;
+import org.indt.esbox.core.StreamMonitor;
+import org.indt.esbox.core.scratchbox.ScratchboxCommandLauncher;
+import org.indt.esbox.core.scratchbox.ScratchboxException;
+import org.indt.esbox.debug.DebugActivator;
+import org.indt.esbox.ui.UIActivator;
+import org.indt.esbox.ui.connection.ExecConnection;
+import org.indt.esbox.ui.connection.Sftp;
+
+public class ESboxGDBRemoteCDIDebugger extends ESboxGDBCDIDebugger {
+
+	public static final String ATTR_GDB_SERVER_REMOTE = ICDTLaunchConfigurationConstants.CDT_LAUNCH_ID + ".gdb_server_remote"; //$NON-NLS-1$
+	
+	public static final String ATTR_TRANSFER_FILE = ICDTLaunchConfigurationConstants.CDT_LAUNCH_ID + ".gdb_transfer_file"; //$NON-NLS-1$
+	
+	public static final String ATTR_REMOTE_LOCATION = ICDTLaunchConfigurationConstants.CDT_LAUNCH_ID + ".gdb_remote_location"; //$NON-NLS-1$
+
+	public static final boolean GDB_SERVER_REMOTE_DEFAULT = true;
+	
+	public static final boolean TRANSFER_FILE_DEFAULT = true;
+	
+	public static final String REMOTE_LOCATION_DEFAULT = "/home/user";
+		
+	/* (non-Javadoc)
+	 * @see org.eclipse.cdt.debug.mi.core.GDBCDIDebugger#createLaunchSession(org.eclipse.debug.core.ILaunchConfiguration, org.eclipse.cdt.core.IBinaryParser.IBinaryExecutable, org.eclipse.core.runtime.IProgressMonitor)
+	 */
+	public Session createLaunchSession(ILaunchConfiguration config, IBinaryObject exe, IProgressMonitor monitor)
+			throws CoreException {
+				
+		boolean gdbserver = GDB_SERVER_REMOTE_DEFAULT;
+		boolean tranferFile = TRANSFER_FILE_DEFAULT;
+
+		try {
+			gdbserver = config.getAttribute(ATTR_GDB_SERVER_REMOTE, GDB_SERVER_REMOTE_DEFAULT);
+			tranferFile = config.getAttribute(ATTR_TRANSFER_FILE, TRANSFER_FILE_DEFAULT);
+		} catch (CoreException e) {
+			e.printStackTrace();
+		}
+
+		if (tranferFile) {
+			// start GDB server inside scratchbox
+			transferFileToDevice(exe,config);
+			// add 0.5 secs wait for starting GDB server
+			try {
+				Thread.sleep(500);
+			} catch (InterruptedException e) {
+				e.printStackTrace();
+			}
+		}
+		
+		if (gdbserver) {			
+			// start GDB server inside scratchbox
+			startRemoteGDBServer(exe,config);
+			// add 0.5 secs wait for starting GDB server
+			try {
+				Thread.sleep(500);
+			} catch (InterruptedException e) {
+				e.printStackTrace();
+			}
+		}		
+
+		Session session = null;
+		boolean failed = false;
+		try {			
+			String gdb = config.getAttribute(IMILaunchConfigurationConstants.ATTR_DEBUG_NAME, "gdb"); 
+			File cwd = getProjectPath(config).toFile();
+			String gdbinit = config.getAttribute(IMILaunchConfigurationConstants.ATTR_GDB_INIT, ".gdbinit");
+			if (config.getAttribute(IGDBServerMILaunchConfigurationConstants.ATTR_REMOTE_TCP, false)) {
+				String remote = config.getAttribute(IGDBServerMILaunchConfigurationConstants.ATTR_HOST, "invalid");
+				remote += ":";
+				remote += config.getAttribute(IGDBServerMILaunchConfigurationConstants.ATTR_PORT, "invalid"); 
+				String[] args = new String[] {"remote", remote}; 
+				session = DebugActivator.getDefault().createCSession(gdb, exe.getPath().toFile(), 0, args, cwd, gdbinit, monitor);
+			} else {
+				MIPlugin plugin = MIPlugin.getDefault();
+				Preferences prefs = plugin.getPluginPreferences();
+				int launchTimeout = prefs.getInt(IMIConstants.PREF_REQUEST_LAUNCH_TIMEOUT);
+
+				String remote = config.getAttribute(IGDBServerMILaunchConfigurationConstants.ATTR_DEV, "invalid"); 
+				String remoteBaud = config.getAttribute(IGDBServerMILaunchConfigurationConstants.ATTR_DEV_SPEED, "invalid");				
+				session = DebugActivator.getDefault().createCSession(gdb, exe.getPath().toFile(), -1, null, cwd, gdbinit, monitor);
+				ICDITarget[] targets = session.getTargets();
+				for (int i = 0; i < targets.length; ++i) {
+					Target target = (Target)targets[i];
+					MISession miSession = target.getMISession();
+					CommandFactory factory = miSession.getCommandFactory();
+					MIGDBSet setRemoteBaud = factory.createMIGDBSet(new String[]{"remotebaud", remoteBaud}); 
+					// Set serial line parameters
+					miSession.postCommand(setRemoteBaud, launchTimeout);
+					MIInfo info = setRemoteBaud.getMIInfo();
+					if (info == null) {
+						throw new MIException (MIPlugin.getResourceString("src.GDBServerDebugger.Can_not_set_Baud")); 
+					}
+					MITargetSelect select = factory.createMITargetSelect(new String[] {"remote", remote}); 
+					miSession.postCommand(select, launchTimeout);
+					select.getMIInfo();
+					if (info == null) {
+						throw new MIException (MIPlugin.getResourceString("src.common.No_answer")); 
+					}
+				}
+			}
+			initializeLibraries(config, session);
+			return session;
+		} catch (Exception e) {
+			// Catch all wrap them up and rethrow
+			failed = true;
+			if (e instanceof CoreException) {
+				throw (CoreException)e;
+			}
+			throw newCoreException(e);
+		} finally {
+			if (failed) {
+				if (session != null) {
+					try {
+						session.terminate();
+					} catch (Exception ex) {
+						// ignore the exception here.
+					}
+				}
+			}
+		}
+
+	}
+
+	/**
+	 * @param exe
+	 * 
+	 * Method that starts GDB server inside Scratchbox with binary that comes
+	 * from param. Command that will run inside Scratchbox can modify in Window ->
+	 * Preferences -> Scratchbox Preferences
+	 */
+	private void startRemoteGDBServer(IBinaryObject exe, ILaunchConfiguration config) {
+		// get preferences from SbCorePlugin		
+		Preferences prefs = CoreActivator.getDefault().getPluginPreferences();
+		
+		String command = prefs.getString(ESboxPreferenceConstants.SBOX_GDB_REMOTE.toString());
+		
+		String localIP = "";		
+		String port = "";
+		String remoteLocation = "";
+		try {
+			remoteLocation = config.getAttribute(ESboxGDBRemoteCDIDebugger.ATTR_REMOTE_LOCATION, ESboxGDBRemoteCDIDebugger.REMOTE_LOCATION_DEFAULT);
+			remoteLocation += File.separator + exe.getName();
+			port = config.getAttribute( IGDBServerMILaunchConfigurationConstants.ATTR_PORT, "1234" ); 
+		} catch (CoreException e) {
+			ErrorLogger errorLogger = UIActivator.getDefault().getErrorLogger();
+			errorLogger.logAndShowError("Connection error", e);
+		}
+			
+		// check if command exist
+		if (command.length() > 0) {
+			command = command.replaceAll("\\$\\{IP\\}", localIP);
+			command = command.replaceAll("\\$\\{PORT\\}", port);
+			command = command.replaceAll("\\$\\{BINARY\\}", remoteLocation);
+		}
+		
+		ExecConnection execConnection = ExecConnection.getInstance();
+		execConnection.setCommand(command);
+		try {
+			execConnection.start();
+			
+			// print all output to console
+			new StreamMonitor(execConnection.getInputStream(), true, new String("Starting gdbserver in remote device"));
+			// print all errors to console
+			new StreamMonitor(execConnection.getErrInputStream(), false, null);			
+		} catch (Exception e) {
+			ErrorLogger errorLogger = UIActivator.getDefault().getErrorLogger();
+			errorLogger.logAndShowError("Connection error", e);
+		}
+		
+		execConnection.stop();
+	}	
+	
+	private void transferFileToDevice(IBinaryObject exe, ILaunchConfiguration config) {
+
+		try {		
+			//open a sftp channel
+			Sftp sftp = new Sftp();
+			//start this channel
+			sftp.start();			
+			//get all the files and copy them to the remote directory
+			String remoteLocation = config.getAttribute(ESboxGDBRemoteCDIDebugger.ATTR_REMOTE_LOCATION, ESboxGDBRemoteCDIDebugger.REMOTE_LOCATION_DEFAULT);
+			sftp.put(exe.getPath().toOSString(),remoteLocation);			
+			sftp.stop();	
+		} catch (Exception e) {
+			e.printStackTrace();			
+			return;
+		} 
+	}
+	
+}

Added: trunk/org.indt.esbox.debug/src/org/indt/esbox/debug/ui/GDBRemoteDebuggerPage.java
===================================================================
--- trunk/org.indt.esbox.debug/src/org/indt/esbox/debug/ui/GDBRemoteDebuggerPage.java	                        (rev 0)
+++ trunk/org.indt.esbox.debug/src/org/indt/esbox/debug/ui/GDBRemoteDebuggerPage.java	2007-10-15 17:45:05 UTC (rev 131)
@@ -0,0 +1,366 @@
+/*******************************************************************************
+ * Copyright (c) 2007 INdT.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Raul Herbster (raul at embedded.ufcg.edu.br) (UFCG) - initial API and implementation
+ *******************************************************************************/
+package org.indt.esbox.debug.ui;
+
+import java.io.File;
+
+import org.eclipse.cdt.debug.mi.core.IGDBServerMILaunchConfigurationConstants;
+import org.eclipse.cdt.debug.mi.internal.ui.GDBDebuggerPage;
+import org.eclipse.cdt.debug.mi.internal.ui.MIUIMessages;
+import org.eclipse.cdt.debug.mi.internal.ui.PixelConverter;
+import org.eclipse.cdt.debug.mi.internal.ui.SerialPortSettingsBlock;
+import org.eclipse.cdt.debug.mi.internal.ui.TCPSettingsBlock;
+import org.eclipse.cdt.debug.mi.internal.ui.dialogfields.ComboDialogField;
+import org.eclipse.cdt.debug.mi.internal.ui.dialogfields.DialogField;
+import org.eclipse.cdt.debug.mi.internal.ui.dialogfields.IDialogFieldListener;
+import org.eclipse.cdt.debug.mi.internal.ui.dialogfields.LayoutUtil;
+import org.eclipse.cdt.utils.ui.controls.ControlFactory;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.StackLayout;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.FileDialog;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.TabFolder;
+import org.eclipse.swt.widgets.TabItem;
+import org.eclipse.swt.widgets.Text;
+import org.indt.esbox.debug.internal.ESboxGDBRemoteCDIDebugger;
+
+/**
+ *
+ */
+public class GDBRemoteDebuggerPage extends GDBDebuggerPage {
+	
+	private final static String CONNECTION_TCP = MIUIMessages.getString( "GDBServerDebuggerPage.0" ); //$NON-NLS-1$
+
+	private final static String CONNECTION_SERIAL = MIUIMessages.getString( "GDBServerDebuggerPage.1" ); //$NON-NLS-1$
+
+	private ComboDialogField fConnectionField;
+
+	private String[] fConnections = new String[] { CONNECTION_TCP, CONNECTION_SERIAL };
+
+	private TCPSettingsBlock fTCPBlock;
+
+	private SerialPortSettingsBlock fSerialBlock;
+
+	private Composite fConnectionStack;
+	
+	private Button fGDBServerButton;
+	
+	private Button fTransferBinaryButton;
+	
+	private Text fRemoteLocationText;
+
+	private boolean fIsInitializing = false;
+
+	/**
+	 * Constructor.
+	 */
+	public GDBRemoteDebuggerPage() {
+		super();
+		fConnectionField = createConnectionField();
+		fTCPBlock = new TCPSettingsBlock();
+		fSerialBlock = new SerialPortSettingsBlock();
+		fTCPBlock.addObserver( this );
+		fSerialBlock.addObserver( this );
+	}
+
+	@Override
+	public void createTabs(TabFolder tabFolder) {
+		super.createTabs(tabFolder);
+		createConnectionTab(tabFolder);
+	}
+	
+	public void createConnectionTab( TabFolder tabFolder ) {
+		TabItem tabItem = new TabItem( tabFolder, SWT.NONE );
+		tabItem.setText( "Connection" ); //$NON-NLS-1$
+		Composite comp = ControlFactory.createCompositeEx( fTabFolder, 1, GridData.FILL_BOTH );
+		((GridLayout)comp.getLayout()).makeColumnsEqualWidth = false;
+		tabItem.setControl( comp );
+		
+		Composite remoteComp = ControlFactory.createCompositeEx( comp, 4, GridData.FILL_HORIZONTAL );
+		((GridLayout)remoteComp.getLayout()).makeColumnsEqualWidth = false;
+		
+		Label label2 = new Label(remoteComp, SWT.LEFT); //$NON-NLS-1$
+		label2.setText("Remote location: ");
+		GridData gd = new GridData();
+		label2.setLayoutData( gd );
+		fRemoteLocationText = ControlFactory.createTextField( remoteComp, SWT.SINGLE | SWT.BORDER );
+		gd = new GridData( GridData.FILL_BOTH );
+		gd.horizontalSpan = 3;
+		fRemoteLocationText.setLayoutData( gd );
+		fRemoteLocationText.setText(ESboxGDBRemoteCDIDebugger.REMOTE_LOCATION_DEFAULT);
+		fRemoteLocationText.addModifyListener( new ModifyListener() {
+			public void modifyText( ModifyEvent evt ) {
+				updateLaunchConfigurationDialog();
+			}
+		} );
+		
+		fGDBServerButton = createCheckButton(comp, "Start gdbServer in remote device automatically");
+		fGDBServerButton.setSelection(ESboxGDBRemoteCDIDebugger.GDB_SERVER_REMOTE_DEFAULT);
+		fGDBServerButton.addSelectionListener(new SelectionAdapter() {
+
+			public void widgetSelected(SelectionEvent evt) {
+				updateLaunchConfigurationDialog();
+
+			}
+		});
+		
+		fTransferBinaryButton = createCheckButton(comp, "Copy binary to remote target");
+		fTransferBinaryButton.setSelection(ESboxGDBRemoteCDIDebugger.TRANSFER_FILE_DEFAULT);
+		fTransferBinaryButton.addSelectionListener(new SelectionAdapter() {
+
+			public void widgetSelected(SelectionEvent evt) {
+				updateLaunchConfigurationDialog();
+
+			}
+		});
+				
+		extendMainTab( comp );
+	}
+	
+	/*
+	 *  (non-Javadoc)
+	 * @see org.eclipse.cdt.debug.mi.internal.ui.GDBDebuggerPage#createMainTab(org.eclipse.swt.widgets.TabFolder)
+	 */
+	public void createMainTab( TabFolder tabFolder ) {
+		TabItem tabItem = new TabItem( tabFolder, SWT.NONE );
+		tabItem.setText( MIUIMessages.getString( "GDBServerDebuggerPage.2" ) ); //$NON-NLS-1$
+		Composite comp = ControlFactory.createCompositeEx( fTabFolder, 1, GridData.FILL_BOTH );
+		((GridLayout)comp.getLayout()).makeColumnsEqualWidth = false;
+		tabItem.setControl( comp );
+		Composite subComp = ControlFactory.createCompositeEx( comp, 3, GridData.FILL_HORIZONTAL );
+		((GridLayout)subComp.getLayout()).makeColumnsEqualWidth = false;
+		Label label = ControlFactory.createLabel( subComp, MIUIMessages.getString( "GDBServerDebuggerPage.3" ) ); //$NON-NLS-1$
+		GridData gd = new GridData();
+		label.setLayoutData( gd );
+						
+		fGDBCommandText = ControlFactory.createTextField( subComp, SWT.SINGLE | SWT.BORDER );
+		fGDBCommandText.addModifyListener( new ModifyListener() {
+
+			public void modifyText( ModifyEvent evt ) {
+				if ( !isInitializing() )
+					updateLaunchConfigurationDialog();
+			}
+		} );
+		Button button = createPushButton( subComp, MIUIMessages.getString( "GDBServerDebuggerPage.4" ), null ); //$NON-NLS-1$
+		button.addSelectionListener( new SelectionAdapter() {
+
+			public void widgetSelected( SelectionEvent evt ) {
+				if ( !isInitializing() ) {
+					handleGDBButtonSelected();
+					updateLaunchConfigurationDialog();
+				}
+			}
+
+			private void handleGDBButtonSelected() {
+				FileDialog dialog = new FileDialog( getShell(), SWT.NONE );
+				dialog.setText( MIUIMessages.getString( "GDBServerDebuggerPage.5" ) ); //$NON-NLS-1$
+				String gdbCommand = fGDBCommandText.getText().trim();
+				int lastSeparatorIndex = gdbCommand.lastIndexOf( File.separator );
+				if ( lastSeparatorIndex != -1 ) {
+					dialog.setFilterPath( gdbCommand.substring( 0, lastSeparatorIndex ) );
+				}
+				String res = dialog.open();
+				if ( res == null ) {
+					return;
+				}
+				fGDBCommandText.setText( res );
+			}
+		} );
+		label = ControlFactory.createLabel( subComp, MIUIMessages.getString( "GDBServerDebuggerPage.6" ) ); //$NON-NLS-1$
+		gd = new GridData();
+		label.setLayoutData( gd );
+		fGDBInitText = ControlFactory.createTextField( subComp, SWT.SINGLE | SWT.BORDER );
+		gd = new GridData( GridData.FILL_HORIZONTAL );
+		fGDBInitText.setLayoutData( gd );
+		fGDBInitText.addModifyListener( new ModifyListener() {
+
+			public void modifyText( ModifyEvent evt ) {
+				if ( !isInitializing() )
+					updateLaunchConfigurationDialog();
+			}
+		} );
+		button = createPushButton( subComp, MIUIMessages.getString( "GDBServerDebuggerPage.7" ), null ); //$NON-NLS-1$
+		button.addSelectionListener( new SelectionAdapter() {
+
+			public void widgetSelected( SelectionEvent evt ) {
+				if ( !isInitializing() ) {
+					handleGDBInitButtonSelected();
+					updateLaunchConfigurationDialog();
+				}
+			}
+
+			private void handleGDBInitButtonSelected() {
+				FileDialog dialog = new FileDialog( getShell(), SWT.NONE );
+				dialog.setText( MIUIMessages.getString( "GDBServerDebuggerPage.8" ) ); //$NON-NLS-1$
+				String gdbCommand = fGDBInitText.getText().trim();
+				int lastSeparatorIndex = gdbCommand.lastIndexOf( File.separator );
+				if ( lastSeparatorIndex != -1 ) {
+					dialog.setFilterPath( gdbCommand.substring( 0, lastSeparatorIndex ) );
+				}
+				String res = dialog.open();
+				if ( res == null ) {
+					return;
+				}
+				fGDBInitText.setText( res );
+			}
+		} );
+		
+		label = ControlFactory.createLabel( subComp, MIUIMessages.getString( "StandardGDBDebuggerPage.9" ), //$NON-NLS-1$
+				200, SWT.DEFAULT, SWT.WRAP );
+		gd = new GridData( GridData.FILL_HORIZONTAL );
+		gd.horizontalSpan = 3;
+		gd.widthHint = 200;
+		label.setLayoutData( gd );
+		
+		createProtocolCombo( subComp );
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.eclipse.cdt.debug.mi.internal.ui.GDBDebuggerPage#extendMainTab(org.eclipse.swt.widgets.Composite)
+	 */
+	protected void extendMainTab( Composite parent ) {
+		Composite comp = ControlFactory.createCompositeEx( parent, 2, GridData.FILL_BOTH );
+		((GridLayout)comp.getLayout()).makeColumnsEqualWidth = false;
+		fConnectionField.doFillIntoGrid( comp, 2 );
+		((GridData)fConnectionField.getComboControl( null ).getLayoutData()).horizontalAlignment = GridData.BEGINNING;
+		PixelConverter converter = new PixelConverter( comp );
+		LayoutUtil.setWidthHint( fConnectionField.getComboControl( null ), converter.convertWidthInCharsToPixels( 15 ) );
+		fConnectionStack = ControlFactory.createCompositeEx( comp, 1, GridData.FILL_BOTH );
+		StackLayout stackLayout = new StackLayout();
+		fConnectionStack.setLayout( stackLayout );
+		((GridData)fConnectionStack.getLayoutData()).horizontalSpan = 2;
+		fTCPBlock.createBlock( fConnectionStack );
+		fSerialBlock.createBlock( fConnectionStack );
+	}
+
+	private ComboDialogField createConnectionField() {
+		ComboDialogField field = new ComboDialogField( SWT.DROP_DOWN | SWT.READ_ONLY );
+		field.setLabelText( MIUIMessages.getString( "GDBServerDebuggerPage.9" ) ); //$NON-NLS-1$
+		field.setItems( fConnections );
+		field.setDialogFieldListener( new IDialogFieldListener() {
+
+			public void dialogFieldChanged( DialogField f ) {
+				if ( !isInitializing() )
+					connectionTypeChanged();
+			}
+		} );
+		return field;
+	}
+
+	protected void connectionTypeChanged() {
+		connectionTypeChanged0();
+		updateLaunchConfigurationDialog();
+	}
+
+	private void connectionTypeChanged0() {
+		((StackLayout)fConnectionStack.getLayout()).topControl = null;
+		int index = fConnectionField.getSelectionIndex();
+		if ( index >= 0 && index < fConnections.length ) {
+			String[] connTypes = fConnectionField.getItems();
+			if ( CONNECTION_TCP.equals( connTypes[index] ) )
+				((StackLayout)fConnectionStack.getLayout()).topControl = fTCPBlock.getControl();
+			else if ( CONNECTION_SERIAL.equals( connTypes[index] ) )
+				((StackLayout)fConnectionStack.getLayout()).topControl = fSerialBlock.getControl();
+		}
+		fConnectionStack.layout();
+	}
+
+	public boolean isValid( ILaunchConfiguration launchConfig ) {
+		if ( super.isValid( launchConfig ) ) {
+			setErrorMessage( null );
+			setMessage( null );
+			int index = fConnectionField.getSelectionIndex();
+			if ( index >= 0 && index < fConnections.length ) {
+				String[] connTypes = fConnectionField.getItems();
+				if ( CONNECTION_TCP.equals( connTypes[index] ) ) {
+					if ( !fTCPBlock.isValid( launchConfig ) ) {
+						setErrorMessage( fTCPBlock.getErrorMessage() );
+						return false;
+					}
+				}
+				else if ( CONNECTION_SERIAL.equals( connTypes[index] ) ) {
+					if ( !fSerialBlock.isValid( launchConfig ) ) {
+						setErrorMessage( fSerialBlock.getErrorMessage() );
+						return false;
+					}
+				}
+				return true;
+			}
+		}
+		return false;
+	}
+
+	public void initializeFrom( ILaunchConfiguration configuration ) {
+		setInitializing( true );
+		super.initializeFrom( configuration );
+		boolean isTcp = false;
+		try {
+			isTcp = configuration.getAttribute( IGDBServerMILaunchConfigurationConstants.ATTR_REMOTE_TCP, false );
+		}
+		catch( CoreException e ) {
+		}
+		fTCPBlock.initializeFrom( configuration );
+		fSerialBlock.initializeFrom( configuration );
+		fConnectionField.selectItem( (isTcp) ? 0 : 1 );
+		connectionTypeChanged0();
+		setInitializing( false );
+		updateGdbServerStateFromConfig(configuration);
+	}
+	
+    protected void updateGdbServerStateFromConfig(ILaunchConfiguration config) {
+    }
+
+	public void performApply( ILaunchConfigurationWorkingCopy configuration ) {
+		super.performApply( configuration );
+		if ( fConnectionField != null )
+			configuration.setAttribute( IGDBServerMILaunchConfigurationConstants.ATTR_REMOTE_TCP, fConnectionField.getSelectionIndex() == 0 );
+		fTCPBlock.performApply( configuration );
+		fSerialBlock.performApply( configuration );
+		configuration.setAttribute(ESboxGDBRemoteCDIDebugger.ATTR_GDB_SERVER_REMOTE, fGDBServerButton.getSelection());
+		configuration.setAttribute(ESboxGDBRemoteCDIDebugger.ATTR_TRANSFER_FILE, fTransferBinaryButton.getSelection());
+		configuration.setAttribute(ESboxGDBRemoteCDIDebugger.ATTR_REMOTE_LOCATION, fRemoteLocationText.getText());
+	}
+
+	public void setDefaults( ILaunchConfigurationWorkingCopy configuration ) {
+		super.setDefaults( configuration );
+		configuration.setAttribute( IGDBServerMILaunchConfigurationConstants.ATTR_REMOTE_TCP, true );
+		fTCPBlock.setDefaults( configuration );
+		configuration.setAttribute( IGDBServerMILaunchConfigurationConstants.ATTR_PORT, "1234" );
+		fSerialBlock.setDefaults( configuration );
+    	configuration.setAttribute(ESboxGDBRemoteCDIDebugger.ATTR_GDB_SERVER_REMOTE,
+    			ESboxGDBRemoteCDIDebugger.GDB_SERVER_REMOTE_DEFAULT);
+    	configuration.setAttribute(ESboxGDBRemoteCDIDebugger.ATTR_TRANSFER_FILE,
+    			ESboxGDBRemoteCDIDebugger.TRANSFER_FILE_DEFAULT);
+    	configuration.setAttribute(ESboxGDBRemoteCDIDebugger.ATTR_REMOTE_LOCATION, 
+    			ESboxGDBRemoteCDIDebugger.REMOTE_LOCATION_DEFAULT);
+	}
+
+	protected boolean isInitializing() {
+		return fIsInitializing;
+	}
+
+	private void setInitializing( boolean isInitializing ) {
+		fIsInitializing = isInitializing;
+	}
+}

Modified: trunk/org.indt.esbox.debug/src/org/indt/esbox/debug/ui/GDBServerDebuggerPage.java
===================================================================
--- trunk/org.indt.esbox.debug/src/org/indt/esbox/debug/ui/GDBServerDebuggerPage.java	2007-10-15 15:14:40 UTC (rev 130)
+++ trunk/org.indt.esbox.debug/src/org/indt/esbox/debug/ui/GDBServerDebuggerPage.java	2007-10-15 17:45:05 UTC (rev 131)
@@ -77,7 +77,35 @@
 		fTCPBlock.addObserver( this );
 		fSerialBlock.addObserver( this );
 	}
+	
+	@Override
+	public void createTabs(TabFolder tabFolder) {
+		super.createTabs(tabFolder);
+		createConnectionTab(tabFolder);
+	}
+	
+	public void createConnectionTab(TabFolder tabFolder) {
+		TabItem tabItem = new TabItem( tabFolder, SWT.NONE );
+		tabItem.setText( "Connection" ); //$NON-NLS-1$
+		Composite comp = ControlFactory.createCompositeEx( fTabFolder, 1, GridData.FILL_BOTH );
+		((GridLayout)comp.getLayout()).makeColumnsEqualWidth = false;
+		tabItem.setControl( comp );
+		Composite subComp = ControlFactory.createCompositeEx( comp, 3, GridData.FILL_HORIZONTAL );
+		((GridLayout)subComp.getLayout()).makeColumnsEqualWidth = false;
 
+		fGDBServerButton = createCheckButton(comp, "Start gdbServer in Scratchbox automatically");
+		fGDBServerButton.setSelection(ESboxGDBServerCDIDebugger.GDB_SERVER_DEFAULT);
+		fGDBServerButton.addSelectionListener(new SelectionAdapter() {
+
+			public void widgetSelected(SelectionEvent evt) {
+				updateLaunchConfigurationDialog();
+
+			}
+		});
+								
+		extendMainTab( comp );
+	}
+
 	/*
 	 *  (non-Javadoc)
 	 * @see org.eclipse.cdt.debug.mi.internal.ui.GDBDebuggerPage#createMainTab(org.eclipse.swt.widgets.TabFolder)
@@ -93,17 +121,6 @@
 		Label label = ControlFactory.createLabel( subComp, MIUIMessages.getString( "GDBServerDebuggerPage.3" ) ); //$NON-NLS-1$
 		GridData gd = new GridData();
 		label.setLayoutData( gd );
-
-		fGDBServerButton = createCheckButton(comp, "Start gdbServer in Scratchbox automatically");
-		fGDBServerButton.setSelection(ESboxGDBServerCDIDebugger.GDB_SERVER_DEFAULT);
-		fGDBServerButton.addSelectionListener(new SelectionAdapter() {
-
-			public void widgetSelected(SelectionEvent evt) {
-				updateLaunchConfigurationDialog();
-
-			}
-		});
-		
 				
 		fGDBCommandText = ControlFactory.createTextField( subComp, SWT.SINGLE | SWT.BORDER );
 		fGDBCommandText.addModifyListener( new ModifyListener() {
@@ -176,7 +193,14 @@
 				fGDBInitText.setText( res );
 			}
 		} );
-		extendMainTab( comp );
+		
+		label = ControlFactory.createLabel( subComp, MIUIMessages.getString( "StandardGDBDebuggerPage.9" ), //$NON-NLS-1$
+				200, SWT.DEFAULT, SWT.WRAP );
+		gd = new GridData( GridData.FILL_HORIZONTAL );
+		gd.horizontalSpan = 3;
+		gd.widthHint = 200;
+		label.setLayoutData( gd );
+		
 		createProtocolCombo( subComp );
 	}
 



More information about the Esbox-commits mailing list