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

Bug 398136 - ILaunchable is confusing

Bug 398137 - Exporters/Importers should be filterable based on the address size they support
This commit is contained in:
Randy Rohrbach 2013-01-14 17:19:44 -05:00
parent 997f7b6607
commit dc114aff98
8 changed files with 191 additions and 16 deletions

View file

@ -128,17 +128,17 @@
<!-- Adapters for contextual launch --> <!-- Adapters for contextual launch -->
<extension point="org.eclipse.core.runtime.adapters"> <extension point="org.eclipse.core.runtime.adapters">
<factory <factory
class="" class="org.eclipse.cdt.debug.internal.ui.launch.InvalidLaunchableAdapterFactory"
adaptableType="org.eclipse.cdt.core.model.IBinary"> adaptableType="org.eclipse.cdt.core.model.IBinary">
<adapter type="org.eclipse.debug.ui.actions.ILaunchable"/> <adapter type="org.eclipse.debug.ui.actions.ILaunchable"/>
</factory> </factory>
<factory <factory
class="" class="org.eclipse.cdt.debug.internal.ui.launch.InvalidLaunchableAdapterFactory"
adaptableType="org.eclipse.core.resources.IResource"> adaptableType="org.eclipse.core.resources.IResource">
<adapter type="org.eclipse.debug.ui.actions.ILaunchable"/> <adapter type="org.eclipse.debug.ui.actions.ILaunchable"/>
</factory> </factory>
<factory <factory
class="" class="org.eclipse.cdt.debug.internal.ui.launch.InvalidLaunchableAdapterFactory"
adaptableType="org.eclipse.cdt.core.model.ICProject"> adaptableType="org.eclipse.cdt.core.model.ICProject">
<adapter type="org.eclipse.debug.ui.actions.ILaunchable"/> <adapter type="org.eclipse.debug.ui.actions.ILaunchable"/>
</factory> </factory>

View file

@ -0,0 +1,88 @@
/*******************************************************************************
* Copyright (c) 2013 Wind River Systems, Inc. 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:
* Wind River Systems - initial implementation
*******************************************************************************/
package org.eclipse.cdt.debug.internal.ui.launch;
import java.util.ArrayList;
import org.eclipse.cdt.debug.ui.CDebugUIPlugin;
import org.eclipse.core.runtime.IAdapterFactory;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.debug.ui.actions.ILaunchable;
/**
* This is an invalid Adapter factory which insures that there are no false
* usages of this class when defining ILaunchable contexts. Please reference
* the ILaunchable interface and Bugzilla : 396822.
*/
public class InvalidLaunchableAdapterFactory implements IAdapterFactory {
private static final Class<?>[] TYPES = { ILaunchable.class };
private static ArrayList<String> currentTraces = new ArrayList<String>();
/*
* (non-Javadoc)
* @see org.eclipse.core.runtime.IAdapterFactory#getAdapter(java.lang.Object, java.lang.Class)
*/
@Override
@SuppressWarnings("rawtypes")
public Object getAdapter(Object adaptableObject, Class adapterType) {
/*
* Calculate the trace to see if we already have seen this one. We only
* want to report new instances of the violation.
*/
String trace = getStackTrace();
if ( ! currentTraces.contains( trace ) ) {
/*
* Note we have seen this one for the first time.
*/
currentTraces.add( trace );
/*
* Generate a message for this in the log file.
*/
String msg = LaunchMessages.getString("Launch.ILaunchable.Interface.Error"); //$NON-NLS-1$
CDebugUIPlugin.log( new Status( IStatus.INFO, CDebugUIPlugin.PLUGIN_ID, 0, msg, new Throwable( "" ) ) ); //$NON-NLS-1$
}
/*
* We do not actually provide an adapter factory for this.
*/
return null;
}
/*
* Constructs the stack trace for comparison to see if we have seen this exact trace before.
* We only report each unique instance once.
*/
private String getStackTrace() {
String trace = ""; //$NON-NLS-1$
for (StackTraceElement elem : new Throwable().getStackTrace()) {
trace += elem.getClassName() + elem.getMethodName() + elem.getFileName() + elem.getLineNumber();
}
return trace;
}
/*
* Indicates that we are adapting ILaunchable.
*
* (non-Javadoc)
* @see org.eclipse.core.runtime.IAdapterFactory#getAdapterList()
*/
@Override
@SuppressWarnings("rawtypes")
public Class[] getAdapterList() {
return TYPES;
}
}

