From 73c1e5e2248432ac6740d2d033f4eb8cb7c4e26e Mon Sep 17 00:00:00 2001 From: Marc Khouzam Date: Thu, 20 Nov 2014 10:57:54 -0500 Subject: [PATCH] Bug 450080 - Add option for remote launch to stand-alone debugger Change-Id: Ifcbfd598d90305ac24bddf96893d4170201858c9 Signed-off-by: Marc Khouzam Reviewed-on: https://git.eclipse.org/r/36700 Tested-by: Hudson CI Reviewed-by: Jeff Johnston Tested-by: Jeff Johnston --- .../tasks/cdt_t_standalone_startup.htm | 17 +- .../plugin.properties | 4 + .../plugin.xml | 7 + .../scripts/README | 15 +- .../scripts/cdtdebug.sh | 5 +- .../ApplicationActionBarAdvisor.java | 33 +++ .../ApplicationWorkbenchWindowAdvisor.java | 84 +++++- .../cdt/debug/application/CoreFileDialog.java | 6 +- .../cdt/debug/application/Messages.java | 18 +- .../application/NewExecutableDialog.java | 6 +- .../application/RemoteExecutableDialog.java | 251 ++++++++++++++++++ .../application/RemoteExecutableInfo.java | 70 +++++ .../cdt/debug/application/messages.properties | 21 +- .../application/DebugRemoteExecutable.java | 86 ++++++ .../DebugRemoteExecutableHandler.java | 67 +++++ 15 files changed, 671 insertions(+), 19 deletions(-) create mode 100644 debug/org.eclipse.cdt.debug.application/src/org/eclipse/cdt/debug/application/RemoteExecutableDialog.java create mode 100644 debug/org.eclipse.cdt.debug.application/src/org/eclipse/cdt/debug/application/RemoteExecutableInfo.java create mode 100644 debug/org.eclipse.cdt.debug.application/src/org/eclipse/cdt/internal/debug/application/DebugRemoteExecutable.java create mode 100644 debug/org.eclipse.cdt.debug.application/src/org/eclipse/cdt/internal/debug/application/DebugRemoteExecutableHandler.java diff --git a/debug/org.eclipse.cdt.debug.application.doc/tasks/cdt_t_standalone_startup.htm b/debug/org.eclipse.cdt.debug.application.doc/tasks/cdt_t_standalone_startup.htm index d88f34d9313..faaf1261120 100644 --- a/debug/org.eclipse.cdt.debug.application.doc/tasks/cdt_t_standalone_startup.htm +++ b/debug/org.eclipse.cdt.debug.application.doc/tasks/cdt_t_standalone_startup.htm @@ -49,6 +49,21 @@ as desired. If the executable location you specify is invalid or no executable a dialog will be brought up to allow you to enter the required information. The dialog will be appropriate to whether you have selected to debug a core file (-c specified) or not.

+

-r <addr:port>

+

This option specified a hostname or IP address and and IP port to connect to to perform remote debugging. +The gdbserver must be running on the target and waiting for a connection on the specified port. +This option can be used at the same time as the -a option. In such a case +a Remote-Attach session will be started allowing the user to attach to +different processes on the remote target. The user will need to press +the 'connect' button or use the context-menu of the Debug view to choose one or more processes +to attach to. In this case the -e flag is optional, and when not specified, +a dialog will be used instead to prompt for the binary's location. +This option, when used without -a, will trigger a manual Remote debugging session towards +a single, pre-selected binary and therefore requires the use of the -e option +to specify the location of the binary on the local machine that matches the one on the +remote target.

+ +

Automated Set-up

