From f433cb1e85d119f6ca3db33eb298d9695bb2d10b Mon Sep 17 00:00:00 2001 From: Jeff Johnston Date: Wed, 28 Jan 2015 19:14:22 -0500 Subject: [PATCH] Bug 458066 - cannot specify pid to Standalone Debugger - allow pid to be specified following -a option for Standalone debugger - if pid is specified, use it to set the ATTR_ATTACH_PROCESS_ID setting for the launch configuration - setting the pid will cause the process dialog not to appear and the debugger will attempt to debug the given process - an invalid pid will result in in the dialog being opened - the pid is not used with the -r option and is ignored - updated the README file and docs Change-Id: I5a1d39f97285ad41dcb986dfb4692f9d808bafeb --- .../tasks/cdt_t_standalone_startup.htm | 8 ++--- .../META-INF/MANIFEST.MF | 2 +- .../org.eclipse.cdt.debug.application/pom.xml | 2 +- .../scripts/README | 7 +++-- .../scripts/cdtdebug.sh | 4 +-- .../ApplicationWorkbenchWindowAdvisor.java | 13 ++++++-- .../application/DebugAttachedExecutable.java | 31 ++++++++++++++++--- 7 files changed, 51 insertions(+), 16 deletions(-) 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 faaf1261120..e25ec36f093 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 @@ -16,11 +16,11 @@ The script contains the command-line needed to start Eclipse and to pass appropriate parameters at start-up. The following are the command-line options supported: -

-a

+

-a [pid]

This option specifies that you want to attach and debug an existing executable that is running on your system. -The option will bring up a dialog which contains a list of current executables running and you may choose the -executable(s) you wish to attach to. You also have the option of starting a new executable, if desired, but you -cannot specify a build log using this method. +If no pid is specified or an invalid pid is specified, the option will bring up a dialog which contains a list of current executables running and you may choose the +executable(s) you wish to attach to. The dialog will also give you the option of starting a new executable, if desired, but you +cannot specify a build log using this method. When used at the same as the -r option, the pid argument is ignored.

-b <build log>

