1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-23 00:45:28 +02:00

Update the source search path of the underlyuing debugger when the source containers are changed.

This commit is contained in:
Mikhail Khodjaiants 2005-04-27 23:14:58 +00:00
parent 9e7f365eba
commit cd8ccc6b17
4 changed files with 143 additions and 1 deletions

View file

@ -1,3 +1,10 @@
2005-04-25 Mikhail Khodjaiants
Update the source search path of the underlyuing debugger when the source
containers are changed.
+ ISourceLookupChangeListener.java
* CDebugTarget.java
* CSourceLookupParticipant.java
2005-04-27 Alain Magloire
Change in the CDI interface
* cdi/org/eclipse/cdt/debug/core/cdi/model/ICDISourceManagent.java

View file

@ -0,0 +1,24 @@
/**********************************************************************
* Copyright (c) 2004 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* QNX Software Systems - Initial API and implementation
***********************************************************************/
package org.eclipse.cdt.debug.core.sourcelookup;
import org.eclipse.debug.core.sourcelookup.ISourceLookupDirector;
/**
* A source lookup change listener is notified of changes in the source lookup path.
*/
public interface ISourceLookupChangeListener {
/**
* Notification that the source lookup containers have changed.
*/
public void sourceContainersChanged( ISourceLookupDirector director );
}

View file