As mentioned, the Stand-alone Debugger will initialize Eclipse objects on your behalf on @@ -99,4 +114,4 @@ View such as gdb settings (e.g. gdb path, reverse debugging) and environment var - \ No newline at end of file + diff --git a/debug/org.eclipse.cdt.debug.application/plugin.properties b/debug/org.eclipse.cdt.debug.application/plugin.properties index a46064d1c3e..c4fb803cfbe 100644 --- a/debug/org.eclipse.cdt.debug.application/plugin.properties +++ b/debug/org.eclipse.cdt.debug.application/plugin.properties @@ -7,6 +7,7 @@ # # Contributors: # Red Hat Incorporated - initial API and implementation +# Marc Khouzam (Ericsson) - Update for remote debugging support (bug 450080) ################################################################################# bundleName=C/C++ Stand-alone Debugger provider=Eclipse CDT @@ -31,6 +32,9 @@ DebugNewExecutableMenu.label=&New Executable... DebugAttachedExecutable.description=Debug an attached executable DebugAttachedExecutable.name=Debug Attached Executable DebugAttachedExecutableMenu.label=&Attach Executable... +DebugRemoteExecutable.description=Debug a Remote executable +DebugRemoteExecutable.name=Debug Remote Executable +DebugRemoteExecutableMenu.label=&Remote Executable... DebugCore.description=Debug a corefile DebugCore.name=Debug Core File DebugCoreMenu.label=Debug &Core File... diff --git a/debug/org.eclipse.cdt.debug.application/plugin.xml b/debug/org.eclipse.cdt.debug.application/plugin.xml index f152b4044fc..391ce581776 100644 --- a/debug/org.eclipse.cdt.debug.application/plugin.xml +++ b/debug/org.eclipse.cdt.debug.application/plugin.xml @@ -225,6 +225,13 @@ id="org.eclipse.cdt.debug.application.command.debugAttachedExecutable" name="%DebugAttachedExecutable.name"> + + 0 && + remotePort != null && remotePort.length() > 0) { + config = DebugRemoteExecutable.createLaunchConfig(monitor, buildLog, executable, remoteAddress, remotePort, attachExecutable); + } else if (attachExecutable) { config = DebugAttachedExecutable.createLaunchConfig(monitor, buildLog); } else if (corefile != null && corefile.length() > 0) { config = DebugCoreFile.createLaunchConfig(monitor, buildLog, executable, corefile); diff --git a/debug/org.eclipse.cdt.debug.application/src/org/eclipse/cdt/debug/application/CoreFileDialog.java b/debug/org.eclipse.cdt.debug.application/src/org/eclipse/cdt/debug/application/CoreFileDialog.java index 3cfc916b132..7e9f648af04 100644 --- a/debug/org.eclipse.cdt.debug.application/src/org/eclipse/cdt/debug/application/CoreFileDialog.java +++ b/debug/org.eclipse.cdt.debug.application/src/org/eclipse/cdt/debug/application/CoreFileDialog.java @@ -87,7 +87,7 @@ public class CoreFileDialog extends TitleAreaDialog { comp.setLayout( layout ); comp.setLayoutData( gd ); - new Label( comp, SWT.None ).setText( remote ? Messages.GdbDebugNewExecutableCommand_Binary_on_host : Messages.GdbDebugNewExecutableCommand_Binary ); + new Label( comp, SWT.None ).setText( remote ? Messages.GdbDebugNewExecutableCommand_Binary_on_host : Messages.GdbDebugExecutableCommand_Binary ); fHostBinaryText = new Text( comp, SWT.BORDER ); if (fHostBinary != null) fHostBinaryText.setText(fHostBinary); @@ -100,7 +100,7 @@ public class CoreFileDialog extends TitleAreaDialog { } } ); Button browseButton = new Button( comp, SWT.PUSH ); - browseButton.setText( Messages.GdbDebugNewExecutableCommand_Browse ); + browseButton.setText( Messages.GdbDebugExecutableCommand_Browse ); browseButton.setFont( JFaceResources.getDialogFont() ); setButtonLayoutData( browseButton ); browseButton.addSelectionListener( new SelectionAdapter() { @@ -144,7 +144,7 @@ public class CoreFileDialog extends TitleAreaDialog { } ); Button browseButton2 = new Button( comp, SWT.PUSH ); - browseButton2.setText( Messages.GdbDebugNewExecutableCommand_Browse ); + browseButton2.setText( Messages.GdbDebugExecutableCommand_Browse ); browseButton2.setFont( JFaceResources.getDialogFont() ); setButtonLayoutData( browseButton2 ); browseButton2.addSelectionListener( new SelectionAdapter() { diff --git a/debug/org.eclipse.cdt.debug.application/src/org/eclipse/cdt/debug/application/Messages.java b/debug/org.eclipse.cdt.debug.application/src/org/eclipse/cdt/debug/application/Messages.java index d52e2700e2d..7559e974c44 100644 --- a/debug/org.eclipse.cdt.debug.application/src/org/eclipse/cdt/debug/application/Messages.java +++ b/debug/org.eclipse.cdt.debug.application/src/org/eclipse/cdt/debug/application/Messages.java @@ -7,6 +7,7 @@ * * Contributors: * Red Hat Inc. - initial API and implementation + * Marc Khouzam (Ericsson) - Update for remote debugging support (bug 450080) *******************************************************************************/ package org.eclipse.cdt.debug.application; @@ -35,14 +36,15 @@ public class Messages extends NLS { public static String DebuggerInitializingProblem; public static String GdbDebugNewExecutableCommand_Arguments; - public static String GdbDebugNewExecutableCommand_Binary; + public static String GdbDebugExecutableCommand_Binary; + public static String GdbDebugExecutableCommand_Binary_Optional; public static String GdbDebugNewExecutableCommand_Binary_file_does_not_exist; public static String GdbDebugNewExecutableCommand_Binary_must_be_specified; public static String GdbDebugNewExecutableCommand_Binary_on_host; public static String GdbDebugNewExecutableCommand_Binary_on_target; public static String GdbDebugNewExecutableCommand_Binary_on_target_must_be_specified; - public static String GdbDebugNewExecutableCommand_Browse; - public static String GdbDebugNewExecutableCommand_BuildLog; + public static String GdbDebugExecutableCommand_Browse; + public static String GdbDebugExecutableCommand_BuildLog; public static String GdbDebugNewExecutableCommand_BuildLog_file_does_not_exist; public static String GdbDebugNewExecutableCommand_Debug_New_Executable; public static String GdbDebugNewExecutableCommand_Host_binary_file_does_not_exist; @@ -53,6 +55,14 @@ public class Messages extends NLS { public static String GdbDebugNewExecutableCommand_Select_binaries_on_host_and_target; public static String GdbDebugNewExecutableCommand_Select_Binary; public static String GdbDebugNewExecutableCommand_Select_binary_and_specify_arguments; + public static String GdbDebugRemoteExecutableCommand_Debug_Remote_Executable; + public static String GdbDebugRemoteExecutableCommand_Select_Remote_Options; + public static String GdbDebugRemoteExecutableCommand_Host_name_or_ip_address; + public static String GdbDebugRemoteExecutableCommand_Port_number; + public static String GdbDebugRemoteExecutableCommand_Attach; + public static String GdbDebugRemoteExecutableCommand_address_must_be_specified; + public static String GdbDebugRemoteExecutableCommand_port_must_be_specified; + public static String GdbDebugRemoteExecutableCommand_port_must_be_a_number; public static String GdbDebugCoreFileCommand_CoreFile; public static String GdbDebugCoreFileCommand_Debug_Core_File; public static String GdbDebugCoreFileCommand_Select_binary_and_specify_corefile; @@ -90,6 +100,8 @@ public class Messages extends NLS { public static String CoreFile_toolTip; public static String NewExecutable_toolTip; public static String NewExecutableMenuName; + public static String RemoteExecutable_toolTip; + public static String RemoteExecutableMenuName; public static String AttachedExecutable_toolTip; public static String AttachedExecutableMenuName; diff --git a/debug/org.eclipse.cdt.debug.application/src/org/eclipse/cdt/debug/application/NewExecutableDialog.java b/debug/org.eclipse.cdt.debug.application/src/org/eclipse/cdt/debug/application/NewExecutableDialog.java index 654ffc7dcfe..54835ab51ed 100644 --- a/debug/org.eclipse.cdt.debug.application/src/org/eclipse/cdt/debug/application/NewExecutableDialog.java +++ b/debug/org.eclipse.cdt.debug.application/src/org/eclipse/cdt/debug/application/NewExecutableDialog.java @@ -90,7 +90,7 @@ public class NewExecutableDialog extends TitleAreaDialog { comp.setLayout( layout ); comp.setLayoutData( gd ); - new Label( comp, SWT.None ).setText( remote ? Messages.GdbDebugNewExecutableCommand_Binary_on_host : Messages.GdbDebugNewExecutableCommand_Binary ); + new Label( comp, SWT.None ).setText( remote ? Messages.GdbDebugNewExecutableCommand_Binary_on_host : Messages.GdbDebugExecutableCommand_Binary ); fHostBinaryText = new Text( comp, SWT.BORDER ); if (fHostBinary != null) fHostBinaryText.setText(fHostBinary); @@ -103,7 +103,7 @@ public class NewExecutableDialog extends TitleAreaDialog { } } ); Button browseButton = new Button( comp, SWT.PUSH ); - browseButton.setText( Messages.GdbDebugNewExecutableCommand_Browse ); + browseButton.setText( Messages.GdbDebugExecutableCommand_Browse ); browseButton.setFont( JFaceResources.getDialogFont() ); setButtonLayoutData( browseButton ); browseButton.addSelectionListener( new SelectionAdapter() { @@ -140,7 +140,7 @@ public class NewExecutableDialog extends TitleAreaDialog { fArgumentsText.setText(fArgs); - new Label( comp, SWT.None ).setText( Messages.GdbDebugNewExecutableCommand_BuildLog ); + new Label( comp, SWT.None ).setText( Messages.GdbDebugExecutableCommand_BuildLog ); fBuildLogText = new Text( comp, SWT.BORDER ); if (fBuildLog != null) fBuildLogText.setText(fBuildLog); diff --git a/debug/org.eclipse.cdt.debug.application/src/org/eclipse/cdt/debug/application/RemoteExecutableDialog.java b/debug/org.eclipse.cdt.debug.application/src/org/eclipse/cdt/debug/application/RemoteExecutableDialog.java new file mode 100644 index 00000000000..d6e94a547bc --- /dev/null +++ b/debug/org.eclipse.cdt.debug.application/src/org/eclipse/cdt/debug/application/RemoteExecutableDialog.java @@ -0,0 +1,251 @@ +/******************************************************************************* + * Copyright (c) 2013, 2014 Mentor Graphics and others. + * 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: + * Mentor Graphics - Initial API and implementation + * Red Hat Inc. - modified for use in Standalone Debugger + * Marc Khouzam (Ericsson) - Modified for remote launch (bug 450080) + *******************************************************************************/ + +package org.eclipse.cdt.debug.application; + +import java.io.File; + +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.jface.dialogs.TitleAreaDialog; +import org.eclipse.jface.resource.JFaceResources; +import org.eclipse.swt.SWT; +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.events.SelectionListener; +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.Control; +import org.eclipse.swt.widgets.FileDialog; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; + +public class RemoteExecutableDialog extends TitleAreaDialog { + + private RemoteExecutableInfo fInfo = null; + + private Text fHostBinaryText; + private Label fBinaryLabel; + private Text fBuildLogText; + private Text fAddressText; + private Text fPortText; + private Button fAttachButton; + + private final String fHostBinary; + private final String fBuildLog; + private final String fAddress; + private final String fPort; + private final boolean fAttach; + + public RemoteExecutableDialog (Shell parentShell) { + this(parentShell, null, null, null, null, false); + } + + public RemoteExecutableDialog( Shell parentShell, String hostBinary, String buildLog, String address, String port, boolean attach) { + super( parentShell ); + setShellStyle( getShellStyle() | SWT.RESIZE ); + fHostBinary = hostBinary; + fBuildLog = buildLog; + fAddress = address; + fPort = port; + fAttach = attach; + } + + @Override + protected Control createContents( Composite parent ) { + Control control = super.createContents( parent ); + validate(); + return control; + } + + @Override + protected Control createDialogArea( Composite parent ) { + + getShell().setText( Messages.GdbDebugRemoteExecutableCommand_Debug_Remote_Executable ); + setTitle( Messages.GdbDebugRemoteExecutableCommand_Select_Remote_Options ); + String message = Messages.GdbDebugRemoteExecutableCommand_Select_Remote_Options; + setMessage( message ); + + Composite control = (Composite)super.createDialogArea( parent ); + Composite comp = new Composite( control, SWT.NONE ); + GridData gd = new GridData( SWT.FILL, SWT.FILL, true, true ); + GridLayout layout = new GridLayout( 3, false ); + comp.setLayout( layout ); + comp.setLayoutData( gd ); + + fBinaryLabel = new Label( comp, SWT.None ); + fBinaryLabel.setText(fAttach ? Messages.GdbDebugExecutableCommand_Binary_Optional : + Messages.GdbDebugExecutableCommand_Binary ); + fHostBinaryText = new Text( comp, SWT.BORDER ); + if (fHostBinary != null) + fHostBinaryText.setText(fHostBinary); + fHostBinaryText.setLayoutData( new GridData( SWT.FILL, SWT.CENTER, true, false ) ); + fHostBinaryText.addModifyListener( new ModifyListener() { + + @Override + public void modifyText( ModifyEvent e ) { + validate(); + } + } ); + Button browseButton = new Button( comp, SWT.PUSH ); + browseButton.setText( Messages.GdbDebugExecutableCommand_Browse ); + browseButton.setFont( JFaceResources.getDialogFont() ); + setButtonLayoutData( browseButton ); + browseButton.addSelectionListener( new SelectionAdapter() { + + @Override + public void widgetSelected( SelectionEvent e ) { + FileDialog dialog = new FileDialog( getShell() ); + dialog.setFileName( fHostBinaryText.getText() ); + String result = dialog.open(); + if ( result != null ) { + fHostBinaryText.setText( result ); + } + } + } ); + + new Label( comp, SWT.None ).setText( Messages.GdbDebugExecutableCommand_BuildLog ); + fBuildLogText = new Text( comp, SWT.BORDER ); + if (fBuildLog != null) + fBuildLogText.setText(fBuildLog); + fBuildLogText.setLayoutData( new GridData( SWT.FILL, SWT.CENTER, true, false, 2, 1 ) ); + fBuildLogText.addModifyListener( new ModifyListener() { + + @Override + public void modifyText( ModifyEvent e ) { + validate(); + } + } ); + + new Label( comp, SWT.None ).setText( Messages.GdbDebugRemoteExecutableCommand_Host_name_or_ip_address ); + fAddressText = new Text( comp, SWT.BORDER ); + if (fAddress != null) + fAddressText.setText(fAddress); + fAddressText.setLayoutData( new GridData( SWT.FILL, SWT.CENTER, true, false, 2, 1 ) ); + fAddressText.addModifyListener( new ModifyListener() { + + @Override + public void modifyText( ModifyEvent e ) { + validate(); + } + } ); + + new Label( comp, SWT.None ).setText( Messages.GdbDebugRemoteExecutableCommand_Port_number ); + fPortText = new Text( comp, SWT.BORDER ); + if (fPort != null) + fPortText.setText(fPort); + fPortText.setLayoutData( new GridData( SWT.FILL, SWT.CENTER, true, false, 2, 1 ) ); + fPortText.addModifyListener( new ModifyListener() { + + @Override + public void modifyText( ModifyEvent e ) { + validate(); + } + } ); + + fAttachButton = new Button( comp, SWT.CHECK); + fAttachButton.setText( Messages.GdbDebugRemoteExecutableCommand_Attach); + fAttachButton.setSelection(fAttach); + fAttachButton.addSelectionListener(new SelectionListener() { + + @Override + public void widgetSelected(SelectionEvent e) { + fBinaryLabel.setText(fAttachButton.getSelection() ? + Messages.GdbDebugExecutableCommand_Binary_Optional : + Messages.GdbDebugExecutableCommand_Binary ); + + validate(); + } + + @Override + public void widgetDefaultSelected(SelectionEvent e) { + fBinaryLabel.setText(fAttachButton.getSelection() ? + Messages.GdbDebugExecutableCommand_Binary_Optional : + Messages.GdbDebugExecutableCommand_Binary ); + + validate(); + } + }); + + return control; + } + + @Override + protected void okPressed() { + fInfo = new RemoteExecutableInfo( fHostBinaryText.getText().trim(), + fBuildLogText.getText().trim(), + fAddressText.getText().trim(), + fPortText.getText().trim(), + fAttachButton.getSelection() ); + super.okPressed(); + } + + public RemoteExecutableInfo getExecutableInfo() { + return fInfo; + } + + private void validate() { + String error = null; + + String hostBinary = fHostBinaryText.getText().trim(); + if (hostBinary.isEmpty()) { + boolean attach = fAttachButton.getSelection(); + if (!attach) error = Messages.GdbDebugNewExecutableCommand_Binary_must_be_specified; + } + else { + File file = new File(hostBinary); + if (!file.exists() ) { + error = Messages.GdbDebugNewExecutableCommand_Binary_file_does_not_exist; + } + else if (file.isDirectory()) { + error = Messages.GdbDebugNewExecutableCommand_Invalid_binary; + } + } + + String buildLog = fBuildLogText.getText(); + if (error == null && !buildLog.isEmpty()) { + File file = new File(buildLog); + if (!file.exists()) { + error = Messages.GdbDebugNewExecutableCommand_BuildLog_file_does_not_exist; + } + else if (file.isDirectory()) { + error = Messages.GdbDebugNewExecutableCommand_Invalid_buildLog; + } + } + + String address = fAddressText.getText().trim(); + if (error == null && address.isEmpty()) { + error = Messages.GdbDebugRemoteExecutableCommand_address_must_be_specified; + } + + String port = fPortText.getText().trim(); + if (error == null) { + if (port.isEmpty()) { + error = Messages.GdbDebugRemoteExecutableCommand_port_must_be_specified; + } else { + try { + Integer.parseInt(port); + } catch (NumberFormatException e) { + error = Messages.GdbDebugRemoteExecutableCommand_port_must_be_a_number; + } + } + } + + setErrorMessage((error != null ) ? error : null); + getButton(IDialogConstants.OK_ID).setEnabled(getErrorMessage() == null); + } +} \ No newline at end of file diff --git a/debug/org.eclipse.cdt.debug.application/src/org/eclipse/cdt/debug/application/RemoteExecutableInfo.java b/debug/org.eclipse.cdt.debug.application/src/org/eclipse/cdt/debug/application/RemoteExecutableInfo.java new file mode 100644 index 00000000000..5979b57b3b1 --- /dev/null +++ b/debug/org.eclipse.cdt.debug.application/src/org/eclipse/cdt/debug/application/RemoteExecutableInfo.java @@ -0,0 +1,70 @@ +/******************************************************************************* + * Copyright (c) 2013, 2014 Mentor Graphics and others. + * 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: + * Mentor Graphics - Initial API and implementation + * Red Hat Inc. - modified for use in Standalone Debugger + * Marc Khouzam (Ericsson) - Modified for Remote launch (bug 450080) + *******************************************************************************/ + +package org.eclipse.cdt.debug.application; + +/** + * This class provides information required to start debugging a remote executable. + */ +public class RemoteExecutableInfo { + private final String fHostPath; + private final String fBuildLog; + private final String fAddress; + private final String fPort; + private final boolean fAttach; + + public RemoteExecutableInfo(String hostPath, String buildLog, String address, String port, boolean attach) { + super(); + fHostPath = hostPath; + fBuildLog = buildLog; + fAddress = address; + fPort = port; + fAttach = attach; + } + + public RemoteExecutableInfo(RemoteExecutableInfo info) { + fHostPath = info.getHostPath(); + fBuildLog = info.getBuildLog(); + fAddress = info.getAddress(); + fPort = info.getPort(); + fAttach = info.isAttach(); + } + + /** + * Returns the path of the executable on the host + */ + public String getHostPath() { + return fHostPath; + } + + public String getAddress() { + return fAddress; + } + + public String getPort() { + return fPort; + } + + public boolean isAttach() { + return fAttach; + } + + /** + * Get the build log path. + * + * @return the build log path or null + */ + public String getBuildLog() { + return fBuildLog; + } +} \ No newline at end of file diff --git a/debug/org.eclipse.cdt.debug.application/src/org/eclipse/cdt/debug/application/messages.properties b/debug/org.eclipse.cdt.debug.application/src/org/eclipse/cdt/debug/application/messages.properties index 898fa231247..3d9b963404b 100644 --- a/debug/org.eclipse.cdt.debug.application/src/org/eclipse/cdt/debug/application/messages.properties +++ b/debug/org.eclipse.cdt.debug.application/src/org/eclipse/cdt/debug/application/messages.properties @@ -8,6 +8,7 @@ # Contributors: # Red Hat Inc. - initial API and implementation # Mentor Graphics - GDB Debug New Executable messages +# Marc Khouzam (Ericsson) - Update for remote debugging support (bug 450080) ############################################################################### ExecutablesView_ImportExecutables=Importing Executables Debugger_Title=Eclipse C/C++ Stand-alone Debugger @@ -27,14 +28,15 @@ LaunchMissingError=Previous launch configuration cannot be found DebuggerInitializingProblem=Problem occurred in start-up GdbDebugNewExecutableCommand_Arguments=Arguments: -GdbDebugNewExecutableCommand_Binary=Binary: -GdbDebugNewExecutableCommand_Binary_file_does_not_exist=Debugger will start up with no input +GdbDebugExecutableCommand_Binary=Binary: +GdbDebugExecutableCommand_Binary_Optional=Binary (optional): +GdbDebugNewExecutableCommand_Binary_file_does_not_exist=Binary does not exist GdbDebugNewExecutableCommand_Binary_must_be_specified=Binary must be specified GdbDebugNewExecutableCommand_Binary_on_host=Binary on host: GdbDebugNewExecutableCommand_Binary_on_target=Binary on target: -GdbDebugNewExecutableCommand_BuildLog=Build Log path: +GdbDebugExecutableCommand_BuildLog=Build Log path (optional): GdbDebugNewExecutableCommand_Binary_on_target_must_be_specified=Binary on target must be specified -GdbDebugNewExecutableCommand_Browse=Browse... +GdbDebugExecutableCommand_Browse=Browse... GdbDebugNewExecutableCommand_Debug_New_Executable=Debug New Executable GdbDebugNewExecutableCommand_Host_binary_file_does_not_exist=Host binary file does not exist GdbDebugNewExecutableCommand_Host_binary_must_be_specified=Host binary must be specified @@ -46,6 +48,15 @@ GdbDebugNewExecutableCommand_Select_binaries_on_host_and_target=Select binaries GdbDebugNewExecutableCommand_Select_Binary=Select Binary GdbDebugNewExecutableCommand_Select_binary_and_specify_arguments=Select a binary and specify the arguments +GdbDebugRemoteExecutableCommand_Debug_Remote_Executable=Debug Remote Executable +GdbDebugRemoteExecutableCommand_Select_Remote_Options=Select Remote Options +GdbDebugRemoteExecutableCommand_Host_name_or_ip_address=Host name or IP address +GdbDebugRemoteExecutableCommand_Port_number=Port number +GdbDebugRemoteExecutableCommand_Attach=Attach +GdbDebugRemoteExecutableCommand_address_must_be_specified=Host name or IP address must be specified +GdbDebugRemoteExecutableCommand_port_must_be_specified=IP Port must be specified +GdbDebugRemoteExecutableCommand_port_must_be_a_number=Port must be a valid number + GdbDebugCoreFileCommand_CoreFile=Core File Path: GdbDebugCoreFileCommand_Debug_Core_File=Debug Core File GdbDebugCoreFileCommand_Select_binary_and_specify_corefile=Select a binary and specify the core file @@ -84,5 +95,7 @@ CoreFileMenuName=Debug &Core File... CoreFile_toolTip=Debug an executable that has generated a core file NewExecutable_toolTip=Load a new executable and debug it NewExecutableMenuName=&Debug New Executable... +RemoteExecutable_toolTip=Connect to a remote target and debug it +RemoteExecutableMenuName=Debug &Remote Executable... AttachedExecutable_toolTip=Attach to an existing executable on the system and debug AttachedExecutableMenuName=Debug &Attached Executable... diff --git a/debug/org.eclipse.cdt.debug.application/src/org/eclipse/cdt/internal/debug/application/DebugRemoteExecutable.java b/debug/org.eclipse.cdt.debug.application/src/org/eclipse/cdt/internal/debug/application/DebugRemoteExecutable.java new file mode 100644 index 00000000000..d51dddabf55 --- /dev/null +++ b/debug/org.eclipse.cdt.debug.application/src/org/eclipse/cdt/internal/debug/application/DebugRemoteExecutable.java @@ -0,0 +1,86 @@ +/******************************************************************************* + * Copyright (c) 2014 Red Hat, Inc. + * 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: + * Marc Khouzam (Ericsson) - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.debug.application; + +import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants; +import org.eclipse.cdt.dsf.gdb.IGDBLaunchConfigurationConstants; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.debug.core.DebugPlugin; +import org.eclipse.debug.core.ILaunchConfiguration; +import org.eclipse.debug.core.ILaunchConfigurationType; +import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; +import org.eclipse.debug.core.ILaunchManager; + +public class DebugRemoteExecutable { + + public DebugRemoteExecutable() { + } + + public static ILaunchManager getLaunchManager() { + return DebugPlugin.getDefault().getLaunchManager(); + } + + public static ILaunchConfiguration createLaunchConfig(IProgressMonitor monitor, + String buildLog, String executable, String address, String port, boolean attach) + throws CoreException, InterruptedException { + ILaunchConfiguration config = null; + + config = createConfiguration(executable, address, port, attach, true); + monitor.worked(1); + return config; + } + + protected static ILaunchConfigurationType getLaunchConfigType(boolean attach) { + return getLaunchManager().getLaunchConfigurationType( + attach ? ICDTLaunchConfigurationConstants.ID_LAUNCH_C_ATTACH : + ICDTLaunchConfigurationConstants.ID_LAUNCH_C_REMOTE_APP); + } + + protected static ILaunchConfiguration createConfiguration(String exePath, String address, String port, boolean attach, boolean save) { + ILaunchConfiguration config = null; + try { + ILaunchConfigurationType configType = getLaunchConfigType(attach); + ILaunchConfigurationWorkingCopy wc = configType.newInstance( + null, + getLaunchManager().generateLaunchConfigurationName( + attach ? "CDT_REMOTE_ATTACH" : "CDT_REMOTE")); //$NON-NLS-1$ //$NON-NLS-2$ + + wc.setAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_START_MODE, + attach ? IGDBLaunchConfigurationConstants.DEBUGGER_MODE_REMOTE_ATTACH : + IGDBLaunchConfigurationConstants.DEBUGGER_MODE_REMOTE); + + if (exePath != null && exePath.length() > 0) { + wc.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, exePath); + } else { + assert attach; + } + wc.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, + "Executables"); //$NON-NLS-1$ + wc.setAttribute( + ICDTLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY, + (String) null); + + wc.setAttribute(IGDBLaunchConfigurationConstants.ATTR_REMOTE_TCP, true); + wc.setAttribute(IGDBLaunchConfigurationConstants.ATTR_HOST, address); + wc.setAttribute(IGDBLaunchConfigurationConstants.ATTR_PORT, port); + + if (save) { + config = wc.doSave(); + } else { + config = wc; + } + } catch (CoreException e) { + e.printStackTrace(); + } + return config; + } +} diff --git a/debug/org.eclipse.cdt.debug.application/src/org/eclipse/cdt/internal/debug/application/DebugRemoteExecutableHandler.java b/debug/org.eclipse.cdt.debug.application/src/org/eclipse/cdt/internal/debug/application/DebugRemoteExecutableHandler.java new file mode 100644 index 00000000000..7ee88567433 --- /dev/null +++ b/debug/org.eclipse.cdt.debug.application/src/org/eclipse/cdt/internal/debug/application/DebugRemoteExecutableHandler.java @@ -0,0 +1,67 @@ +/******************************************************************************* + * Copyright (c) 2014 Mentor Graphics and others. + * 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: + * Marc Khouzam (Ericsson) - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.cdt.internal.debug.application; + +import org.eclipse.cdt.debug.application.RemoteExecutableDialog; +import org.eclipse.cdt.debug.application.RemoteExecutableInfo; +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.debug.core.ILaunchConfiguration; +import org.eclipse.debug.core.ILaunchManager; +import org.eclipse.debug.ui.DebugUITools; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; + +public class DebugRemoteExecutableHandler extends AbstractHandler { + + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + + RemoteExecutableDialog dialog = new RemoteExecutableDialog(new Shell()); + + if (dialog.open() == IDialogConstants.OK_ID) { + RemoteExecutableInfo info = dialog.getExecutableInfo(); + String executable = info.getHostPath(); + String buildLog = info.getBuildLog(); + String address = info.getAddress(); + String port = info.getPort(); + boolean attach = info.isAttach(); + + try { + final ILaunchConfiguration config = DebugRemoteExecutable.createLaunchConfig(new NullProgressMonitor(), buildLog, executable, address, port, attach); + if (config != null) { + Display.getDefault().syncExec(new Runnable() { + + @Override + public void run() { + DebugUITools.launch(config, ILaunchManager.DEBUG_MODE); + } + }); + } + } catch (InterruptedException e) { + e.printStackTrace(); + } catch (CoreException e) { + e.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); + } finally { + } + } + + return null; + } + +}