Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc-Andre Laperle2016-08-02 05:55:19 +0000
committerMarc-Andre Laperle2016-08-18 19:49:30 +0000
commitb7e23cab72c8c21cb710dec9192148c1aeba8ab5 (patch)
tree4ea84caeb41b12bd132dbc356eeaeb37861b63f0
parent5e32334aa01341525ffc24c88cacb23eaf963ba8 (diff)
downloadorg.eclipse.cdt-b7e23cab72c8c21cb710dec9192148c1aeba8ab5.tar.gz
org.eclipse.cdt-b7e23cab72c8c21cb710dec9192148c1aeba8ab5.tar.xz
org.eclipse.cdt-b7e23cab72c8c21cb710dec9192148c1aeba8ab5.zip
LLDB: Add support for attaching to local process
Bug: 405670 Change-Id: I3fb967ec7536a92f67e87954814ebaf499352d7f Signed-off-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>
-rw-r--r--llvm/org.eclipse.cdt.llvm.dsf.lldb.core/plugin.properties2
-rw-r--r--llvm/org.eclipse.cdt.llvm.dsf.lldb.core/plugin.xml10
-rw-r--r--llvm/org.eclipse.cdt.llvm.dsf.lldb.core/src/org/eclipse/cdt/llvm/dsf/lldb/core/internal/launching/LLDBAttachLaunchDelegate.java24
-rw-r--r--llvm/org.eclipse.cdt.llvm.dsf.lldb.core/src/org/eclipse/cdt/llvm/dsf/lldb/core/internal/service/LLDBProcesses.java154
-rw-r--r--llvm/org.eclipse.cdt.llvm.dsf.lldb.core/src/org/eclipse/cdt/llvm/dsf/lldb/core/internal/service/LLDBServiceFactory.java6
-rw-r--r--llvm/org.eclipse.cdt.llvm.dsf.lldb.core/src/org/eclipse/cdt/llvm/dsf/lldb/core/internal/service/Messages.java27
-rw-r--r--llvm/org.eclipse.cdt.llvm.dsf.lldb.core/src/org/eclipse/cdt/llvm/dsf/lldb/core/internal/service/messages.properties9
-rw-r--r--llvm/org.eclipse.cdt.llvm.dsf.lldb.ui/plugin.xml33
-rw-r--r--llvm/org.eclipse.cdt.llvm.dsf.lldb.ui/src/org/eclipse/cdt/llvm/dsf/lldb/ui/internal/LLDBAttachCDebuggerTab.java25
-rw-r--r--llvm/org.eclipse.cdt.llvm.dsf.lldb.ui/src/org/eclipse/cdt/llvm/dsf/lldb/ui/internal/LLDBLocalApplicationCDebuggerTab.java14
10 files changed, 302 insertions, 2 deletions
diff --git a/llvm/org.eclipse.cdt.llvm.dsf.lldb.core/plugin.properties b/llvm/org.eclipse.cdt.llvm.dsf.lldb.core/plugin.properties
index b42673bcb3a..12837dfaca9 100644
--- a/llvm/org.eclipse.cdt.llvm.dsf.lldb.core/plugin.properties
+++ b/llvm/org.eclipse.cdt.llvm.dsf.lldb.core/plugin.properties
@@ -10,3 +10,5 @@ providerName=Eclipse CDT
launchDelegate.localApplication.name=LLDB-MI Debug Process
launchDelegate.localApplication.description=Start new application under control of LLBM-MI debugger
+launchDelegate.attach.name=LLDB-MI Attach to Process
+launchDelegate.attach.description=Attach the LLDB-MI debugger to a running program locally or remotely.
diff --git a/llvm/org.eclipse.cdt.llvm.dsf.lldb.core/plugin.xml b/llvm/org.eclipse.cdt.llvm.dsf.lldb.core/plugin.xml
index 81b79e5d4ff..c2fc1ad624a 100644
--- a/llvm/org.eclipse.cdt.llvm.dsf.lldb.core/plugin.xml
+++ b/llvm/org.eclipse.cdt.llvm.dsf.lldb.core/plugin.xml
@@ -13,6 +13,16 @@
sourcePathComputerId="org.eclipse.cdt.debug.core.sourcePathComputer"
type="org.eclipse.cdt.launch.applicationLaunchType">
</launchDelegate>
+ <launchDelegate
+ id="org.eclipse.cdt.llvm.dsf.lldb.launch.attachCLaunch"
+ type="org.eclipse.cdt.launch.attachLaunchType"
+ modes="debug"
+ delegate="org.eclipse.cdt.llvm.dsf.lldb.core.internal.launching.LLDBAttachLaunchDelegate"
+ name="%launchDelegate.attach.name"
+ delegateDescription="%launchDelegate.attach.description"
+ sourceLocatorId="org.eclipse.cdt.debug.core.sourceLocator"
+ sourcePathComputerId="org.eclipse.cdt.debug.core.sourcePathComputer">
+ </launchDelegate>
</extension>
<extension
point="org.eclipse.core.runtime.preferences">
diff --git a/llvm/org.eclipse.cdt.llvm.dsf.lldb.core/src/org/eclipse/cdt/llvm/dsf/lldb/core/internal/launching/LLDBAttachLaunchDelegate.java b/llvm/org.eclipse.cdt.llvm.dsf.lldb.core/src/org/eclipse/cdt/llvm/dsf/lldb/core/internal/launching/LLDBAttachLaunchDelegate.java
new file mode 100644
index 00000000000..bdeb5667579
--- /dev/null
+++ b/llvm/org.eclipse.cdt.llvm.dsf.lldb.core/src/org/eclipse/cdt/llvm/dsf/lldb/core/internal/launching/LLDBAttachLaunchDelegate.java
@@ -0,0 +1,24 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Ericsson.
+ * 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
+ *******************************************************************************/
+
+package org.eclipse.cdt.llvm.dsf.lldb.core.internal.launching;
+
+/**
+ * LLDB launch delegate for attaching.
+ */
+public class LLDBAttachLaunchDelegate extends LLDBLaunchDelegate {
+
+ /**
+ * Creates the launch delegate.
+ */
+ public LLDBAttachLaunchDelegate() {
+ // For an attach session, we don't require a project
+ // to be specified
+ super(false);
+ }
+}
diff --git a/llvm/org.eclipse.cdt.llvm.dsf.lldb.core/src/org/eclipse/cdt/llvm/dsf/lldb/core/internal/service/LLDBProcesses.java b/llvm/org.eclipse.cdt.llvm.dsf.lldb.core/src/org/eclipse/cdt/llvm/dsf/lldb/core/internal/service/LLDBProcesses.java
new file mode 100644
index 00000000000..133148f3081
--- /dev/null
+++ b/llvm/org.eclipse.cdt.llvm.dsf.lldb.core/src/org/eclipse/cdt/llvm/dsf/lldb/core/internal/service/LLDBProcesses.java
@@ -0,0 +1,154 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Ericsson.
+ * 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
+ *******************************************************************************/
+
+package org.eclipse.cdt.llvm.dsf.lldb.core.internal.service;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.cdt.core.CCorePlugin;
+import org.eclipse.cdt.core.IProcessInfo;
+import org.eclipse.cdt.core.IProcessList;
+import org.eclipse.cdt.dsf.concurrent.DataRequestMonitor;
+import org.eclipse.cdt.dsf.datamodel.DMContexts;
+import org.eclipse.cdt.dsf.datamodel.IDMContext;
+import org.eclipse.cdt.dsf.debug.service.IProcesses;
+import org.eclipse.cdt.dsf.debug.service.command.ICommandControlService.ICommandControlDMContext;
+import org.eclipse.cdt.dsf.gdb.service.GDBProcesses_7_4;
+import org.eclipse.cdt.dsf.gdb.service.IGDBBackend;
+import org.eclipse.cdt.dsf.gdb.service.SessionType;
+import org.eclipse.cdt.dsf.mi.service.IMIProcessDMContext;
+import org.eclipse.cdt.dsf.service.DsfSession;
+import org.eclipse.core.runtime.CoreException;
+
+/**
+ * Provides processes information see {@link IProcesses}
+ *
+ * This LLDB specific implementation was initially created in order to be able
+ * to get the list of processes in the absence of the MI command
+ *
+ * <pre>
+ * -list-thread-groups --available
+ * </pre>
+ *
+ * This is used notably when attaching to processes.
+ */
+public class LLDBProcesses extends GDBProcesses_7_4 {
+
+ // A map of pid to names. It is filled when we get all the
+ // processes that are running
+ private Map<Integer, String> fProcessNames = new HashMap<Integer, String>();
+
+ /**
+ * Constructs the {@link LLDBProcesses} service.
+ *
+ * @param session
+ * The debugging session
+ */
+ public LLDBProcesses(DsfSession session) {
+ super(session);
+ }
+
+ @Override
+ public void getRunningProcesses(IDMContext dmc, DataRequestMonitor<IProcessDMContext[]> rm) {
+ // '-list-thread-groups --available' is not supported by lldm-mi so we
+ // fall back to CDT Core's implementation of listing running processes.
+ // This works just like GDBProcesses#getRunningProcesses.
+
+ final ICommandControlDMContext controlDmc = DMContexts.getAncestorOfType(dmc, ICommandControlDMContext.class);
+ IGDBBackend backend = getServicesTracker().getService(IGDBBackend.class);
+ if (backend.getSessionType() == SessionType.LOCAL) {
+ IProcessList list = null;
+ try {
+ list = CCorePlugin.getDefault().getProcessList();
+ } catch (CoreException e) {
+ }
+
+ if (list == null) {
+ // If the list is null, the prompter will deal with it
+ fProcessNames.clear();
+ rm.setData(null);
+ } else {
+ fProcessNames.clear();
+ IProcessInfo[] procInfos = list.getProcessList();
+ for (IProcessInfo procInfo : procInfos) {
+ fProcessNames.put(procInfo.getPid(), procInfo.getName());
+ }
+ rm.setData(makeProcessDMCs(controlDmc, procInfos));
+ }
+ rm.done();
+ } else {
+ // Remote not supported for now
+ fProcessNames.clear();
+ rm.setData(new IProcessDMContext[0]);
+ rm.done();
+ }
+ }
+
+ private IProcessDMContext[] makeProcessDMCs(ICommandControlDMContext controlDmc, IProcessInfo[] processes) {
+ IProcessDMContext[] procDmcs = new IMIProcessDMContext[processes.length];
+ for (int i = 0; i < procDmcs.length; i++) {
+ procDmcs[i] = createProcessContext(controlDmc, Integer.toString(processes[i].getPid()));
+ }
+ return procDmcs;
+ }
+
+ @Override
+ public void getExecutionData(IThreadDMContext dmc, DataRequestMonitor<IThreadDMData> rm) {
+ if (dmc instanceof IMIProcessDMContext) {
+ String pidStr = ((IMIProcessDMContext) dmc).getProcId();
+ int pid = -1;
+ try {
+ pid = Integer.parseInt(pidStr);
+ } catch (NumberFormatException e) {
+ }
+
+ // It's possible that we get here without getRunningProcesses called
+ // yet so the process names map will be empty. This can happen when
+ // doing local debugging but not attach mode.
+ if (fProcessNames.isEmpty()) {
+ getRunningProcesses(dmc, new DataRequestMonitor<>(getExecutor(), rm));
+ }
+
+ String name = fProcessNames.get(pid);
+ if (name == null) {
+ name = Messages.LLDBProcesses_unknown_process_name;
+ }
+
+ rm.setData(new LLDBMIThreadDMData(name, pidStr));
+ rm.done();
+ } else {
+ super.getExecutionData(dmc, rm);
+ }
+ }
+
+ private static class LLDBMIThreadDMData implements IThreadDMData {
+ final String fName;
+ final String fId;
+
+ public LLDBMIThreadDMData(String name, String id) {
+ fName = name;
+ fId = id;
+ }
+
+ @Override
+ public String getId() {
+ return fId;
+ }
+
+ @Override
+ public String getName() {
+ return fName;
+ }
+
+ @Override
+ public boolean isDebuggerAttached() {
+ return true;
+ }
+ }
+}
diff --git a/llvm/org.eclipse.cdt.llvm.dsf.lldb.core/src/org/eclipse/cdt/llvm/dsf/lldb/core/internal/service/LLDBServiceFactory.java b/llvm/org.eclipse.cdt.llvm.dsf.lldb.core/src/org/eclipse/cdt/llvm/dsf/lldb/core/internal/service/LLDBServiceFactory.java
index 6af98c79837..8f3b60681e3 100644
--- a/llvm/org.eclipse.cdt.llvm.dsf.lldb.core/src/org/eclipse/cdt/llvm/dsf/lldb/core/internal/service/LLDBServiceFactory.java
+++ b/llvm/org.eclipse.cdt.llvm.dsf.lldb.core/src/org/eclipse/cdt/llvm/dsf/lldb/core/internal/service/LLDBServiceFactory.java
@@ -9,6 +9,7 @@
package org.eclipse.cdt.llvm.dsf.lldb.core.internal.service;
import org.eclipse.cdt.dsf.debug.service.IBreakpoints;
+import org.eclipse.cdt.dsf.debug.service.IProcesses;
import org.eclipse.cdt.dsf.debug.service.IRunControl;
import org.eclipse.cdt.dsf.debug.service.command.ICommandControl;
import org.eclipse.cdt.dsf.gdb.service.GdbDebugServicesFactory;
@@ -47,4 +48,9 @@ public class LLDBServiceFactory extends GdbDebugServicesFactory {
protected IRunControl createRunControlService(DsfSession session) {
return new LLDBRunControl(session);
}
+
+ @Override
+ protected IProcesses createProcessesService(DsfSession session) {
+ return new LLDBProcesses(session);
+ }
}
diff --git a/llvm/org.eclipse.cdt.llvm.dsf.lldb.core/src/org/eclipse/cdt/llvm/dsf/lldb/core/internal/service/Messages.java b/llvm/org.eclipse.cdt.llvm.dsf.lldb.core/src/org/eclipse/cdt/llvm/dsf/lldb/core/internal/service/Messages.java
new file mode 100644
index 00000000000..79112d09549
--- /dev/null
+++ b/llvm/org.eclipse.cdt.llvm.dsf.lldb.core/src/org/eclipse/cdt/llvm/dsf/lldb/core/internal/service/Messages.java
@@ -0,0 +1,27 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Ericsson.
+ * 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
+ *******************************************************************************/
+
+package org.eclipse.cdt.llvm.dsf.lldb.core.internal.service;
+
+import org.eclipse.osgi.util.NLS;
+
+/**
+ * Messages related to LLDB services.
+ */
+@SuppressWarnings("javadoc")
+public class Messages extends NLS {
+ private static final String BUNDLE_NAME = "org.eclipse.cdt.llvm.dsf.lldb.core.internal.service.messages"; //$NON-NLS-1$
+ public static String LLDBProcesses_unknown_process_name;
+ static {
+ // initialize resource bundle
+ NLS.initializeMessages(BUNDLE_NAME, Messages.class);
+ }
+
+ private Messages() {
+ }
+}
diff --git a/llvm/org.eclipse.cdt.llvm.dsf.lldb.core/src/org/eclipse/cdt/llvm/dsf/lldb/core/internal/service/messages.properties b/llvm/org.eclipse.cdt.llvm.dsf.lldb.core/src/org/eclipse/cdt/llvm/dsf/lldb/core/internal/service/messages.properties
new file mode 100644
index 00000000000..0a0833274f5
--- /dev/null
+++ b/llvm/org.eclipse.cdt.llvm.dsf.lldb.core/src/org/eclipse/cdt/llvm/dsf/lldb/core/internal/service/messages.properties
@@ -0,0 +1,9 @@
+###############################################################################
+# Copyright (c) 2016 Ericsson.
+# 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
+###############################################################################
+
+LLDBProcesses_unknown_process_name=Unknown name
diff --git a/llvm/org.eclipse.cdt.llvm.dsf.lldb.ui/plugin.xml b/llvm/org.eclipse.cdt.llvm.dsf.lldb.ui/plugin.xml
index 35303bc11f2..b50351d6783 100644
--- a/llvm/org.eclipse.cdt.llvm.dsf.lldb.ui/plugin.xml
+++ b/llvm/org.eclipse.cdt.llvm.dsf.lldb.ui/plugin.xml
@@ -50,6 +50,39 @@
<associatedDelegate delegate="org.eclipse.cdt.llvm.dsf.lldb.launch.localCLaunch"/>
<placement after="org.eclipse.debug.ui.sourceLookupTab"/>
</tab>
+
+ <!-- Attach launch tabs-->
+ <tab
+ id="org.eclipse.cdt.llvm.dsf.lldb.launch.attachLaunch.mainTab"
+ group="org.eclipse.cdt.launch.attachLaunchTabGroup"
+ name="%launchTab.main.name"
+ class="org.eclipse.cdt.dsf.gdb.internal.ui.launching.CMainAttachTab">
+ <associatedDelegate delegate="org.eclipse.cdt.llvm.dsf.lldb.launch.attachCLaunch"/>
+ </tab>
+ <tab
+ id="org.eclipse.cdt.llvm.dsf.lldb.launch.attachLaunch.debuggerTab"
+ group="org.eclipse.cdt.launch.attachLaunchTabGroup"
+ name="%launchTab.debugger.name"
+ class="org.eclipse.cdt.llvm.dsf.lldb.ui.internal.LLDBAttachCDebuggerTab">
+ <associatedDelegate delegate="org.eclipse.cdt.llvm.dsf.lldb.launch.attachCLaunch"/>
+ <placement after="org.eclipse.cdt.dsf.gdb.launch.mainTab"/>
+ </tab>
+ <tab
+ id="org.eclipse.cdt.llvm.dsf.lldb.launch.attachLaunch.sourceLookupTab"
+ group="org.eclipse.cdt.launch.attachLaunchTabGroup"
+ name="%launchTab.sourceLookup.name"
+ class="org.eclipse.debug.ui.sourcelookup.SourceLookupTab">
+ <associatedDelegate delegate="org.eclipse.cdt.llvm.dsf.lldb.launch.attachCLaunch"/>
+ <placement after="org.eclipse.cdt.dsf.gdb.launch.debuggerTab"/>
+ </tab>
+ <tab
+ id="org.eclipse.cdt.llvm.dsf.lldb.launch.attachLaunch.commonTab"
+ group="org.eclipse.cdt.launch.attachLaunchTabGroup"
+ name="%launchTab.common.name"
+ class="org.eclipse.debug.ui.CommonTab">
+ <associatedDelegate delegate="org.eclipse.cdt.llvm.dsf.lldb.launch.attachCLaunch"/>
+ <placement after="org.eclipse.debug.ui.sourceLookupTab"/>
+ </tab>
</extension>
</plugin>
diff --git a/llvm/org.eclipse.cdt.llvm.dsf.lldb.ui/src/org/eclipse/cdt/llvm/dsf/lldb/ui/internal/LLDBAttachCDebuggerTab.java b/llvm/org.eclipse.cdt.llvm.dsf.lldb.ui/src/org/eclipse/cdt/llvm/dsf/lldb/ui/internal/LLDBAttachCDebuggerTab.java
new file mode 100644
index 00000000000..8ecf2ea01d7
--- /dev/null
+++ b/llvm/org.eclipse.cdt.llvm.dsf.lldb.ui/src/org/eclipse/cdt/llvm/dsf/lldb/ui/internal/LLDBAttachCDebuggerTab.java
@@ -0,0 +1,25 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Ericsson.
+ * 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
+ *******************************************************************************/
+
+package org.eclipse.cdt.llvm.dsf.lldb.ui.internal;
+
+/**
+ * A LLDB-specific debugger tab for attaching.
+ */
+public class LLDBAttachCDebuggerTab extends LLDBLocalApplicationCDebuggerTab {
+
+ /**
+ * Constructs the {@link LLDBAttachCDebuggerTab}. This sets the tab to
+ * attach mode.
+ */
+ @SuppressWarnings("restriction")
+ public LLDBAttachCDebuggerTab() {
+ super();
+ fAttachMode = true;
+ }
+}
diff --git a/llvm/org.eclipse.cdt.llvm.dsf.lldb.ui/src/org/eclipse/cdt/llvm/dsf/lldb/ui/internal/LLDBLocalApplicationCDebuggerTab.java b/llvm/org.eclipse.cdt.llvm.dsf.lldb.ui/src/org/eclipse/cdt/llvm/dsf/lldb/ui/internal/LLDBLocalApplicationCDebuggerTab.java
index 4f50fbb1e31..38b29781ff9 100644
--- a/llvm/org.eclipse.cdt.llvm.dsf.lldb.ui/src/org/eclipse/cdt/llvm/dsf/lldb/ui/internal/LLDBLocalApplicationCDebuggerTab.java
+++ b/llvm/org.eclipse.cdt.llvm.dsf.lldb.ui/src/org/eclipse/cdt/llvm/dsf/lldb/ui/internal/LLDBLocalApplicationCDebuggerTab.java
@@ -30,8 +30,18 @@ public class LLDBLocalApplicationCDebuggerTab extends LocalApplicationCDebuggerT
private final static String LOCAL_DEBUGGER_ID = "lldb-mi";//$NON-NLS-1$
protected void initDebuggerTypes(String selection) {
- setDebuggerId(LOCAL_DEBUGGER_ID);
- updateComboFromSelection();
+ if (fAttachMode) {
+ setInitializeDefault(selection.isEmpty());
+
+ if (selection.isEmpty()) {
+ selection = LOCAL_DEBUGGER_ID;
+ }
+
+ loadDebuggerCombo(new String[] { LOCAL_DEBUGGER_ID }, selection);
+ } else {
+ setDebuggerId(LOCAL_DEBUGGER_ID);
+ updateComboFromSelection();
+ }
}
/*

Back to the top