View file

@ -32,3 +32,6 @@ CApplicationLaunchShortcut.Launch_failed_no_project_selected=Launch failed no pr
Launch.common.BinariesColon=Binaries: Launch.common.BinariesColon=Binaries:
Launch.common.QualifierColon=Qualifier: Launch.common.QualifierColon=Qualifier:
Launch.ILaunchable.Interface.Error=An attempt to instantiate an adapter factory for ILaunchable. By API specification this is not allowed. Use hasAdapter() to determine existense.

View file

@ -7,17 +7,6 @@
name="%extension.name.0" name="%extension.name.0"
point="org.eclipse.cdt.debug.ui.memory.transport.memoryTransport"> point="org.eclipse.cdt.debug.ui.memory.transport.memoryTransport">
<importer
name="%importer.name.0"
id="org.eclipse.cdt.debug.ui.memory.transport.SRecordImporter"
class="org.eclipse.cdt.debug.ui.memory.transport.SRecordImporter">
</importer>
<exporter
name="%exporter.name.0"
id="org.eclipse.cdt.debug.ui.memory.transport.SRecordExporter"
class="org.eclipse.cdt.debug.ui.memory.transport.SRecordExporter">
</exporter>
<importer <importer
name="%importer.name.1" name="%importer.name.1"
id="org.eclipse.cdt.debug.ui.memory.transport.PlainTextImporter" id="org.eclipse.cdt.debug.ui.memory.transport.PlainTextImporter"
@ -40,6 +29,19 @@
class="org.eclipse.cdt.debug.ui.memory.transport.RAWBinaryExporter"> class="org.eclipse.cdt.debug.ui.memory.transport.RAWBinaryExporter">
</exporter> </exporter>
<importer
name="%importer.name.0"
id="org.eclipse.cdt.debug.ui.memory.transport.SRecordImporter"
maxmemorysize="32"
class="org.eclipse.cdt.debug.ui.memory.transport.SRecordImporter">
</importer>
<exporter
name="%exporter.name.0"
id="org.eclipse.cdt.debug.ui.memory.transport.SRecordExporter"
maxmemorysize="32"
class="org.eclipse.cdt.debug.ui.memory.transport.SRecordExporter">
</exporter>
</extension> </extension>
<extension point="org.eclipse.ui.viewActions"> <extension point="org.eclipse.ui.viewActions">

View file

@ -77,6 +77,13 @@
</appInfo> </appInfo>
</annotation> </annotation>
</attribute> </attribute>
<attribute name="maxmemorysize" type="string">
<annotation>
<documentation>
Maximum size of the addressable memory this exporter can support in bits.
</documentation>
</annotation>
</attribute>
</complexType> </complexType>
</element> </element>
@ -109,6 +116,13 @@
</appInfo> </appInfo>
</annotation> </annotation>
</attribute> </attribute>
<attribute name="maxmemorysize" type="string">
<annotation>
<documentation>
Maximum size of the addressable memory this importer can support in bits.
</documentation>
</annotation>
</attribute>
</complexType> </complexType>
</element> </element>

View file

