1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 14:42:11 +02:00

The program executable would be expandable (in the Modules view) only if it lived in the output directory of a CDT project. It should be expandable as long as it's anywhere in a CDT project. I fixed this for shared libraries last month, and realized today the same issue is happening for the program executable. This refactors that earlier solution to fix both cases. It also fixes an NPE that would happen if the shared library was in a non-CDT project, or outside the workspace altogether.

This commit is contained in:
John Cortell 2008-08-20 22:13:45 +00:00
parent f98068dadf
commit 6d4d1d2bed

View file

@ -65,12 +65,12 @@ public class CModule extends CDebugElement implements ICModule {
}
/**
* Constructor for CModule.
* Constructor for CModule. Used for the program.
*/
private CModule( int type, CDebugTarget target, IPath path ) {
super( target );
fType = type;
fCElement = CoreModel.getDefault().create( path );
fCElement = createBinary(path);
fCDIObject = null;
fImageName = path;
fSymbolsFileName = path;
@ -83,19 +83,24 @@ public class CModule extends CDebugElement implements ICModule {
super( target );
fType = type;
if ( cdiObject instanceof ICDISharedLibrary ) {
if ( cdiObject instanceof ICDISharedLibrary ) {
// We used to ask the CoreModel to create the Binary (ICElement) for
// us but it will do so only for binary files that are in a project
// output directory (for performance reasons). So, we do all the
// leg work ourselves, duplicating much of the code, unfortunately.
//
// THE OLD WAY...
// fCElement = CoreModel.getDefault().create( new Path( ((ICDISharedLibrary)cdiObject).getFileName() ) );
ICDISharedLibrary cdiSharedLib = (ICDISharedLibrary)cdiObject;
IPath path = new Path(cdiSharedLib.getFileName());
fCElement = createBinary(new Path(cdiSharedLib.getFileName()));
}
fCDIObject = cdiObject;
fImageName = ( ( cdiObject instanceof ICDISharedLibrary ) ) ? new Path( ((ICDISharedLibrary)cdiObject).getFileName() ) : new Path( CoreModelMessages.getString( "CModule.0" ) ); //$NON-NLS-1$
fSymbolsFileName = fImageName;
}
/**
* We used to ask the CoreModel to create the Binary (ICElement) for us but
* it will do so only for binary files that are in a project output
* directory (for performance reasons). So, we do all the leg work
* ourselves, duplicating much of the code, unfortunately.
*
* THE OLD WAY...
* fCElement = CoreModel.getDefault().create(path);
*/
private Binary createBinary(IPath path) {
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IFile file = root.getFileForLocation(path);
if (file != null && !file.exists()) {
@ -124,17 +129,14 @@ public class CModule extends CDebugElement implements ICModule {
cfolder = sourceRoot;
IBinaryFile bin = CModelManager.getDefault().createBinaryFile(file);
fCElement = new Binary(cfolder, file, (IBinaryObject)bin);
if (bin != null) {
return new Binary(cfolder, file, (IBinaryObject)bin);
}
} catch (CModelException e) {
CDebugCorePlugin.log(e);
}
}
}
}
fCDIObject = cdiObject;
fImageName = ( ( cdiObject instanceof ICDISharedLibrary ) ) ? new Path( ((ICDISharedLibrary)cdiObject).getFileName() ) : new Path( CoreModelMessages.getString( "CModule.0" ) ); //$NON-NLS-1$
fSymbolsFileName = fImageName;
return null;
}
/* (non-Javadoc)