diff --git a/plugins/org.eclipse.dd.gdb.launch/src/org/eclipse/dd/gdb/launch/launching/LaunchSequence.java b/plugins/org.eclipse.dd.gdb.launch/src/org/eclipse/dd/gdb/launch/launching/LaunchSequence.java index 6a7676d65a1..8575b06d410 100644 --- a/plugins/org.eclipse.dd.gdb.launch/src/org/eclipse/dd/gdb/launch/launching/LaunchSequence.java +++ b/plugins/org.eclipse.dd.gdb.launch/src/org/eclipse/dd/gdb/launch/launching/LaunchSequence.java @@ -92,11 +92,11 @@ public class LaunchSequence extends Sequence { }}, new Step() { @Override public void execute(RequestMonitor requestMonitor) { - new MIMemory(fSession).initialize(requestMonitor); + new MIMemory(fSession).initialize(requestMonitor); }}, new Step() { @Override public void execute(RequestMonitor requestMonitor) { - new MIModules(fSession).initialize(requestMonitor); + new MIModules(fSession).initialize(requestMonitor); }}, new Step() { @Override public void execute(RequestMonitor requestMonitor) { @@ -113,10 +113,11 @@ public class LaunchSequence extends Sequence { }}, new Step() { @Override public void execute(RequestMonitor requestMonitor) { - fSourceLookup.setSourceLookupDirector( - fCommandControl.getGDBDMContext(), - ((CSourceLookupDirector)fLaunch.getSourceLocator())); - requestMonitor.done(); + CSourceLookupDirector locator = (CSourceLookupDirector)fLaunch.getSourceLocator(); + + fSourceLookup.setSourceLookupDirector(fCommandControl.getGDBDMContext(), locator); + fSourceLookup.setSourceLookupPath(fCommandControl.getGDBDMContext(), + locator.getSourceContainers(), requestMonitor); }}, new Step() { @Override public void execute(final RequestMonitor requestMonitor) { @@ -222,7 +223,9 @@ public class LaunchSequence extends Sequence { } }, - /* Start tracking the breakpoints once we know we are connected to the target (necessary for remote debugging) */ + /* + * Start tracking the breakpoints once we know we are connected to the target (necessary for remote debugging) + */ new Step() { @Override public void execute(final RequestMonitor requestMonitor) { fBpmService.startTrackingBreakpoints(fCommandControl.getGDBDMContext(), requestMonitor); diff --git a/plugins/org.eclipse.dd.mi/src/org/eclipse/dd/mi/service/CSourceLookup.java b/plugins/org.eclipse.dd.mi/src/org/eclipse/dd/mi/service/CSourceLookup.java index f13439a23fc..7390c09f05a 100644 --- a/plugins/org.eclipse.dd.mi/src/org/eclipse/dd/mi/service/CSourceLookup.java +++ b/plugins/org.eclipse.dd.mi/src/org/eclipse/dd/mi/service/CSourceLookup.java @@ -10,24 +10,37 @@ *******************************************************************************/ package org.eclipse.dd.mi.service; +import java.io.File; +import java.util.ArrayList; import java.util.HashMap; import java.util.Hashtable; +import java.util.List; import java.util.Map; import org.eclipse.cdt.debug.internal.core.sourcelookup.CSourceLookupDirector; +import org.eclipse.core.resources.IContainer; +import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.jobs.Job; import org.eclipse.dd.dsf.concurrent.DataRequestMonitor; import org.eclipse.dd.dsf.concurrent.RequestMonitor; import org.eclipse.dd.dsf.debug.service.ISourceLookup; +import org.eclipse.dd.dsf.debug.service.command.ICommandControl; import org.eclipse.dd.dsf.service.AbstractDsfService; import org.eclipse.dd.dsf.service.DsfSession; import org.eclipse.dd.dsf.service.IDsfService; import org.eclipse.dd.mi.internal.MIPlugin; +import org.eclipse.dd.mi.service.command.commands.MIEnvironmentDirectory; +import org.eclipse.dd.mi.service.command.output.MIInfo; +import org.eclipse.debug.core.sourcelookup.ISourceContainer; +import org.eclipse.debug.core.sourcelookup.containers.DirectorySourceContainer; +import org.eclipse.debug.core.sourcelookup.containers.FolderSourceContainer; +import org.eclipse.debug.core.sourcelookup.containers.ProjectSourceContainer; import org.osgi.framework.BundleContext; /** @@ -37,6 +50,8 @@ public class CSourceLookup extends AbstractDsfService implements ISourceLookup { private Map fDirectors = new HashMap(); + ICommandControl fConnection; + public CSourceLookup(DsfSession session) { super(session); } @@ -51,6 +66,48 @@ public class CSourceLookup extends AbstractDsfService implements ISourceLookup { fDirectors.put(ctx, director); } + public void setSourceLookupPath(ISourceLookupDMContext ctx, ISourceContainer[] containers, RequestMonitor rm) { + List pathList = getSourceLookupPath(containers); + String[] paths = pathList.toArray(new String[pathList.size()]); + + fConnection.queueCommand( + new MIEnvironmentDirectory(ctx, paths, false), + new DataRequestMonitor(getExecutor(), rm)); + } + + private List getSourceLookupPath(ISourceContainer[] containers) { + ArrayList list = new ArrayList(containers.length); + + for (int i = 0; i < containers.length; ++i) { + if (containers[i] instanceof ProjectSourceContainer) { + IProject project = ((ProjectSourceContainer)containers[i]).getProject(); + if (project != null && project.exists()) + list.add(project.getLocation().toPortableString()); + } + if (containers[i] instanceof FolderSourceContainer) { + IContainer container = ((FolderSourceContainer)containers[i]).getContainer(); + if (container != null && container.exists()) + list.add(container.getLocation().toPortableString()); + } + if (containers[i] instanceof DirectorySourceContainer) { + File dir = ((DirectorySourceContainer)containers[i]).getDirectory(); + if (dir != null && dir.exists()) { + IPath path = new Path( dir.getAbsolutePath()); + list.add(path.toPortableString()); + } + } + if (containers[i].isComposite()) { + try { + list.addAll(getSourceLookupPath(containers[i].getSourceContainers())); + } catch (CoreException e) { + } + } + } + + return list; + } + + @Override public void initialize(final RequestMonitor requestMonitor) { super.initialize( @@ -62,8 +119,11 @@ public class CSourceLookup extends AbstractDsfService implements ISourceLookup { } private void doInitialize(final RequestMonitor requestMonitor) { - // Register this service + fConnection = getServicesTracker().getService(ICommandControl.class); + + // Register this service register(new String[] { CSourceLookup.class.getName(), ISourceLookup.class.getName() }, new Hashtable()); + requestMonitor.done(); } diff --git a/plugins/org.eclipse.dd.mi/src/org/eclipse/dd/mi/service/command/commands/MIEnvironmentDirectory.java b/plugins/org.eclipse.dd.mi/src/org/eclipse/dd/mi/service/command/commands/MIEnvironmentDirectory.java new file mode 100644 index 00000000000..ca3de1ed31d --- /dev/null +++ b/plugins/org.eclipse.dd.mi/src/org/eclipse/dd/mi/service/command/commands/MIEnvironmentDirectory.java @@ -0,0 +1,47 @@ +/******************************************************************************* + * Copyright (c) 2000, 2005, 2008 QNX Software Systems 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: + * QNX Software Systems - Initial API and implementation + * ERicsson - Updated + *******************************************************************************/ +package org.eclipse.dd.mi.service.command.commands; + +import org.eclipse.dd.dsf.datamodel.IDMContext; +import org.eclipse.dd.mi.service.command.output.MIInfo; + +/** + * + * -environment-directory [-r] PATHDIR + * + * Add directory PATHDIR to beginning of search path for source files. + * -r will first reset the path to its default + * + */ +public class MIEnvironmentDirectory extends MICommand { + + public MIEnvironmentDirectory(IDMContext ctx, String[] paths, boolean reset) { + super(ctx, "-environment-directory"); //$NON-NLS-1$ + + String[] options; + if (reset) { + if (paths == null) { + options = new String[] {"-r"}; //$NON-NLS-1$ + } else { + options = new String[paths.length + 1]; + options[0] = "-r"; //$NON-NLS-1$ + for (int i = 1; i < options.length; i++) { + options[i] = paths[i-1]; + } + } + } else { + options = paths; + } + + setOptions(options); + } +} \ No newline at end of file