@ -23,6 +23,7 @@ import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.Status;
import org.eclipse.debug.core.DebugException; import org.eclipse.debug.core.DebugException;
import org.eclipse.debug.core.model.IMemoryBlock; import org.eclipse.debug.core.model.IMemoryBlock;
import org.eclipse.debug.core.model.IMemoryBlockExtension;
import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.IDialogSettings; import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.swt.SWT; import org.eclipse.swt.SWT;
@ -186,13 +187,40 @@ public class ExportMemoryDialog extends SelectionDialog
IConfigurationElement element = points[i]; IConfigurationElement element = points[i];
if("exporter".equals(element.getName())) //$NON-NLS-1$ if("exporter".equals(element.getName())) //$NON-NLS-1$
{ {
String maxSizeStr = element.getAttribute("maxmemorysize");
if ( maxSizeStr != null ) {
if ( fMemoryBlock instanceof IMemoryBlockExtension ) {
IMemoryBlockExtension memBlock = (IMemoryBlockExtension) fMemoryBlock;
try {
BigInteger endAddress = memBlock.getBigBaseAddress();
BigInteger length = memBlock.getBigLength();
if ( length != null && ! length.equals(new BigInteger("-1",10) ) ) {
endAddress = endAddress.add( length ) ;
}
int maxAddressSizeInBits = endAddress.bitLength();
int maxSupportedAddressSizeInBits = Integer.decode(maxSizeStr);
if ( maxAddressSizeInBits > maxSupportedAddressSizeInBits ) {
continue;
}
} catch (DebugException e1) {
continue;
}
}
else {
int maxSupportedAddressSizeInBits = Integer.decode(maxSizeStr);
if ( maxSupportedAddressSizeInBits < 32 ) {
continue;
}
}
}
try try
{ {
exporters.addElement((IMemoryExporter) element.createExecutableExtension("class")); //$NON-NLS-1$ exporters.addElement((IMemoryExporter) element.createExecutableExtension("class")); //$NON-NLS-1$
} }
catch(Exception e) { catch(Exception e) {
MemoryTransportPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, MemoryTransportPlugin.getUniqueIdentifier(), MemoryTransportPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, MemoryTransportPlugin.getUniqueIdentifier(),
DebugException.INTERNAL_ERROR, "Failure", e)); //$NON-NLS-1$ DebugException.INTERNAL_ERROR, "Failure", e)); //$NON-NLS-1$
} }
} }
} }

View file

@ -25,6 +25,7 @@ import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.Status;
import org.eclipse.debug.core.DebugException; import org.eclipse.debug.core.DebugException;
import org.eclipse.debug.core.model.IMemoryBlock; import org.eclipse.debug.core.model.IMemoryBlock;
import org.eclipse.debug.core.model.IMemoryBlockExtension;
import org.eclipse.debug.ui.memory.IMemoryRendering; import org.eclipse.debug.ui.memory.IMemoryRendering;
import org.eclipse.debug.ui.memory.IMemoryRenderingContainer; import org.eclipse.debug.ui.memory.IMemoryRenderingContainer;
import org.eclipse.debug.ui.memory.IMemoryRenderingSite; import org.eclipse.debug.ui.memory.IMemoryRenderingSite;
@ -219,6 +220,30 @@ public class ImportMemoryDialog extends SelectionDialog
IConfigurationElement element = points[i]; IConfigurationElement element = points[i];
if("importer".equals(element.getName())) //$NON-NLS-1$ if("importer".equals(element.getName())) //$NON-NLS-1$
{ {
String maxSizeStr = element.getAttribute("maxmemorysize");
if ( maxSizeStr != null ) {
if ( fMemoryBlock instanceof IMemoryBlockExtension ) {
IMemoryBlockExtension memBlock = (IMemoryBlockExtension) fMemoryBlock;
try {
int maxAddressSizeInBits = memBlock.getAddressSize() * 8;
int maxSupportedAddressSizeInBits = Integer.decode(maxSizeStr);
if ( maxAddressSizeInBits > maxSupportedAddressSizeInBits ) {
continue;
}
} catch (DebugException e1) {
continue;
}
}
else {
int maxSupportedAddressSizeInBits = Integer.decode(maxSizeStr);
if ( maxSupportedAddressSizeInBits < 32 ) {
continue;
}
}
}
try try
{ {
importers.addElement(element.createExecutableExtension("class")); //$NON-NLS-1$ importers.addElement(element.createExecutableExtension("class")); //$NON-NLS-1$

View file

@ -280,6 +280,21 @@ public class PlainTextExporter implements IMemoryExporter {
composite.pack(); composite.pack();
/*
* We need to perform a validation. If we do it immediately we will get an exception
* because things are not totally setup. So we schedule an immediate running of the
* validation. For a very brief time the view logically may show a state which does
* not reflect the true state of affairs. But the validate immediately corrects the
* info. In practice the user never sees the invalid state displayed, because of the
* speed of the draw of the dialog.
*/
Display.getDefault().asyncExec(new Runnable(){
public void run()
{
validate();
}
});
return composite; return composite;
} }