1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

LLDB: Add support for attaching to local process

Bug: 405670
Change-Id: I3fb967ec7536a92f67e87954814ebaf499352d7f
Signed-off-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>
This commit is contained in:
Marc-Andre Laperle 2016-08-02 01:55:19 -04:00
parent 5e32334aa0
commit b7e23cab72
10 changed files with 302 additions and 2 deletions

View file

@ -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.

View file

@ -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">

View file

@ -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);
}
}

View file

@ -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;
}
}
}

View file

@ -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);
}
}

View file

@ -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() {
}
}

View file

@ -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

View file

@ -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>

View file

@ -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;
}
}

View file

@ -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();
}
}
/*