This option specifies an optional build log to use for indexing the source. The build log diff --git a/debug/org.eclipse.cdt.debug.application/META-INF/MANIFEST.MF b/debug/org.eclipse.cdt.debug.application/META-INF/MANIFEST.MF index c0cbae92232..bc66ac66a08 100644 --- a/debug/org.eclipse.cdt.debug.application/META-INF/MANIFEST.MF +++ b/debug/org.eclipse.cdt.debug.application/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %bundleName Bundle-SymbolicName: org.eclipse.cdt.debug.application;singleton:=true -Bundle-Version: 1.0.0.qualifier +Bundle-Version: 1.1.0.qualifier Bundle-Activator: org.eclipse.cdt.debug.application.Activator Bundle-Vendor: %provider Require-Bundle: org.eclipse.ui, diff --git a/debug/org.eclipse.cdt.debug.application/pom.xml b/debug/org.eclipse.cdt.debug.application/pom.xml index 80c2eea77a1..5f78414a357 100644 --- a/debug/org.eclipse.cdt.debug.application/pom.xml +++ b/debug/org.eclipse.cdt.debug.application/pom.xml @@ -11,7 +11,7 @@ ../../pom.xml - 1.0.0-SNAPSHOT + 1.1.0-SNAPSHOT org.eclipse.cdt.debug.application eclipse-plugin diff --git a/debug/org.eclipse.cdt.debug.application/scripts/README b/debug/org.eclipse.cdt.debug.application/scripts/README index 876b3ada2a4..0bed384f9d4 100644 --- a/debug/org.eclipse.cdt.debug.application/scripts/README +++ b/debug/org.eclipse.cdt.debug.application/scripts/README @@ -20,8 +20,11 @@ The script takes a few options which are mentioned below: -consoleLog : if you want error messages reported directly to the command console --a : specify attaching to an existing executable on system. A dialog will - be brought up to allow you to select which one. +-a [pid] : specify attaching to an existing executable running on system. If no pid is + specified, a dialog will be brought up to allow you to select an executable + from the list of existing processes. The same dialog will be brought up if + the specified pid is invalid. The pid is not used for a remote debugging + session triggered by the -r option described below. -b $PATH : path to build log for an executable. This will be used to figure out include paths and compilation flags. This option assumes you will diff --git a/debug/org.eclipse.cdt.debug.application/scripts/cdtdebug.sh b/debug/org.eclipse.cdt.debug.application/scripts/cdtdebug.sh index d70c330f239..4e51a2a54eb 100755 --- a/debug/org.eclipse.cdt.debug.application/scripts/cdtdebug.sh +++ b/debug/org.eclipse.cdt.debug.application/scripts/cdtdebug.sh @@ -1,6 +1,6 @@ #!/bin/sh ############################################################################### -# Copyright (c) 2014 Red Hat, Inc. and others +# Copyright (c) 2014, 2015 Red Hat, Inc. 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 @@ -27,7 +27,7 @@ Indexing assist options: -b BUILD_LOG build log to use for compiler includes/flags Target options: - -a attach to an existing process (list will be shown) + -a [pid] attach using the optional pid or prompt for a pid -c COREFILE debug core-file (should also specify executable) -e EXECUTABLE [ARGS...] debug given executable (passing ARGS to main) -r ADDRESS:PORT debug toward the specified remote server. Can be diff --git a/debug/org.eclipse.cdt.debug.application/src/org/eclipse/cdt/debug/application/ApplicationWorkbenchWindowAdvisor.java b/debug/org.eclipse.cdt.debug.application/src/org/eclipse/cdt/debug/application/ApplicationWorkbenchWindowAdvisor.java index 7daf6375c78..9069ace3c80 100644 --- a/debug/org.eclipse.cdt.debug.application/src/org/eclipse/cdt/debug/application/ApplicationWorkbenchWindowAdvisor.java +++ b/debug/org.eclipse.cdt.debug.application/src/org/eclipse/cdt/debug/application/ApplicationWorkbenchWindowAdvisor.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2013, 2014 Red Hat, Inc. + * Copyright (c) 2013, 2015 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 @@ -143,6 +143,7 @@ public class ApplicationWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor { String arguments = null; String remoteAddress = null; String remotePort = null; + String pid = null; String[] args = Platform.getCommandLineArgs(); try { @@ -161,6 +162,14 @@ public class ApplicationWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor { // Make sure 'executable' is still null in case we are dealing with a remote // session that is also an attach, as the -r flag could have been set first executable = null; + + // Check for optional pid + if (i + 1 < args.length) { + if (!args[i+1].startsWith("-")) { //$NON-NLS-1$ + ++i; + pid = args[i]; + } + } } else if ("-c".equals(args[i])) { //$NON-NLS-1$ ++i; @@ -347,7 +356,7 @@ public class ApplicationWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor { remotePort != null && remotePort.length() > 0) { config = DebugRemoteExecutable.createLaunchConfig(monitor, buildLog, executable, remoteAddress, remotePort, attachExecutable); } else if (attachExecutable) { - config = DebugAttachedExecutable.createLaunchConfig(monitor, buildLog); + config = DebugAttachedExecutable.createLaunchConfig(monitor, buildLog, pid); } else if (corefile != null && corefile.length() > 0) { config = DebugCoreFile.createLaunchConfig(monitor, buildLog, executable, corefile); } else if (executable != null && executable.length() > 0) { diff --git a/debug/org.eclipse.cdt.debug.application/src/org/eclipse/cdt/internal/debug/application/DebugAttachedExecutable.java b/debug/org.eclipse.cdt.debug.application/src/org/eclipse/cdt/internal/debug/application/DebugAttachedExecutable.java index 33b25c729b9..bbce3ec3a1f 100644 --- a/debug/org.eclipse.cdt.debug.application/src/org/eclipse/cdt/internal/debug/application/DebugAttachedExecutable.java +++ b/debug/org.eclipse.cdt.debug.application/src/org/eclipse/cdt/internal/debug/application/DebugAttachedExecutable.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2014 Red Hat, Inc. + * Copyright (c) 2014, 2015 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 @@ -82,15 +82,28 @@ public class DebugAttachedExecutable { * Import given executable into the Executables project then create a launch configuration. * * @param monitor - * @param executable * @param buildLog - * @param arguments * @throws CoreException * @throws InterruptedException */ public static ILaunchConfiguration createLaunchConfig(IProgressMonitor monitor, String buildLog) throws CoreException, InterruptedException { + return createLaunchConfig(monitor, buildLog, null); + } + + /** + * Import given executable into the Executables project then create a launch configuration. + * + * @param monitor + * @param buildLog + * @param pid + * @throws CoreException + * @throws InterruptedException + */ + public static ILaunchConfiguration createLaunchConfig(IProgressMonitor monitor, + String buildLog, String pid) + throws CoreException, InterruptedException { ILaunchConfiguration config = null; String defaultProjectName = "Executables"; //$NON-NLS-1$ @@ -202,7 +215,7 @@ public class DebugAttachedExecutable { } } - config = createConfiguration(true); + config = createConfiguration(pid, true); monitor.worked(1); return config; } @@ -212,6 +225,10 @@ public class DebugAttachedExecutable { } protected static ILaunchConfiguration createConfiguration(boolean save) { + return createConfiguration(null, save); + } + + protected static ILaunchConfiguration createConfiguration(String pid, boolean save) { ILaunchConfiguration config = null; try { ILaunchConfigurationType configType = getLaunchConfigType(); @@ -226,6 +243,12 @@ public class DebugAttachedExecutable { wc.setAttribute( ICDTLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY, (String) null); + + if (pid != null) { + wc.setAttribute(ICDTLaunchConfigurationConstants.ATTR_ATTACH_PROCESS_ID, + Integer.valueOf(pid)); + } + if (save) { config = wc.doSave(); } else {