@ -78,13 +78,16 @@ import org.eclipse.cdt.debug.core.model.IJumpToAddress;
import org.eclipse.cdt.debug.core.model.IJumpToLine;
import org.eclipse.cdt.debug.core.model.IRunToAddress;
import org.eclipse.cdt.debug.core.model.IRunToLine;
import org.eclipse.cdt.debug.core.sourcelookup.CDirectorySourceContainer;
import org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocator;
import org.eclipse.cdt.debug.core.sourcelookup.ISourceLookupChangeListener;
import org.eclipse.cdt.debug.internal.core.CBreakpointManager;
import org.eclipse.cdt.debug.internal.core.CGlobalVariableManager;
import org.eclipse.cdt.debug.internal.core.CMemoryBlockRetrievalExtension;
import org.eclipse.cdt.debug.internal.core.CRegisterManager;
import org.eclipse.cdt.debug.internal.core.CSignalManager;
import org.eclipse.cdt.debug.internal.core.ICDebugInternalConstants;
import org.eclipse.cdt.debug.internal.core.sourcelookup.CSourceLookupParticipant;
import org.eclipse.cdt.debug.internal.core.sourcelookup.CSourceManager;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarkerDelta;
@ -115,11 +118,16 @@ import org.eclipse.debug.core.model.IProcess;
import org.eclipse.debug.core.model.IRegisterGroup;
import org.eclipse.debug.core.model.ISourceLocator;
import org.eclipse.debug.core.model.IThread;
import org.eclipse.debug.core.sourcelookup.ISourceContainer;
import org.eclipse.debug.core.sourcelookup.ISourceLookupDirector;
import org.eclipse.debug.core.sourcelookup.ISourceLookupParticipant;
import org.eclipse.debug.core.sourcelookup.containers.FolderSourceContainer;
import org.eclipse.debug.core.sourcelookup.containers.ProjectSourceContainer;
/**
* Debug target for C/C++ debug model.
*/
public class CDebugTarget extends CDebugElement implements ICDebugTarget, ICDIEventListener, ILaunchListener, IExpressionListener {
public class CDebugTarget extends CDebugElement implements ICDebugTarget, ICDIEventListener, ILaunchListener, IExpressionListener, ISourceLookupChangeListener {
/**
* Threads contained in this debug target.
@ -243,6 +251,7 @@ public class CDebugTarget extends CDebugElement implements ICDebugTarget, ICDIEv
}
protected void initialize() {
initializeSourceLookupPath();
ArrayList debugEvents = new ArrayList( 1 );
debugEvents.add( createCreateEvent() );
initializeThreads( debugEvents );
@ -329,6 +338,19 @@ public class CDebugTarget extends CDebugElement implements ICDebugTarget, ICDIEv
}
}
protected void initializeSourceLookupPath() {
ISourceLocator locator = getLaunch().getSourceLocator();
if ( locator instanceof ISourceLookupDirector ) {
ISourceLookupParticipant[] participants = ((ISourceLookupDirector)locator).getParticipants();
for ( int i = 0; i < participants.length; ++i ) {
if ( participants[i] instanceof CSourceLookupParticipant ) {
((CSourceLookupParticipant)participants[i]).addSourceLookupChangeListener( this );
}
}
setSourceLookupPath( ((ISourceLookupDirector)locator).getSourceContainers() );
}
}
protected void initializeModuleManager() {
getModuleManager().addModules( new ICModule[] { CModule.createExecutable( this, getExecFile().getPath() ) } );
}
@ -979,6 +1001,7 @@ public class CDebugTarget extends CDebugElement implements ICDebugTarget, ICDIEv
disposeRegisterManager();
disposeDisassembly();
disposeSourceManager();
disposeSourceLookupPath();
disposeBreakpointManager();
removeAllExpressions();
disposePreferences();
@ -1574,6 +1597,18 @@ public class CDebugTarget extends CDebugElement implements ICDebugTarget, ICDIEv
}
}
protected void disposeSourceLookupPath() {
ISourceLocator locator = getLaunch().getSourceLocator();
if ( locator instanceof ISourceLookupDirector ) {
ISourceLookupParticipant[] participants = ((ISourceLookupDirector)locator).getParticipants();
for ( int i = 0; i < participants.length; ++i ) {
if ( participants[i] instanceof CSourceLookupParticipant ) {
((CSourceLookupParticipant)participants[i]).removeSourceLookupChangeListener( this );
}
}
}
}
public IFile getCurrentBreakpointFile() {
Object info = getCurrentStateInfo();
if ( info instanceof ICDIBreakpointHit ) {
@ -1799,4 +1834,41 @@ public class CDebugTarget extends CDebugElement implements ICDebugTarget, ICDIEv
CModuleManager mm = getModuleManager();
mm.loadSymbolsForAll();
}
public void sourceContainersChanged( ISourceLookupDirector director ) {
setSourceLookupPath( director.getSourceContainers() );
}
private void setSourceLookupPath( ISourceContainer[] containers ) {
ArrayList list = new ArrayList( containers.length );
getSourceLookupPath( list, containers );
try {
getCDITarget().setSourcePaths( (String[])list.toArray( new String[list.size()] ) );
}
catch( CDIException e ) {
CDebugCorePlugin.log( e );
}
}
private void getSourceLookupPath( List list, ISourceContainer[] containers ) {
for ( int i = 0; i < containers.length; ++i ) {
if ( containers[i] instanceof ProjectSourceContainer ) {
list.add( ((ProjectSourceContainer)containers[i]).getProject().getLocation().toOSString() );
}
if ( containers[i] instanceof FolderSourceContainer ) {
list.add( ((FolderSourceContainer)containers[i]).getContainer().getLocation().toOSString() );
}
if ( containers[i] instanceof CDirectorySourceContainer ) {
list.add( ((CDirectorySourceContainer)containers[i]).getDirectory().getAbsolutePath() );
}
if ( containers[i].isComposite() ) {
try {
getSourceLookupPath( list, containers[i].getSourceContainers() );
}
catch( CoreException e ) {
CDebugCorePlugin.log( e.getStatus() );
}
}
}
}
}

View file

@ -12,12 +12,15 @@ package org.eclipse.cdt.debug.internal.core.sourcelookup;
import java.io.File;
import org.eclipse.cdt.debug.core.model.ICStackFrame;
import org.eclipse.cdt.debug.core.sourcelookup.ISourceLookupChangeListener;
import org.eclipse.cdt.debug.internal.core.ListenerList;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.Path;
import org.eclipse.debug.core.sourcelookup.AbstractSourceLookupParticipant;
import org.eclipse.debug.core.sourcelookup.ISourceLookupDirector;
import org.eclipse.debug.core.sourcelookup.containers.LocalFileStorage;
/**
@ -30,6 +33,16 @@ public class CSourceLookupParticipant extends AbstractSourceLookupParticipant {
private static final NoSourceElement gfNoSource = new NoSourceElement();
private ListenerList fListeners;
/**
* Constructor for CSourceLookupParticipant.
*/
public CSourceLookupParticipant() {
super();
fListeners = new ListenerList( 1 );
}
/* (non-Javadoc)
* @see org.eclipse.debug.core.sourcelookup.ISourceLookupParticipant#getSourceName(java.lang.Object)
*/
@ -80,4 +93,30 @@ public class CSourceLookupParticipant extends AbstractSourceLookupParticipant {
return wfiles;
return new LocalFileStorage[] { new LocalFileStorage( file ) };
}
/* (non-Javadoc)
* @see org.eclipse.debug.core.sourcelookup.AbstractSourceLookupParticipant#dispose()
*/
public void dispose() {
fListeners.removeAll();
super.dispose();
}
public void addSourceLookupChangeListener( ISourceLookupChangeListener listener ) {
fListeners.add( listener );
}
public void removeSourceLookupChangeListener( ISourceLookupChangeListener listener ) {
fListeners.remove( listener );
}
/* (non-Javadoc)
* @see org.eclipse.debug.core.sourcelookup.AbstractSourceLookupParticipant#sourceContainersChanged(org.eclipse.debug.core.sourcelookup.ISourceLookupDirector)
*/
public void sourceContainersChanged( ISourceLookupDirector director ) {
Object[] listeners = fListeners.getListeners();
for ( int i = 0; i < listeners.length; ++i )
((ISourceLookupChangeListener)listeners[i]).sourceContainersChanged( director );
super.sourceContainersChanged( director );
}
}