diff options
Diffstat (limited to 'debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug')
67 files changed, 2 insertions, 16637 deletions
diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/CDIDebugModel.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/CDIDebugModel.java index 9d549066e8c..d9feb25195f 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/CDIDebugModel.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/CDIDebugModel.java @@ -14,20 +14,11 @@ *******************************************************************************/ package org.eclipse.cdt.debug.core; -import java.io.IOException; import java.math.BigInteger; import java.util.HashMap; import java.util.Map; -import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.IAddress; -import org.eclipse.cdt.core.IBinaryParser; -import org.eclipse.cdt.core.IBinaryParser.IBinaryExecutable; -import org.eclipse.cdt.core.IBinaryParser.IBinaryFile; -import org.eclipse.cdt.core.IBinaryParser.IBinaryObject; -import org.eclipse.cdt.core.model.CoreModelUtil; -import org.eclipse.cdt.core.settings.model.ICConfigExtensionReference; -import org.eclipse.cdt.debug.core.cdi.model.ICDITarget; import org.eclipse.cdt.debug.core.model.ICAddressBreakpoint; import org.eclipse.cdt.debug.core.model.ICBreakpoint; import org.eclipse.cdt.debug.core.model.ICBreakpoint2; @@ -51,10 +42,7 @@ import org.eclipse.cdt.debug.internal.core.breakpoints.CLineBreakpoint; import org.eclipse.cdt.debug.internal.core.breakpoints.CLineDynamicPrintf; import org.eclipse.cdt.debug.internal.core.breakpoints.CLineTracepoint; import org.eclipse.cdt.debug.internal.core.breakpoints.CWatchpoint; -import org.eclipse.cdt.debug.internal.core.model.CDebugTarget; -import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IMarker; -import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IWorkspaceRunnable; import org.eclipse.core.resources.ResourcesPlugin; @@ -64,14 +52,10 @@ 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.debug.core.DebugException; import org.eclipse.debug.core.DebugPlugin; import org.eclipse.debug.core.IBreakpointManager; -import org.eclipse.debug.core.ILaunch; import org.eclipse.debug.core.model.IBreakpoint; -import org.eclipse.debug.core.model.IDebugTarget; import org.eclipse.debug.core.model.ILineBreakpoint; -import org.eclipse.debug.core.model.IProcess; /** * Provides utility methods for creating debug sessions, targets and breakpoints @@ -89,154 +73,6 @@ public class CDIDebugModel { } /** - * Creates and returns a debug target for the given CDI target, with the - * specified name, and associates it with the given process for console I/O. - * The debug target is added to the given launch. - * - * @param launch - * the launch the new debug target will be contained in - * @param project - * the project to use to persist breakpoints. - * @param cdiTarget - * the CDI target to create a debug target for - * @param name - * the name to associate with this target, which will be returned - * from <code>IDebugTarget.getName</code>. - * @param debuggeeProcess - * the process to associate with the debug target, which will be - * returned from <code>IDebugTarget.getProcess</code> - * @param file - * the executable to debug. - * @param allowTerminate - * allow terminate(). - * @param allowDisconnect - * allow disconnect(). - * @param stopSymbol - * place temporary breakpoint at <code>stopSymbol</code>, ignore - * if <code>null</code> or empty. - * @param resumeTarget - * resume target. - * @return a debug target - * @throws DebugException - * @since 3.1 - */ - public static IDebugTarget newDebugTarget(final ILaunch launch, final IProject project, final ICDITarget cdiTarget, - final String name, final IProcess debuggeeProcess, final IBinaryObject file, final boolean allowTerminate, - final boolean allowDisconnect, final String stopSymbol, final boolean resumeTarget) throws DebugException { - final IDebugTarget[] target = new IDebugTarget[1]; - IWorkspaceRunnable r = new IWorkspaceRunnable() { - - @Override - public void run(IProgressMonitor m) throws CoreException { - target[0] = new CDebugTarget(launch, project, cdiTarget, name, debuggeeProcess, file, allowTerminate, - allowDisconnect); - ((CDebugTarget) target[0]).start(stopSymbol, resumeTarget); - } - }; - try { - ResourcesPlugin.getWorkspace().run(r, null); - } catch (CoreException e) { - CDebugCorePlugin.log(e); - throw new DebugException(e.getStatus()); - } - return target[0]; - } - - /** - * Creates and returns a debug target for the given CDI target, with the - * specified name, and associates it with the given process for console I/O. - * The debug target is added to the given launch. - * - * @param launch - * the launch the new debug target will be contained in - * @param project - * the project to use to persist breakpoints. - * @param cdiTarget - * the CDI target to create a debug target for - * @param name - * the name to associate with this target, which will be returned - * from <code>IDebugTarget.getName</code>. - * @param debuggeeProcess - * the process to associate with the debug target, which will be - * returned from <code>IDebugTarget.getProcess</code> - * @param file - * the executable to debug. - * @param allowTerminate - * allow terminate(). - * @param allowDisconnect - * allow disconnect(). - * @param stopInMain - * place temporary breakpoint at main() - * @param resumeTarget - * resume target. - * @return a debug target - * @throws DebugException - * @deprecated - */ - @Deprecated - public static IDebugTarget newDebugTarget(final ILaunch launch, final IProject project, final ICDITarget cdiTarget, - final String name, final IProcess debuggeeProcess, final IBinaryObject file, final boolean allowTerminate, - final boolean allowDisconnect, final boolean stopInMain, final boolean resumeTarget) throws DebugException { - final IDebugTarget[] target = new IDebugTarget[1]; - IWorkspaceRunnable r = new IWorkspaceRunnable() { - - @Override - public void run(IProgressMonitor m) throws CoreException { - String stopSymbol = null; - if (stopInMain) - stopSymbol = launch.getLaunchConfiguration().getAttribute( - ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_STOP_AT_MAIN_SYMBOL, - ICDTLaunchConfigurationConstants.DEBUGGER_STOP_AT_MAIN_SYMBOL_DEFAULT); - target[0] = new CDebugTarget(launch, project, cdiTarget, name, debuggeeProcess, file, allowTerminate, - allowDisconnect); - ((CDebugTarget) target[0]).start(stopSymbol, resumeTarget); - } - }; - try { - ResourcesPlugin.getWorkspace().run(r, null); - } catch (CoreException e) { - CDebugCorePlugin.log(e); - throw new DebugException(e.getStatus()); - } - return target[0]; - } - - /** - * Creates and returns a debug target for the given CDI target, with the - * specified name, and associates it with the given process for console I/O. - * The debug target is added to the given launch. - * - * @param launch - * the launch the new debug target will be contained in - * @param project - * the project to use to persist breakpoints. - * @param cdiTarget - * the CDI target to create a debug target for - * @param name - * the name to associate with this target, which will be returned - * from <code>IDebugTarget.getName</code>. - * @param debuggeeProcess - * the process to associate with the debug target, which will be - * returned from <code>IDebugTarget.getProcess</code> - * @param file - * the executable to debug. - * @param allowTerminate - * allow terminate(). - * @param allowDisconnect - * allow disconnect(). - * @param resumeTarget - * resume target. - * @return a debug target - * @throws DebugException - */ - public static IDebugTarget newDebugTarget(ILaunch launch, IProject project, ICDITarget cdiTarget, - final String name, IProcess debuggeeProcess, IBinaryObject file, boolean allowTerminate, - boolean allowDisconnect, boolean resumeTarget) throws DebugException { - return newDebugTarget(launch, project, cdiTarget, name, debuggeeProcess, file, allowTerminate, allowDisconnect, - null, resumeTarget); - } - - /** * Calculates breakpoint marker ID based on the breakpoint object type. * * @since 7.2 @@ -1376,61 +1212,6 @@ public class CDIDebugModel { return null; } - /** - * @deprecated - */ - @Deprecated - public static IDebugTarget newDebugTarget(ILaunch launch, ICDITarget target, String name, IProcess iprocess, - IProcess debuggerProcess, IFile file, boolean allowTerminate, boolean allowDisconnect, boolean stopInMain) - throws CoreException { - IBinaryExecutable exeFile = getBinary(file); - String stopSymbol = null; - if (stopInMain) - stopSymbol = launch.getLaunchConfiguration().getAttribute( - ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_STOP_AT_MAIN_SYMBOL, - ICDTLaunchConfigurationConstants.DEBUGGER_STOP_AT_MAIN_SYMBOL_DEFAULT); - return newDebugTarget(launch, file.getProject(), target, name, iprocess, exeFile, allowTerminate, - allowDisconnect, stopSymbol, true); - } - - /** - * @deprecated - */ - @Deprecated - public static IDebugTarget newAttachDebugTarget(ILaunch launch, ICDITarget target, String name, - IProcess debuggerProcess, IFile file) throws CoreException { - IBinaryExecutable exeFile = getBinary(file); - return newDebugTarget(launch, file.getProject(), target, name, null, exeFile, true, true, false); - } - - /** - * @deprecated - */ - @Deprecated - public static IDebugTarget newCoreFileDebugTarget(final ILaunch launch, final ICDITarget target, final String name, - final IProcess debuggerProcess, final IFile file) throws CoreException { - IBinaryExecutable exeFile = getBinary(file); - return newDebugTarget(launch, file.getProject(), target, name, null, exeFile, true, false, false); - } - - private static IBinaryExecutable getBinary(IFile file) throws CoreException { - IProject project = file.getProject(); - ICConfigExtensionReference[] binaryParsersExt = CCorePlugin.getDefault().getDefaultBinaryParserExtensions( - project); - for (int i = 0; i < binaryParsersExt.length; i++) { - IBinaryParser parser = CoreModelUtil.getBinaryParser(binaryParsersExt[i]); - try { - IBinaryFile exe = parser.getBinary(file.getLocation()); - if (exe instanceof IBinaryExecutable) { - return (IBinaryExecutable) exe; - } - } catch (IOException e) { - } - } - throw new CoreException(new Status(IStatus.ERROR, CDebugCorePlugin.getUniqueIdentifier(), -1, - DebugCoreMessages.getString("CDIDebugModel.0"), null)); //$NON-NLS-1$ - } - private static boolean sameSourceHandle(String handle1, String handle2) { if (handle1 == null || handle2 == null) return false; diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/CDebugCorePlugin.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/CDebugCorePlugin.java index 41274aa5adb..177b245c5d1 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/CDebugCorePlugin.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/CDebugCorePlugin.java @@ -12,11 +12,7 @@ *******************************************************************************/ package org.eclipse.cdt.debug.core; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; import java.util.HashSet; -import java.util.List; import org.eclipse.cdt.debug.core.breakpointactions.BreakpointActionManager; import org.eclipse.cdt.debug.core.command.CCommandAdapterFactory; @@ -27,11 +23,9 @@ import org.eclipse.cdt.debug.core.sourcelookup.AbsolutePathSourceContainer; import org.eclipse.cdt.debug.core.sourcelookup.CProjectSourceContainer; import org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocation; import org.eclipse.cdt.debug.core.sourcelookup.ProgramRelativePathSourceContainer; -import org.eclipse.cdt.debug.internal.core.DebugConfiguration; import org.eclipse.cdt.debug.internal.core.DebugModelProvider; import org.eclipse.cdt.debug.internal.core.ICDebugInternalConstants; import org.eclipse.cdt.debug.internal.core.ListenerList; -import org.eclipse.cdt.debug.internal.core.SessionManager; import org.eclipse.cdt.debug.internal.core.Trace; import org.eclipse.cdt.debug.internal.core.disassembly.DisassemblyContextService; import org.eclipse.cdt.debug.internal.core.sourcelookup.CSourceLookupDirector; @@ -41,8 +35,6 @@ import org.eclipse.core.resources.IWorkspace; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IAdapterManager; -import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.core.runtime.IExtensionPoint; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Plugin; @@ -74,10 +66,6 @@ public class CDebugCorePlugin extends Plugin { */ private static CDebugCorePlugin plugin; - private HashMap<String, DebugConfiguration> fDebugConfigurations; - - private HashSet<String> fActiveDebugConfigurations; - /** * Breakpoint listener list. */ @@ -105,8 +93,6 @@ public class CDebugCorePlugin extends Plugin { */ private CommonSourceLookupDirector fCommonSourceLookupDirector; - private SessionManager fSessionManager = null; - /** * The constructor. */ @@ -179,117 +165,6 @@ public class CDebugCorePlugin extends Plugin { getDefault().getLog().log(new Status(IStatus.ERROR, CDIDebugModel.getPluginIdentifier(), INTERNAL_ERROR, message, null)); } - private void initializeDebugConfiguration() { - IExtensionPoint extensionPoint = Platform.getExtensionRegistry().getExtensionPoint(getUniqueIdentifier(), CDEBUGGER_EXTENSION_POINT_ID); - IConfigurationElement[] infos = extensionPoint.getConfigurationElements(); - fDebugConfigurations = new HashMap<String, DebugConfiguration>(infos.length); - for(int i = 0; i < infos.length; i++) { - IConfigurationElement configurationElement = infos[i]; - if (configurationElement.getName().equals(DEBUGGER_ELEMENT)) { - DebugConfiguration configType = new DebugConfiguration(configurationElement); - fDebugConfigurations.put(configType.getID(), configType); - } - } - } - - private void initializeActiveDebugConfigurations() { - fActiveDebugConfigurations = new HashSet<String>(getDebugConfigurations().length); - fActiveDebugConfigurations.addAll(fDebugConfigurations.keySet()); - String[] filteredTypes = CDebugCorePlugin.getDefault().getPluginPreferences().getString(ICDebugConstants.PREF_FILTERED_DEBUGGERS).split("\\,"); //$NON-NLS-1$ - fActiveDebugConfigurations.removeAll(Arrays.asList(filteredTypes)); - } - - public ICDebugConfiguration[] getDebugConfigurations() { - if (fDebugConfigurations == null) { - initializeDebugConfiguration(); - } - return fDebugConfigurations.values().toArray(new ICDebugConfiguration[fDebugConfigurations.size()]); - } - - public ICDebugConfiguration[] getActiveDebugConfigurations() { - if (fDebugConfigurations == null) { - initializeDebugConfiguration(); - } - if (fActiveDebugConfigurations == null) { - initializeActiveDebugConfigurations(); - } - ArrayList<DebugConfiguration> list = new ArrayList<DebugConfiguration>(fActiveDebugConfigurations.size()); - - for (String id : fActiveDebugConfigurations) { - DebugConfiguration dc = fDebugConfigurations.get(id); - if (dc != null) - list.add(dc); - } - return list.toArray(new ICDebugConfiguration[list.size()]); - } - - public ICDebugConfiguration[] getDefaultActiveDebugConfigurations() { - List<String> filtered = Arrays.asList(CDebugCorePlugin.getDefault().getPluginPreferences().getDefaultString(ICDebugConstants.PREF_FILTERED_DEBUGGERS).split("\\,")); //$NON-NLS-1$ - HashMap<String, DebugConfiguration> all = new HashMap<String, DebugConfiguration>(fDebugConfigurations); - all.keySet().removeAll(filtered); - return all.values().toArray(new ICDebugConfiguration[all.size()]); - } - - public void saveFilteredDebugConfigurations(ICDebugConfiguration[] configurations) { - disposeActiveDebugConfigurations(); - StringBuffer sb = new StringBuffer(); - for (int i = 0; i < configurations.length; ++i) { - sb.append(configurations[i].getID()).append(','); - } - CDebugCorePlugin.getDefault().getPluginPreferences().setValue(ICDebugConstants.PREF_FILTERED_DEBUGGERS, sb.toString()); - CDebugCorePlugin.getDefault().savePluginPreferences(); - } - - public void saveDefaultDebugConfiguration(String id) { - CDebugCorePlugin.getDefault().getPluginPreferences().setValue(ICDebugConstants.PREF_DEFAULT_DEBUGGER_TYPE, (id != null) ? id : ""); //$NON-NLS-1$ - } - - public ICDebugConfiguration getDefaultDebugConfiguration() { - ICDebugConfiguration result = null; - try { - result = getDebugConfiguration(CDebugCorePlugin.getDefault().getPluginPreferences().getString(ICDebugConstants.PREF_DEFAULT_DEBUGGER_TYPE)); - } catch (CoreException e) { - } - return result; - } - - public ICDebugConfiguration getDefaultDefaultDebugConfiguration() { - ICDebugConfiguration result = null; - try { - result = getDebugConfiguration(CDebugCorePlugin.getDefault().getPluginPreferences().getDefaultString(ICDebugConstants.PREF_DEFAULT_DEBUGGER_TYPE)); - } catch (CoreException e) { - } - if (result == null) { - } - return result; - } - - public boolean isDefaultDebugConfiguration(String id) { - return id.compareTo(CDebugCorePlugin.getDefault().getPluginPreferences().getString(ICDebugConstants.PREF_DEFAULT_DEBUGGER_TYPE)) == 0; - } - - public ICDebugConfiguration getDebugConfiguration(String id) throws CoreException { - if (fDebugConfigurations == null) { - initializeDebugConfiguration(); - } - ICDebugConfiguration dbgCfg = fDebugConfigurations.get(id); - if (dbgCfg == null) { - IStatus status = new Status(IStatus.ERROR, getUniqueIdentifier(), 100, DebugCoreMessages.getString("CDebugCorePlugin.0"), null); //$NON-NLS-1$ - throw new CoreException(status); - } - return dbgCfg; - } - - protected SessionManager getSessionManager() { - return fSessionManager; - } - - protected void setSessionManager(SessionManager sm) { - if (fSessionManager != null) - fSessionManager.dispose(); - fSessionManager = sm; - } - public void saveCommonSourceLocations(ICSourceLocation[] locations) { CDebugCorePlugin.getDefault().getPluginPreferences().setValue(ICDebugConstants.PREF_SOURCE_LOCATIONS, SourceUtils.getCommonSourceLocationsMemento(locations)); } @@ -348,7 +223,6 @@ public class CDebugCorePlugin extends Plugin { createCommandAdapterFactory(); createBreakpointListenersList(); createDisassemblyContextService(); - setSessionManager(new SessionManager()); setDefaultLaunchDelegates(); Platform.getAdapterManager().registerAdapters(new DebugModelProvider(), ICDebugElement.class); @@ -359,11 +233,9 @@ public class CDebugCorePlugin extends Plugin { */ @Override public void stop(BundleContext context) throws Exception { - setSessionManager(null); disposeDisassemblyContextService(); disposeBreakpointListenersList(); disposeCommonSourceLookupDirector(); - disposeDebugConfigurations(); super.stop(context); } @@ -423,21 +295,6 @@ public class CDebugCorePlugin extends Plugin { private void convertSourceLocations(CommonSourceLookupDirector director) { director.setSourceContainers(SourceUtils.convertSourceLocations(getCommonSourceLocations())); } - - private void disposeActiveDebugConfigurations() { - if (fActiveDebugConfigurations != null) { - fActiveDebugConfigurations.clear(); - fActiveDebugConfigurations = null; - } - } - - private void disposeDebugConfigurations() { - disposeActiveDebugConfigurations(); - if (fDebugConfigurations != null) { - fDebugConfigurations.clear(); - fDebugConfigurations = null; - } - } public BreakpointActionManager getBreakpointActionManager() { if (breakpointActionManager == null) diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/CDebugUtils.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/CDebugUtils.java index 3d6329c3b9d..0c607e563cb 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/CDebugUtils.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/CDebugUtils.java @@ -32,17 +32,14 @@ import javax.xml.transform.stream.StreamResult; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.model.ICProject; -import org.eclipse.cdt.debug.core.cdi.CDIException; import org.eclipse.cdt.debug.core.model.ICAddressBreakpoint; import org.eclipse.cdt.debug.core.model.ICBreakpoint; import org.eclipse.cdt.debug.core.model.ICBreakpointType; import org.eclipse.cdt.debug.core.model.ICDynamicPrintf; import org.eclipse.cdt.debug.core.model.ICFunctionBreakpoint; import org.eclipse.cdt.debug.core.model.ICLineBreakpoint; -import org.eclipse.cdt.debug.core.model.ICValue; import org.eclipse.cdt.debug.core.model.ICWatchpoint; import org.eclipse.cdt.debug.core.model.ICWatchpoint2; -import org.eclipse.cdt.debug.internal.core.model.CFloatingPointValue; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IMarker; import org.eclipse.core.resources.IProject; @@ -246,16 +243,6 @@ public class CDebugUtils { return serializeDocument(doc, true); } - public static Number getFloatingPointValue(ICValue value) { - if (value instanceof CFloatingPointValue) { - try { - return ((CFloatingPointValue)value).getFloatingPointValue(); - } catch (CDIException e) { - } - } - return null; - } - public static boolean isNaN(Number value) { if (value instanceof Double) { return ((Double) value).isNaN(); diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/ICDIDebugger.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/ICDIDebugger.java deleted file mode 100644 index a50cf3bb6ae..00000000000 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/ICDIDebugger.java +++ /dev/null @@ -1,31 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2012 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 - *******************************************************************************/ -package org.eclipse.cdt.debug.core; - -import org.eclipse.cdt.core.IBinaryParser.IBinaryObject; -import org.eclipse.cdt.debug.core.cdi.ICDISession; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.debug.core.ILaunch; - -/** - * @deprecated use <code>ICDIDebugger2</code>. - */ -@Deprecated -public interface ICDIDebugger { - - /** - * @deprecated use <code>createSession</code> of <code>ICDIDebugger2</code> - */ - @Deprecated - public ICDISession createDebuggerSession(ILaunch launch, IBinaryObject exe, IProgressMonitor monitor) throws CoreException; - -} diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/ICDIDebugger2.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/ICDIDebugger2.java deleted file mode 100644 index bc9cba0550b..00000000000 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/ICDIDebugger2.java +++ /dev/null @@ -1,29 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2010 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 - *******************************************************************************/ -package org.eclipse.cdt.debug.core; - -import java.io.File; -import org.eclipse.cdt.debug.core.cdi.ICDISession; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.debug.core.ILaunch; - -/** - * Replacement for deprecated <code>ICDIDebugger</code>. - */ -public interface ICDIDebugger2 extends ICDIDebugger { - - /** - * <code>null</code> can be passed as <code>executable</code> allowing debuggers to create session without executables, - * or load executables later during the session. - */ - public ICDISession createSession(ILaunch launch, File executable, IProgressMonitor monitor) throws CoreException; -} diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/ICDebugConfiguration.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/ICDebugConfiguration.java deleted file mode 100644 index 8573f5fd077..00000000000 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/ICDebugConfiguration.java +++ /dev/null @@ -1,44 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2012 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 - *******************************************************************************/ -package org.eclipse.cdt.debug.core; - -import org.eclipse.core.runtime.CoreException; - -public interface ICDebugConfiguration { - final static String CPU_NATIVE = "native"; //$NON-NLS-1$ - - /** - * @return - * @throws CoreException - * @deprecated - */ - @Deprecated - ICDebugger getDebugger() throws CoreException; - - ICDIDebugger createDebugger() throws CoreException; - String getName(); - String getID(); - String getPlatform(); - String[] getCPUList(); - String[] getModeList(); - String[] getCoreFileExtensions(); - boolean supportsCPU(String cpu); - boolean supportsMode(String mode); - - /** - * Returns a list of supported build configuration ids. - * Returns an empty array if a list has not been specified, - * which means that this debug configuration supports all - * build configurations. - */ - String[] getSupportedBuildConfigPatterns(); - -} diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/ICDebugger.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/ICDebugger.java deleted file mode 100644 index 633d1014228..00000000000 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/ICDebugger.java +++ /dev/null @@ -1,28 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2012 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 - *******************************************************************************/ -package org.eclipse.cdt.debug.core; - -import org.eclipse.cdt.debug.core.cdi.CDIException; -import org.eclipse.cdt.debug.core.cdi.ICDISession; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.runtime.IPath; -import org.eclipse.debug.core.ILaunchConfiguration; - -/** - * - * @deprecated - see ICDIDebugger - */ -@Deprecated -public interface ICDebugger { - public ICDISession createLaunchSession(ILaunchConfiguration config, IFile exe) throws CDIException ; - public ICDISession createAttachSession(ILaunchConfiguration config, IFile exe, int pid) throws CDIException; - public ICDISession createCoreSession(ILaunchConfiguration config, IFile exe, IPath corefile) throws CDIException; -} diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/ICGlobalVariableManager.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/ICGlobalVariableManager.java deleted file mode 100644 index fbe4523ccaa..00000000000 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/ICGlobalVariableManager.java +++ /dev/null @@ -1,48 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2005 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 - *******************************************************************************/ -package org.eclipse.cdt.debug.core; - -import org.eclipse.cdt.debug.core.model.ICGlobalVariable; -import org.eclipse.cdt.debug.core.model.IGlobalVariableDescriptor; -import org.eclipse.debug.core.DebugException; - -/** - * Manages the collection of global variables added to a debug target. - */ -public interface ICGlobalVariableManager { - - /** - * Registers with this manager the global variables specified by given descriptors. - * - * @param descriptors the descriptors of global variables to register with this manager - * @throws DebugException - */ - public void addGlobals( IGlobalVariableDescriptor[] descriptors ) throws DebugException; - - /** - * Removes specified global variables from this manager. - * - * @param globals global variables to remove - */ - public void removeGlobals( ICGlobalVariable[] globals ); - - /** - * Removes all global variables from this manager. - */ - public void removeAllGlobals(); - - /** - * Returns the array of descriptors of global varibales added to this manager. - * - * @return the array of descriptors - */ - public IGlobalVariableDescriptor[] getDescriptors(); -} diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/breakpointactions/BreakpointActionAdapterFactory.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/breakpointactions/BreakpointActionAdapterFactory.java deleted file mode 100644 index 00aafd75368..00000000000 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/breakpointactions/BreakpointActionAdapterFactory.java +++ /dev/null @@ -1,38 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2012 Nokia 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: - * Nokia - initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.debug.core.breakpointactions; - -import org.eclipse.cdt.debug.internal.core.model.CThread; -import org.eclipse.core.runtime.IAdapterFactory; - -public class BreakpointActionAdapterFactory implements IAdapterFactory { - - @Override - public Object getAdapter(Object adaptableObject, Class adapterType) { - if (adapterType.equals(ILogActionEnabler.class)) { - if (adaptableObject instanceof CThread) { - return new LogActionEnabler((CThread) adaptableObject); - } - } - if (adapterType.equals(IResumeActionEnabler.class)) { - if (adaptableObject instanceof CThread) { - return new ResumeActionEnabler((CThread) adaptableObject); - } - } - return null; - } - - @Override - public Class[] getAdapterList() { - return new Class[] { ILogActionEnabler.class, IResumeActionEnabler.class, }; - } - -} diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/breakpointactions/LogActionEnabler.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/breakpointactions/LogActionEnabler.java deleted file mode 100644 index 8f3c3198145..00000000000 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/breakpointactions/LogActionEnabler.java +++ /dev/null @@ -1,34 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2012 Nokia 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: - * Nokia - initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.debug.core.breakpointactions; - -import java.util.List; - -import org.eclipse.cdt.debug.internal.core.model.CStackFrame; -import org.eclipse.cdt.debug.internal.core.model.CThread; - -public class LogActionEnabler implements ILogActionEnabler { - - private CThread thread; - - public LogActionEnabler(CThread thread) { - this.thread = thread; - } - - @Override - public String evaluateExpression(String expression) throws Exception { - List frames = thread.computeStackFrames(); - CStackFrame frame = (CStackFrame) frames.get(0); - - return frame.evaluateExpressionToString(expression); - } - -} diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/breakpointactions/ResumeActionEnabler.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/breakpointactions/ResumeActionEnabler.java deleted file mode 100644 index 0412f310f84..00000000000 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/breakpointactions/ResumeActionEnabler.java +++ /dev/null @@ -1,28 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2012 Nokia 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: - * Nokia - initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.debug.core.breakpointactions; - -import org.eclipse.cdt.debug.internal.core.model.CThread; - -public class ResumeActionEnabler implements IResumeActionEnabler { - - private CThread thread; - - public ResumeActionEnabler(CThread adaptableObject) { - thread = adaptableObject; - } - - @Override - public void resume() throws Exception { - thread.resume(); - } - -} diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/CVariableFormat.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/CVariableFormat.java deleted file mode 100644 index 21e5b3a6c94..00000000000 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/CVariableFormat.java +++ /dev/null @@ -1,57 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2012 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 - *******************************************************************************/ -package org.eclipse.cdt.debug.core.model; - -/** - * Defines the variable format types. - */ -public class CVariableFormat { - - private final String fName; - private final int fNum; - - private CVariableFormat( String name, int num ) { - this.fName = name; - this.fNum= num; - } - - @Override - public String toString() { - return this.fName; - } - - public int getFormatNumber() { - return this.fNum; - } - - public static CVariableFormat getFormat( int code ) { - if ( code == NATURAL.getFormatNumber() ) { - return NATURAL; - } else if ( code == DECIMAL.getFormatNumber() ) { - return DECIMAL; - } else if ( code == BINARY.getFormatNumber() ) { - return BINARY; - } else if ( code == OCTAL.getFormatNumber() ) { - return OCTAL; - } else if ( code == HEXADECIMAL.getFormatNumber() ) { - return HEXADECIMAL; - } else { - // unexpected value, mapping to NATURAL - return NATURAL; - } - } - - public static final CVariableFormat NATURAL = new CVariableFormat( "natural", 0 ); //$NON-NLS-1$ - public static final CVariableFormat DECIMAL = new CVariableFormat( "decimal", 1 ); //$NON-NLS-1$ - public static final CVariableFormat BINARY = new CVariableFormat( "binary", 2 ); //$NON-NLS-1$ - public static final CVariableFormat OCTAL = new CVariableFormat( "octal", 3 ); //$NON-NLS-1$ - public static final CVariableFormat HEXADECIMAL = new CVariableFormat( "hexadecimal", 4 ); //$NON-NLS-1$ -} diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/IAddRegisterGroupHandler.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/IAddRegisterGroupHandler.java deleted file mode 100644 index 1e402ad491b..00000000000 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/IAddRegisterGroupHandler.java +++ /dev/null @@ -1,21 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2014 Ericsson 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: - * Marc Khouzam (Ericsson) - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.debug.core.model; - -import org.eclipse.debug.core.commands.IDebugCommandHandler; - -/** - * Handler interface to for the addRegisterGroup command - * - * @since 7.6 - */ -public interface IAddRegisterGroupHandler extends IDebugCommandHandler { -} diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/ICBreakpointFilterExtension.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/ICBreakpointFilterExtension.java deleted file mode 100644 index a30526da030..00000000000 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/ICBreakpointFilterExtension.java +++ /dev/null @@ -1,81 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 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 - * Wind River Systems - Refactored from ICBreakpoint - *******************************************************************************/ -package org.eclipse.cdt.debug.core.model; - -import org.eclipse.core.runtime.CoreException; - -/** - * Breakpoint extension to allow filtering based on CDTs extended standard debug - * model elements. - */ -public interface ICBreakpointFilterExtension extends ICBreakpointExtension { - - /** - * Add the given target to the list of this breakpoint's targets. - * Target filters are not persisted across workbench invocations. - * - * @param target the target to add to the list of this breakpoint's targets. - * @throws CoreException if unable to set the target filter - */ - public void setTargetFilter( ICDebugTarget target ) throws CoreException; - - /** - * Removes the given target from the breakpoint's target list. - * The breakpoint has no effect in the given target. - * - * @param target the target filter to be removed - * @exception CoreException if unable to remove the target filter - */ - public void removeTargetFilter( ICDebugTarget target ) throws CoreException; - - /** - * Restricts this breakpoint to suspend only in the given threads - * when encounterd in the given threads' target. - * All threads must be from the same target. - * Thread filters are not persisted across workbench invocations. - * - * @param threads the thread filters to be set - * @exception CoreException if unable to set the thread filters - */ - public void setThreadFilters( ICThread[] threads ) throws CoreException; - - /** - * Returns all target filters set on this breakpoint. - * - * @return the targets that this breakpoint is resticted to - * @exception CoreException if unable to determine this breakpoint's - * target filters - */ - public ICDebugTarget[] getTargetFilters() throws CoreException; - - /** - * Removes this breakpoint's thread filters in the given target, if any. - * Has no effect if this breakpoint does not have filters in the given target. - * All threads must be from the same target. - * - * @param threads the thread filters to be removed - * @exception CoreException if unable to remove the thread filter - */ - public void removeThreadFilters( ICThread[] threads ) throws CoreException; - - /** - * Returns the threads in the given target in which this breakpoint - * is enabled or <code>null</code> if this breakpoint is enabled in - * all threads in the given target. - * - * @return the threads in the given target that this breakpoint is enabled for - * @exception CoreException if unable to determine this breakpoint's thread - * filters - */ - public ICThread[] getThreadFilters( ICDebugTarget target ) throws CoreException; - -} diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/ICDebugTarget.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/ICDebugTarget.java deleted file mode 100644 index 9962c470315..00000000000 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/ICDebugTarget.java +++ /dev/null @@ -1,123 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2012 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 - *******************************************************************************/ -package org.eclipse.cdt.debug.core.model; - -import org.eclipse.cdt.core.IAddress; -import org.eclipse.debug.core.DebugException; -import org.eclipse.debug.core.model.IDebugTarget; -import org.eclipse.debug.core.model.IRegisterGroup; - -/** - * C/C++ extension of <code>IDebugTarget</code>. - */ -public interface ICDebugTarget extends IDebugTarget, - IExecFileInfo, - IRestart, - IResumeWithoutSignal, - ICDebugElement, - ISteppingModeTarget, - IModuleRetrieval, - ITargetProperties { - - /** - * Returns whether this target is little endian. - * - * @return whether this target is little endian - */ - @Override - public boolean isLittleEndian(); - - /** - * Returns whether this target supports signals. - * - * @return whether this target supports signals - * @throws DebugException if this method fails. - */ - public boolean hasSignals() throws DebugException; - - /** - * Returns the list of signals defined for this target. - * - * @return the list of signals defined for this target - * @throws DebugException if this method fails. - */ - public ICSignal[] getSignals() throws DebugException; - - /** - * Returns the disassembly provider of this debug target. - * - * @return the disassembly provider of this debug target - * @throws DebugException if this method fails. - */ - public IDisassembly getDisassembly() throws DebugException; - - /** - * Returns whether this target is a post mortem type. - * - * @return whether this target is a post mortem type - */ - public boolean isPostMortem(); - - /** - * Returns the list of descriptors of the target registers - * - * @return the list register descriptors - * @throws DebugException if this method fails. Reasons include: - * - * @since 3.0 - */ - public IRegisterDescriptor[] getRegisterDescriptors() throws DebugException; - - /** - * Adds a new user-defined register group to this target - * - * @param name the group name - * @param descriptors the list of registers to be grouped - * - * @since 3.0 - */ - public void addRegisterGroup( String name, IRegisterDescriptor[] descriptors ); - - /** - * Removes the given register group from the target - * - * @param group a group to be removed - * - * @since 3.0 - */ - public void removeRegisterGroups( IRegisterGroup[] groups ); - - /** - * Replace the given group's register descriptors by the specified descriptors. - * - * @param group a group to be modified - * @param descriptors a descriptor array to replace existing descriptors - * - * @since 3.0 - */ - public void modifyRegisterGroup( IPersistableRegisterGroup group, IRegisterDescriptor[] descriptors ); - - - /** - * Removes all user-defined register groups and restores the hardware groups. - * - * @since 3.0 - */ - public void restoreDefaultRegisterGroups(); - - /** - * Returns the target address of the given breakpoint. - * - * @return the target address of the given breakpoint - * @throws DebugException if the address is not available - */ - public IAddress getBreakpointAddress( ICLineBreakpoint breakpoint ) throws DebugException; -} diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/ICGlobalVariable.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/ICGlobalVariable.java deleted file mode 100644 index 19e9eb06c3e..00000000000 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/ICGlobalVariable.java +++ /dev/null @@ -1,24 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 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 - *******************************************************************************/ -package org.eclipse.cdt.debug.core.model; - -/** - * Represents a global C/C++ variable. - */ -public interface ICGlobalVariable extends ICVariable { - - /** - * Returns the descriptor of this variable. Will be null if a child of a global. - * - * @return the descriptor of this variable - */ - public IGlobalVariableDescriptor getDescriptor(); -} diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/ICRegister.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/ICRegister.java deleted file mode 100644 index 4e619d63765..00000000000 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/ICRegister.java +++ /dev/null @@ -1,21 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 ARM Limited 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: - * ARM Limited - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.debug.core.model; - -import org.eclipse.debug.core.model.IRegister; - -/** - * C/C++ specific extension of <code>IRegister</code>. - * Added to be able to contribute a label provider. - * See https://bugs.eclipse.org/bugs/show_bug.cgi?id=186981 - */ -public interface ICRegister extends ICVariable, IRegister { -} diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/ICVariable.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/ICVariable.java deleted file mode 100644 index cbd92257e8b..00000000000 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/ICVariable.java +++ /dev/null @@ -1,44 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2007 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 - *******************************************************************************/ -package org.eclipse.cdt.debug.core.model; - -import org.eclipse.debug.core.DebugException; -import org.eclipse.debug.core.model.IValueModification; -import org.eclipse.debug.core.model.IVariable; - -/** - * C/C++ specific extension <code>IVariable</code>. - */ -public interface ICVariable extends IVariable, ICDebugElement, IFormatSupport, ICastToArray, IValueModification, IEnableDisableTarget { - - /** - * Returns the type of this variable. - * - * @return the type of this variable - * @throws DebugException - */ - ICType getType() throws DebugException; - - /** - * Returns whether this variable is an argument. - * - * @return whether this variable is an argument - */ - boolean isArgument(); - - /** - * Returns the text presentation of this variable as an expression. - * - * @return the text presentation of this variable as an expression - * @throws DebugException - */ - public String getExpressionString() throws DebugException; -} diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/IChangeReverseMethodHandler.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/IChangeReverseMethodHandler.java index 5766dea6b0b..c24f3ec3169 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/IChangeReverseMethodHandler.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/IChangeReverseMethodHandler.java @@ -15,7 +15,7 @@ import org.eclipse.debug.core.commands.IDebugCommandHandler; /** * Handler interface for the reverse debug change trace method command * - * @since 7.8 + * @since 8.0 */ public interface IChangeReverseMethodHandler extends IReverseToggleHandler, IDebugCommandHandler { diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/IFormatSupport.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/IFormatSupport.java deleted file mode 100644 index 290b9e3f857..00000000000 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/IFormatSupport.java +++ /dev/null @@ -1,41 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2006 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 - *******************************************************************************/ -package org.eclipse.cdt.debug.core.model; - -import org.eclipse.debug.core.DebugException; - -/** - * Provides the ability to set and get the format of a variable. - */ -public interface IFormatSupport { - - /** - * Returns whether this variable supports formatting operations. - * - * @return whether this variable supports formatting operations - */ - boolean supportsFormatting(); - - /** - * Returns the current format of this variable. - * - * @return the current format of this variable - */ - CVariableFormat getFormat(); - - /** - * Sets the current format of this variable to <code>format</code>. - * - * @param format the new format type - * @throws DebugException if this method fails. - */ - void changeFormat( CVariableFormat format ) throws DebugException; -} diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CBreakpointManager.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CBreakpointManager.java deleted file mode 100644 index bdd060f4cb0..00000000000 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CBreakpointManager.java +++ /dev/null @@ -1,1542 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2015 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 - * Matthias Spycher (matthias@coware.com) - patch for bug #112008 - * Ken Ryall (Nokia) - bugs 170027, 105196 - * Ling Wang (Nokia) - bug 176081 - * Freescale Semiconductor - Address watchpoints, https://bugs.eclipse.org/bugs/show_bug.cgi?id=118299 - * QNX Software Systems - catchpoints - bug 226689 - * James Blackburn (Broadcom) - bug 314865 - * Marc Khouzam (Ericsson) - Support for dynamic printf (400628) - *******************************************************************************/ -package org.eclipse.cdt.debug.internal.core; - -import java.io.File; -import java.io.IOException; -import java.math.BigInteger; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import org.eclipse.cdt.core.IAddress; -import org.eclipse.cdt.core.IAddressFactory; -import org.eclipse.cdt.core.IBinaryParser.IBinaryObject; -import org.eclipse.cdt.core.model.ITranslationUnit; -import org.eclipse.cdt.debug.core.CDIDebugModel; -import org.eclipse.cdt.debug.core.CDebugCorePlugin; -import org.eclipse.cdt.debug.core.CDebugUtils; -import org.eclipse.cdt.debug.core.cdi.CDIException; -import org.eclipse.cdt.debug.core.cdi.ICDIAddressLocation; -import org.eclipse.cdt.debug.core.cdi.ICDICondition; -import org.eclipse.cdt.debug.core.cdi.ICDIFunctionLocation; -import org.eclipse.cdt.debug.core.cdi.ICDILineLocation; -import org.eclipse.cdt.debug.core.cdi.ICDILocator; -import org.eclipse.cdt.debug.core.cdi.event.ICDIBreakpointMovedEvent; -import org.eclipse.cdt.debug.core.cdi.event.ICDIBreakpointProblemEvent; -import org.eclipse.cdt.debug.core.cdi.event.ICDIChangedEvent; -import org.eclipse.cdt.debug.core.cdi.event.ICDICreatedEvent; -import org.eclipse.cdt.debug.core.cdi.event.ICDIDestroyedEvent; -import org.eclipse.cdt.debug.core.cdi.event.ICDIEvent; -import org.eclipse.cdt.debug.core.cdi.event.ICDIEventListener; -import org.eclipse.cdt.debug.core.cdi.event.ICDIExecutableReloadedEvent; -import org.eclipse.cdt.debug.core.cdi.model.ICDIAddressBreakpoint; -import org.eclipse.cdt.debug.core.cdi.model.ICDIBreakpoint; -import org.eclipse.cdt.debug.core.cdi.model.ICDIBreakpoint2; -import org.eclipse.cdt.debug.core.cdi.model.ICDIBreakpointManagement2; -import org.eclipse.cdt.debug.core.cdi.model.ICDIBreakpointManagement3; -import org.eclipse.cdt.debug.core.cdi.model.ICDIEventBreakpoint; -import org.eclipse.cdt.debug.core.cdi.model.ICDIFunctionBreakpoint; -import org.eclipse.cdt.debug.core.cdi.model.ICDILineBreakpoint; -import org.eclipse.cdt.debug.core.cdi.model.ICDILocationBreakpoint; -import org.eclipse.cdt.debug.core.cdi.model.ICDIObject; -import org.eclipse.cdt.debug.core.cdi.model.ICDITarget; -import org.eclipse.cdt.debug.core.cdi.model.ICDITargetConfiguration; -import org.eclipse.cdt.debug.core.cdi.model.ICDITargetConfiguration2; -import org.eclipse.cdt.debug.core.cdi.model.ICDIWatchpoint; -import org.eclipse.cdt.debug.core.cdi.model.ICDIWatchpoint2; -import org.eclipse.cdt.debug.core.model.ICAddressBreakpoint; -import org.eclipse.cdt.debug.core.model.ICBreakpoint; -import org.eclipse.cdt.debug.core.model.ICBreakpointFilterExtension; -import org.eclipse.cdt.debug.core.model.ICBreakpointType; -import org.eclipse.cdt.debug.core.model.ICDebugTarget; -import org.eclipse.cdt.debug.core.model.ICDynamicPrintf; -import org.eclipse.cdt.debug.core.model.ICEventBreakpoint; -import org.eclipse.cdt.debug.core.model.ICFunctionBreakpoint; -import org.eclipse.cdt.debug.core.model.ICLineBreakpoint; -import org.eclipse.cdt.debug.core.model.ICThread; -import org.eclipse.cdt.debug.core.model.ICTracepoint; -import org.eclipse.cdt.debug.core.model.ICWatchpoint; -import org.eclipse.cdt.debug.core.model.ICWatchpoint2; -import org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocator; -import org.eclipse.cdt.debug.internal.core.breakpoints.BreakpointProblems; -import org.eclipse.cdt.debug.internal.core.breakpoints.CBreakpoint; -import org.eclipse.cdt.debug.internal.core.model.CDebugTarget; -import org.eclipse.cdt.debug.internal.core.sourcelookup.CSourceLookupDirector; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IMarker; -import org.eclipse.core.resources.IMarkerDelta; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.IStorage; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Path; -import org.eclipse.debug.core.DebugException; -import org.eclipse.debug.core.DebugPlugin; -import org.eclipse.debug.core.IBreakpointManager; -import org.eclipse.debug.core.IBreakpointManagerListener; -import org.eclipse.debug.core.IBreakpointsListener; -import org.eclipse.debug.core.model.IBreakpoint; -import org.eclipse.debug.core.model.IDebugTarget; -import org.eclipse.debug.core.model.ILineBreakpoint; -import org.eclipse.debug.core.model.ISourceLocator; -import org.eclipse.debug.core.sourcelookup.containers.LocalFileStorage; - -public class CBreakpointManager implements IBreakpointsListener, IBreakpointManagerListener, ICDIEventListener, IAdaptable { - - static class BreakpointInProgess { - - private ICDIBreakpoint fCDIBreakpoint; - - void setCDIBreakpoint( ICDIBreakpoint b ) { - fCDIBreakpoint = b; - } - - ICDIBreakpoint getCDIBreakpoint() { - return fCDIBreakpoint; - } - } - - class BreakpointMap { - - /** - * Maps CBreakpoints to CDI breakpoints. - */ - private HashMap fCBreakpoints; - - /** - * Maps CDI breakpoints to CBreakpoints. - */ - private HashMap fCDIBreakpoints; - - protected BreakpointMap() { - fCBreakpoints = new HashMap( 10 ); - fCDIBreakpoints = new HashMap( 10 ); - } - - void register( ICBreakpoint breakpoint ) { - fCBreakpoints.put( breakpoint, new BreakpointInProgess() ); - } - - void put( ICBreakpoint breakpoint, ICDIBreakpoint cdiBreakpoint ) { - fCBreakpoints.put( breakpoint, cdiBreakpoint ); - fCDIBreakpoints.put( cdiBreakpoint, breakpoint ); - } - - Object get( ICBreakpoint breakpoint ) { - return fCBreakpoints.get( breakpoint ); - } - - ICDIBreakpoint getCDIBreakpoint( ICBreakpoint breakpoint ) { - Object b = fCBreakpoints.get( breakpoint ); - return ( b instanceof ICDIBreakpoint ) ? (ICDIBreakpoint)b : null; - } - - ICBreakpoint getCBreakpoint( ICDIBreakpoint cdiBreakpoint ) { - ICBreakpoint breakpoint = (ICBreakpoint)fCDIBreakpoints.get( cdiBreakpoint ); - if ( breakpoint == null ) { - ICBreakpoint[] bip = getBreakpointsInProgress(); - for ( int i = 0; i < bip.length; ++i ) { - if ( isSameBreakpoint( bip[i], cdiBreakpoint ) ) { - breakpoint = bip[i]; - break; - } - } - } - return breakpoint; - } - - void removeCDIBreakpoint( ICDIBreakpoint cdiBreakpoint ) { - if ( cdiBreakpoint != null ) { - ICBreakpoint breakpoint = (ICBreakpoint)fCDIBreakpoints.remove( cdiBreakpoint ); - if ( breakpoint != null ) - fCBreakpoints.remove( breakpoint ); - } - } - - boolean isRegistered( ICBreakpoint breakpoint ) { - return ( fCBreakpoints.get( breakpoint ) != null ); - } - - boolean isInProgress( ICBreakpoint breakpoint ) { - return ( fCBreakpoints.get( breakpoint ) instanceof BreakpointInProgess ); - } - - ICBreakpoint[] getAllCBreakpoints() { - Set set = fCBreakpoints.keySet(); - return (ICBreakpoint[])set.toArray( new ICBreakpoint[set.size()] ); - } - - void dispose() { - fCBreakpoints.clear(); - fCDIBreakpoints.clear(); - } - - private ICBreakpoint[] getBreakpointsInProgress() { - ArrayList list = new ArrayList(); - Set set = fCBreakpoints.entrySet(); - Iterator it = set.iterator(); - while ( it.hasNext() ) { - Map.Entry entry = (Map.Entry)it.next(); - if ( entry.getValue() instanceof BreakpointInProgess ) { - list.add( entry.getKey() ); - } - } - return (ICBreakpoint[])list.toArray( new ICBreakpoint[list.size()] ); - } - - private boolean isSameBreakpoint( ICBreakpoint breakpoint, ICDIBreakpoint cdiBreakpoint ) { - try { - if ( breakpoint instanceof ICFunctionBreakpoint && cdiBreakpoint instanceof ICDIFunctionBreakpoint ) { - return ( ((ICFunctionBreakpoint)breakpoint).getFunction().compareTo( ((ICDIFunctionBreakpoint)cdiBreakpoint).getLocator().getFunction() ) == 0 ); - } - if ( breakpoint instanceof ICAddressBreakpoint && cdiBreakpoint instanceof ICDIAddressBreakpoint ) { - IAddressFactory factory = getDebugTarget().getAddressFactory(); - return factory.createAddress( ((ICAddressBreakpoint)breakpoint).getAddress() ).equals( factory.createAddress( ((ICDIAddressBreakpoint)cdiBreakpoint).getLocator().getAddress() ) ); - } - if ( breakpoint instanceof ICLineBreakpoint && cdiBreakpoint instanceof ICDILineBreakpoint ) { - ICDILocator location = ((ICDILineBreakpoint)cdiBreakpoint).getLocator(); - String file = location.getFile(); - String sourceHandle = file; - if ( !isEmpty( file ) ) { - Object sourceElement = getSourceElement( file ); - if ( sourceElement instanceof IFile ) { - sourceHandle = ((IFile)sourceElement).getLocation().toOSString(); - } - else if ( sourceElement instanceof IStorage ) { - sourceHandle = ((IStorage)sourceElement).getFullPath().toOSString(); - } - else if ( sourceElement instanceof ITranslationUnit ) { - sourceHandle = ((ITranslationUnit)sourceElement).getLocation().toOSString(); - } - String bpSourceHandle = ((ICLineBreakpoint)breakpoint).getSourceHandle(); - if ( sourceElement instanceof LocalFileStorage ) { // see bug #112008 - try { - bpSourceHandle = new File( bpSourceHandle ).getCanonicalPath(); - } - catch( IOException e ) { - } - } - return sourceHandle.equals( bpSourceHandle ) && location.getLineNumber() == ((ICLineBreakpoint)breakpoint).getLineNumber(); - } - } - if ( breakpoint instanceof ICWatchpoint && cdiBreakpoint instanceof ICDIWatchpoint ) { - try { - ICWatchpoint watchpoint = (ICWatchpoint)breakpoint; - if ( watchpoint instanceof ICWatchpoint2 && cdiBreakpoint instanceof ICDIWatchpoint2 ) { - ICWatchpoint2 wp2 = (ICWatchpoint2)breakpoint; - ICDIWatchpoint2 cdiwp2 = (ICDIWatchpoint2)cdiBreakpoint; - if ( !wp2.getMemorySpace().equals( cdiwp2.getMemorySpace() ) - || !wp2.getRange().equals( cdiwp2.getRange() ) ) { - return false; - } - } - ICDIWatchpoint cdiWatchpoint = (ICDIWatchpoint)cdiBreakpoint; - return ( watchpoint.getExpression().compareTo( cdiWatchpoint.getWatchExpression() ) == 0 && - watchpoint.isReadType() == cdiWatchpoint.isReadType() && - watchpoint.isWriteType() == cdiWatchpoint.isWriteType() ); - } - catch( CDIException e ) { - } - } - if ( breakpoint instanceof ICEventBreakpoint && cdiBreakpoint instanceof ICDIEventBreakpoint) { - ICEventBreakpoint mevtbkpt = (ICEventBreakpoint) breakpoint; - ICDIEventBreakpoint cdievtbkpt = (ICDIEventBreakpoint) cdiBreakpoint; - if (!mevtbkpt.getEventType().equals(cdievtbkpt.getEventType())) return false; - return (mevtbkpt.getEventArgument().equals(cdievtbkpt.getExtraArgument())); - } - } - catch( CoreException e ) { - } - return false; - } - } - - private CDebugTarget fDebugTarget; - - private BreakpointMap fMap; - - private boolean fSkipBreakpoint = false; - - private ArrayList fBreakpointProblems = new ArrayList(); - - public CBreakpointManager( CDebugTarget target ) { - super(); - fDebugTarget = target; - fMap = new BreakpointMap(); - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.IBreakpointsListener#breakpointsAdded(org.eclipse.debug.core.model.IBreakpoint[]) - */ - @Override - public void breakpointsAdded( IBreakpoint[] breakpoints ) { - if ( !isTargetAvailable() ) - return; - setBreakpointsOnTarget( breakpoints ); - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.IBreakpointsListener#breakpointsRemoved(org.eclipse.debug.core.model.IBreakpoint[], org.eclipse.core.resources.IMarkerDelta[]) - */ - @Override - public void breakpointsRemoved( IBreakpoint[] breakpoints, IMarkerDelta[] deltas ) { - if ( !isTargetAvailable() ) - return; - ArrayList list = new ArrayList( breakpoints.length ); - synchronized( getBreakpointMap() ) { - for ( int i = 0; i < breakpoints.length; ++i ) { - if ( breakpoints[i] instanceof ICBreakpoint ) { - try { // Remove any problem markers for this breakpoint - BreakpointProblems.removeProblemsForBreakpoint((ICBreakpoint)breakpoints[i]); - } catch (CoreException e) {} - Object obj = getBreakpointMap().get( (ICBreakpoint)breakpoints[i] ); - ICDIBreakpoint b = null; - if ( obj instanceof ICDIBreakpoint ) { - b = (ICDIBreakpoint)obj; - } - else if ( obj instanceof BreakpointInProgess ) { - b = ((BreakpointInProgess)obj).getCDIBreakpoint(); - } - if ( b != null ) { - list.add( b ); - } - } - } - } - if ( list.isEmpty() ) - return; - final ICDIBreakpoint[] cdiBreakpoints = (ICDIBreakpoint[])list.toArray( new ICDIBreakpoint[list.size()] ); - final ICDITarget cdiTarget = getCDITarget(); - DebugPlugin.getDefault().asyncExec( new Runnable() { - @Override - public void run() { - try { - cdiTarget.deleteBreakpoints( cdiBreakpoints ); - } - catch( CDIException e ) { - } - } - } ); - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.IBreakpointsListener#breakpointsChanged(org.eclipse.debug.core.model.IBreakpoint[], org.eclipse.core.resources.IMarkerDelta[]) - */ - @Override - public void breakpointsChanged( IBreakpoint[] breakpoints, IMarkerDelta[] deltas ) { - ArrayList removeList = new ArrayList( breakpoints.length ); - ArrayList installList = new ArrayList( breakpoints.length ); - synchronized ( getBreakpointMap() ) { - for ( int i = 0; i < breakpoints.length; ++i ) { - if ( !(breakpoints[i] instanceof ICBreakpoint) || !isTargetAvailable() ) - continue; - ICBreakpoint b = (ICBreakpoint)breakpoints[i]; - boolean install = false; - try { - ICDebugTarget[] tfs = getFilterExtension(b).getTargetFilters(); - install = Arrays.asList( tfs ).contains( getDebugTarget() ); - } - catch( CoreException e ) { - } - boolean registered = getBreakpointMap().isRegistered( b ); - boolean inProgress = getBreakpointMap().isInProgress( b ); - if ( registered && !inProgress && !install ) { - removeList.add( b ); - } - if ( !registered && install ) { - installList.add( b ); - } - } - } - breakpointsRemoved( (ICBreakpoint[])removeList.toArray( new ICBreakpoint[removeList.size()] ), new IMarkerDelta[0] ); - breakpointsAdded( (ICBreakpoint[])installList.toArray( new ICBreakpoint[removeList.size()] ) ); - for ( int i = 0; i < breakpoints.length; ++i ) { - if ( breakpoints[i] instanceof ICBreakpoint && isTargetAvailable() ) - changeBreakpointProperties( (ICBreakpoint)breakpoints[i], deltas[i] ); - } - } - - @Override - public void breakpointManagerEnablementChanged( boolean enabled ) { - doSkipBreakpoints( !enabled ); - } - - @Override - public void handleDebugEvents( ICDIEvent[] events ) { - for( int i = 0; i < events.length; i++ ) { - ICDIEvent event = events[i]; - ICDIObject source = event.getSource(); - if ( source != null && source.getTarget().equals( getDebugTarget().getCDITarget() ) ) { - if ( event instanceof ICDICreatedEvent ) { - if ( source instanceof ICDIBreakpoint ) - handleBreakpointCreatedEvent( (ICDIBreakpoint)source ); - } - else if ( event instanceof ICDIDestroyedEvent ) { - if ( source instanceof ICDIBreakpoint ) - handleBreakpointDestroyedEvent( (ICDIBreakpoint)source ); - } - else if ( event instanceof ICDIChangedEvent ) { - if ( source instanceof ICDIBreakpoint ) - handleBreakpointChangedEvent( (ICDIBreakpoint)source ); - } - else if ( event instanceof ICDIBreakpointMovedEvent ) { - if ( source instanceof ICDIBreakpoint ) - handleBreakpointMovedEvent( (ICDIBreakpointMovedEvent) event ); - } - else if ( event instanceof ICDIExecutableReloadedEvent ) { - if ( source instanceof ICDITarget ) - handleExecutableReloadedEvent( (ICDIExecutableReloadedEvent) event ); - } - else if ( event instanceof ICDIBreakpointProblemEvent ) { - if ( source instanceof ICDIBreakpoint ) - handleBreakpointProblemEvent( (ICDIBreakpointProblemEvent) event ); - } - } - } - } - - @Override - public Object getAdapter( Class adapter ) { - if ( CBreakpointManager.class.equals( adapter ) ) - return this; - if ( CDebugTarget.class.equals( adapter ) ) - return getDebugTarget(); - if ( ICDebugTarget.class.equals( adapter ) ) - return getDebugTarget(); - if ( IDebugTarget.class.equals( adapter ) ) - return getDebugTarget(); - return null; - } - - public CDebugTarget getDebugTarget() { - return fDebugTarget; - } - - public void initialize() { - DebugPlugin.getDefault().getBreakpointManager().addBreakpointListener( this ); - DebugPlugin.getDefault().getBreakpointManager().addBreakpointManagerListener( this ); - getDebugTarget().getCDISession().getEventManager().addEventListener( this ); - } - - public void dispose() { - getDebugTarget().getCDISession().getEventManager().removeEventListener( this ); - DebugPlugin.getDefault().getBreakpointManager().removeBreakpointListener( this ); - DebugPlugin.getDefault().getBreakpointManager().removeBreakpointManagerListener( this ); - removeAllBreakpoints(); - getBreakpointMap().dispose(); - } - - public IAddress getBreakpointAddress( ICLineBreakpoint breakpoint ) { - BigInteger address = null; - synchronized ( getBreakpointMap() ) { - ICDIBreakpoint cdiBreakpoint = getBreakpointMap().getCDIBreakpoint( breakpoint ); - if ( cdiBreakpoint instanceof ICDILocationBreakpoint ) { - ICDILocator locator = ((ICDILocationBreakpoint)cdiBreakpoint).getLocator(); - if ( locator != null ) { - address = locator.getAddress(); - } - } - } - return ( address != null ) ? getDebugTarget().getAddressFactory().createAddress( address ) : null; - } - - public IBreakpoint getBreakpoint( ICDIBreakpoint cdiBreakpoint ) { - ICBreakpoint b; - synchronized ( getBreakpointMap() ) { - b = getBreakpointMap().getCBreakpoint( cdiBreakpoint ); - } - return b; - } - - /** - * @return true if the breakpoint is of a temporary type, otherwise false - */ - private boolean isTemporary(ICDIBreakpoint cdiBreakpoint) { - if (cdiBreakpoint instanceof ICDIBreakpoint2) { - return (((ICDIBreakpoint2)cdiBreakpoint).getType() & ICBreakpointType.TEMPORARY) != 0; - } - else { - return cdiBreakpoint.isTemporary(); - } - } - - private void handleBreakpointCreatedEvent( ICDIBreakpoint cdiBreakpoint ) { - if ( cdiBreakpoint instanceof ICDIWatchpoint ) - doHandleWatchpointCreatedEvent( (ICDIWatchpoint)cdiBreakpoint ); - if ( cdiBreakpoint instanceof ICDIEventBreakpoint ) - doHandleEventBreakpointCreatedEvent( (ICDIEventBreakpoint)cdiBreakpoint ); - else if ( cdiBreakpoint instanceof ICDILocationBreakpoint ) - doHandleLocationBreakpointCreatedEvent( (ICDILocationBreakpoint)cdiBreakpoint ); - try { - if ( !isTemporary(cdiBreakpoint) && !DebugPlugin.getDefault().getBreakpointManager().isEnabled() && cdiBreakpoint.isEnabled() ) { - changeBreakpointPropertiesOnTarget(cdiBreakpoint, false, null); - } - } catch (CDIException e){ - } - } - - private void doHandleEventBreakpointCreatedEvent(ICDIEventBreakpoint cdiEventBkpt) { - ICBreakpoint breakpoint = null; - ICBreakpoint newBreakpoint = null; - boolean createNewCBkpt = false; - final BreakpointMap bkptMap = getBreakpointMap(); - - synchronized( bkptMap ) { - createNewCBkpt = (bkptMap.getCBreakpoint( cdiEventBkpt ) == null); - } - - // This has to be done outside the breakpoint map lock, or a deadlock - // can occur (according to rev 1.71). Not certain we'll use this new CDT - // breakpoint; we need to check the map again. - if (createNewCBkpt) { - try { - newBreakpoint = createEventBreakpoint( cdiEventBkpt ); - } - catch( CDIException e ) {} - catch( CoreException e ) {} - } - - synchronized( bkptMap ) { - breakpoint = bkptMap.getCBreakpoint( cdiEventBkpt ); - if ( breakpoint == null ) { - breakpoint = newBreakpoint; - } - - if ( breakpoint != null ) { - // filter must be set up prior to adding the breakpoint to the - // map to avoid a race condition in breakpointsChanged for the - // "registered && !inProgress && !install" condition - try { - getFilterExtension(breakpoint).setTargetFilter( getDebugTarget() ); - } - catch( CoreException e ) {} - - bkptMap.put( breakpoint, cdiEventBkpt ); - } - } - - // Delete the new CDT breakpoint if we didn't end up using it - if (newBreakpoint != null && newBreakpoint != breakpoint) { - try { - newBreakpoint.delete(); - } catch (CoreException e) {} - } - - if ( breakpoint != null ) { - try { - ((CBreakpoint)breakpoint).register( true ); - } - catch( CoreException e ) { - } - getBreakpointNotifier().breakpointInstalled( getDebugTarget(), breakpoint ); - changeBreakpointProperties( breakpoint, cdiEventBkpt ); - } - - } - - private void doHandleLocationBreakpointCreatedEvent( ICDILocationBreakpoint cdiBreakpoint ) { - if ( isTemporary(cdiBreakpoint) ) - return; - ICBreakpoint breakpoint = null; - ICBreakpoint newBreakpoint = null; - final BreakpointMap bkptMap = getBreakpointMap(); - boolean createNewCBkpt = false; - synchronized( bkptMap ) { - createNewCBkpt = (bkptMap.getCBreakpoint( cdiBreakpoint ) == null); - } - - // This has to be done outside the breakpoint map lock, or a deadlock - // can occur (according to rev 1.71). Not certain we'll use this new CDT - // breakpoint; we need to check the map again. - if ( createNewCBkpt ) { - newBreakpoint = createLocationBreakpoint( cdiBreakpoint ); - } - - synchronized( bkptMap ) { - breakpoint = bkptMap.getCBreakpoint( cdiBreakpoint ); - if ( breakpoint == null ) { - breakpoint = newBreakpoint; - } - - if ( breakpoint != null ) { - // filter must be set up prior to adding the breakpoint to the - // map to avoid a race condition in breakpointsChanged for the - // "registered && !inProgress && !install" condition - try { - getFilterExtension(breakpoint).setTargetFilter( getDebugTarget() ); - } - catch( CoreException e ) {} - - bkptMap.put( breakpoint, cdiBreakpoint ); - } - } - - // Delete the new CDT breakpoint if we didn't end up using it - if (newBreakpoint != null && newBreakpoint != breakpoint) { - try { - newBreakpoint.delete(); - } catch (CoreException e) {} - } - - if ( breakpoint != null ) { - try { - BreakpointProblems.removeProblemsForResolvedBreakpoint(breakpoint, getDebugTarget().getInternalID()); - ((CBreakpoint)breakpoint).register( true ); - } - catch( CoreException e ) { - } - getBreakpointNotifier().breakpointInstalled( getDebugTarget(), breakpoint ); - changeBreakpointProperties( breakpoint, cdiBreakpoint ); - } - } - - private void doHandleWatchpointCreatedEvent( ICDIWatchpoint cdiWatchpoint ) { - ICBreakpoint breakpoint = null; - ICBreakpoint newBreakpoint = null; - boolean createNewCBkpt = false; - final BreakpointMap bkptMap = getBreakpointMap(); - - synchronized( bkptMap ) { - createNewCBkpt = (bkptMap.getCBreakpoint( cdiWatchpoint ) == null); - } - - // This has to be done outside the breakpoint map lock, or a deadlock - // can occur (according to rev 1.71). Not certain we'll use this new CDT - // breakpoint; we need to check the map again. - if (createNewCBkpt) { - try { - newBreakpoint = createWatchpoint( cdiWatchpoint ); - } - catch( CDIException e ) {} - catch( CoreException e ) {} - } - - synchronized( bkptMap ) { - breakpoint = bkptMap.getCBreakpoint( cdiWatchpoint ); - if ( breakpoint == null ) { - breakpoint = newBreakpoint; - } - - if ( breakpoint != null ) { - // filter must be set up prior to adding the breakpoint to the - // map to avoid a race condition in breakpointsChanged for the - // "registered && !inProgress && !install" condition - try { - getFilterExtension(breakpoint).setTargetFilter( getDebugTarget() ); - } - catch( CoreException e ) {} - - bkptMap.put( breakpoint, cdiWatchpoint ); - } - } - - // Delete the new CDT breakpoint if we didn't end up using it - if (newBreakpoint != null && newBreakpoint != breakpoint) { - try { - newBreakpoint.delete(); - } catch (CoreException e) {} - } - - - if ( breakpoint != null ) { - try { - ((CBreakpoint)breakpoint).register( true ); - } - catch( CoreException e ) { - } - getBreakpointNotifier().breakpointInstalled( getDebugTarget(), breakpoint ); - changeBreakpointProperties( breakpoint, cdiWatchpoint ); - } - } - - private void handleBreakpointMovedEvent( ICDIBreakpointMovedEvent movedEvent ) - { - ICBreakpoint breakpoint = getBreakpointMap().getCBreakpoint( (ICDIBreakpoint) movedEvent.getSource() ); - if (breakpoint != null) - { - try { - int newLineNumber = movedEvent.getNewLocation().getLineNumber(); - int currLineNumber = breakpoint.getMarker().getAttribute(IMarker.LINE_NUMBER, newLineNumber); - breakpoint.getMarker().setAttribute(IMarker.LINE_NUMBER, newLineNumber); - IMarker marker = BreakpointProblems.reportBreakpointMoved( - breakpoint, currLineNumber, newLineNumber, getDebugTarget().getName(), getDebugTarget().getInternalID()); - if (marker != null) - fBreakpointProblems.add(marker); - } catch (CoreException e) {} - } - - } - - private void handleExecutableReloadedEvent( ICDIExecutableReloadedEvent reloadedEvent ) - { - ArrayList uninstalledCBplist = new ArrayList(); - - IBreakpointManager manager = DebugPlugin.getDefault().getBreakpointManager(); - IBreakpoint[] breakpoints = manager.getBreakpoints( CDIDebugModel.getPluginIdentifier() ); - - for (int i = 0; i < breakpoints.length; i++) { - if (breakpoints[i] instanceof ICBreakpoint && (getBreakpointMap().getCDIBreakpoint((ICBreakpoint) breakpoints[i]) == null)) - { - uninstalledCBplist.add(breakpoints[i]); - } - } - - setBreakpointsOnTarget((IBreakpoint[]) uninstalledCBplist.toArray(new IBreakpoint[uninstalledCBplist.size()])); - } - - private void handleBreakpointProblemEvent( ICDIBreakpointProblemEvent problemEvent ) - { - ICBreakpoint breakpoint = getBreakpointMap().getCBreakpoint( problemEvent.getBreakpoint() ); - if (breakpoint != null) - { - try { - IMarker marker; - marker = BreakpointProblems.reportBreakpointProblem(breakpoint, problemEvent.getDescription(), - problemEvent.getSeverity(), problemEvent.getProblemType(), problemEvent.removeExisting(), - problemEvent.removeOnly(), getDebugTarget().getName(), getDebugTarget().getInternalID()); - if (marker != null) - fBreakpointProblems.add(marker); - } catch (DebugException e) {} - } - - } - - private void handleBreakpointChangedEvent( ICDIBreakpoint cdiBreakpoint ) { - ICBreakpoint breakpoint = getBreakpointMap().getCBreakpoint( cdiBreakpoint ); - if ( breakpoint != null ) { - Map map = new HashMap( 3 ); - try { - if ( !fSkipBreakpoint && DebugPlugin.getDefault().getBreakpointManager().isEnabled() ) { - map.put( IBreakpoint.ENABLED, Boolean.valueOf( cdiBreakpoint.isEnabled() ) ); - } - else { - map.put( IBreakpoint.ENABLED, Boolean.valueOf( breakpoint.isEnabled() ) ); - } - } - catch( CDIException e ) { - } - catch( CoreException e ) { - } - try { - map.put( ICBreakpoint.IGNORE_COUNT, new Integer( cdiBreakpoint.getCondition().getIgnoreCount() ) ); - } - catch( CDIException e ) { - } - try { - map.put( ICBreakpoint.CONDITION, cdiBreakpoint.getCondition().getExpression() ); - } - catch( CDIException e ) { - } - getBreakpointNotifier().breakpointChanged( getDebugTarget(), breakpoint, map ); - } - } - - private void handleBreakpointDestroyedEvent( ICDIBreakpoint cdiBreakpoint ) { - ICBreakpoint breakpoint = null; - synchronized( getBreakpointMap() ) { - breakpoint = getBreakpointMap().getCBreakpoint( cdiBreakpoint ); - getBreakpointMap().removeCDIBreakpoint( cdiBreakpoint ); - } - if ( breakpoint != null ) { - if ( isFilteredByTarget( breakpoint, getDebugTarget() ) ) { - try { - getFilterExtension(breakpoint).removeTargetFilter( getDebugTarget() ); - } - catch( CoreException e ) { - } - } - try { - BreakpointProblems.removeProblemsForBreakpoint(breakpoint); - } catch (CoreException e) {} - getBreakpointNotifier().breakpointsRemoved( getDebugTarget(), new IBreakpoint[] { breakpoint } ); - } - } - - private BreakpointMap getBreakpointMap() { - return fMap; - } - - private void removeAllBreakpoints() { - // Remove all breakpoint problem markers - for (Iterator iter = fBreakpointProblems.iterator(); iter.hasNext();) { - IMarker marker = (IMarker) iter.next(); - try { - marker.delete(); - } catch (CoreException e) {} - } - - ArrayList installedCDIBplist = new ArrayList(); - ArrayList installedCBplist = new ArrayList(); - ICBreakpoint[] breakpoints; - synchronized( getBreakpointMap() ) { - breakpoints = getBreakpointMap().getAllCBreakpoints(); - for ( int i = 0; i < breakpoints.length; ++i ) { - if ( !getBreakpointMap().isInProgress( breakpoints[i] ) ) { - installedCDIBplist.add( getBreakpointMap().getCDIBreakpoint( breakpoints[i] ) ); - - installedCBplist.add(breakpoints[i]); - } - } - } - if ( installedCDIBplist.isEmpty() ) - return; - - final ICDIBreakpoint[] cdiBreakpoints = (ICDIBreakpoint[])installedCDIBplist.toArray( new ICDIBreakpoint[installedCDIBplist.size()] ); - final ICDITarget cdiTarget = getCDITarget(); - - // Clean up the target filter to avoid that the CDebugTarget remains referenced by the breakpoint. - // Note that though we're "removing" breakpoints from a debug session, the breakpoint objects in the - // platform aren't going anywhere. They are "global" model elements. They go away only when the user - // deletes them. - CDebugTarget target = getDebugTarget(); - for (Iterator iter = installedCBplist.iterator(); iter.hasNext();) { - ICBreakpoint breakpoint = (ICBreakpoint) iter.next(); - if ( isFilteredByTarget( breakpoint, target ) ) { - try { - getFilterExtension(breakpoint).removeTargetFilter( target ); - } - catch( CoreException e ) { - CDebugCorePlugin.log( e.getStatus() ); - } - } - } - - DebugPlugin.getDefault().asyncExec( new Runnable() { - @Override - public void run() { - try { - cdiTarget.deleteBreakpoints( cdiBreakpoints ); - } - catch( CDIException e ) { - } - } - } ); - - getBreakpointNotifier().breakpointsRemoved( getDebugTarget(), (ICBreakpoint[])installedCBplist.toArray( new ICBreakpoint[installedCBplist.size()] ) ); - } - - private ICBreakpoint[] register( IBreakpoint[] breakpoints ) { - ArrayList list = new ArrayList( breakpoints.length ); - synchronized ( getBreakpointMap() ) { - for ( int i = 0; i < breakpoints.length; ++i ) { - if ( breakpoints[i] instanceof ICBreakpoint && isTargetBreakpoint( (ICBreakpoint)breakpoints[i] ) && !(getBreakpointMap().isRegistered( (ICBreakpoint)breakpoints[i] )) ) { - getBreakpointMap().register( (ICBreakpoint)breakpoints[i] ); - list.add( breakpoints[i] ); - } - } - } - return (ICBreakpoint[])list.toArray( new ICBreakpoint[list.size()] ); - } - - private void setBreakpointsOnTarget( IBreakpoint[] breakpoints ) { - final ICBreakpoint[] bkpts = register( breakpoints ); - if ( bkpts.length > 0 ) { - DebugPlugin.getDefault().asyncExec( new Runnable() { - @Override - public void run() { - setBreakpointsOnTarget0( bkpts ); - } - } ); - } - } - - protected void setBreakpointsOnTarget0( ICBreakpoint[] breakpoints ) { - ICDITarget cdiTarget = getCDITarget(); - ICDIBreakpointManagement2 bpManager2 = null; - if (cdiTarget instanceof ICDIBreakpointManagement2) - bpManager2 = (ICDIBreakpointManagement2) cdiTarget; - for ( int i = 0; i < breakpoints.length; ++i ) { - try { - ICDIBreakpoint b = null; - int breakpointType = ICBreakpointType.REGULAR; - ICBreakpoint icbreakpoint = breakpoints[i]; - // Bug 314865: CDI breakpoint is only created enabled if the global breakpoint disable toggle isn't set - boolean enabled = icbreakpoint.isEnabled() && DebugPlugin.getDefault().getBreakpointManager().isEnabled(); - if (icbreakpoint instanceof ICBreakpointType) { - breakpointType = ((ICBreakpointType) icbreakpoint).getType(); - } - if ( icbreakpoint instanceof ICTracepoint) { - ICTracepoint tracepoint = (ICTracepoint)icbreakpoint; - IMarker marker = BreakpointProblems.reportUnsupportedTracepoint(tracepoint, getDebugTarget().getName(), getDebugTarget().getInternalID()); - if (marker != null) - fBreakpointProblems.add(marker); - } else if ( icbreakpoint instanceof ICDynamicPrintf) { - ICDynamicPrintf dprintf = (ICDynamicPrintf)icbreakpoint; - IMarker marker = BreakpointProblems.reportUnsupportedDynamicPrintf(dprintf, getDebugTarget().getName(), getDebugTarget().getInternalID()); - if (marker != null) - fBreakpointProblems.add(marker); - } - else if ( icbreakpoint instanceof ICFunctionBreakpoint ) { - ICFunctionBreakpoint breakpoint = (ICFunctionBreakpoint)icbreakpoint; - String function = breakpoint.getFunction(); - String fileName = breakpoint.getFileName(); - ICDIFunctionLocation location = cdiTarget.createFunctionLocation( fileName, function ); - ICDICondition condition = createCondition( breakpoint ); - IMarker marker = BreakpointProblems.reportUnresolvedBreakpoint(breakpoint, getDebugTarget().getName(), getDebugTarget().getInternalID()); - if (marker != null) - fBreakpointProblems.add(marker); - if (bpManager2 != null) - b = bpManager2.setFunctionBreakpoint( breakpointType, location, condition, true, enabled ); - else - b = cdiTarget.setFunctionBreakpoint( breakpointType, location, condition, true ); - } else if ( icbreakpoint instanceof ICAddressBreakpoint ) { - ICAddressBreakpoint breakpoint = (ICAddressBreakpoint)icbreakpoint; - String address = breakpoint.getAddress(); - ICDIAddressLocation location = cdiTarget.createAddressLocation( new BigInteger ( ( address.startsWith( "0x" ) ) ? address.substring( 2 ) : address, 16 ) ); //$NON-NLS-1$ - ICDICondition condition = createCondition( breakpoint ); - if (bpManager2 != null) - b = bpManager2.setAddressBreakpoint( breakpointType, location, condition, true, enabled ); - else - b = cdiTarget.setAddressBreakpoint( breakpointType, location, condition, true ); - } else if ( icbreakpoint instanceof ICLineBreakpoint ) { - ICLineBreakpoint breakpoint = (ICLineBreakpoint)icbreakpoint; - String handle = breakpoint.getSourceHandle(); - IPath path = convertPath( handle ); - ICDILineLocation location = cdiTarget.createLineLocation( path.toPortableString(), breakpoint.getLineNumber() ); - ICDICondition condition = createCondition( breakpoint ); - IMarker marker = BreakpointProblems.reportUnresolvedBreakpoint(breakpoint, getDebugTarget().getName(), getDebugTarget().getInternalID()); - if (marker != null) - fBreakpointProblems.add(marker); - if (bpManager2 != null) - b = bpManager2.setLineBreakpoint( breakpointType, location, condition, true, enabled ); - else - b = cdiTarget.setLineBreakpoint( breakpointType, location, condition, true ); - } else if ( icbreakpoint instanceof ICWatchpoint ) { - ICWatchpoint watchpoint = (ICWatchpoint)icbreakpoint; - int accessType = 0; - accessType |= (watchpoint.isWriteType()) ? ICDIWatchpoint.WRITE : 0; - accessType |= (watchpoint.isReadType()) ? ICDIWatchpoint.READ : 0; - String expression = watchpoint.getExpression(); - ICDICondition condition = createCondition( watchpoint ); - if ( bpManager2 != null ) { - if ( icbreakpoint instanceof ICWatchpoint2 ) { - ICWatchpoint2 wp2 = (ICWatchpoint2)watchpoint; - b = bpManager2.setWatchpoint( breakpointType, accessType, expression, wp2.getMemorySpace(), - wp2.getRange(), condition, enabled ); - } else { - b = bpManager2.setWatchpoint( breakpointType, accessType, expression, condition, enabled ); - } - } else { - b = cdiTarget.setWatchpoint(breakpointType, accessType, expression, condition ); - } - } else if (icbreakpoint instanceof ICEventBreakpoint) { - ICEventBreakpoint eventbkpt = (ICEventBreakpoint) icbreakpoint; - ICDICondition condition = createCondition(eventbkpt); - if (cdiTarget instanceof ICDIBreakpointManagement3) { - ICDIBreakpointManagement3 bpManager3 = (ICDIBreakpointManagement3) cdiTarget; - b = bpManager3.setEventBreakpoint(eventbkpt.getEventType(), eventbkpt - .getEventArgument(), breakpointType, condition, true, enabled); - } else { - throw new UnsupportedOperationException("BreakpointManager does not support this type of breapoints"); - } - - } - if ( b != null ) { - Object obj = getBreakpointMap().get( icbreakpoint ); - if ( obj instanceof BreakpointInProgess ) { - ((BreakpointInProgess)obj).setCDIBreakpoint( b ); - } - } - // Hack: see bug 105196: [CDI]: Add "enabled" flag to the "set...Breakpoint" methods - if (bpManager2 == null && b != null && b.isEnabled() != enabled ) { - b.setEnabled( enabled ); - } - } - catch( CoreException e ) { - } - catch( NumberFormatException e ) { - } - catch( CDIException e ) { - } - } - } - - protected ICDITarget getCDITarget() { - return getDebugTarget().getCDITarget(); - } - - private ICDICondition createCondition( ICBreakpoint breakpoint ) throws CoreException, CDIException { - return getCDITarget().createCondition( breakpoint.getIgnoreCount(), breakpoint.getCondition(), getThreadNames( breakpoint ) ); - } - - private String[] getThreadNames( ICBreakpoint breakpoint ) { - try { - ICThread[] threads = getFilterExtension(breakpoint).getThreadFilters( getDebugTarget() ); - if ( threads == null ) - return new String[0]; - String[] names = new String[threads.length]; - for ( int i = 0; i < threads.length; ++i ) { - names[i] = threads[i].getName(); - } - return names; - } - catch( DebugException e ) { - } - catch( CoreException e ) { - } - return new String[0]; - } - - private ICLineBreakpoint createLocationBreakpoint( ICDILocationBreakpoint cdiBreakpoint ) { - ICLineBreakpoint breakpoint = null; - try { - ICDILocator location = cdiBreakpoint.getLocator(); - String file = location.getFile(); - String sourceHandle = file; - IResource resource = getProject(); - if (file != null && file.length() > 0) { - Object sourceElement = getSourceElement(file); - if ( sourceElement instanceof IFile ) { - sourceHandle = ((IFile)sourceElement).getLocation().toOSString(); - resource = (IResource)sourceElement; - } - else if ( sourceElement instanceof IStorage ) { - sourceHandle = ((IStorage)sourceElement).getFullPath().toOSString(); - resource = ResourcesPlugin.getWorkspace().getRoot(); - } - else if ( sourceElement instanceof ITranslationUnit ) { - ITranslationUnit translationUnit = (ITranslationUnit)sourceElement; - sourceHandle = translationUnit.getPath().toString(); - resource = translationUnit.getResource(); - - // an IExternalTranslationUnit doesn't have an IResource - if (resource == null) { - resource = getProject(); - } - } - } else { - sourceHandle = getExecFileHandle(); - } - if ( cdiBreakpoint instanceof ICDILineBreakpoint ) { - breakpoint = createLineBreakpoint( sourceHandle, resource, cdiBreakpoint ); - } - else if ( cdiBreakpoint instanceof ICDIFunctionBreakpoint ) { - breakpoint = createFunctionBreakpoint( sourceHandle, resource,cdiBreakpoint ); - } - else if ( cdiBreakpoint instanceof ICDIAddressBreakpoint ) { - breakpoint = createAddressBreakpoint( sourceHandle, resource,cdiBreakpoint ); - } - } - catch( CDIException e ) { - } - catch( CoreException e ) { - } - return breakpoint; - } - - private ICLineBreakpoint createLineBreakpoint( String sourceHandle, IResource resource, ICDILocationBreakpoint cdiBreakpoint ) throws CDIException, CoreException { - ICLineBreakpoint breakpoint = CDIDebugModel.createLineBreakpoint( sourceHandle, - resource, - getCdiBreakpointType(cdiBreakpoint), - cdiBreakpoint.getLocator().getLineNumber(), - cdiBreakpoint.isEnabled(), - cdiBreakpoint.getCondition().getIgnoreCount(), - cdiBreakpoint.getCondition().getExpression(), - false ); -// ICDILocator locator = cdiBreakpoint.getLocator(); -// if ( locator != null ) { -// BigInteger address = locator.getAddress(); -// if ( address != null ) { -// breakpoint.setAddress( address.toString() ); -// } -// } - return breakpoint; - } - - /** - * Utility method that queries the CDI client for the breakpoint type. - * - * @param cdiBreakpoint - * the CDI breakpoint - * @return an ICDIBreakpointType constant - */ - @SuppressWarnings("deprecation") - private int getCdiBreakpointType(ICDIBreakpoint cdiBreakpoint) { - if (cdiBreakpoint instanceof ICDIBreakpoint2) { - // the new way - return ((ICDIBreakpoint2)cdiBreakpoint).getType(); - } - else { - // the old way - int type = cdiBreakpoint.isHardware() ? ICBreakpointType.HARDWARE : ICBreakpointType.REGULAR; - if (cdiBreakpoint.isTemporary()) { - type |= ICBreakpointType.TEMPORARY; - } - return type; - } - } - - private ICFunctionBreakpoint createFunctionBreakpoint( String sourceHandle, IResource resource, ICDILocationBreakpoint cdiBreakpoint ) throws CDIException, CoreException { - ICDILocator location = cdiBreakpoint.getLocator(); - int line = location.getLineNumber(); - ICFunctionBreakpoint breakpoint = CDIDebugModel.createFunctionBreakpoint( - sourceHandle, - resource, - getCdiBreakpointType(cdiBreakpoint), - location.getFunction(), - -1, - -1, - line, - cdiBreakpoint.isEnabled(), - cdiBreakpoint.getCondition().getIgnoreCount(), - cdiBreakpoint.getCondition().getExpression(), - false); - return breakpoint; - } - - private ICAddressBreakpoint createAddressBreakpoint( String sourceHandle, IResource resource, ICDILocationBreakpoint cdiBreakpoint ) throws CDIException, CoreException { - String binary = getExecFileHandle(); - IAddress address = getDebugTarget().getAddressFactory().createAddress( cdiBreakpoint.getLocator().getAddress() ); - ICDILocator location = cdiBreakpoint.getLocator(); - int line = location.getLineNumber(); - ICAddressBreakpoint breakpoint = CDIDebugModel.createAddressBreakpoint( - binary, - sourceHandle, - resource, - ICBreakpointType.REGULAR, - line, - address, - cdiBreakpoint.isEnabled(), - cdiBreakpoint.getCondition().getIgnoreCount(), - cdiBreakpoint.getCondition().getExpression(), - false); - return breakpoint; - } - - private ICWatchpoint createWatchpoint( ICDIWatchpoint cdiWatchpoint ) throws CDIException, CoreException { - String sourceHandle = getExecFileHandle(); - ICWatchpoint watchpoint = null; - if ( cdiWatchpoint instanceof ICDIWatchpoint2 ){ - watchpoint = CDIDebugModel.createWatchpoint( sourceHandle, - getProject(), - cdiWatchpoint.isWriteType(), - cdiWatchpoint.isReadType(), - cdiWatchpoint.getWatchExpression(), - ( (ICDIWatchpoint2)cdiWatchpoint ).getMemorySpace(), - ( (ICDIWatchpoint2)cdiWatchpoint ).getRange(), - cdiWatchpoint.isEnabled(), - cdiWatchpoint.getCondition().getIgnoreCount(), - cdiWatchpoint.getCondition().getExpression(), - false); - } else { - watchpoint = CDIDebugModel.createWatchpoint( sourceHandle, - getProject(), - cdiWatchpoint.isWriteType(), - cdiWatchpoint.isReadType(), - cdiWatchpoint.getWatchExpression(), - cdiWatchpoint.isEnabled(), - cdiWatchpoint.getCondition().getIgnoreCount(), - cdiWatchpoint.getCondition().getExpression(), - false ); - } - return watchpoint; - } - - private ICEventBreakpoint createEventBreakpoint(ICDIEventBreakpoint cdiEventBkpt) throws CDIException, - CoreException { - - ICEventBreakpoint eventBkpt; - eventBkpt = CDIDebugModel.eventBreakpointExists(cdiEventBkpt.getEventType(), cdiEventBkpt - .getExtraArgument()); - if (eventBkpt != null) - return eventBkpt; - eventBkpt = CDIDebugModel.createEventBreakpoint(cdiEventBkpt.getEventType(), cdiEventBkpt - .getExtraArgument(), false); - return eventBkpt; - } - - private void changeBreakpointProperties( ICBreakpoint breakpoint, IMarkerDelta delta ) { - ICDIBreakpoint cdiBreakpoint = null; - synchronized( getBreakpointMap() ) { - if ( !getBreakpointMap().isInProgress( breakpoint ) ) - cdiBreakpoint = getBreakpointMap().getCDIBreakpoint( breakpoint ); - } - if ( cdiBreakpoint == null ) - return; - ICDITarget cdiTarget = getCDITarget(); - try { - boolean enabled = breakpoint.isEnabled() && DebugPlugin.getDefault().getBreakpointManager().isEnabled(); - boolean oldEnabled = ( delta != null ) ? delta.getAttribute( IBreakpoint.ENABLED, true ) : enabled; - int ignoreCount = breakpoint.getIgnoreCount(); - int oldIgnoreCount = ( delta != null ) ? delta.getAttribute( ICBreakpoint.IGNORE_COUNT, 0 ) : ignoreCount; - String condition = breakpoint.getCondition(); - String oldCondition = ( delta != null ) ? delta.getAttribute( ICBreakpoint.CONDITION, "" ) : condition; //$NON-NLS-1$ - String[] newThreadIs = getThreadNames( breakpoint ); - Boolean enabled0 = null; - ICDICondition condition0 = null; - if ( enabled != oldEnabled && enabled != cdiBreakpoint.isEnabled() ) { - enabled0 = Boolean.valueOf( enabled ); - } - if ( ignoreCount != oldIgnoreCount || condition.compareTo( oldCondition ) != 0 || areThreadFiltersChanged( newThreadIs, cdiBreakpoint ) ) { - ICDICondition cdiCondition = cdiTarget.createCondition( ignoreCount, condition, newThreadIs ); - if ( !cdiCondition.equals( cdiBreakpoint.getCondition() ) ) { - condition0 = cdiCondition; - } - } - int line = 0; - if (breakpoint instanceof ILineBreakpoint) { - ILineBreakpoint l = (ILineBreakpoint) breakpoint; - line = l.getLineNumber(); - } - int oldLine = ( delta != null ) ? delta.getAttribute( IMarker.LINE_NUMBER, 0 ) : 0; - boolean basic = oldLine>0 && oldLine != line; - - if (breakpoint instanceof ICBreakpointType) { - int oldType = ( delta != null ) ? delta.getAttribute( ICBreakpointType.TYPE, -1 ) : -1; - basic |= oldType != -1 && (oldType != ((ICBreakpointType) breakpoint).getType()); - } - - if (basic) { - final ICBreakpoint[] breakpoints = new ICBreakpoint[] {breakpoint}; - breakpointsRemoved(breakpoints, null); - handleBreakpointDestroyedEvent(cdiBreakpoint); // events has to processed before add executes - breakpointsAdded(breakpoints); - } else if (enabled0 != null || condition0 != null) { - changeBreakpointPropertiesOnTarget(cdiBreakpoint, enabled0, condition0); - } - } - catch( CoreException e ) { - } - catch( CDIException e ) { - } - } - - private void changeBreakpointProperties( ICBreakpoint breakpoint, ICDIBreakpoint cdiBreakpoint ) { - Boolean enabled = null; - try { - boolean shouldBeEnabled = breakpoint.isEnabled() && DebugPlugin.getDefault().getBreakpointManager().isEnabled(); - if ( cdiBreakpoint.isEnabled() != shouldBeEnabled ) - enabled = shouldBeEnabled; - } - catch( CDIException e ) { - } - catch( CoreException e ) { - } - ICDICondition condition = null; - try { - ICDICondition c = createCondition( breakpoint ); - if ( !cdiBreakpoint.getCondition().equals( c ) ) - condition = c; - } - catch( CDIException e ) { - } - catch( CoreException e ) { - } - if ( enabled != null || condition != null ) - changeBreakpointPropertiesOnTarget( cdiBreakpoint, enabled, condition ); - } - - private void changeBreakpointPropertiesOnTarget( final ICDIBreakpoint breakpoint, final Boolean enabled, final ICDICondition condition ) { - DebugPlugin.getDefault().asyncExec( new Runnable() { - @Override - public void run() { - if ( enabled != null ) { - try { - breakpoint.setEnabled( enabled.booleanValue() ); - } - catch( CDIException e ) { - } - } - if ( condition != null ) { - try { - breakpoint.setCondition( condition ); - } - catch( CDIException e ) { - } - } - } - } ); - } - - public void setInitialBreakpoints() { - IBreakpointManager manager = DebugPlugin.getDefault().getBreakpointManager(); - IBreakpoint[] bps = manager.getBreakpoints( CDIDebugModel.getPluginIdentifier() ); - - ICDITargetConfiguration config = getDebugTarget().getCDITarget().getConfiguration(); - - if (!(config instanceof ICDITargetConfiguration2) || !((ICDITargetConfiguration2)config).supportsAddressBreaksOnStartup()) - { // Disable address breaks of the target does not support setting them on startup - for( int i = 0; i < bps.length; i++ ) { - if ( bps[i] instanceof ICBreakpoint && isTargetBreakpoint( (ICBreakpoint)bps[i] ) && !getBreakpointMap().isRegistered( (ICBreakpoint)bps[i] ) ) { - if ( bps[i] instanceof ICAddressBreakpoint ) { - // disable address breakpoints to prevent the debugger to insert them prematurely - try { - bps[i].setEnabled( false ); - } - catch( CoreException e ) { - } - } - } - } - } - - ICBreakpoint[] breakpoints = register( bps ); - setBreakpointsOnTarget0( breakpoints ); - } - - /** - * Checks if matching between the symbolics referenced by the breakpoint - * and the symbolics of the contained CDebugTarget should be done using also source handle. - * @param breakpoint - * @return true if source handle should be used - */ - private boolean breakpointUsesSourceMatching(ICBreakpoint breakpoint) { - boolean result = false; - if (breakpoint instanceof ICLineBreakpoint) { - result = true; - if (breakpoint instanceof ICFunctionBreakpoint) { - // ICDIFunctionBreakpoint on function elements from binary objects can be - // set without having a source handle. For this case of line breakpoint - // don't try to match breakpoints with source locator of contained CDebugTarget. - String handle = null; - try { - handle = breakpoint.getSourceHandle(); - } catch (CoreException ex) { - // ignore exception. source handle will be empty anyway. - } - result = (handle != null) && (handle.length() > 0); - - } - } - return result; - } - - private boolean isTargetBreakpoint( ICBreakpoint breakpoint ) { - if ( breakpoint instanceof ICAddressBreakpoint ) - return supportsAddressBreakpoint( (ICAddressBreakpoint)breakpoint ); - - // If the breakpoint is set on a resource in this project - // it should be enabled irrespective of what the CSourceLookupDirector thinks - if (breakpoint.getMarker() != null) { - IProject project = breakpoint.getMarker().getResource().getProject(); - if (getProject().equals(project)) - return true; - if (CDebugUtils.isReferencedProject(getProject(), project)) - return true; - } - - // Is it a line breakpoint with source handle ? - if ( breakpointUsesSourceMatching( breakpoint ) ) { - try { - String handle = breakpoint.getSourceHandle(); - ISourceLocator sl = getSourceLocator(); - if ( sl instanceof ICSourceLocator ) - return ( ((ICSourceLocator)sl).findSourceElement( handle ) != null ); - else if ( sl instanceof CSourceLookupDirector ) { - return ( ((CSourceLookupDirector)sl).contains( breakpoint ) ); - } - } - catch( CoreException e ) { - CDebugCorePlugin.log(e); - } - } else { - // Check the marker resource against the source containers ... - IResource resource = breakpoint.getMarker().getResource(); - IProject project = resource.getProject(); - if ( project != null && project.exists() ) { - ISourceLocator sl = getSourceLocator(); - if ( sl instanceof ICSourceLocator ) - return ((ICSourceLocator)sl).contains( project ); - else if ( sl instanceof CSourceLookupDirector ) - return ((CSourceLookupDirector)sl).contains( project ); - } - } - // Allow unclassified breakpoints i.e. those which aren't project scoped, - // or not resource related (e.g. watchpoints) - return true; - } - - public boolean supportsBreakpoint( ICBreakpoint breakpoint ) { - boolean s = false; - synchronized( getBreakpointMap() ) { - s = getBreakpointMap().isRegistered( breakpoint ); - } - return s; - } - - /** - * Checks for a match between the symbolics referenced by the breakpoint - * and the symbolics of the contained CDebugTarget. - * @param breakpoint - * @return true if the symbolics match or if the breakpoint has no symbolics - */ - public boolean supportsAddressBreakpoint( ICAddressBreakpoint breakpoint ) { - boolean sessionHasSymbols = getExecFileHandle() != null && getExecFileHandle().length() > 0; - boolean bpHasSymbols = false; - try { - String module = breakpoint.getModule(); - if ( module != null && module.length() > 0 ) { - bpHasSymbols = true; - if ( sessionHasSymbols ) { - return getExecFileHandle().equals( module ); - } - } - } - catch( CoreException e ) { - } - - // supporting old breakpoints (> 3.0) - try { - String sourceHandle = breakpoint.getSourceHandle(); - if ( sourceHandle != null && sourceHandle.length() > 0 ) { - bpHasSymbols = true; - if ( sessionHasSymbols ) { - return getExecFileHandle().equals( sourceHandle ); - } - } - } - catch( CoreException e ) { - } - - // an address breakpoint can also be set in the absence of any symbols - return !bpHasSymbols; - } - - public void skipBreakpoints( boolean enabled ) { - if ( fSkipBreakpoint != enabled && (DebugPlugin.getDefault().getBreakpointManager().isEnabled() || !enabled) ) { - fSkipBreakpoint = enabled; - doSkipBreakpoints( enabled ); - } - } - - public void watchpointOutOfScope( ICDIWatchpoint cdiWatchpoint ) { - handleBreakpointDestroyedEvent( cdiWatchpoint ); - } - - private void doSkipBreakpoints( boolean enabled ) { - ICBreakpoint[] cBreakpoints = getBreakpointMap().getAllCBreakpoints(); - for ( int i = 0; i < cBreakpoints.length; ++i ) { - try { - if ( cBreakpoints[i].isEnabled() ) { - ICDIBreakpoint cdiBreakpoint = getBreakpointMap().getCDIBreakpoint( cBreakpoints[i] ); - if ( cdiBreakpoint != null ) { - cdiBreakpoint.setEnabled( !enabled ); - } - } - } - catch( CoreException e ) { - // ignore - } - catch( CDIException e ) { - // ignore - } - } - } - - private IPath convertPath( String sourceHandle ) { - IPath path = null; - if ( Path.EMPTY.isValidPath( sourceHandle ) ) { - ISourceLocator sl = getSourceLocator(); - if ( sl instanceof CSourceLookupDirector ) { - path = ((CSourceLookupDirector)sl).getCompilationPath( sourceHandle ); - } - if ( path == null ) { - path = new Path( sourceHandle ); - } - } - return path; - } - - private IProject getProject() { - return getDebugTarget().getProject(); - } - - private String getExecFileHandle() { - CDebugTarget target = getDebugTarget(); - if ( target != null ) { - IBinaryObject binary = target.getExecFile(); - if ( binary != null ) { - IPath path = binary.getPath(); - if ( path != null ) { - return path.toOSString(); - } - } - } - return null; - } - - private ISourceLocator getSourceLocator() { - return getDebugTarget().getLaunch().getSourceLocator(); - } - - protected Object getSourceElement( String file ) { - Object sourceElement = null; - ISourceLocator locator = getSourceLocator(); - if ( locator instanceof ICSourceLocator || locator instanceof CSourceLookupDirector ) { - if ( locator instanceof ICSourceLocator ) - sourceElement = ((ICSourceLocator)locator).findSourceElement( file ); - else - sourceElement = ((CSourceLookupDirector)locator).getSourceElement( file ); - } - return sourceElement; - } - - protected boolean isEmpty( String str ) { - return !( str != null && str.trim().length() > 0 ); - } - - private boolean isTargetAvailable() { - return getDebugTarget().getCDITarget().getConfiguration().supportsBreakpoints() && getDebugTarget().isAvailable(); - } - - private CBreakpointNotifier getBreakpointNotifier() { - return CBreakpointNotifier.getInstance(); - } - - private boolean isFilteredByTarget( ICBreakpoint breakpoint, ICDebugTarget target ) { - boolean result = false; - try { - ICDebugTarget[] tfs = getFilterExtension(breakpoint).getTargetFilters(); - result = Arrays.asList( tfs ).contains( target ); - } - catch( CoreException e ) { - // ignore - } - return result; - } - - private boolean areThreadFiltersChanged( String[] newIds, ICDIBreakpoint cdiBreakpoint ) { - try { - String[] oldIds = cdiBreakpoint.getCondition().getThreadIds(); - if ( oldIds.length != newIds.length ) - return true; - List list = Arrays.asList( oldIds ); - for ( int i = 0; i < newIds.length; ++i ) { - if ( !list.contains( newIds[i] ) ) { - return true; - } - } - } - catch( CDIException e ) { - } - return false; - } - - private ICBreakpointFilterExtension getFilterExtension(ICBreakpoint bp) throws CoreException{ - return bp.getExtension( - CDIDebugModel.getPluginIdentifier(), ICBreakpointFilterExtension.class); - } -} diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CDebugAdapter.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CDebugAdapter.java deleted file mode 100644 index 01ea87d4319..00000000000 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CDebugAdapter.java +++ /dev/null @@ -1,142 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2013 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 - *******************************************************************************/ -package org.eclipse.cdt.debug.internal.core; - -import java.util.Date; - -import org.eclipse.cdt.core.CCorePlugin; -import org.eclipse.cdt.core.IBinaryParser.IBinaryObject; -import org.eclipse.cdt.core.model.ICProject; -import org.eclipse.cdt.debug.core.CDebugCorePlugin; -import org.eclipse.cdt.debug.core.ICDIDebugger; -import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants; -import org.eclipse.cdt.debug.core.ICDebugger; -import org.eclipse.cdt.debug.core.cdi.CDIException; -import org.eclipse.cdt.debug.core.cdi.ICDISession; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.ResourcesPlugin; -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.MultiStatus; -import org.eclipse.core.runtime.Path; -import org.eclipse.core.runtime.Status; -import org.eclipse.core.variables.VariablesPlugin; -import org.eclipse.debug.core.DebugPlugin; -import org.eclipse.debug.core.ILaunch; -import org.eclipse.debug.core.ILaunchConfiguration; -import org.eclipse.debug.core.model.IProcess; - -import com.ibm.icu.text.DateFormat; -import com.ibm.icu.text.MessageFormat; - -public class CDebugAdapter implements ICDIDebugger { - final ICDebugger fDebugger; - - /** - * @param debugger - */ - public CDebugAdapter(ICDebugger debugger) { - fDebugger = debugger; - } - - /* (non-Javadoc) - * - * @see org.eclipse.cdt.debug.core.ICDIDebugger#createDebuggerSession(org.eclipse.debug.core.ILaunch, - * org.eclipse.cdt.core.IBinaryParser.IBinaryExecutable, - * org.eclipse.core.runtime.IProgressMonitor) - */ - @Override - public ICDISession createDebuggerSession(ILaunch launch, IBinaryObject exe, IProgressMonitor monitor) throws CoreException { - ILaunchConfiguration config = launch.getLaunchConfiguration(); - if (exe == null) { - abort(InternalDebugCoreMessages.CDebugAdapter_Program_file_not_specified, null, - ICDTLaunchConfigurationConstants.ERR_UNSPECIFIED_PROGRAM); - } - IFile[] exeFile = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation(exe.getPath()); - if (exeFile.length == 0) { - abort(InternalDebugCoreMessages.CDebugAdapter_0, null, -1); - } - int pid = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_ATTACH_PROCESS_ID, -1); - String coreFile = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_COREFILE_PATH, (String)null); - ICDISession session; - try { - if (pid == -1 && coreFile == null) { - session = fDebugger.createLaunchSession(config, exeFile[0]); - } else if (pid != -1) { - session = fDebugger.createAttachSession(config, exeFile[0], pid); - } else { - session = fDebugger.createCoreSession(config, exeFile[0], new Path(coreFile)); - } - Process debugger = session.getSessionProcess(); - if (debugger != null) { - IProcess debuggerProcess = DebugPlugin.newProcess(launch, debugger, renderDebuggerProcessLabel()); - launch.addProcess(debuggerProcess); - } - return session; - } catch (CDIException e) { - abort(e.getLocalizedMessage(), e, -1); - } - throw new IllegalStateException(); // should never happen - } - - protected String renderDebuggerProcessLabel() { - String format = "{0} ({1})"; //$NON-NLS-1$ - String timestamp = DateFormat.getInstance().format(new Date(System.currentTimeMillis())); - String message = InternalDebugCoreMessages.CDebugAdapter_1; - return MessageFormat.format(format, message, timestamp); - } - - protected void abort(String message, Throwable exception, int code) throws CoreException { - MultiStatus status = new MultiStatus(CDebugCorePlugin.getUniqueIdentifier(), code, message, exception); - status.add(new Status(IStatus.ERROR, CDebugCorePlugin.getUniqueIdentifier(), code, - exception == null ? "" : exception.getLocalizedMessage(), //$NON-NLS-1$ - exception)); - throw new CoreException(status); - } - - public static ICProject getCProject(ILaunchConfiguration configuration) throws CoreException { - String projectName = getProjectName(configuration); - if (projectName != null) { - projectName = projectName.trim(); - if (projectName.length() > 0) { - IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName); - ICProject cProject = CCorePlugin.getDefault().getCoreModel().create(project); - if (cProject != null && cProject.exists()) { - return cProject; - } - } - } - return null; - } - - public static String getProjectName(ILaunchConfiguration configuration) throws CoreException { - return configuration.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, (String)null); - } - - public static String getProgramName(ILaunchConfiguration configuration) throws CoreException { - String programName = configuration.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, (String) null); - if (programName != null) { - programName = VariablesPlugin.getDefault().getStringVariableManager().performStringSubstitution(programName); - } - return programName; - } - - public static IPath getProgramPath(ILaunchConfiguration configuration) throws CoreException { - String path = getProgramName(configuration); - if (path == null) { - return null; - } - return new Path(path); - } -} diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CDebugCorePreferenceInitializer.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CDebugCorePreferenceInitializer.java index a6a33294142..d951fd1b0e7 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CDebugCorePreferenceInitializer.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CDebugCorePreferenceInitializer.java @@ -16,7 +16,6 @@ import java.nio.charset.Charset; import org.eclipse.cdt.debug.core.CDebugCorePlugin; import org.eclipse.cdt.debug.core.ICDebugConstants; -import org.eclipse.cdt.debug.core.cdi.ICDIFormat; import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer; import org.eclipse.core.runtime.preferences.DefaultScope; @@ -42,9 +41,6 @@ public class CDebugCorePreferenceInitializer extends AbstractPreferenceInitializ IEclipsePreferences defaultPreferences = DefaultScope.INSTANCE.getNode(CDebugCorePlugin.PLUGIN_ID); defaultPreferences.putInt(ICDebugConstants.PREF_MAX_NUMBER_OF_INSTRUCTIONS, ICDebugConstants.DEF_NUMBER_OF_INSTRUCTIONS); - defaultPreferences.putInt(ICDebugConstants.PREF_DEFAULT_VARIABLE_FORMAT, ICDIFormat.NATURAL); - defaultPreferences.putInt(ICDebugConstants.PREF_DEFAULT_EXPRESSION_FORMAT, ICDIFormat.NATURAL); - defaultPreferences.putInt(ICDebugConstants.PREF_DEFAULT_REGISTER_FORMAT, ICDIFormat.NATURAL); defaultPreferences.put(ICDebugConstants.PREF_DEBUG_CHARSET, Charset.defaultCharset().name()); if (Platform.getOS().equals(Platform.OS_WIN32)) { defaultPreferences.put(ICDebugConstants.PREF_DEBUG_WIDE_CHARSET, "UTF-16"); //$NON-NLS-1$ diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CDisassemblyContextProvider.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CDisassemblyContextProvider.java deleted file mode 100644 index 469781e5fc0..00000000000 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CDisassemblyContextProvider.java +++ /dev/null @@ -1,36 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2012 ARM Limited 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: - * ARM Limited - Initial API and implementation - *******************************************************************************/ - -package org.eclipse.cdt.debug.internal.core; - -import org.eclipse.cdt.debug.core.disassembly.IDisassemblyContextProvider; -import org.eclipse.cdt.debug.core.model.ICDebugElement; -import org.eclipse.cdt.debug.internal.core.model.CDebugTarget; -import org.eclipse.debug.core.model.IDebugTarget; - -/** - * org.eclipse.cdt.debug.internal.core.CDisassemblyContextProvider: - * //TODO Add description. - */ -public class CDisassemblyContextProvider implements IDisassemblyContextProvider { - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.disassembly.IDisassemblyContextProvider#getDisassemblyContext(java.lang.Object) - */ - @Override - public Object getDisassemblyContext( Object element ) { - if ( element instanceof ICDebugElement ) { - IDebugTarget target = ((ICDebugElement)element).getDebugTarget(); - return ((CDebugTarget)target).getDisassemblyRetrieval(); - } - return null; - } -} diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CGlobalVariableManager.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CGlobalVariableManager.java deleted file mode 100644 index 24bc5b35688..00000000000 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CGlobalVariableManager.java +++ /dev/null @@ -1,297 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2013 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 - * Gaetano Santoro (gaetano.santoro@st.com): patch for - * https://bugs.eclipse.org/bugs/show_bug.cgi?id=274499 - *******************************************************************************/ -package org.eclipse.cdt.debug.internal.core; - -import java.io.IOException; -import java.io.StringReader; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.transform.TransformerException; - -import org.eclipse.cdt.debug.core.CDebugCorePlugin; -import org.eclipse.cdt.debug.core.CDebugUtils; -import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants; -import org.eclipse.cdt.debug.core.ICGlobalVariableManager; -import org.eclipse.cdt.debug.core.model.ICGlobalVariable; -import org.eclipse.cdt.debug.core.model.IGlobalVariableDescriptor; -import org.eclipse.cdt.debug.internal.core.model.CDebugTarget; -import org.eclipse.cdt.debug.internal.core.model.CVariable; -import org.eclipse.cdt.debug.internal.core.model.CVariableFactory; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.MultiStatus; -import org.eclipse.core.runtime.Path; -import org.eclipse.core.runtime.Status; -import org.eclipse.debug.core.DebugEvent; -import org.eclipse.debug.core.DebugException; -import org.eclipse.debug.core.DebugPlugin; -import org.eclipse.debug.core.ILaunchConfiguration; -import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; -import org.xml.sax.InputSource; -import org.xml.sax.SAXException; - -/** - * Manages all global variables registered with a debug target. - */ -public class CGlobalVariableManager implements ICGlobalVariableManager { - - private static final String GLOBAL_VARIABLE_LIST = "globalVariableList"; //$NON-NLS-1$ - private static final String GLOBAL_VARIABLE = "globalVariable"; //$NON-NLS-1$ - private static final String ATTR_GLOBAL_VARIABLE_PATH = "path"; //$NON-NLS-1$ - private static final String ATTR_GLOBAL_VARIABLE_NAME = "name"; //$NON-NLS-1$ - - private CDebugTarget fDebugTarget; - - private IGlobalVariableDescriptor[] fInitialDescriptors = new IGlobalVariableDescriptor[0]; - - private List<ICGlobalVariable> fGlobals; - - /** - * Constructor for CGlobalVariableManager. - */ - public CGlobalVariableManager( CDebugTarget target ) { - super(); - setDebugTarget( target ); - initialize(); - } - - protected CDebugTarget getDebugTarget() { - return fDebugTarget; - } - - private void setDebugTarget( CDebugTarget debugTarget ) { - fDebugTarget = debugTarget; - } - - public ICGlobalVariable[] getGlobals() { - if ( fGlobals == null ) { - try { - addGlobals( getInitialDescriptors() ); - } - catch( DebugException e ) { - DebugPlugin.log( e ); - } - } - return fGlobals.toArray( new ICGlobalVariable[fGlobals.size()] ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.ICGlobalVariableManager#addGlobals(IGlobalVariableDescriptor[]) - */ - @Override - public void addGlobals( IGlobalVariableDescriptor[] descriptors ) throws DebugException { - fGlobals = new ArrayList<ICGlobalVariable>( 10 ); - MultiStatus ms = new MultiStatus( CDebugCorePlugin.getUniqueIdentifier(), 0, "", null ); //$NON-NLS-1$ - List<ICGlobalVariable> globals = new ArrayList<ICGlobalVariable>( descriptors.length ); - for ( int i = 0; i < descriptors.length; ++i ) { - try { - globals.add( getDebugTarget().createGlobalVariable( descriptors[i] ) ); - } - catch( DebugException e ) { - ms.add( e.getStatus() ); - } - } - if ( globals.size() > 0 ) { - synchronized( fGlobals ) { - fGlobals.addAll( globals ); - } - } - getDebugTarget().fireChangeEvent( DebugEvent.CONTENT ); - if ( !ms.isOK() ) { - throw new DebugException( ms ); - } - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.ICGlobalVariableManager#removeGlobals(ICGlobalVariable[]) - */ - @Override - public void removeGlobals( ICGlobalVariable[] globals ) { - synchronized( fGlobals ) { - fGlobals.removeAll( Arrays.asList( globals ) ); - } - for ( int i = 0; i < globals.length; ++i ) { - if ( globals[i] instanceof CVariable ) - ((CVariable)globals[i]).dispose(); - } - getDebugTarget().fireChangeEvent( DebugEvent.CONTENT ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.ICGlobalVariableManager#removeAllGlobals() - */ - @Override - public void removeAllGlobals() { - if (fGlobals == null ) { - return; - } - - ICGlobalVariable[] globals; - synchronized( fGlobals ) { - globals = fGlobals.toArray( new ICGlobalVariable[fGlobals.size()] ); - fGlobals.clear(); - } - for ( int i = 0; i < globals.length; ++i ) { - if ( globals[i] instanceof CVariable ) - ((CVariable)globals[i]).dispose(); - } - getDebugTarget().fireChangeEvent( DebugEvent.CONTENT ); - } - - public void dispose() { - if ( fGlobals != null ) { - for (ICGlobalVariable global : fGlobals) { - ((CVariable)global).dispose(); - } - fGlobals.clear(); - fGlobals = null; - } - } - - public String getMemento() { - Document document = null; - try { - document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); - Element node = document.createElement( GLOBAL_VARIABLE_LIST ); - document.appendChild( node ); - ICGlobalVariable[] globals = getGlobals(); - for (ICGlobalVariable global : globals) { - IGlobalVariableDescriptor descriptor = global.getDescriptor(); - // children of globals don't have a descriptor, though getGlobals() shouldn't return only top level globals - if (descriptor != null) { - Element child = document.createElement( GLOBAL_VARIABLE ); - child.setAttribute( ATTR_GLOBAL_VARIABLE_NAME, descriptor.getName() ); - child.setAttribute( ATTR_GLOBAL_VARIABLE_PATH, descriptor.getPath().toOSString() ); - node.appendChild( child ); - } - } - return CDebugUtils.serializeDocument( document ); - } - catch( ParserConfigurationException e ) { - DebugPlugin.log( e ); - } - catch( IOException e ) { - DebugPlugin.log( e ); - } - catch( TransformerException e ) { - DebugPlugin.log( e ); - } - return null; - } - - private void initializeFromMemento( String memento ) throws CoreException { - Exception ex = null; - try { - Element root = null; - DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder(); - StringReader reader = new StringReader( memento ); - InputSource source = new InputSource( reader ); - root = parser.parse( source ).getDocumentElement(); - if ( root.getNodeName().equalsIgnoreCase( GLOBAL_VARIABLE_LIST ) ) { - List<IGlobalVariableDescriptor> descriptors = new ArrayList<IGlobalVariableDescriptor>(); - NodeList list = root.getChildNodes(); - int length = list.getLength(); - for( int i = 0; i < length; ++i ) { - Node node = list.item( i ); - short type = node.getNodeType(); - if ( type == Node.ELEMENT_NODE ) { - Element entry = (Element)node; - if ( entry.getNodeName().equalsIgnoreCase( GLOBAL_VARIABLE ) ) { - String name = entry.getAttribute( ATTR_GLOBAL_VARIABLE_NAME ); - String pathString = entry.getAttribute( ATTR_GLOBAL_VARIABLE_PATH ); - IPath path = new Path( pathString ); - if ( path.isValidPath( pathString ) ) { - descriptors.add( CVariableFactory.createGlobalVariableDescriptor( name, path ) ); - } - } - } - } - fInitialDescriptors = descriptors.toArray( new IGlobalVariableDescriptor[descriptors.size()] ); - return; - } - } - catch( ParserConfigurationException e ) { - ex = e; - } - catch( SAXException e ) { - ex = e; - } - catch( IOException e ) { - ex = e; - } - abort(InternalDebugCoreMessages.CGlobalVariableManager_0, ex); - } - - private void initialize() { - ILaunchConfiguration config = getDebugTarget().getLaunch().getLaunchConfiguration(); - try { - String memento = config.getAttribute( ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_GLOBAL_VARIABLES, "" ); //$NON-NLS-1$ - if ( memento != null && memento.trim().length() != 0 ) - initializeFromMemento( memento ); - } - catch( CoreException e ) { - DebugPlugin.log( e ); - } - } - - /** - * Throws an internal error exception - */ - private void abort( String message, Throwable e ) throws CoreException { - IStatus s = new Status( IStatus.ERROR, CDebugCorePlugin.getUniqueIdentifier(), CDebugCorePlugin.INTERNAL_ERROR, message, e ); - throw new CoreException( s ); - } - - private IGlobalVariableDescriptor[] getInitialDescriptors() { - return fInitialDescriptors; - } - - public void save() { - ILaunchConfiguration config = getDebugTarget().getLaunch().getLaunchConfiguration(); - try { - ILaunchConfigurationWorkingCopy wc = config.getWorkingCopy(); - wc.setAttribute( ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_GLOBAL_VARIABLES, getMemento() ); - wc.doSave(); - } - catch( CoreException e ) { - DebugPlugin.log( e ); - } - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.ICGlobalVariableManager#getDescriptors() - */ - @Override - public IGlobalVariableDescriptor[] getDescriptors() { - if ( fGlobals == null ) - return getInitialDescriptors(); - List<IGlobalVariableDescriptor> descrs = new ArrayList<IGlobalVariableDescriptor>(); - for (ICGlobalVariable global : fGlobals) { - IGlobalVariableDescriptor descr = global.getDescriptor(); - if (descr != null) { // children of globals don't have a descriptor, though 'fGlobals' should contain only top level globals - descrs.add(descr); - } - } - return descrs.toArray(new IGlobalVariableDescriptor[descrs.size()]); - } -} diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CMemoryBlockRetrievalExtension.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CMemoryBlockRetrievalExtension.java deleted file mode 100644 index bdb16e2bb53..00000000000 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CMemoryBlockRetrievalExtension.java +++ /dev/null @@ -1,499 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2013 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 - *******************************************************************************/ -package org.eclipse.cdt.debug.internal.core; - -import java.math.BigInteger; -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.cdt.core.IAddress; -import org.eclipse.cdt.core.IAddressFactory; -import org.eclipse.cdt.core.IAddressFactory2; -import org.eclipse.cdt.debug.core.CDebugCorePlugin; -import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants; -import org.eclipse.cdt.debug.core.cdi.CDIException; -import org.eclipse.cdt.debug.core.cdi.model.ICDIExpression; -import org.eclipse.cdt.debug.core.cdi.model.ICDIMemorySpaceEncoder; -import org.eclipse.cdt.debug.core.cdi.model.ICDIMemorySpaceManagement; -import org.eclipse.cdt.debug.core.cdi.model.ICDITarget; -import org.eclipse.cdt.debug.core.model.ICType; -import org.eclipse.cdt.debug.core.model.ICValue; -import org.eclipse.cdt.debug.core.model.provisional.IMemorySpaceAwareMemoryBlock; -import org.eclipse.cdt.debug.core.model.provisional.IMemorySpaceAwareMemoryBlockRetrieval; -import org.eclipse.cdt.debug.internal.core.model.CDebugTarget; -import org.eclipse.cdt.debug.internal.core.model.CExpression; -import org.eclipse.cdt.debug.internal.core.model.CMemoryBlockExtension; -import org.eclipse.cdt.debug.internal.core.model.CStackFrame; -import org.eclipse.cdt.debug.internal.core.model.CThread; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.PlatformObject; -import org.eclipse.core.runtime.Status; -import org.eclipse.debug.core.DebugEvent; -import org.eclipse.debug.core.DebugException; -import org.eclipse.debug.core.DebugPlugin; -import org.eclipse.debug.core.ILaunchConfiguration; -import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; -import org.eclipse.debug.core.model.IDebugElement; -import org.eclipse.debug.core.model.IDebugTarget; -import org.eclipse.debug.core.model.IMemoryBlock; -import org.eclipse.debug.core.model.IMemoryBlockExtension; -import org.eclipse.debug.core.model.IStackFrame; -import org.eclipse.debug.core.model.IValue; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; - -import com.ibm.icu.text.MessageFormat; - -/** - * Implements the memory retrieval features based on the CDI model. - */ -public class CMemoryBlockRetrievalExtension extends PlatformObject implements IMemorySpaceAwareMemoryBlockRetrieval { - - private static final String MEMORY_BLOCK_EXPRESSION_LIST = "memoryBlockExpressionList"; //$NON-NLS-1$ - private static final String MEMORY_BLOCK_EXPRESSION_ITEM = "memoryBlockExpressionItem"; //$NON-NLS-1$ - private static final String MEMORY_BLOCK_EXPRESSION = "expression"; //$NON-NLS-1$ - private static final String MEMORY_BLOCK_MEMSPACEID = "memorySpaceID"; //$NON-NLS-1$ - private static final String ATTR_MEMORY_BLOCK_MEMSPACEID_TEXT = "text"; //$NON-NLS-1$ - private static final String ATTR_MEMORY_BLOCK_EXPRESSION_TEXT = "text"; //$NON-NLS-1$ - - CDebugTarget fDebugTarget; - - /** - * Constructor for CMemoryBlockRetrievalExtension. - */ - public CMemoryBlockRetrievalExtension( CDebugTarget debugTarget ) { - fDebugTarget = debugTarget; - } - - protected CDebugTarget getDebugTarget() { - return fDebugTarget; - } - - public void initialize() { - ILaunchConfiguration config = getDebugTarget().getLaunch().getLaunchConfiguration(); - try { - String memento = config.getAttribute( ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_MEMORY_BLOCKS, "" ); //$NON-NLS-1$ - if ( memento != null && memento.trim().length() != 0 ) - initializeFromMemento( memento ); - } - catch( CoreException e ) { - CDebugCorePlugin.log( e ); - } - } - - private void parseMementoExprItem(Element element, List<String> expressions, List<String> memorySpaceIDs) { - NodeList list = element.getChildNodes(); - int length = list.getLength(); - String exp = null; - String memorySpaceID = null; - for( int i = 0; i < length; ++i ) { - Node node = list.item( i ); - if ( node.getNodeType() == Node.ELEMENT_NODE ) { - Element entry = (Element)node; - if ( entry.getNodeName().equalsIgnoreCase( MEMORY_BLOCK_EXPRESSION ) ) { - exp = entry.getAttribute( ATTR_MEMORY_BLOCK_EXPRESSION_TEXT ); - } else if ( entry.getNodeName().equalsIgnoreCase( MEMORY_BLOCK_MEMSPACEID ) ) { - memorySpaceID = entry.getAttribute( ATTR_MEMORY_BLOCK_MEMSPACEID_TEXT ); - } - } - } - if (exp != null) { - expressions.add( exp ); - memorySpaceIDs.add( memorySpaceID ); - } - } - - - private void initializeFromMemento( String memento ) throws CoreException { - Element root = DebugPlugin.parseDocument( memento ); - if ( root.getNodeName().equalsIgnoreCase( MEMORY_BLOCK_EXPRESSION_LIST ) ) { - List<String> expressions = new ArrayList<String>(); - List<String> memorySpaceIDs = new ArrayList<String>(); - NodeList list = root.getChildNodes(); - int length = list.getLength(); - for( int i = 0; i < length; ++i ) { - Node node = list.item( i ); - if ( node.getNodeType() == Node.ELEMENT_NODE ) { - Element entry = (Element)node; - if ( entry.getNodeName().equalsIgnoreCase( MEMORY_BLOCK_EXPRESSION_ITEM ) ) { - parseMementoExprItem(entry, expressions, memorySpaceIDs); - } - } - } - createMemoryBlocks( expressions.toArray( new String[expressions.size()]) , - memorySpaceIDs.toArray( new String[memorySpaceIDs.size()])); - - return; - } - abort(InternalDebugCoreMessages.CMemoryBlockRetrievalExtension_3, null); - } - - /** - * Convert a simple literal address (e.g., "0x1000") to a BigInteger value - * using the debug target's address factory. - * - * We throw a NumberFormatException if the string is not a valid literal - * address. If the backend implements the new&improved factory interface, - * we'll throw a NumberFormatException if the string is a literal address - * but is outside of the valid range. Old address factories will simply - * truncate the value. - * - * @param expression - * @return - * @throws DebugException if target not available - */ - private BigInteger evaluateLiteralAddress(String addr) throws DebugException { - CDebugTarget target = getDebugTarget(); - if (target == null) { - throw new DebugException(new Status(IStatus.ERROR, CDebugCorePlugin.getUniqueIdentifier(), DebugException.REQUEST_FAILED, - InternalDebugCoreMessages.CMemoryBlockRetrievalExtension_CDebugTarget_not_available, null)); - } - IAddressFactory addrFactory = target.getAddressFactory(); - if (addrFactory instanceof IAddressFactory2) { - return ((IAddressFactory2)addrFactory).createAddress(addr, false).getValue(); - } - else { - return addrFactory.createAddress(addr).getValue(); - } - } - - private void createMemoryBlocks( String[] expressions, String[] memorySpaceIDs ) { - List<CMemoryBlockExtension> list = new ArrayList<CMemoryBlockExtension>( expressions.length ); - for ( int i = 0; i < expressions.length; ++i ) { - try { - IAddress address = getDebugTarget().getAddressFactory().createAddress( expressions[i] ); - if ( address != null ) { - if (memorySpaceIDs[i] == null) { - list.add( new CMemoryBlockExtension( getDebugTarget(), address.toHexAddressString(), address.getValue() ) ); - } else { - list.add( new CMemoryBlockExtension( getDebugTarget(), expressions[i], address.getValue(), memorySpaceIDs[i] ) ); - } - } - } catch (NumberFormatException exc) { - CDebugCorePlugin.log(exc); - } - } - DebugPlugin.getDefault().getMemoryBlockManager().addMemoryBlocks( list.toArray( new IMemoryBlock[list.size()] ) ); - } - - public String getMemento() throws CoreException { - IMemoryBlock[] blocks = DebugPlugin.getDefault().getMemoryBlockManager().getMemoryBlocks( getDebugTarget() ); - Document document = DebugPlugin.newDocument(); - Element exprList = document.createElement( MEMORY_BLOCK_EXPRESSION_LIST ); - for ( int i = 0; i < blocks.length; ++i ) { - if ( blocks[i] instanceof IMemoryBlockExtension ) { - IMemoryBlockExtension memBlockExt = (IMemoryBlockExtension)blocks[i]; - Element exprItem = document.createElement( MEMORY_BLOCK_EXPRESSION_ITEM ); - exprList.appendChild(exprItem); - - String memorySpaceID = null; - if (memBlockExt instanceof IMemorySpaceAwareMemoryBlock) { - memorySpaceID = ((IMemorySpaceAwareMemoryBlock)memBlockExt).getMemorySpaceID(); - } - BigInteger addrBigInt = memBlockExt.getBigBaseAddress(); - - Element child = document.createElement( MEMORY_BLOCK_EXPRESSION ); - child.setAttribute( ATTR_MEMORY_BLOCK_EXPRESSION_TEXT, "0x" + addrBigInt.toString(16) ); //$NON-NLS-1$ - exprItem.appendChild( child ); - - if (memorySpaceID != null) { - child = document.createElement( MEMORY_BLOCK_MEMSPACEID ); - child.setAttribute( ATTR_MEMORY_BLOCK_MEMSPACEID_TEXT, memorySpaceID); - exprItem.appendChild( child ); - } - } - } - document.appendChild( exprList ); - return DebugPlugin.serializeDocument( document ); - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.IMemoryBlockExtensionRetrieval#getExtendedMemoryBlock(java.lang.String, org.eclipse.debug.core.model.IDebugElement) - */ - @Override - public IMemoryBlockExtension getExtendedMemoryBlock( String expression, Object selected ) throws DebugException { - return getMemoryBlock(expression, selected, null); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.internal.core.model.provisional.IMemorySpaceAwareMemoryBlockRetrieval#getExtendedMemoryBlock(java.lang.String, java.lang.Object, java.lang.String) - */ - @Override - public IMemorySpaceAwareMemoryBlock getMemoryBlock( String expression, Object selected, String memorySpaceID ) throws DebugException { - String address = null; - CExpression exp = null; - String msg = null; - try { - if (selected instanceof IDebugElement) { - IDebugElement debugElement = (IDebugElement)selected; - IDebugTarget target = debugElement.getDebugTarget(); - if (!(target instanceof CDebugTarget)) { - throw new DebugException( new Status( IStatus.ERROR, CDebugCorePlugin.getUniqueIdentifier(), DebugException.REQUEST_FAILED, msg, null ) ); - } - - // See if the expression is a simple numeric value; if it is, we can avoid some costly - // processing (calling the backend to resolve the expression) - try { - return new CMemoryBlockExtension((CDebugTarget)target, expression, evaluateLiteralAddress(expression), memorySpaceID); - } catch (NumberFormatException nfexc) {} - - // OK, expression is not a simple literal address; keep trucking and try to resolve as expression - CStackFrame frame = getStackFrame( debugElement ); - if ( frame != null ) { - // Get the address of the expression - ICDIExpression cdiExpression = frame.getCDITarget().createExpression( expression ); - exp = new CExpression( frame, cdiExpression, null ); - IValue value = exp.getValue(); - if ( value instanceof ICValue ) { - ICType type = ((ICValue)value).getType(); - if ( type != null ) { - // get the address for the expression, allow all types - String rawExpr = exp.getExpressionString(); - String voidExpr = "(void *)(" + rawExpr + ')'; //$NON-NLS-1$ - String attempts[] = { rawExpr, voidExpr }; - for (int i = 0; i < attempts.length; i++) { - String expr = attempts[i]; - address = frame.evaluateExpressionToString(expr); - if (address != null) { - try { - BigInteger a = (address.startsWith("0x")) ? new BigInteger(address.substring(2), 16) : new BigInteger(address); //$NON-NLS-1$ - return new CMemoryBlockExtension((CDebugTarget) target, expression, a, memorySpaceID); - } catch (NumberFormatException e) { - // not pointer? lets cast it to void* - if (i == 0) - continue; - throw e; - } - } - } - - } - else { - msg = MessageFormat.format(InternalDebugCoreMessages.CMemoryBlockRetrievalExtension_1, expression); - } - } - else { - msg = MessageFormat.format(InternalDebugCoreMessages.CMemoryBlockRetrievalExtension_2, expression); - } - } - } - } - catch( CDIException e ) { - msg = e.getMessage(); - } - catch( NumberFormatException e ) { - msg = MessageFormat.format(InternalDebugCoreMessages.CMemoryBlockRetrievalExtension_0, expression); - } - finally { - if (exp != null) { - exp.dispose(); - } - } - - throw new DebugException( new Status( IStatus.ERROR, CDebugCorePlugin.getUniqueIdentifier(), DebugException.REQUEST_FAILED, msg, null ) ); - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.IMemoryBlockRetrieval#supportsStorageRetrieval() - */ - @Override - public boolean supportsStorageRetrieval() { - return true; - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.IMemoryBlockRetrieval#getMemoryBlock(long, long) - */ - @Override - public IMemoryBlock getMemoryBlock( long startAddress, long length ) throws DebugException { - String expression = Long.toHexString(startAddress); - BigInteger address = new BigInteger(expression, 16); - expression = "0x" + expression; //$NON-NLS-1$ - return new CMemoryBlockExtension( getDebugTarget(), expression, address ); - } - - private CStackFrame getStackFrame( IDebugElement selected ) throws DebugException { - if ( selected instanceof CStackFrame ) { - return (CStackFrame)selected; - } - if ( selected instanceof CThread ) { - IStackFrame frame = ((CThread)selected).getTopStackFrame(); - if ( frame instanceof CStackFrame ) - return (CStackFrame)frame; - } - return null; - } - - public void save() { - ILaunchConfiguration config = getDebugTarget().getLaunch().getLaunchConfiguration(); - try { - ILaunchConfigurationWorkingCopy wc = config.getWorkingCopy(); - wc.setAttribute( ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_MEMORY_BLOCKS, getMemento() ); - wc.doSave(); - } - catch( CoreException e ) { - CDebugCorePlugin.log( e.getStatus() ); - } - } - - /** - * Throws an internal error exception - */ - private void abort( String message, Throwable e ) throws CoreException { - IStatus s = new Status( IStatus.ERROR, CDebugCorePlugin.getUniqueIdentifier(), CDebugCorePlugin.INTERNAL_ERROR, message, e ); - throw new CoreException( s ); - } - - public void dispose() { - // Fire a terminate event so our hosts can clean up. See 255120 and 283586 - DebugPlugin.getDefault().fireDebugEventSet( new DebugEvent[]{new DebugEvent( this, DebugEvent.TERMINATE )}); - - // Minimize leaks in case we are ourselves are leaked - fDebugTarget = null; - } - - /** - * Checks the CDI backend to see is memory spaces are supported and actually - * available for the target process. - * - * @return true if the backend supports memory spaces - */ - public boolean hasMemorySpaces() { - return getMemorySpaces().length > 0; - } - - /** - * @see org.eclipse.cdt.debug.core.model.provisional.IMemorySpaceAwareMemoryBlockRetrieval#getMemorySpaces(java.lang.Object, org.eclipse.cdt.debug.internal.core.model.provisional.IRequestListener) - */ - @Override - public void getMemorySpaces(final Object context, GetMemorySpacesRequest request) { - // We're not very asynchronous in CDI. DSF is another story. Also, note - // that we ignore the context. That's because we know that there's only - // one instance of this object per process object, and all elements of - // the project object (process, threads, frames) will have the same - // memory spaces - request.setMemorySpaces(getMemorySpaces()); - request.done(); - } - - /** - * This variant is called by code that is CDI-specific. This method and its - * uses predate the introduction of the DSF/CDI-agnostic - * IMemorySpaceAwareMemoryBlockRetrieval - * - * @return the memory spaces available in this debug session - */ - public String [] getMemorySpaces(){ - if (fDebugTarget != null) { - ICDITarget cdiTarget = fDebugTarget.getCDITarget(); - if (cdiTarget instanceof ICDIMemorySpaceManagement) - return ((ICDIMemorySpaceManagement)cdiTarget).getMemorySpaces(); - } - - return new String[0]; - } - - /** - * The default encoding of an {expression, memory space ID} pair into a - * string. A CDI client can provide custom decoding by implementing - * ICDIMemorySpaceEncoder - */ - public static String encodeAddressDefault(String expression, String memorySpaceID) { - return memorySpaceID + ':' + expression; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.internal.core.model.provisional.IMemorySpaceAwareMemoryBlockRetrieval#encodeAddress(java.math.BigInteger, java.lang.String) - */ - @Override - public String encodeAddress(final String expression, final String memorySpaceID) { - // See if the CDI client provides customized encoding/decoding - if (fDebugTarget != null) { - ICDITarget cdiTarget = fDebugTarget.getCDITarget(); - if (cdiTarget instanceof ICDIMemorySpaceEncoder) { - return ((ICDIMemorySpaceEncoder)cdiTarget).encodeAddress(expression, memorySpaceID); - } - } - - // Nope; use default encoding - return encodeAddressDefault(expression, memorySpaceID); - } - - /* - * The default decoding of a string into an {expression, memory space ID} - * pair. A CDI client can provide custom decoding by implementing ICDIMemorySpaceEncoder - */ - public static DecodeResult decodeAddressDefault(String str) throws CoreException { - int index = str.lastIndexOf(':'); - - // minimum is "<space>:<expression>" - if ((index == -1) || (index == str.length()-1)) { - IStatus s = new Status(IStatus.ERROR, CDebugCorePlugin.getUniqueIdentifier(), - CDebugCorePlugin.INTERNAL_ERROR, - InternalDebugCoreMessages.CMemoryBlockRetrievalExtension_invalid_encoded_address, null); - throw new CoreException( s ); - } - - final String memorySpaceID = str.substring(0, index); - final String expression = str.substring(index+1); - - return new DecodeResult() { - @Override - public String getMemorySpaceId() { return memorySpaceID; } - @Override - public String getExpression() { return expression; } - }; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.internal.core.model.provisional.IMemorySpaceAwareMemoryBlockRetrieval#decodeAddress(java.lang.String, java.lang.StringBuffer) - */ - @Override - public DecodeResult decodeAddress(final String str) throws CoreException { - - // See if the CDI client provides customized encoding/decoding - if (fDebugTarget != null) { - ICDITarget cdiTarget = fDebugTarget.getCDITarget(); - if (cdiTarget instanceof ICDIMemorySpaceEncoder) { - try { - final ICDIMemorySpaceEncoder.DecodeResult result = ((ICDIMemorySpaceEncoder)cdiTarget).decodeAddress(str); - return new DecodeResult() { - @Override - public String getMemorySpaceId() { return result.getMemorySpaceId(); } - @Override - public String getExpression() { return result.getExpression(); } - }; - } - catch (CDIException exc) { - IStatus s = new Status(IStatus.ERROR, CDebugCorePlugin.getUniqueIdentifier(), CDebugCorePlugin.INTERNAL_ERROR, InternalDebugCoreMessages.CMemoryBlockRetrievalExtension_invalid_encoded_address, exc); - throw new CoreException(s); - - } - } - } - - // Nope; use default decoding - return decodeAddressDefault(str); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.provisional.IMemorySpaceAwareMemoryBlockRetrieval#creatingBlockRequiresMemorySpaceID() - */ - @Override - public boolean creatingBlockRequiresMemorySpaceID() { - // A behavioral control we're not extending to CDI clients, but is being - // extended to DSF ones. - return false; - } -} diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CRegisterManager.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CRegisterManager.java deleted file mode 100644 index cc1d7ced85f..00000000000 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CRegisterManager.java +++ /dev/null @@ -1,381 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2013 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 - *******************************************************************************/ -package org.eclipse.cdt.debug.internal.core; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; -import java.util.concurrent.locks.ReentrantLock; - -import org.eclipse.cdt.debug.core.CDebugCorePlugin; -import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants; -import org.eclipse.cdt.debug.core.cdi.CDIException; -import org.eclipse.cdt.debug.core.cdi.model.ICDIRegisterDescriptor; -import org.eclipse.cdt.debug.core.cdi.model.ICDIRegisterGroup; -import org.eclipse.cdt.debug.core.model.ICStackFrame; -import org.eclipse.cdt.debug.core.model.IPersistableRegisterGroup; -import org.eclipse.cdt.debug.core.model.IRegisterDescriptor; -import org.eclipse.cdt.debug.internal.core.model.CDebugTarget; -import org.eclipse.cdt.debug.internal.core.model.CRegisterDescriptor; -import org.eclipse.cdt.debug.internal.core.model.CRegisterGroup; -import org.eclipse.cdt.debug.internal.core.model.CStackFrame; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.debug.core.DebugEvent; -import org.eclipse.debug.core.DebugException; -import org.eclipse.debug.core.DebugPlugin; -import org.eclipse.debug.core.ILaunchConfiguration; -import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; -import org.eclipse.debug.core.model.IRegisterGroup; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.Node; - -/** - * Manages all register groups in a debug target. - */ -public class CRegisterManager { - - private static final String ELEMENT_REGISTER_GROUP_LIST = "registerGroups"; //$NON-NLS-1$ - private static final String ELEMENT_REGISTER_GROUP = "group"; //$NON-NLS-1$ - private static final String ATTR_REGISTER_GROUP_MEMENTO = "memento"; //$NON-NLS-1$ - - /** - * The debug target associated with this manager. - */ - private CDebugTarget fDebugTarget; - - /** - * Collection of register groups added to this target. Values are of type <code>CRegisterGroup</code>. - */ - protected List fRegisterGroups; - - /** - * The list of all register descriptors. - */ - private IRegisterDescriptor[] fRegisterDescriptors; - - private boolean fUseDefaultRegisterGroups = true; - - private CStackFrame fCurrentFrame; - - private ReentrantLock fInitializationLock = new ReentrantLock(); - - private boolean fInitialized = false; - - /** - * Constructor for CRegisterManager. - */ - public CRegisterManager( CDebugTarget target ) { - fDebugTarget = target; - } - - /* (non-Javadoc) - * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class) - */ - public Object getAdapter( Class adapter ) { - if ( CRegisterManager.class.equals( adapter ) ) - return this; - return null; - } - - public void dispose() { - DebugPlugin.getDefault().asyncExec( - new Runnable() { - @Override - public void run() { - synchronized( fRegisterGroups ) { - Iterator it = fRegisterGroups.iterator(); - while( it.hasNext() ) { - ((CRegisterGroup)it.next()).dispose(); - } - fRegisterGroups.clear(); - } - } - } ); - } - - public IRegisterDescriptor[] getAllRegisterDescriptors() throws DebugException { - return fRegisterDescriptors; - } - - public IRegisterGroup[] getRegisterGroups() { - return (IRegisterGroup[])fRegisterGroups.toArray( new IRegisterGroup[fRegisterGroups.size()] ); - } - - public IRegisterGroup[] getRegisterGroups( CStackFrame frame ) throws DebugException { - setCurrentFrame( frame ); - return getRegisterGroups(); - } - - public void setCurrentFrame( ICStackFrame frame ) throws DebugException { - if ( frame != null && !frame.equals( getCurrentFrame() ) ) { - for ( IRegisterGroup group : getRegisterGroups() ) { - ((CRegisterGroup)group).resetRegisterValues(); - } - setCurrentFrame0( (CStackFrame)frame ); - } - } - - public void initialize() { - if ( !fInitialized ) { - synchronized( fInitializationLock ) { - if ( !fInitialized ) { - boolean failed = false; - ICDIRegisterGroup[] groups = new ICDIRegisterGroup[0]; - try { - groups = getDebugTarget().getCDITarget().getRegisterGroups(); - } - catch( CDIException e ) { - CDebugCorePlugin.log( e ); - failed = true; - } - List<CRegisterDescriptor> list = new ArrayList<CRegisterDescriptor>(); - for( int i = 0; i < groups.length; ++i ) { - try { - ICDIRegisterDescriptor[] cdiDescriptors = groups[i].getRegisterDescriptors(); - for ( int j = 0; j < cdiDescriptors.length; ++j ) { - list.add( new CRegisterDescriptor( groups[i], cdiDescriptors[j] ) ); - } - } - catch( CDIException e ) { - CDebugCorePlugin.log( e ); - failed = true; - } - } - fRegisterDescriptors = list.toArray( new IRegisterDescriptor[list.size()] ); - fInitialized = !failed; - if ( failed ) - fRegisterGroups = Collections.emptyList(); - else - createRegisterGroups(); - } - } - } - } - - public void addRegisterGroup( final String name, final IRegisterDescriptor[] descriptors ) { - DebugPlugin.getDefault().asyncExec( - new Runnable() { - @Override - public void run() { - fRegisterGroups.add( new CRegisterGroup( getDebugTarget(), name, descriptors ) ); - setUseDefaultRegisterGroups( false ); - getDebugTarget().fireChangeEvent( DebugEvent.CONTENT ); - } - } ); - } - - public void removeAllRegisterGroups() { - DebugPlugin.getDefault().asyncExec( - new Runnable() { - @Override - public void run() { - synchronized( fRegisterGroups ) { - Iterator it = fRegisterGroups.iterator(); - while( it.hasNext() ) { - ((CRegisterGroup)it.next()).dispose(); - } - fRegisterGroups.clear(); - } - setUseDefaultRegisterGroups( false ); - getDebugTarget().fireChangeEvent( DebugEvent.CONTENT ); - } - } ); - } - - public void removeRegisterGroups( final IRegisterGroup[] groups ) { - DebugPlugin.getDefault().asyncExec( - new Runnable() { - @Override - public void run() { - for ( int i = 0; i < groups.length; ++i ) { - ((CRegisterGroup)groups[i]).dispose(); - } - fRegisterGroups.removeAll( Arrays.asList( groups ) ); - setUseDefaultRegisterGroups( false ); - getDebugTarget().fireChangeEvent( DebugEvent.CONTENT ); - } - } ); - } - - public void restoreDefaults() { - DebugPlugin.getDefault().asyncExec( - new Runnable() { - @Override - public void run() { - synchronized( fRegisterGroups ) { - Iterator it = fRegisterGroups.iterator(); - while( it.hasNext() ) { - ((CRegisterGroup)it.next()).dispose(); - } - fRegisterGroups.clear(); - initializeDefaults(); - } - getDebugTarget().fireChangeEvent( DebugEvent.CONTENT ); - } - } ); - } - - private void createRegisterGroups() { - fRegisterGroups = Collections.synchronizedList( new ArrayList( 20 ) ); - ILaunchConfiguration config = getDebugTarget().getLaunch().getLaunchConfiguration(); - try { - String memento = config.getAttribute( ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_REGISTER_GROUPS, "" ); //$NON-NLS-1$ - if ( memento != null && memento.length() > 0 ) { - initializeFromMemento( memento ); - return; - } - } - catch( CoreException e ) { - } - initializeDefaults(); - } - - public void targetSuspended() { - Iterator it = fRegisterGroups.iterator(); - while( it.hasNext() ) { - ((CRegisterGroup)it.next()).targetSuspended(); - } - } - - public CDebugTarget getDebugTarget() { - return fDebugTarget; - } - - private void initializeFromMemento( String memento ) throws CoreException { - Node node = DebugPlugin.parseDocument( memento ); - if ( node.getNodeType() != Node.ELEMENT_NODE ) { - abort(InternalDebugCoreMessages.CRegisterManager_0, null); - } - Element element = (Element)node; - if ( !ELEMENT_REGISTER_GROUP_LIST.equals( element.getNodeName() ) ) { - abort(InternalDebugCoreMessages.CRegisterManager_1, null); - } - Node childNode = element.getFirstChild(); - while( childNode != null ) { - if ( childNode.getNodeType() == Node.ELEMENT_NODE ) { - Element child = (Element)childNode; - if ( ELEMENT_REGISTER_GROUP.equals( child.getNodeName() ) ) { - String groupMemento = child.getAttribute( ATTR_REGISTER_GROUP_MEMENTO ); - CRegisterGroup group = new CRegisterGroup( getDebugTarget() ); - try { - group.initializeFromMemento( groupMemento ); - doAddRegisterGroup( group ); - } - catch( CoreException e ) { - // skip this group - } - } - } - childNode = childNode.getNextSibling(); - } - setUseDefaultRegisterGroups( false ); - } - - protected void initializeDefaults() { - setUseDefaultRegisterGroups( true ); - String current = null; - int startIndex = 0; - for ( int i = 0; i < fRegisterDescriptors.length; ++i ) { - CRegisterDescriptor d = (CRegisterDescriptor)fRegisterDescriptors[i]; - if ( current != null && d.getGroupName().compareTo( current ) != 0 ) { - IRegisterDescriptor[] descriptors = new IRegisterDescriptor[i - startIndex]; - System.arraycopy( fRegisterDescriptors, startIndex, descriptors, 0, descriptors.length ); - fRegisterGroups.add( new CRegisterGroup( getDebugTarget(), current, descriptors ) ); - startIndex = i; - } - current = d.getGroupName(); - } - if ( startIndex < fRegisterDescriptors.length ) { - IRegisterDescriptor[] descriptors = new IRegisterDescriptor[fRegisterDescriptors.length - startIndex]; - System.arraycopy( fRegisterDescriptors, startIndex, descriptors, 0, descriptors.length ); - fRegisterGroups.add( new CRegisterGroup( getDebugTarget(), current, descriptors ) ); - } - } - - protected synchronized void doAddRegisterGroup( IRegisterGroup group ) { - fRegisterGroups.add( group ); - } - - public void save() { - ILaunchConfiguration config = getDebugTarget().getLaunch().getLaunchConfiguration(); - try { - ILaunchConfigurationWorkingCopy wc = config.getWorkingCopy(); - wc.setAttribute( ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_REGISTER_GROUPS, getMemento() ); - wc.doSave(); - } - catch( CoreException e ) { - CDebugCorePlugin.log( e ); - } - } - - private String getMemento() throws CoreException { - if ( useDefaultRegisterGroups() || fRegisterGroups == null ) - return ""; //$NON-NLS-1$ - Document document = DebugPlugin.newDocument(); - Element element = document.createElement( ELEMENT_REGISTER_GROUP_LIST ); - Iterator it = fRegisterGroups.iterator(); - while( it.hasNext() ) { - CRegisterGroup group = (CRegisterGroup)it.next(); - Element child = document.createElement( ELEMENT_REGISTER_GROUP ); - child.setAttribute( ATTR_REGISTER_GROUP_MEMENTO, group.getMemento() ); - element.appendChild( child ); - } - document.appendChild( element ); - return DebugPlugin.serializeDocument( document ); - } - - private void abort( String message, Throwable exception ) throws CoreException { - IStatus status = new Status( IStatus.ERROR, CDebugCorePlugin.getUniqueIdentifier(), CDebugCorePlugin.INTERNAL_ERROR, message, exception ); - throw new CoreException( status ); - } - - public IRegisterDescriptor findDescriptor( String groupName, String name ) { - for ( int i = 0; i < fRegisterDescriptors.length; ++i ) { - IRegisterDescriptor d = fRegisterDescriptors[i]; - if ( groupName.equals( d.getGroupName() ) && name.equals( d.getName() ) ) - return d; - } - return null; - } - - public void modifyRegisterGroup( final IPersistableRegisterGroup group, final IRegisterDescriptor[] descriptors ) { - DebugPlugin.getDefault().asyncExec( - new Runnable() { - @Override - public void run() { - group.setRegisterDescriptors( descriptors ); - ((CRegisterGroup)group).fireChangeEvent( DebugEvent.CONTENT ); - } - } ); - - } - - protected boolean useDefaultRegisterGroups() { - return fUseDefaultRegisterGroups; - } - - protected void setUseDefaultRegisterGroups( boolean useDefaultRegisterGroups ) { - fUseDefaultRegisterGroups = useDefaultRegisterGroups; - } - - public CStackFrame getCurrentFrame() { - return fCurrentFrame; - } - - private void setCurrentFrame0( CStackFrame currentFrame ) { - fCurrentFrame = currentFrame; - } -} diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CSettingsManager.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CSettingsManager.java deleted file mode 100644 index c833a098d21..00000000000 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CSettingsManager.java +++ /dev/null @@ -1,268 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2012 Freescale Semiconductor 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: - * Freescale Semiconductor - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.debug.internal.core; - -import java.io.IOException; -import java.io.StringReader; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.Set; - -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.transform.TransformerException; - -import org.eclipse.cdt.debug.core.CDebugUtils; -import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants; -import org.eclipse.cdt.debug.internal.core.model.CDebugTarget; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.debug.core.DebugPlugin; -import org.eclipse.debug.core.ILaunchConfiguration; -import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; -import org.eclipse.debug.core.model.IDebugTarget; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; -import org.xml.sax.InputSource; -import org.xml.sax.SAXException; - -/** - * Settings manager - * - * The settings manager stores a set of settings, - * (key/value) pairs in the launch configuration so they exist across debug sessions. - * - * All active settings are stored together in a single configuration entry - * (ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_FORMAT). - * - * Every setting is identified by a string identifier. That string identifier can be used to - * store an additional setting, to remove an exiting one or to retrieve a previously stored setting. - * - * The setting value consists of a String. - * - * Settings fade out automatically so clients do not necessarily need to delete old settings. This makes it - * possible to build the string identifiers with names out of the user application, like function names or - * variable names, without the danger of a constantly growing launch configuration. - * However it also causes that the settings manager must only be used for configurations and customizations for which - * always reasonable defaults exist. - * - * As cleanup policy the settings manager only keeps a certain number of settings and drops the - * least recently used one when more settings are added. The least recently used order is maintained - * across debug sessions. - * - */ - -public class CSettingsManager { - - /** - * the name of the XML node for the list - */ - private static final String CONTENT_LIST = "contentList"; //$NON-NLS-1$ - - /** - * the name of the XML node for every format entry - */ - private static final String CONTENT = "content"; //$NON-NLS-1$ - - /** - * the attribute name used to identify the object to store the content for. - */ - private static final String ATTR_CONTENT_ID = "id"; //$NON-NLS-1$ - - /** - * the attribute name of the actual content - */ - private static final String ATTR_CONTENT_VALUE = "val"; //$NON-NLS-1$ - - /** - * Number defining how many settings are stored. - * Whenever an additional setting is added when there are already MAX_USED_COUNT settings, the - * least recently used setting is dropped. - * - * The actual value is chosen to be high enough for normal use cases, but still low enough to avoid that the launch configuration - * gets arbitrarily large - */ - private static int MAX_ELEMENT_COUNT = 100; - - /** - * the map used to actually store the format information - * as key String are used, values are of type String too. - * - * The map automatically is limited to MAX_ELEMENT_COUNT - * elements, dropping the least recently used one - * when more elements are added. - */ - private Map fContentMap = new LinkedHashMap(MAX_ELEMENT_COUNT, 0.75f, true) { - private static final long serialVersionUID = 1; - @Override - protected boolean removeEldestEntry(Map.Entry eldest) { - return size() > MAX_ELEMENT_COUNT; - } - }; - - /** - * the debug target we store the values for - */ - private CDebugTarget fDebugTarget; - - /** - * Store the value for the given id. - * @param id used to identify the information. Different objects/topics should use different identifiers. - * @param value content to be stored - */ - public synchronized void putValue( String id, String value ) { - fContentMap.put(id, value); - } - /** - * remove the stored format for the given id. - * @param id used to identify the formatting information. Different objects/topics should use different identifiers. - */ - public synchronized void removeValue( String id ) { - fContentMap.remove( id ); - } - - /** Retrieve the value for the given id. - * @param id used to identify the formatting information. Different objects/topics should use different identifiers. - * @return returns the entry information for the given id, or null if no such information is available. - */ - public synchronized String getValue( String id ) { - String entry= (String) fContentMap.get( id ); - return entry; - } - - /** constructor. - * @param debugTarget - */ - public CSettingsManager( CDebugTarget debugTarget ) { - fDebugTarget = debugTarget; - initialize(); - } - - /** get the string format of the current content. - * Only stores entries which have been used in the last MAX_USED_COUNT debug sessions. - * @return - */ - private String getMemento() { - Document document = null; - try { - document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); - Element node = document.createElement( CONTENT_LIST ); - document.appendChild( node ); - Set entrySet = fContentMap.entrySet(); - Iterator it = entrySet.iterator(); - while ( it.hasNext() ) { - Map.Entry entry= (Map.Entry) it.next(); - String id= (String)entry.getKey(); - String value= (String)entry.getValue(); - Element child = document.createElement( CONTENT ); - child.setAttribute( ATTR_CONTENT_ID, id ); - child.setAttribute( ATTR_CONTENT_VALUE, value ); - node.appendChild( child ); - } - return CDebugUtils.serializeDocument( document, false ); - } - catch( ParserConfigurationException e ) { - DebugPlugin.log( e ); - } - catch( IOException e ) { - DebugPlugin.log( e ); - } - catch( TransformerException e ) { - DebugPlugin.log( e ); - } - return null; - } - - /** set the current state to the one given by the memento. - * @param memento a string representation of the state to be loaded. - * @throws CoreException - */ - private void initializeFromMemento( String memento ) throws CoreException { - try { - fContentMap.clear(); - DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder(); - StringReader reader = new StringReader( memento ); - InputSource source = new InputSource( reader ); - Element root = parser.parse( source ).getDocumentElement(); - if ( root.getNodeName().equalsIgnoreCase( CONTENT_LIST ) ) { - NodeList list = root.getChildNodes(); - int i = list.getLength() - 1; // backwards to keep least recent access order. - for( ; i >= 0; i-- ) { - Node node = list.item( i ); - short type = node.getNodeType(); - if ( type == Node.ELEMENT_NODE ) { - Element elem = (Element)node; - if ( elem.getNodeName().equalsIgnoreCase( CONTENT ) ) { - String id = elem.getAttribute( ATTR_CONTENT_ID ); - String value= elem.getAttribute( ATTR_CONTENT_VALUE ); - if ( id == null || id.length() == 0 ) { - DebugPlugin.logMessage( "unexpected entry in CSettingsManager.initializeFromMemento", null ); //$NON-NLS-1$ - continue; - } - putValue( id, value ); - } - } - } - return; - } - DebugPlugin.logMessage( "unexpected content", null ); //$NON-NLS-1$ - } - catch( ParserConfigurationException e ) { - DebugPlugin.log( e ); - } - catch( SAXException e ) { - DebugPlugin.log( e ); - } - catch( IOException e ) { - DebugPlugin.log( e ); - } - } - - /** - * read the stored format from the launch configuration - */ - private void initialize() { - ILaunchConfiguration config = getDebugTarget().getLaunch().getLaunchConfiguration(); - try { - String memento = config.getAttribute( ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_FORMAT, "" ); //$NON-NLS-1$ - if ( memento != null && memento.trim().length() != 0 ) - initializeFromMemento( memento ); - } - catch( CoreException e ) { - DebugPlugin.log( e ); - } - } - - /** - * store the current content in the launch configuration. - */ - public synchronized void save() { - ILaunchConfiguration config = getDebugTarget().getLaunch().getLaunchConfiguration(); - try { - ILaunchConfigurationWorkingCopy wc = config.getWorkingCopy(); - wc.setAttribute( ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_FORMAT, getMemento() ); - wc.doSave(); - } - catch( CoreException e ) { - DebugPlugin.log( e ); - } - } - - /** - * accessor to the debug target - */ - IDebugTarget getDebugTarget() { - return fDebugTarget; - } -} diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CSignalManager.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CSignalManager.java deleted file mode 100644 index 1326eefebd6..00000000000 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CSignalManager.java +++ /dev/null @@ -1,132 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2012 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 - *******************************************************************************/ -package org.eclipse.cdt.debug.internal.core; - -import java.util.ArrayList; -import org.eclipse.cdt.debug.core.CDIDebugModel; -import org.eclipse.cdt.debug.core.cdi.CDIException; -import org.eclipse.cdt.debug.core.cdi.model.ICDISignal; -import org.eclipse.cdt.debug.core.model.ICSignal; -import org.eclipse.cdt.debug.internal.core.model.CDebugTarget; -import org.eclipse.cdt.debug.internal.core.model.CSignal; -import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.debug.core.DebugEvent; -import org.eclipse.debug.core.DebugException; - -/** - * Manages the collection of signals on a debug target. - */ -public class CSignalManager implements IAdaptable { - - /** - * The debug target associated with this manager. - */ - private CDebugTarget fDebugTarget; - - /** - * The list of signals. - */ - private ICSignal[] fSignals = null; - - /** - * The dispose flag. - */ - private boolean fIsDisposed = false; - - /** - * Constructor for CSignalManager. - */ - public CSignalManager( CDebugTarget target ) { - fDebugTarget = target; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.ICSignalManager#getSignals() - */ - public ICSignal[] getSignals() throws DebugException { - if ( !isDisposed() && fSignals == null ) { - try { - ICDISignal[] cdiSignals = getDebugTarget().getCDITarget().getSignals(); - ArrayList list = new ArrayList( cdiSignals.length ); - for( int i = 0; i < cdiSignals.length; ++i ) { - list.add( new CSignal( getDebugTarget(), cdiSignals[i] ) ); - } - fSignals = (ICSignal[])list.toArray( new ICSignal[list.size()] ); - } - catch( CDIException e ) { - throwDebugException( e.getMessage(), DebugException.TARGET_REQUEST_FAILED, e ); - } - } - return (fSignals != null) ? fSignals : new ICSignal[0]; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.internal.core.CUpdateManager#dispose() - */ - public void dispose() { - if ( fSignals != null ) - for( int i = 0; i < fSignals.length; ++i ) { - ((CSignal)fSignals[i]).dispose(); - } - fSignals = null; - fIsDisposed = true; - } - - /* (non-Javadoc) - * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class) - */ - @Override - public Object getAdapter( Class adapter ) { - if ( adapter.equals( CSignalManager.class ) ) { - return this; - } - if ( adapter.equals( CDebugTarget.class ) ) { - return getDebugTarget(); - } - return null; - } - - public void signalChanged( ICDISignal cdiSignal ) { - CSignal signal = find( cdiSignal ); - if ( signal != null ) { - signal.fireChangeEvent( DebugEvent.STATE ); - } - } - - private CSignal find( ICDISignal cdiSignal ) { - try { - ICSignal[] signals = getSignals(); - for( int i = 0; i < signals.length; ++i ) - if ( signals[i].getName().equals( cdiSignal.getName() ) ) - return (CSignal)signals[i]; - } - catch( DebugException e ) { - } - return null; - } - - protected boolean isDisposed() { - return fIsDisposed; - } - - /** - * Throws a debug exception with the given message, error code, and underlying exception. - */ - protected void throwDebugException( String message, int code, Throwable exception ) throws DebugException { - throw new DebugException( new Status( IStatus.ERROR, CDIDebugModel.getPluginIdentifier(), code, message, exception ) ); - } - - protected CDebugTarget getDebugTarget() { - return fDebugTarget; - } -} diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/DebugConfiguration.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/DebugConfiguration.java deleted file mode 100644 index 321256d94da..00000000000 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/DebugConfiguration.java +++ /dev/null @@ -1,190 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2013 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 - *******************************************************************************/ -package org.eclipse.cdt.debug.internal.core; - -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.StringTokenizer; - -import org.eclipse.cdt.debug.core.CDebugCorePlugin; -import org.eclipse.cdt.debug.core.ICDIDebugger; -import org.eclipse.cdt.debug.core.ICDebugConfiguration; -import org.eclipse.cdt.debug.core.ICDebugger; -import org.eclipse.cdt.utils.Platform; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; - - - -public class DebugConfiguration implements ICDebugConfiguration { - /** - * The configuration element of the extension. - */ - private IConfigurationElement fElement; - private HashSet fModes; - private HashSet fCPUs; - private String[] fCoreExt; - - public DebugConfiguration(IConfigurationElement element) { - fElement = element; - } - - private IConfigurationElement getConfigurationElement() { - return fElement; - } - - @Override - public ICDebugger getDebugger() throws CoreException { - Object debugger = getConfigurationElement().createExecutableExtension("class"); //$NON-NLS-1$ - if (debugger instanceof ICDebugger) { - return (ICDebugger)debugger; - } - throw new CoreException(new Status(IStatus.ERROR, CDebugCorePlugin.getUniqueIdentifier(), -1, - InternalDebugCoreMessages.DebugConfiguration_0, null)); - } - - @Override - public ICDIDebugger createDebugger() throws CoreException { - Object debugger = getConfigurationElement().createExecutableExtension("class"); //$NON-NLS-1$ - if (debugger instanceof ICDIDebugger) { - return (ICDIDebugger)debugger; - } - return new CDebugAdapter((ICDebugger)debugger); - } - - @Override - public String getName() { - String name = getConfigurationElement().getAttribute("name"); //$NON-NLS-1$ - return name != null ? name : ""; //$NON-NLS-1$ - } - - @Override - public String getID() { - return getConfigurationElement().getAttribute("id"); //$NON-NLS-1$ - } - - @Override - public String getPlatform() { - String platform = getConfigurationElement().getAttribute("platform"); //$NON-NLS-1$ - if (platform == null) { - return "*"; //$NON-NLS-1$ - } - return platform; - } - - @Override - public String[] getCPUList() { - return (String[]) getCPUs().toArray(new String[0]); - } - - @Override - public String[] getModeList() { - return (String[]) getModes().toArray(new String[0]); - } - - @Override - public boolean supportsMode(String mode) { - return getModes().contains(mode); - } - - @Override - public boolean supportsCPU(String cpu) { - String nativeCPU = Platform.getOSArch(); - boolean ret = false; - if (nativeCPU.startsWith(cpu) - || nativeCPU.equalsIgnoreCase("powerpc") //$NON-NLS-1$ - && (cpu.equalsIgnoreCase("ppc") //$NON-NLS-1$ - || cpu.equalsIgnoreCase("xcoff32") || cpu //$NON-NLS-1$ - .equalsIgnoreCase("xcoff64"))) { //$NON-NLS-1$ - ret = getCPUs().contains(CPU_NATIVE); - } - return ret || getCPUs().contains(cpu) || getCPUs().contains("*"); //$NON-NLS-1$ - } - /** - * Returns the set of modes specified in the configuration data. - * - * @return the set of modes specified in the configuration data - */ - protected Set getModes() { - if (fModes == null) { - String modes = getConfigurationElement().getAttribute("modes"); //$NON-NLS-1$ - if (modes == null) { - return new HashSet(0); - } - StringTokenizer tokenizer = new StringTokenizer(modes, ","); //$NON-NLS-1$ - fModes = new HashSet(tokenizer.countTokens()); - while (tokenizer.hasMoreTokens()) { - fModes.add(tokenizer.nextToken().trim()); - } - } - return fModes; - } - - protected Set getCPUs() { - if (fCPUs == null) { - String cpus = getConfigurationElement().getAttribute("cpu"); //$NON-NLS-1$ - if (cpus == null) { - fCPUs = new HashSet(1); - fCPUs.add(CPU_NATIVE); - } - else { - String nativeCPU = Platform.getOSArch(); - StringTokenizer tokenizer = new StringTokenizer(cpus, ","); //$NON-NLS-1$ - fCPUs = new HashSet(tokenizer.countTokens()); - while (tokenizer.hasMoreTokens()) { - String cpu = tokenizer.nextToken().trim(); - fCPUs.add(cpu); - if (nativeCPU.startsWith(cpu)) { // os arch be cpu{le/be} - fCPUs.add(CPU_NATIVE); - } - } - } - } - return fCPUs; - } - - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.ICDebugConfiguration#getCoreFileExtensions() - */ - @Override - public String[] getCoreFileExtensions() { - if (fCoreExt == null) { - List exts = new ArrayList(); - String cexts = getConfigurationElement().getAttribute("coreFileFilter"); //$NON-NLS-1$ - if (cexts != null) { - StringTokenizer tokenizer = new StringTokenizer(cexts, ","); //$NON-NLS-1$ - while (tokenizer.hasMoreTokens()) { - String ext = tokenizer.nextToken().trim(); - exts.add(ext); - } - } - exts.add("*"); //$NON-NLS-1$ - fCoreExt = (String[])exts.toArray(new String[exts.size()]); - } - return fCoreExt; - } - - @Override - public String[] getSupportedBuildConfigPatterns() { - IConfigurationElement[] patternElems = fElement.getChildren("buildIdPattern"); //$NON-NLS-1$ - String[] patterns = new String[patternElems.length]; - for (int i = 0; i < patternElems.length; ++i) { - patterns[i] = patternElems[i].getAttribute("pattern"); //$NON-NLS-1$ - } - return patterns; - } - -} diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/SessionManager.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/SessionManager.java deleted file mode 100644 index df341b2f776..00000000000 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/SessionManager.java +++ /dev/null @@ -1,81 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2015 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 - *******************************************************************************/ -package org.eclipse.cdt.debug.internal.core; - -import org.eclipse.cdt.debug.core.CDebugCorePlugin; -import org.eclipse.cdt.debug.core.cdi.CDIException; -import org.eclipse.cdt.debug.core.cdi.ICDISession; -import org.eclipse.cdt.debug.core.cdi.model.ICDITarget; -import org.eclipse.debug.core.DebugEvent; -import org.eclipse.debug.core.DebugPlugin; -import org.eclipse.debug.core.IDebugEventSetListener; -import org.eclipse.debug.core.ILaunch; -import org.eclipse.debug.core.model.IDebugTarget; - -/** - * Default implementation of the session manager. Terminates the session when the last target is terminated; - */ -public class SessionManager implements IDebugEventSetListener { - - public SessionManager() { - DebugPlugin.getDefault().addDebugEventListener( this ); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class) - */ - public Object getAdapter( Class adapter ) { - if ( SessionManager.class.equals( adapter ) ) - return this; - return null; - } - - public void dispose() { - DebugPlugin.getDefault().removeDebugEventListener( this ); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.debug.core.IDebugEventSetListener#handleDebugEvents(org.eclipse.debug.core.DebugEvent[]) - */ - @Override - public void handleDebugEvents( DebugEvent[] events ) { - for( int i = 0; i < events.length; i++ ) { - DebugEvent event = events[i]; - if ( event.getKind() == DebugEvent.TERMINATE ) { - Object element = event.getSource(); - if ( element instanceof IDebugTarget && ((IDebugTarget)element).getAdapter( ICDITarget.class ) != null ) { - handleTerminateEvent( ((IDebugTarget)element).getLaunch(), ((IDebugTarget)element).getAdapter( ICDITarget.class ).getSession() ); - } - } - } - } - - private void handleTerminateEvent( ILaunch launch, ICDISession session ) { - IDebugTarget[] targets = launch.getDebugTargets(); - boolean terminate = true; - for( int i = 0; i < targets.length; ++i ) { - if ( targets[i].getAdapter( ICDITarget.class ) != null && session.equals( targets[i].getAdapter( ICDITarget.class ).getSession() ) && !targets[i].isTerminated() && !targets[i].isDisconnected() ) - terminate = false; - } - if ( terminate ) { - try { - session.terminate(); - } - catch( CDIException e ) { - CDebugCorePlugin.log( e ); - } - } - } -} diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/breakpoints/CBreakpointFilterExtension.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/breakpoints/CBreakpointFilterExtension.java deleted file mode 100644 index 608ba1bbfbe..00000000000 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/breakpoints/CBreakpointFilterExtension.java +++ /dev/null @@ -1,103 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2012 Wind River 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: - * Wind River Systems - initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.debug.internal.core.breakpoints; - -import java.util.Arrays; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -import org.eclipse.cdt.debug.core.model.ICBreakpoint; -import org.eclipse.cdt.debug.core.model.ICBreakpointFilterExtension; -import org.eclipse.cdt.debug.core.model.ICDebugTarget; -import org.eclipse.cdt.debug.core.model.ICThread; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.debug.core.model.IDebugTarget; - -/** - * - */ -public class CBreakpointFilterExtension implements ICBreakpointFilterExtension { - - @Override - public void initialize(ICBreakpoint breakpoint) { - } - - private Map fFilteredThreadsByTarget = new HashMap( 10 ); - - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.ICBreakpoint#getTargetFilters() - */ - @Override - public ICDebugTarget[] getTargetFilters() throws CoreException { - Set set = fFilteredThreadsByTarget.keySet(); - return (ICDebugTarget[])set.toArray( new ICDebugTarget[set.size()] ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.ICBreakpoint#getThreadFilters(org.eclipse.cdt.debug.core.model.ICDebugTarget) - */ - @Override - public ICThread[] getThreadFilters( ICDebugTarget target ) throws CoreException { - Set set = (Set)fFilteredThreadsByTarget.get( target ); - return ( set != null ) ? (ICThread[])set.toArray( new ICThread[set.size()] ) : null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.ICBreakpoint#removeTargetFilter(org.eclipse.cdt.debug.core.model.ICDebugTarget) - */ - @Override - public void removeTargetFilter( ICDebugTarget target ) throws CoreException { - if ( fFilteredThreadsByTarget.containsKey( target ) ) { - fFilteredThreadsByTarget.remove( target ); - } - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.ICBreakpoint#removeThreadFilters(org.eclipse.cdt.debug.core.model.ICThread[]) - */ - @Override - public void removeThreadFilters( ICThread[] threads ) throws CoreException { - if ( threads != null && threads.length > 0 ) { - IDebugTarget target = threads[0].getDebugTarget(); - if ( fFilteredThreadsByTarget.containsKey( target ) ) { - Set set = (Set)fFilteredThreadsByTarget.get( target ); - if ( set != null ) { - set.removeAll( Arrays.asList( threads ) ); - if ( set.isEmpty() ) { - fFilteredThreadsByTarget.remove( target ); - } - } - } - } - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.ICBreakpoint#setTargetFilter(org.eclipse.cdt.debug.core.model.ICDebugTarget) - */ - @Override - public void setTargetFilter( ICDebugTarget target ) throws CoreException { - fFilteredThreadsByTarget.put( target, null ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.ICBreakpoint#setThreadFilters(org.eclipse.cdt.debug.core.model.ICThread[]) - */ - @Override - public void setThreadFilters( ICThread[] threads ) throws CoreException { - if ( threads != null && threads.length > 0 ) { - fFilteredThreadsByTarget.put( threads[0].getDebugTarget(), new HashSet( Arrays.asList( threads ) ) ); - } - } - -} diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/AbstractCValue.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/AbstractCValue.java deleted file mode 100644 index 1147e964ece..00000000000 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/AbstractCValue.java +++ /dev/null @@ -1,66 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2012 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 - *******************************************************************************/ -package org.eclipse.cdt.debug.internal.core.model; - -import org.eclipse.cdt.debug.core.model.ICStackFrame; -import org.eclipse.cdt.debug.core.model.ICValue; -import org.eclipse.debug.core.DebugException; - -/** - * The abstract super class for the C/C++ value types. - */ -public abstract class AbstractCValue extends CDebugElement implements ICValue { - - /** - * Parent variable. - */ - private AbstractCVariable fParent = null; - - /** - * Constructor for AbstractCValue. - */ - public AbstractCValue( AbstractCVariable parent ) { - super( (CDebugTarget)parent.getDebugTarget() ); - fParent = parent; - } - - public AbstractCVariable getParentVariable() { - return fParent; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.ICValue#evaluateAsExpression(org.eclipse.cdt.debug.core.model.ICStackFrame) - */ - @Override - public String evaluateAsExpression( ICStackFrame frame ) { - String valueString = ""; //$NON-NLS-1$ - AbstractCVariable parent = getParentVariable(); - if ( parent != null ) { - if ( frame != null && frame.canEvaluate() ) { - try { - valueString = frame.evaluateExpressionToString( parent.getExpressionString() ); - } - catch( DebugException e ) { - valueString = e.getMessage(); - } - } - } - return valueString; - } - - abstract protected void setChanged( boolean changed ); - - abstract public void dispose(); - - abstract protected void reset(); - - abstract protected void preserve(); -} diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/AbstractCVariable.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/AbstractCVariable.java deleted file mode 100644 index b68d61fb821..00000000000 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/AbstractCVariable.java +++ /dev/null @@ -1,72 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2012 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 - *******************************************************************************/ -package org.eclipse.cdt.debug.internal.core.model; - -import org.eclipse.cdt.debug.core.model.ICStackFrame; -import org.eclipse.cdt.debug.core.model.ICVariable; -import org.eclipse.cdt.debug.core.model.IEnableDisableTarget; - -/** - * The super class for all variable types. - */ -public abstract class AbstractCVariable extends CDebugElement implements ICVariable { - - /** - * The parent object this variable is contained in. - */ - private CDebugElement fParent; - - /** - * Constructor for AbstractCVariable. - */ - public AbstractCVariable( CDebugElement parent ) { - super( (CDebugTarget)parent.getDebugTarget() ); - setParent( parent ); - } - - protected CDebugElement getParent() { - return fParent; - } - - private void setParent( CDebugElement parent ) { - fParent = parent; - } - - protected ICStackFrame getStackFrame() { - CDebugElement parent = getParent(); - if ( parent instanceof AbstractCValue ) { - AbstractCVariable pv = ((AbstractCValue)parent).getParentVariable(); - if ( pv != null ) - return pv.getStackFrame(); - } - if ( parent instanceof CStackFrame ) - return (CStackFrame)parent; - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class) - */ - @Override - public Object getAdapter( Class adapter ) { - if ( IEnableDisableTarget.class.equals( adapter ) ) - return this; - return super.getAdapter( adapter ); - } - - public abstract void dispose(); - - protected abstract void resetValue(); - - protected abstract void setChanged( boolean changed ); - - protected abstract void preserve(); -} diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/AsmInstruction.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/AsmInstruction.java deleted file mode 100644 index c2a386120dd..00000000000 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/AsmInstruction.java +++ /dev/null @@ -1,82 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2012 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 - *******************************************************************************/ -package org.eclipse.cdt.debug.internal.core.model; - -import org.eclipse.cdt.core.IAddress; -import org.eclipse.cdt.core.IAddressFactory; -import org.eclipse.cdt.debug.core.cdi.model.ICDIInstruction; -import org.eclipse.cdt.debug.core.model.IAsmInstruction; - -/** - * Adapter for ICDIInstruction. - */ -public class AsmInstruction implements IAsmInstruction { - - private ICDIInstruction fCDIInstruction; - - private IAddress fAddress; - - /** - * Constructor for AsmInstruction. - */ - public AsmInstruction( IAddressFactory factory, ICDIInstruction cdiInstruction ) { - fCDIInstruction = cdiInstruction; - fAddress = factory.createAddress( cdiInstruction.getAdress() ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.IAsmInstruction#getAdress() - */ - @Override - public IAddress getAdress() { - return fAddress; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.IAsmInstruction#getFunctionName() - */ - @Override - public String getFunctionName() { - return fCDIInstruction.getFuntionName(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.IAsmInstruction#getInstructionText() - */ - @Override - public String getInstructionText() { - return fCDIInstruction.getInstruction(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.IAsmInstruction#getOpcode() - */ - @Override - public String getOpcode() { - return fCDIInstruction.getOpcode(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.IAsmInstruction#getArguments() - */ - @Override - public String getArguments() { - return fCDIInstruction.getArgs(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.IAsmInstruction#getOffset() - */ - @Override - public long getOffset() { - return fCDIInstruction.getOffset(); - } -} diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/AsmSourceLine.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/AsmSourceLine.java deleted file mode 100644 index 0065605b923..00000000000 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/AsmSourceLine.java +++ /dev/null @@ -1,68 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2012 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 - *******************************************************************************/ -package org.eclipse.cdt.debug.internal.core.model; - -import org.eclipse.cdt.core.IAddressFactory; -import org.eclipse.cdt.debug.core.cdi.model.ICDIInstruction; -import org.eclipse.cdt.debug.core.model.IAsmInstruction; -import org.eclipse.cdt.debug.core.model.IAsmSourceLine; - -/** - * Adapter for ICDIMixedInstruction. - */ -public class AsmSourceLine implements IAsmSourceLine { - - private String fText; - - private IAsmInstruction[] fInstructions = null; - - private int fLineNumber; - - /** - * Constructor for AsmSourceLine. - */ - public AsmSourceLine( IAddressFactory factory, String text, ICDIInstruction[] cdiInstructions ) { - this( factory, text, -1, cdiInstructions ); - } - - /** - * Constructor for AsmSourceLine. - */ - public AsmSourceLine( IAddressFactory factory, String text, int lineNumber, ICDIInstruction[] cdiInstructions ) { - fText = text; - fLineNumber = lineNumber; - fInstructions = new IAsmInstruction[cdiInstructions.length]; - for ( int i = 0; i < fInstructions.length; ++i ) { - fInstructions[i] = new AsmInstruction( factory, cdiInstructions[i] ); - } - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.IAsmSourceLine#getLineNumber() - */ - @Override - public int getLineNumber() { - return fLineNumber; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.IAsmSourceLine#getInstructions() - */ - @Override - public IAsmInstruction[] getInstructions() { - return fInstructions; - } - - @Override - public String toString() { - return fText; - } -} diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CCoreFileDebugTarget.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CCoreFileDebugTarget.java deleted file mode 100644 index 6dc83cfe94b..00000000000 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CCoreFileDebugTarget.java +++ /dev/null @@ -1,50 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2012 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 - *******************************************************************************/ -package org.eclipse.cdt.debug.internal.core.model; - -import org.eclipse.cdt.core.IBinaryParser.IBinaryExecutable; -import org.eclipse.cdt.debug.core.cdi.model.ICDITarget; -import org.eclipse.cdt.debug.core.model.CDebugElementState; -import org.eclipse.core.resources.IProject; -import org.eclipse.debug.core.ILaunch; -import org.eclipse.debug.core.model.IProcess; - -/** - * A debug target for the postmortem debugging. - * @deprecated - */ -@Deprecated -public class CCoreFileDebugTarget extends CDebugTarget { - - - /** - * @param launch - * @param project - * @param cdiTarget - * @param name - * @param debuggeeProcess - * @param file - * @param allowsTerminate - * @param allowsDisconnect - */ - public CCoreFileDebugTarget(ILaunch launch, IProject project, ICDITarget cdiTarget, String name, IProcess debuggeeProcess, IBinaryExecutable file) { - super(launch, project, cdiTarget, name, debuggeeProcess, file, false, false); - setState(CDebugElementState.TERMINATED); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.ICDebugTarget#isPostMortem() - */ - @Override - public boolean isPostMortem() { - return true; - } -} diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CDebugElement.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CDebugElement.java deleted file mode 100644 index 0b8c684dbaa..00000000000 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CDebugElement.java +++ /dev/null @@ -1,398 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2015 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 - * Ling Wang, Nokia - Bug 179425 - *******************************************************************************/ -package org.eclipse.cdt.debug.internal.core.model; - -import com.ibm.icu.text.MessageFormat; -import org.eclipse.cdt.debug.core.CDIDebugModel; -import org.eclipse.cdt.debug.core.CDebugCorePlugin; -import org.eclipse.cdt.debug.core.CDebugUtils; -import org.eclipse.cdt.debug.core.cdi.CDIException; -import org.eclipse.cdt.debug.core.cdi.ICDISession; -import org.eclipse.cdt.debug.core.cdi.model.ICDITarget; -import org.eclipse.cdt.debug.core.model.CDebugElementState; -import org.eclipse.cdt.debug.core.model.ICDebugElement; -import org.eclipse.cdt.debug.core.model.ICDebugElementStatus; -import org.eclipse.cdt.debug.core.model.ICDebugTarget; -import org.eclipse.cdt.debug.core.model.IModuleRetrieval; -import org.eclipse.cdt.debug.internal.core.ICDebugInternalConstants; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.PlatformObject; -import org.eclipse.core.runtime.Status; -import org.eclipse.debug.core.DebugEvent; -import org.eclipse.debug.core.DebugException; -import org.eclipse.debug.core.DebugPlugin; -import org.eclipse.debug.core.ILaunch; -import org.eclipse.debug.core.model.IDebugElement; -import org.eclipse.debug.core.model.IDebugTarget; -import org.eclipse.debug.core.model.IMemoryBlockRetrieval; - -/** - * The super class of all C/C++ debug model elements. - */ -abstract public class CDebugElement extends PlatformObject implements ICDebugElement, ICDebugElementStatus { - - /** - * Debug target associated with this element - */ - private CDebugTarget fDebugTarget; - - /** - * The severity code of this element's status - */ - private int fSeverity = ICDebugElementStatus.OK; - - /** - * The message of this element's status - */ - private String fMessage = null; - - /** - * The current state of this element. - */ - private CDebugElementState fState = CDebugElementState.UNDEFINED; - - /** - * The previous state of this element. - */ - private CDebugElementState fOldState = CDebugElementState.UNDEFINED; - - /** - * The current state info. - */ - private Object fCurrentStateInfo = null; - - /** - * Constructor for CDebugElement. - */ - public CDebugElement( CDebugTarget target ) { - setDebugTarget( target ); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.debug.core.model.IDebugElement#getModelIdentifier() - */ - @Override - public String getModelIdentifier() { - return CDIDebugModel.getPluginIdentifier(); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.debug.core.model.IDebugElement#getDebugTarget() - */ - @Override - public IDebugTarget getDebugTarget() { - return fDebugTarget; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.debug.core.model.IDebugElement#getLaunch() - */ - @Override - public ILaunch getLaunch() { - return getDebugTarget().getLaunch(); - } - - protected void setDebugTarget( CDebugTarget target ) { - fDebugTarget = target; - } - - /** - * Convenience method to log errors - */ - protected void logError( Exception e ) { - DebugPlugin.log( e ); - } - - /** - * Convenience method to log errors - * - */ - protected void logError( String message ) { - DebugPlugin.logMessage( message, null ); - } - - /** - * Fires a debug event - * - * @param event The debug event to be fired to the listeners - * @see org.eclipse.debug.core.DebugEvent - */ - protected void fireEvent( DebugEvent event ) { - DebugPlugin.getDefault().fireDebugEventSet( new DebugEvent[]{ event } ); - } - - protected void fireEventSet( DebugEvent[] events ) { - DebugPlugin.getDefault().fireDebugEventSet( events ); - } - - /** - * Fires a debug event marking the creation of this element. - */ - public void fireCreationEvent() { - fireEvent( new DebugEvent( this, DebugEvent.CREATE ) ); - } - - public DebugEvent createCreateEvent() { - return new DebugEvent( this, DebugEvent.CREATE ); - } - - /** - * Fires a debug event marking the RESUME of this element with the associated detail. - * - * @param detail The int detail of the event - * @see org.eclipse.debug.core.DebugEvent - */ - public void fireResumeEvent( int detail ) { - fireEvent( new DebugEvent( this, DebugEvent.RESUME, detail ) ); - } - - public DebugEvent createResumeEvent( int detail ) { - return new DebugEvent( this, DebugEvent.RESUME, detail ); - } - - /** - * Fires a debug event marking the SUSPEND of this element with the associated detail. - * - * @param detail The int detail of the event - * @see org.eclipse.debug.core.DebugEvent - */ - public void fireSuspendEvent( int detail ) { - fireEvent( new DebugEvent( this, DebugEvent.SUSPEND, detail ) ); - } - - public DebugEvent createSuspendEvent( int detail ) { - return new DebugEvent( this, DebugEvent.SUSPEND, detail ); - } - - /** - * Fires a debug event marking the termination of this element. - */ - public void fireTerminateEvent() { - fireEvent( new DebugEvent( this, DebugEvent.TERMINATE ) ); - } - - public DebugEvent createTerminateEvent() { - return new DebugEvent( this, DebugEvent.TERMINATE ); - } - - /** - * Fires a debug event marking the CHANGE of this element with the specifed detail code. - * - * @param detail - * one of <code>STATE</code> or <code>CONTENT</code> - */ - public void fireChangeEvent( int detail ) { - fireEvent( new DebugEvent( this, DebugEvent.CHANGE, detail ) ); - } - - public DebugEvent createChangeEvent( int detail ) { - return new DebugEvent( this, DebugEvent.CHANGE, detail ); - } - - /** - * Returns the CDI session associated with this element. - * - * @return the CDI session - */ - public ICDISession getCDISession() { - final ICDITarget cdiTarget = getCDITarget(); - return cdiTarget != null ? cdiTarget.getSession() : null; - } - - /** - * Returns the underlying CDI target associated with this element. - * - * @return the underlying CDI target - */ - public ICDITarget getCDITarget() { - return getDebugTarget().getAdapter( ICDITarget.class ); - } - - /** - * Throws a new debug exception with a status code of <code>REQUEST_FAILED</code>. - * - * @param message Failure message - * @param e Exception that has occurred (<code>can be null</code>) - * @throws DebugException The exception with a status code of <code>REQUEST_FAILED</code> - */ - public static void requestFailed( String message, Exception e ) throws DebugException { - requestFailed( message, e, DebugException.REQUEST_FAILED ); - } - - /** - * Throws a new debug exception with a status code of <code>TARGET_REQUEST_FAILED</code> with the given underlying exception. - * - * @param message Failure message - * @param e underlying exception that has occurred - * @throws DebugException The exception with a status code of <code>TARGET_REQUEST_FAILED</code> - */ - public static void targetRequestFailed( String message, CDIException e ) throws DebugException { - String format = "Target request failed: {0}"; //$NON-NLS-1$ - // Append a period only when incoming message does not end with one. - if ( !message.endsWith( "." ) ) //$NON-NLS-1$ - format += "."; //$NON-NLS-1$ - - requestFailed( MessageFormat.format( format, new String[] { message } ), e, DebugException.TARGET_REQUEST_FAILED ); - } - - /** - * Throws a new debug exception with the given status code. - * - * @param message Failure message - * @param e Exception that has occurred (<code>can be null</code>) - * @param code status code - * @throws DebugException a new exception with given status code - */ - public static void requestFailed( String message, Throwable e, int code ) throws DebugException { - throwDebugException( message, code, e ); - } - - /** - * Throws a new debug exception with a status code of <code>TARGET_REQUEST_FAILED</code>. - * - * @param message Failure message - * @param e Throwable that has occurred - * @throws DebugException The exception with a status code of <code>TARGET_REQUEST_FAILED</code> - */ - public static void targetRequestFailed( String message, Throwable e ) throws DebugException { - String format = "Target request failed: {0}"; //$NON-NLS-1$ - // Append a period only when incoming message does not end with one. - if ( !message.endsWith( "." ) ) //$NON-NLS-1$ - format += "."; //$NON-NLS-1$ - - throwDebugException( MessageFormat.format( format, new String[]{ message } ), DebugException.TARGET_REQUEST_FAILED, e ); - } - - /** - * Throws a new debug exception with a status code of <code>NOT_SUPPORTED</code>. - * - * @param message Failure message - * @throws DebugException The exception with a status code of <code>NOT_SUPPORTED</code>. - */ - public static void notSupported( String message ) throws DebugException { - throwDebugException( message, DebugException.NOT_SUPPORTED, null ); - } - - /** - * Throws a debug exception with the given message, error code, and underlying exception. - */ - protected static void throwDebugException( String message, int code, Throwable exception ) throws DebugException { - throw new DebugException( new Status( IStatus.ERROR, CDIDebugModel.getPluginIdentifier(), code, message, exception ) ); - } - - protected void infoMessage( Throwable e ) { - IStatus newStatus = new Status( IStatus.INFO, CDebugCorePlugin.getUniqueIdentifier(), ICDebugInternalConstants.STATUS_CODE_INFO, e.getMessage(), null ); - CDebugUtils.info( newStatus, getDebugTarget() ); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.core.runtime.IAdaptable#getAdapter(Class) - */ - @Override - public Object getAdapter( Class adapter ) { - if ( adapter.equals( IDebugElement.class ) ) - return this; - if ( adapter.equals( ICDebugElement.class ) ) - return this; - if ( adapter.equals( CDebugElement.class ) ) - return this; - if ( adapter.equals( ICDebugElementStatus.class ) ) - return this; - if ( adapter.equals( ICDISession.class ) ) - return getCDISession(); - if ( adapter.equals( ICDebugTarget.class ) ) - return getDebugTarget(); - if ( adapter.equals( IDebugTarget.class ) ) - return getDebugTarget(); - // See bug #100261 - if ( adapter.equals( IMemoryBlockRetrieval.class ) ) - return getDebugTarget().getAdapter( adapter ); - if ( adapter.equals( IModuleRetrieval.class ) ) - return getDebugTarget().getAdapter( adapter ); - if ( adapter.equals( ILaunch.class ) ) - return getDebugTarget().getLaunch(); - return super.getAdapter( adapter ); - } - - protected void setStatus( int severity, String message ) { - fSeverity = severity; - fMessage = message; - if ( fMessage != null ) - fMessage = fMessage.trim(); - } - - protected void resetStatus() { - fSeverity = ICDebugElementStatus.OK; - fMessage = null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.ICDebugElementStatus#isOK() - */ - @Override - public boolean isOK() { - return (fSeverity == ICDebugElementStatus.OK); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.ICDebugElementStatus#getSeverity() - */ - @Override - public int getSeverity() { - return fSeverity; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.ICDebugElementStatus#getMessage() - */ - @Override - public String getMessage() { - return fMessage; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.ICDebugElement#getState() - */ - @Override - public CDebugElementState getState() { - return fState; - } - - protected synchronized void setState( CDebugElementState state ) throws IllegalArgumentException { - fOldState = fState; - fState = state; - } - - protected synchronized void restoreState() { - fState = fOldState; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.ICDebugElement#getCurrentStateInfo() - */ - @Override - public Object getCurrentStateInfo() { - return fCurrentStateInfo; - } - - protected void setCurrentStateInfo( Object currentStateInfo ) { - fCurrentStateInfo = currentStateInfo; - } -} diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CDebugTarget.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CDebugTarget.java deleted file mode 100644 index d8ef4fbf3ef..00000000000 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CDebugTarget.java +++ /dev/null @@ -1,2065 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2015 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 - * Ken Ryall (Nokia) - bugs 118894, 170027, 91771 - * Wind River Systems - adapted to work with platform Modules view (bug 210558) - * Marc-Andre Laperle - Bug 382462 - *******************************************************************************/ -package org.eclipse.cdt.debug.internal.core.model; - -import java.io.File; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.StringTokenizer; - -import org.eclipse.cdt.core.CCorePlugin; -import org.eclipse.cdt.core.IAddress; -import org.eclipse.cdt.core.IAddressFactory; -import org.eclipse.cdt.core.IBinaryParser.IBinaryObject; -import org.eclipse.cdt.core.IBinaryParser.ISymbol; -import org.eclipse.cdt.debug.core.CDIDebugModel; -import org.eclipse.cdt.debug.core.CDebugCorePlugin; -import org.eclipse.cdt.debug.core.CDebugUtils; -import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants; -import org.eclipse.cdt.debug.core.ICDebugConstants; -import org.eclipse.cdt.debug.core.ICGlobalVariableManager; -import org.eclipse.cdt.debug.core.cdi.CDIException; -import org.eclipse.cdt.debug.core.cdi.ICDIAddressLocation; -import org.eclipse.cdt.debug.core.cdi.ICDIBreakpointHit; -import org.eclipse.cdt.debug.core.cdi.ICDIEndSteppingRange; -import org.eclipse.cdt.debug.core.cdi.ICDIErrorInfo; -import org.eclipse.cdt.debug.core.cdi.ICDIEventBreakpointHit; -import org.eclipse.cdt.debug.core.cdi.ICDIFunctionLocation; -import org.eclipse.cdt.debug.core.cdi.ICDILineLocation; -import org.eclipse.cdt.debug.core.cdi.ICDILocation; -import org.eclipse.cdt.debug.core.cdi.ICDISession; -import org.eclipse.cdt.debug.core.cdi.ICDISessionConfiguration; -import org.eclipse.cdt.debug.core.cdi.ICDISessionObject; -import org.eclipse.cdt.debug.core.cdi.ICDISharedLibraryEvent; -import org.eclipse.cdt.debug.core.cdi.ICDISignalReceived; -import org.eclipse.cdt.debug.core.cdi.ICDIWatchpointScope; -import org.eclipse.cdt.debug.core.cdi.ICDIWatchpointTrigger; -import org.eclipse.cdt.debug.core.cdi.event.ICDIChangedEvent; -import org.eclipse.cdt.debug.core.cdi.event.ICDICreatedEvent; -import org.eclipse.cdt.debug.core.cdi.event.ICDIDestroyedEvent; -import org.eclipse.cdt.debug.core.cdi.event.ICDIDisconnectedEvent; -import org.eclipse.cdt.debug.core.cdi.event.ICDIEvent; -import org.eclipse.cdt.debug.core.cdi.event.ICDIEventListener; -import org.eclipse.cdt.debug.core.cdi.event.ICDIExitedEvent; -import org.eclipse.cdt.debug.core.cdi.event.ICDIRestartedEvent; -import org.eclipse.cdt.debug.core.cdi.event.ICDIResumedEvent; -import org.eclipse.cdt.debug.core.cdi.event.ICDISuspendedEvent; -import org.eclipse.cdt.debug.core.cdi.model.ICDIAddressFactoryManagement; -import org.eclipse.cdt.debug.core.cdi.model.ICDIDisposable; -import org.eclipse.cdt.debug.core.cdi.model.ICDIGlobalVariableDescriptor; -import org.eclipse.cdt.debug.core.cdi.model.ICDIObject; -import org.eclipse.cdt.debug.core.cdi.model.ICDISharedLibrary; -import org.eclipse.cdt.debug.core.cdi.model.ICDISignal; -import org.eclipse.cdt.debug.core.cdi.model.ICDITarget; -import org.eclipse.cdt.debug.core.cdi.model.ICDITarget2; -import org.eclipse.cdt.debug.core.cdi.model.ICDITargetConfiguration; -import org.eclipse.cdt.debug.core.cdi.model.ICDITargetConfiguration2; -import org.eclipse.cdt.debug.core.cdi.model.ICDIThread; -import org.eclipse.cdt.debug.core.cdi.model.ICDIVariableDescriptor; -import org.eclipse.cdt.debug.core.model.CDebugElementState; -import org.eclipse.cdt.debug.core.model.ICBreakpoint; -import org.eclipse.cdt.debug.core.model.ICBreakpointType; -import org.eclipse.cdt.debug.core.model.ICDebugElement; -import org.eclipse.cdt.debug.core.model.ICDebugElementStatus; -import org.eclipse.cdt.debug.core.model.ICDebugTarget; -import org.eclipse.cdt.debug.core.model.ICGlobalVariable; -import org.eclipse.cdt.debug.core.model.ICLineBreakpoint; -import org.eclipse.cdt.debug.core.model.ICModule; -import org.eclipse.cdt.debug.core.model.ICSignal; -import org.eclipse.cdt.debug.core.model.IDebuggerProcessSupport; -import org.eclipse.cdt.debug.core.model.IDisassembly; -import org.eclipse.cdt.debug.core.model.IExecFileInfo; -import org.eclipse.cdt.debug.core.model.IGlobalVariableDescriptor; -import org.eclipse.cdt.debug.core.model.IModuleRetrieval; -import org.eclipse.cdt.debug.core.model.IPersistableRegisterGroup; -import org.eclipse.cdt.debug.core.model.IRegisterDescriptor; -import org.eclipse.cdt.debug.core.sourcelookup.CProjectSourceContainer; -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.CSettingsManager; -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.cdt.utils.Addr64Factory; -import org.eclipse.core.resources.IContainer; -import org.eclipse.core.resources.IMarkerDelta; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResourceChangeListener; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.MultiStatus; -import org.eclipse.core.runtime.Path; -import org.eclipse.core.runtime.Platform; -import org.eclipse.core.runtime.Preferences; -import org.eclipse.core.runtime.Preferences.IPropertyChangeListener; -import org.eclipse.core.runtime.Status; -import org.eclipse.debug.core.DebugEvent; -import org.eclipse.debug.core.DebugException; -import org.eclipse.debug.core.DebugPlugin; -import org.eclipse.debug.core.IExpressionListener; -import org.eclipse.debug.core.IExpressionManager; -import org.eclipse.debug.core.ILaunch; -import org.eclipse.debug.core.ILaunchConfiguration; -import org.eclipse.debug.core.ILaunchListener; -import org.eclipse.debug.core.model.IBreakpoint; -import org.eclipse.debug.core.model.IDebugTarget; -import org.eclipse.debug.core.model.IExpression; -import org.eclipse.debug.core.model.IMemoryBlock; -import org.eclipse.debug.core.model.IMemoryBlockRetrieval; -import org.eclipse.debug.core.model.IMemoryBlockRetrievalExtension; -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.DirectorySourceContainer; -import org.eclipse.debug.core.sourcelookup.containers.FolderSourceContainer; -import org.eclipse.debug.core.sourcelookup.containers.ProjectSourceContainer; - -import com.ibm.icu.text.MessageFormat; - -/** - * Debug target for C/C++ debug model. - */ -public class CDebugTarget extends CDebugElement implements ICDebugTarget, ICDIEventListener, ILaunchListener, IExpressionListener, ISourceLookupChangeListener { - - /** - * Threads contained in this debug target. - * When a thread starts it is added to the list. - * When a thread ends it is removed from the list. - */ - private ArrayList<CThread> fThreads; - - /** - * Associated inferior process, or <code>null</code> if not available. - */ - private IProcess fDebuggeeProcess = null; - - /** - * The underlying CDI target. - */ - private ICDITarget fCDITarget; - - /** - * The name of this target. - */ - private String fName; - - /** - * The launch this target is contained in - */ - private ILaunch fLaunch; - - /** - * The debug configuration of this session - */ - private ICDITargetConfiguration fConfig; - - /** - * The disassembly manager for this target. - */ - private Disassembly fDisassembly; - - /** - * The new disassembly manager for this target. - */ - private DisassemblyRetrieval fDisassemblyRetrieval; - - /** - * The module manager for this target. - */ - private CModuleManager fModuleManager; - - /** - * The signal manager for this target. - */ - private CSignalManager fSignalManager; - - /** - * The register manager for this target. - */ - private CRegisterManager fRegisterManager; - - /** - * A breakpoint manager for this target. - */ - private CBreakpointManager fBreakpointManager; - - /** - * The global variable manager for this target. - */ - private CGlobalVariableManager fGlobalVariableManager; - - /** - * container for Default format information - */ - private CSettingsManager fFormatManager; - - /** - * The executable binary file associated with this target. - */ - private IBinaryObject fBinaryFile; - - /** - * The project associated with this target. - */ - private IProject fProject; - - /** - * Whether the target is little endian. - */ - private Boolean fIsLittleEndian = null; - - /** - * The target's preference set. - */ - private Preferences fPreferences = null; - - /** - * The address factory of this target. - */ - private IAddressFactory fAddressFactory; - - /** - * Support for the memory retrieval on this target. - */ - private CMemoryBlockRetrievalExtension fMemoryBlockRetrieval; - - /** - * Internal ID that uniquely identifies this CDebugTarget. - */ - private String internalD = Integer.toString(lastInternalID++); - - private static int lastInternalID = 1; - - /** - * Constructor for CDebugTarget. - */ - public CDebugTarget(ILaunch launch, IProject project, ICDITarget cdiTarget, String name, IProcess debuggeeProcess, IBinaryObject file, boolean allowsTerminate, boolean allowsDisconnect) { - super(null); - setLaunch(launch); - setDebugTarget(this); - setName(name); - setProcess(debuggeeProcess); - setProject(project); - setExecFile(file); - setCDITarget(cdiTarget); - setState(CDebugElementState.SUSPENDED); - initializePreferences(); - setConfiguration(cdiTarget.getConfiguration()); - setThreadList(new ArrayList<CThread>(5)); - createDisassembly(); - setModuleManager(new CModuleManager(this)); - setSignalManager(new CSignalManager(this)); - setRegisterManager(new CRegisterManager(this)); - setBreakpointManager(new CBreakpointManager(this)); - setGlobalVariableManager(new CGlobalVariableManager(this)); - setFormatManager(new CSettingsManager(this)); - setMemoryBlockRetrieval(new CMemoryBlockRetrievalExtension(this)); - initialize(); - DebugPlugin.getDefault().getLaunchManager().addLaunchListener(this); - DebugPlugin.getDefault().getExpressionManager().addExpressionListener(this); - getCDISession().getEventManager().addEventListener(this); - } - - protected void initialize() { - initializeSourceLookupPath(); - ArrayList<DebugEvent> debugEvents = new ArrayList<DebugEvent>(1); - debugEvents.add(createCreateEvent()); - initializeThreads(debugEvents); - initializeBreakpoints(); - initializeRegisters(); - initializeSourceManager(); - initializeModuleManager(); - initializeMemoryBlocks(); - getLaunch().addDebugTarget(this); - fireEventSet(debugEvents.toArray(new DebugEvent[debugEvents.size()])); - } - - private void initializeBreakpoints() { - getBreakpointManager().initialize(); - } - - public void start(String stopSymbol, boolean resume) throws DebugException { - ICDITargetConfiguration config = getConfiguration(); - if (config.supportsBreakpoints()) { - getBreakpointManager().setInitialBreakpoints(); - - if (stopSymbol != null && stopSymbol.length() != 0) { - // See if the expression is a numeric address - try { - IAddress address = getAddressFactory().createAddress(stopSymbol); - stopAtAddress(address); - } catch (NumberFormatException nfexc) { - // OK, expression is not a simple, absolute numeric value; keep trucking and try to resolve as expression - stopAtSymbol(stopSymbol); - } - } - } - if (config.supportsResume() && resume) { - resume(); - } - } - - /** - * Adds all of the pre-existing threads to this debug target. - */ - protected void initializeThreads(List<DebugEvent> debugEvents) { - final ICDITarget cdiTarget = getCDITarget(); - if (cdiTarget == null) { - return; - } - - ICDIThread[] cdiThreads = new ICDIThread[0]; - try { - cdiThreads = cdiTarget.getThreads(); - } catch (CDIException e) { - // ignore - } - DebugEvent suspendEvent = null; - for (int i = 0; i < cdiThreads.length; ++i) { - CThread thread = createThread(cdiThreads[i]); - debugEvents.add(thread.createCreateEvent()); - try { - if (cdiThreads[i].equals(cdiTarget.getCurrentThread()) && thread.isSuspended()) { - // Use BREAKPOINT as a detail to force perspective switch - suspendEvent = thread.createSuspendEvent(DebugEvent.BREAKPOINT); - } - } catch (CDIException e) { - // ignore - } - } - if (suspendEvent != null) { - debugEvents.add(suspendEvent); - } - } - - protected void initializeRegisters() { - getRegisterManager().initialize(); - } - - protected void initializeSourceManager() { - ISourceLocator locator = getLaunch().getSourceLocator(); - if (locator instanceof IAdaptable) { - ICSourceLocator clocator = ((IAdaptable)locator).getAdapter(ICSourceLocator.class); - if (clocator instanceof IAdaptable) { - CSourceManager sm = ((IAdaptable)clocator).getAdapter(CSourceManager.class); - if (sm != null) - sm.setDebugTarget(this); - } - IResourceChangeListener listener = ((IAdaptable)locator).getAdapter(IResourceChangeListener.class); - if (listener != null) - CCorePlugin.getWorkspace().addResourceChangeListener(listener); - } - } - - 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() { - final ICDITarget cdiTarget = getCDITarget(); - if (cdiTarget == null) { - return; - } - - ICDISharedLibrary[] slibs = new ICDISharedLibrary[0]; - try { - slibs = cdiTarget.getSharedLibraries(); - } catch (CDIException e) { - DebugPlugin.log(e); - } - ICModule[] modules = null; - if (getExecFile() != null) { - modules = new ICModule[slibs.length + 1]; - modules[0] = CModule.createExecutable(this, getExecFile().getPath()); - } else { - modules = new ICModule[slibs.length]; - } - for (int i = 0; i < slibs.length; ++i) { - modules[i + 1] = CModule.createSharedLibrary(this, slibs[i]); - } - getModuleManager().addModules(modules); - } - - protected void initializeMemoryBlocks() { - getMemoryBlockRetrieval().initialize(); - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.IDebugTarget#getProcess() - */ - @Override - public IProcess getProcess() { - return fDebuggeeProcess; - } - - /** - * Sets the process associated with this debug target, possibly <code>null</code>. Set on creation. - * - * @param process the system process associated with the underlying CDI target, - * or <code>null</code> if no process is associated with this debug target - * (for a core dump debugging). - */ - protected void setProcess(IProcess debuggeeProcess) { - fDebuggeeProcess = debuggeeProcess; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.debug.core.model.IDebugTarget#getThreads() - */ - @Override - public IThread[] getThreads() { - List<CThread> threads = getThreadList(); - return threads.toArray(new IThread[threads.size()]); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.debug.core.model.IDebugTarget#hasThreads() - */ - @Override - public boolean hasThreads() throws DebugException { - return getThreadList().size() > 0; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.debug.core.model.IDebugTarget#getName() - */ - @Override - public String getName() throws DebugException { - return fName; - } - - /** - * Sets the name of this debug target. - * - * @param name the name of this debug target - */ - public void setName(String name) { - fName = name; - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.IDebugTarget#supportsBreakpoint(org.eclipse.debug.core.model.IBreakpoint) - */ - @Override - public boolean supportsBreakpoint(IBreakpoint breakpoint) { - if (!getConfiguration().supportsBreakpoints()) - return false; - return (breakpoint instanceof ICBreakpoint && getBreakpointManager().supportsBreakpoint((ICBreakpoint)breakpoint)); - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.ILaunchListener#launchRemoved(org.eclipse.debug.core.ILaunch) - */ - @Override - public void launchRemoved(ILaunch launch) { - if (!isAvailable()) { - return; - } - if (launch.equals(getLaunch())) { - // This target has been deregistered, but it hasn't been successfully terminated. - // Update internal state to reflect that it is disconnected - disconnected(); - } - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.ILaunchListener#launchAdded(org.eclipse.debug.core.ILaunch) - */ - @Override - public void launchAdded(ILaunch launch) { - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.ILaunchListener#launchChanged(org.eclipse.debug.core.ILaunch) - */ - @Override - public void launchChanged(ILaunch launch) { - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.ITerminate#canTerminate() - */ - @Override - public boolean canTerminate() { - return supportsTerminate() && isAvailable(); - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.ITerminate#isTerminated() - */ - @Override - public boolean isTerminated() { - return (getState().equals(CDebugElementState.TERMINATED)); - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.ITerminate#terminate() - */ - @Override - public void terminate() throws DebugException { - if (!canTerminate()) { - return; - } - final CDebugElementState newState = CDebugElementState.TERMINATING; - changeState(newState); - try { - final ICDITarget cdiTarget = getCDITarget(); - if (cdiTarget != null) { - cdiTarget.terminate(); - } - } catch (CDIException e) { - if (getState() == newState) { - restoreOldState(); - } - targetRequestFailed(e.getMessage(), null); - } - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.ISuspendResume#canResume() - */ - @Override - public boolean canResume() { - return getConfiguration().supportsResume() && isSuspended(); - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.ISuspendResume#canSuspend() - */ - @Override - public boolean canSuspend() { - if (!getConfiguration().supportsSuspend()) - return false; - if (getState().equals(CDebugElementState.RESUMED)) { - // only allow suspend if no threads are currently suspended - IThread[] threads = getThreads(); - for (int i = 0; i < threads.length; i++) { - if (threads[i].isSuspended()) { - return false; - } - } - return true; - } - return false; - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.ISuspendResume#isSuspended() - */ - @Override - public boolean isSuspended() { - return (getState().equals(CDebugElementState.SUSPENDED)); - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.ISuspendResume#resume() - */ - @Override - public void resume() throws DebugException { - if (!canResume()) - return; - final CDebugElementState newState = CDebugElementState.RESUMING; - changeState(newState); - try { - final ICDITarget cdiTarget = getCDITarget(); - if (cdiTarget != null) { - cdiTarget.resume(false); - } - } catch (CDIException e) { - if (getState() == newState) { - restoreOldState(); - } - targetRequestFailed(e.getMessage(), null); - } - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.ISuspendResume#suspend() - */ - @Override - public void suspend() throws DebugException { - if (!canSuspend()) - return; - final CDebugElementState newState = CDebugElementState.SUSPENDING; - changeState(newState); - try { - final ICDITarget cdiTarget = getCDITarget(); - if (cdiTarget != null) { - cdiTarget.suspend(); - } - } catch (CDIException e) { - if (getState() == newState) { - restoreOldState(); - } - targetRequestFailed(e.getMessage(), null); - } - } - - protected boolean isSuspending() { - return (getState().equals(CDebugElementState.SUSPENDING)); - } - - /** - * Notifies threads that the target has been suspended. - */ - protected void suspendThreads(ICDISuspendedEvent event) { - Iterator<CThread> it = getThreadList().iterator(); - while (it.hasNext()) { - CThread thread = it.next(); - ICDIThread suspensionThread = null; - try { - final ICDITarget cdiTarget = getCDITarget(); - if (cdiTarget != null) { - suspensionThread = cdiTarget.getCurrentThread(); - } - } catch (CDIException e) { - // ignore - } - thread.suspendByTarget(event.getReason(), suspensionThread); - } - } - - /** - * Refreshes the thread list. - */ - protected synchronized List<CThread> refreshThreads() { - ArrayList<CThread> newThreads = new ArrayList<CThread>(5); - ArrayList<CThread> list = new ArrayList<CThread>(5); - ArrayList<DebugEvent> debugEvents = new ArrayList<DebugEvent>(5); - List<CThread> oldList = (List<CThread>)getThreadList().clone(); - ICDIThread[] cdiThreads = new ICDIThread[0]; - ICDIThread currentCDIThread = null; - try { - final ICDITarget cdiTarget = getCDITarget(); - if (cdiTarget != null) { - cdiThreads = cdiTarget.getThreads(); - currentCDIThread = cdiTarget.getCurrentThread(); - } - } catch (CDIException e) { - } - for (int i = 0; i < cdiThreads.length; ++i) { - CThread thread = findThread(oldList, cdiThreads[i]); - if (thread == null) { - thread = new CThread(this, cdiThreads[i]); - newThreads.add(thread); - } - else { - oldList.remove(thread); - } - thread.setCurrent(cdiThreads[i].equals(currentCDIThread)); - list.add(thread); - } - Iterator<CThread> it = oldList.iterator(); - while (it.hasNext()) { - CThread thread = it.next(); - thread.terminated(); - debugEvents.add(thread.createTerminateEvent()); - } - setThreadList(list); - it = newThreads.iterator(); - while (it.hasNext()) { - debugEvents.add(it.next().createCreateEvent()); - } - if (debugEvents.size() > 0) - fireEventSet(debugEvents.toArray(new DebugEvent[debugEvents.size()])); - return newThreads; - } - - /** - * Notifies threads that the target has been resumed. - */ - protected synchronized void resumeThreads(List<DebugEvent> debugEvents, int detail) { - Iterator<CThread> it = getThreadList().iterator(); - while (it.hasNext()) { - it.next().resumedByTarget(detail, debugEvents); - } - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.IBreakpointListener#breakpointAdded(org.eclipse.debug.core.model.IBreakpoint) - */ - @Override - public void breakpointAdded(IBreakpoint breakpoint) { - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.IBreakpointListener#breakpointRemoved(org.eclipse.debug.core.model.IBreakpoint, org.eclipse.core.resources.IMarkerDelta) - */ - @Override - public void breakpointRemoved(IBreakpoint breakpoint, IMarkerDelta delta) { - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.IBreakpointListener#breakpointChanged(org.eclipse.debug.core.model.IBreakpoint, org.eclipse.core.resources.IMarkerDelta) - */ - @Override - public void breakpointChanged(IBreakpoint breakpoint, IMarkerDelta delta) { - } - - /** - * Returns whether this debug target supports disconnecting. - * - * @return whether this debug target supports disconnecting - */ - protected boolean supportsDisconnect() { - return getConfiguration().supportsDisconnect(); - } - - /** - * Returns whether this debug target supports termination. - * - * @return whether this debug target supports termination - */ - protected boolean supportsTerminate() { - return getConfiguration().supportsTerminate(); - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.IDisconnect#canDisconnect() - */ - @Override - public boolean canDisconnect() { - return supportsDisconnect() && isAvailable(); - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.IDisconnect#disconnect() - */ - @Override - public void disconnect() throws DebugException { - if (isDisconnecting()) { - return; - } - final CDebugElementState newState = CDebugElementState.DISCONNECTING; - changeState(newState); - try { - final ICDITarget cdiTarget = getCDITarget(); - if (cdiTarget != null) { - cdiTarget.disconnect(); - } - } catch (CDIException e) { - if (getState() == newState) { - restoreOldState(); - } - targetRequestFailed(e.getMessage(), null); - } - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.IDisconnect#isDisconnected() - */ - @Override - public boolean isDisconnected() { - return (getState().equals(CDebugElementState.DISCONNECTED)); - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.IMemoryBlockRetrieval#supportsStorageRetrieval() - */ - @Override - public boolean supportsStorageRetrieval() { - return false; - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.IMemoryBlockRetrieval#getMemoryBlock(long, long) - */ - @Override - public IMemoryBlock getMemoryBlock(long startAddress, long length) throws DebugException { - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.IDebugElement#getLaunch() - */ - @Override - public ILaunch getLaunch() { - return fLaunch; - } - - /** - * Sets the launch this target is contained in - * - * @param launch the launch this target is contained in - */ - private void setLaunch(ILaunch launch) { - fLaunch = launch; - } - - /** - * Returns the list of threads contained in this debug target. - * - * @return list of threads - */ - protected ArrayList<CThread> getThreadList() { - return fThreads; - } - - /** - * Sets the list of threads contained in this debug target. Set to an empty collection on creation. Threads are added and removed as they start and end. On - * termination this collection is set to the immutable singleton empty list. - * - * @param threads empty list - */ - private void setThreadList(ArrayList<CThread> threads) { - fThreads = threads; - } - - private void setCDITarget(ICDITarget cdiTarget) { - fCDITarget = cdiTarget; - } - - /* (non-Javadoc) - * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class) - */ - @Override - public Object getAdapter(@SuppressWarnings("rawtypes") Class adapter) { - if (adapter.equals(ICDebugElement.class)) - return this; - if (adapter.equals(CDebugElement.class)) - return this; - if (adapter.equals(IDebugTarget.class)) - return this; - if (adapter.equals(ICDebugTarget.class)) - return this; - if (adapter.equals(CDebugTarget.class)) - return this; - if (adapter.equals(ICDITarget.class)) - return fCDITarget; - if (adapter.equals(IDebuggerProcessSupport.class)) - return this; - if (adapter.equals(IExecFileInfo.class)) - return this; - if (adapter.equals(CBreakpointManager.class)) - return getBreakpointManager(); - if (adapter.equals(CSignalManager.class)) - return getSignalManager(); - if (adapter.equals(CRegisterManager.class)) - return getRegisterManager(); - if (adapter.equals(ICGlobalVariableManager.class)) - return getGlobalVariableManager(); - if (adapter.equals(ICDISession.class)) - return getCDISession(); - if (adapter.equals(IMemoryBlockRetrievalExtension.class)) - return getMemoryBlockRetrieval(); - if (adapter.equals(IMemoryBlockRetrieval.class)) - return getMemoryBlockRetrieval(); - if (adapter.equals(IModuleRetrieval.class)) - return getModuleManager(); - - // Force adapters to be loaded. Otherwise the adapter manager may not find - // the model proxy adapter for CDT debug elements. - Platform.getAdapterManager().loadAdapter(this, adapter.getName()); - - return super.getAdapter(adapter); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.cdi.event.ICDIEventListener#handleDebugEvents(org.eclipse.cdt.debug.core.cdi.event.ICDIEvent[]) - */ - @Override - public void handleDebugEvents(ICDIEvent[] events) { - for (int i = 0; i < events.length; i++) { - ICDIEvent event = events[i]; - ICDIObject source = event.getSource(); - final ICDITarget cdiTarget = getCDITarget(); - if (source == null && event instanceof ICDIDestroyedEvent) { - handleTerminatedEvent((ICDIDestroyedEvent)event); - } - else if (source != null && cdiTarget != null && source.getTarget().equals(cdiTarget)) { - if (event instanceof ICDICreatedEvent) { - if (source instanceof ICDIThread) { - handleThreadCreatedEvent((ICDICreatedEvent)event); - } - if (source instanceof ICDISharedLibrary) { - getModuleManager().sharedLibraryLoaded((ICDISharedLibrary)source); - } - } - else if (event instanceof ICDISuspendedEvent) { - if (source instanceof ICDITarget) { - handleSuspendedEvent((ICDISuspendedEvent)event); - } - } - else if (event instanceof ICDIResumedEvent) { - if (source instanceof ICDITarget) { - handleResumedEvent((ICDIResumedEvent)event); - } - } - else if (event instanceof ICDIExitedEvent) { - if (source instanceof ICDITarget) { - handleExitedEvent((ICDIExitedEvent)event); - } - } - else if (event instanceof ICDIDestroyedEvent) { - if (source instanceof ICDIThread) { - handleThreadTerminatedEvent((ICDIDestroyedEvent)event); - } - if (source instanceof ICDISharedLibrary) { - getModuleManager().sharedLibraryUnloaded((ICDISharedLibrary)source); - } - } - else if (event instanceof ICDIDisconnectedEvent) { - if (source instanceof ICDITarget) { - handleDisconnectedEvent((ICDIDisconnectedEvent)event); - } - } - else if (event instanceof ICDIChangedEvent) { - if (source instanceof ICDITarget) { - handleChangedEvent((ICDIChangedEvent)event); - } - if (source instanceof ICDISharedLibrary) { - handleSymbolsLoaded((ICDISharedLibrary)source); - } - if (source instanceof ICDISignal) { - getSignalManager().signalChanged((ICDISignal)source); - } - } - else if (event instanceof ICDIRestartedEvent) { - if (source instanceof ICDITarget) { - handleRestartedEvent((ICDIRestartedEvent)event); - } - } - } - } - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.IRestart#canRestart() - */ - @Override - public boolean canRestart() { - return getConfiguration().supportsRestart() && isSuspended(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.IRestart#restart() - */ - @Override - public void restart() throws DebugException { - if (!canRestart()) { - return; - } - final ICDITarget cdiTarget = getCDITarget(); - if (cdiTarget == null) { - return; - } - - try { - ILaunchConfiguration launchConfig = getLaunch().getLaunchConfiguration(); - if (launchConfig.getAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_STOP_AT_MAIN, ICDTLaunchConfigurationConstants.DEBUGGER_STOP_AT_MAIN_DEFAULT)) { - String mainSymbol = launchConfig.getAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_STOP_AT_MAIN_SYMBOL, ICDTLaunchConfigurationConstants.DEBUGGER_STOP_AT_MAIN_SYMBOL_DEFAULT); - ICDILocation location = null; - // See if the expression is a numeric address - try { - IAddress address = getAddressFactory().createAddress(mainSymbol); - location = cdiTarget.createAddressLocation(address.getValue()); - } catch (NumberFormatException nfexc) { - // OK, expression is not a simple, absolute numeric value; keep trucking and try to resolve as expression - location = cdiTarget.createFunctionLocation("", mainSymbol); //$NON-NLS-1$ - } - - setInternalTemporaryBreakpoint(location); - } - } catch (CoreException e) { - requestFailed(e.getMessage(), e); - } - - final CDebugElementState newState = CDebugElementState.RESTARTING; - changeState(newState); - try { - cdiTarget.restart(); - } catch (CDIException e) { - if (getState() == newState) { - restoreOldState(); - } - targetRequestFailed(e.getMessage(), e); - } - } - - /** - * Returns whether this target is available to handle client requests. - * - * @return whether this target is available to handle client requests - */ - public boolean isAvailable() { - return !(isTerminated() || isTerminating() || isDisconnected() || isDisconnecting()); - } - - /** - * Returns whether this target is in the process of terminating. - * - * @return whether this target is terminating - */ - protected boolean isTerminating() { - return (getState().equals(CDebugElementState.TERMINATING)); - } - - /** - * Updates the state of this target to be terminated, if not already terminated. - */ - protected void terminated() { - if (!isTerminated()) { - if (!isDisconnected()) { - setState(CDebugElementState.TERMINATED); - } - cleanup(); - fireTerminateEvent(); - } - } - - /** - * Returns whether this target is in the process of terminating. - * - * @return whether this target is terminating - */ - protected boolean isDisconnecting() { - return (getState().equals(CDebugElementState.DISCONNECTING)); - } - - /** - * Updates the state of this target for disconnection. - */ - protected void disconnected() { - if (!isDisconnected()) { - setState(CDebugElementState.DISCONNECTED); - cleanup(); - fireTerminateEvent(); - } - } - - /** - * Cleans up the internal state of this debug target as a result of a session ending. - */ - protected void cleanup() { - resetStatus(); - removeAllThreads(); - getCDISession().getEventManager().removeEventListener(this); - DebugPlugin.getDefault().getExpressionManager().removeExpressionListener(this); - DebugPlugin.getDefault().getLaunchManager().removeLaunchListener(this); - saveFormats(); - saveGlobalVariables(); - disposeGlobalVariableManager(); - disposeModuleManager(); - disposeSignalManager(); - saveRegisterGroups(); - disposeRegisterManager(); - saveMemoryBlocks(); - disposeMemoryBlockRetrieval(); - disposeDisassembly(); - disposeSourceManager(); - disposeSourceLookupPath(); - disposeBreakpointManager(); - removeAllExpressions(); - disposePreferences(); - - ICDITarget cdiTarget = getCDITarget(); - // TODO: apparently we're not really done with the ICDITarget. The - // arrival of a terminate event from gdb requires access to this (see - // SessionManager.handleDebugEvent()). Reported by Mikhail. Need to - // revisit this. - // setCDITarget(null); - if (cdiTarget instanceof ICDIDisposable) { - ((ICDIDisposable)cdiTarget).dispose(); - } - } - - /** - * Removes all threads from this target's collection of threads, firing a terminate event for each. - */ - protected void removeAllThreads() { - List<CThread> threads = getThreadList(); - setThreadList(new ArrayList<CThread>(0)); - ArrayList<DebugEvent> debugEvents = new ArrayList<DebugEvent>(threads.size()); - Iterator<CThread> it = threads.iterator(); - while (it.hasNext()) { - CThread thread = it.next(); - thread.terminated(); - debugEvents.add(thread.createTerminateEvent()); - } - fireEventSet(debugEvents.toArray(new DebugEvent[debugEvents.size()])); - } - - /** - * Removes all expressions from this target. - */ - protected void removeAllExpressions() { - IExpressionManager em = DebugPlugin.getDefault().getExpressionManager(); - IExpression[] expressions = em.getExpressions(); - for (int i = 0; i < expressions.length; ++i) { - if (expressions[i] instanceof CExpression && expressions[i].getDebugTarget().equals(this)) { - em.removeExpression(expressions[i]); - } - } - } - - /** - * Creates, adds and returns a thread for the given underlying CDI thread. A creation event is fired for the thread. Returns <code>null</code> if during - * the creation of the thread this target is set to the disconnected state. - * - * @param thread the underlying CDI thread - * @return model thread - */ - protected CThread createThread(ICDIThread cdiThread) { - CThread thread = new CThread(this, cdiThread); - getThreadList().add(thread); - return thread; - } - - private void handleSuspendedEvent(ICDISuspendedEvent event) { - setState(CDebugElementState.SUSPENDED); - ICDISessionObject reason = event.getReason(); - setCurrentStateInfo(reason); - // Reset the registers that have errors. - getRegisterManager().targetSuspended(); - getBreakpointManager().skipBreakpoints(false); - List<CThread> newThreads = refreshThreads(); - if (event.getSource() instanceof ICDITarget) { - if (!(this.getConfiguration() instanceof ICDITargetConfiguration2) || !((ICDITargetConfiguration2)this.getConfiguration()).supportsThreadControl()) - suspendThreads(event); - } else if (event.getSource() instanceof ICDIThread) { - // We need this for debuggers that don't have notifications - // for newly created threads. - CThread thread = findThread((ICDIThread)event.getSource()); - if (thread != null && newThreads.contains(thread)) { - ICDIEvent[] evts = new ICDIEvent[]{ event }; - thread.handleDebugEvents(evts); - } - } - if (reason instanceof ICDIEndSteppingRange) { - handleEndSteppingRange((ICDIEndSteppingRange)reason); - } - else if (reason instanceof ICDIBreakpointHit) { - handleBreakpointHit((ICDIBreakpointHit)reason); - } - else if (reason instanceof ICDISignalReceived) { - handleSuspendedBySignal((ICDISignalReceived)reason); - } - else if (reason instanceof ICDIWatchpointTrigger) { - handleWatchpointTrigger((ICDIWatchpointTrigger)reason); - } - else if (reason instanceof ICDIWatchpointScope) { - handleWatchpointScope((ICDIWatchpointScope)reason); - } - else if (reason instanceof ICDIErrorInfo) { - handleErrorInfo((ICDIErrorInfo)reason); - } - else if (reason instanceof ICDISharedLibraryEvent) { - handleSuspendedBySolibEvent((ICDISharedLibraryEvent)reason); - } - else if (reason instanceof ICDIEventBreakpointHit) { - handleEventBreakpointHit((ICDIEventBreakpointHit)reason); - } - else { // reason is not specified - fireSuspendEvent(DebugEvent.UNSPECIFIED); - } - } - - private void handleResumedEvent(ICDIResumedEvent event) { - setState(CDebugElementState.RESUMED); - setCurrentStateInfo(null); - resetStatus(); - ArrayList<DebugEvent> debugEvents = new ArrayList<DebugEvent>(10); - int detail = DebugEvent.UNSPECIFIED; - switch(event.getType()) { - case ICDIResumedEvent.CONTINUE: - detail = DebugEvent.CLIENT_REQUEST; - break; - case ICDIResumedEvent.STEP_INTO: - case ICDIResumedEvent.STEP_INTO_INSTRUCTION: - detail = DebugEvent.STEP_INTO; - break; - case ICDIResumedEvent.STEP_OVER: - case ICDIResumedEvent.STEP_OVER_INSTRUCTION: - detail = DebugEvent.STEP_OVER; - break; - case ICDIResumedEvent.STEP_RETURN: - detail = DebugEvent.STEP_RETURN; - break; - } - debugEvents.add(createResumeEvent(detail)); - - if (!(this.getConfiguration() instanceof ICDITargetConfiguration2) || !((ICDITargetConfiguration2)this.getConfiguration()).supportsThreadControl()) - resumeThreads(debugEvents, detail); - - fireEventSet(debugEvents.toArray(new DebugEvent[debugEvents.size()])); - } - - private void handleEndSteppingRange(ICDIEndSteppingRange endSteppingRange) { - fireSuspendEvent(DebugEvent.UNSPECIFIED); - } - - private void handleBreakpointHit(ICDIBreakpointHit breakpointHit) { - fireSuspendEvent(DebugEvent.BREAKPOINT); - } - - private void handleEventBreakpointHit(ICDIEventBreakpointHit breakpointHit) { - fireSuspendEvent(DebugEvent.BREAKPOINT); - } - - private void handleWatchpointTrigger(ICDIWatchpointTrigger wt) { - fireSuspendEvent(DebugEvent.BREAKPOINT); - } - - private void handleWatchpointScope(ICDIWatchpointScope ws) { - getBreakpointManager().watchpointOutOfScope(ws.getWatchpoint()); - fireSuspendEvent(DebugEvent.BREAKPOINT); - } - - private void handleSuspendedBySignal(ICDISignalReceived signal) { - fireSuspendEvent(DebugEvent.CLIENT_REQUEST); - } - - private void handleErrorInfo(ICDIErrorInfo info) { - setStatus(ICDebugElementStatus.ERROR, (info != null) ? info.getMessage() : null); - if (info != null) { - MultiStatus status = new MultiStatus(CDebugCorePlugin.getUniqueIdentifier(), ICDebugInternalConstants.STATUS_CODE_ERROR, CoreModelMessages.getString("CDebugTarget.1"), //$NON-NLS-1$ - null); - StringTokenizer st = new StringTokenizer(info.getDetailMessage(), "\n\r"); //$NON-NLS-1$ - while (st.hasMoreTokens()) { - String token = st.nextToken(); - if (token.length() > 200) { - token = token.substring(0, 200); - } - status.add(new Status(IStatus.ERROR, status.getPlugin(), ICDebugInternalConstants.STATUS_CODE_ERROR, token, null)); - } - CDebugUtils.error(status, this); - } - fireSuspendEvent(DebugEvent.UNSPECIFIED); - } - - private void handleSuspendedBySolibEvent(ICDISharedLibraryEvent solibEvent) { - fireSuspendEvent(DebugEvent.UNSPECIFIED); - } - - private void handleExitedEvent(ICDIExitedEvent event) { - removeAllThreads(); - setState(CDebugElementState.EXITED); - setCurrentStateInfo(event.getReason()); - fireChangeEvent(DebugEvent.CONTENT); - ICDISessionConfiguration sessionConfig = getCDISession().getConfiguration(); - if (sessionConfig != null && sessionConfig.terminateSessionOnExit()) - terminated(); - } - - private void handleTerminatedEvent(ICDIDestroyedEvent event) { - terminated(); - } - - private void handleDisconnectedEvent(ICDIDisconnectedEvent event) { - disconnected(); - } - - private void handleChangedEvent(ICDIChangedEvent event) { - } - - private void handleRestartedEvent(ICDIRestartedEvent event) { - } - - private void handleThreadCreatedEvent(ICDICreatedEvent event) { - ICDIThread cdiThread = (ICDIThread)event.getSource(); - CThread thread = findThread(cdiThread); - if (thread == null) { - thread = createThread(cdiThread); - thread.fireCreationEvent(); - } - } - - private void handleThreadTerminatedEvent(ICDIDestroyedEvent event) { - ICDIThread cdiThread = (ICDIThread)event.getSource(); - List<CThread> threads = getThreadList(); - List<CThread> threadsToRemove = new ArrayList<CThread>(1); - for (int i = 0; i < threads.size(); i++) { - CThread cthread = threads.get(i); - // It's possible CThread has handled the thread-terminated event - // before us (by appearing first in the EventManager) - // and has disassociated itself from the ICDIThread. - // So handle any disassociated CThreads we find. Chances are - // there's only one and it's the one we got the terminated event - // for. See bugzilla 254888. - ICDIThread cdithread = cthread.getCDIThread(); - if (cdithread == null || cdithread.equals(cdiThread)) { - threadsToRemove.add(cthread); - } - } - for (CThread cthread : threadsToRemove) { - threads.remove(cthread); - cthread.terminated(); - cthread.fireTerminateEvent(); - } - } - - /** - * Finds and returns the model thread for the associated CDI thread, or <code>null</code> if not found. - * - * @param the underlying CDI thread - * @return the associated model thread - */ - public CThread findThread(ICDIThread cdiThread) { - return findThread(getThreadList(), cdiThread); - } - - public CThread findThread(List<CThread> threads, ICDIThread cdiThread) { - for (int i = 0; i < threads.size(); i++) { - CThread t = threads.get(i); - ICDIThread thisCdiThread = t.getCDIThread(); - if (thisCdiThread != null && thisCdiThread.equals(cdiThread)) - return t; - } - return null; - } - - /** - * Returns the debug configuration of this target. - * - * @return the debug configuration of this target - */ - protected ICDITargetConfiguration getConfiguration() { - return fConfig; - } - - /** - * Sets the debug configuration of this target. - * - * @param config the debug configuration to set - */ - private void setConfiguration(ICDITargetConfiguration config) { - fConfig = config; - } - - protected boolean supportsExpressionEvaluation() { - return getConfiguration().supportsExpressionEvaluation(); - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.IExpressionListener#expressionAdded(org.eclipse.debug.core.model.IExpression) - */ - @Override - public void expressionAdded(IExpression expression) { - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.IExpressionListener#expressionChanged(org.eclipse.debug.core.model.IExpression) - */ - @Override - public void expressionChanged(IExpression expression) { - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.IExpressionListener#expressionRemoved(org.eclipse.debug.core.model.IExpression) - */ - @Override - public void expressionRemoved(IExpression expression) { - if (expression instanceof CExpression && expression.getDebugTarget().equals(this)) { - ((CExpression)expression).dispose(); - } - } - - public void setInternalTemporaryBreakpoint(ICDILocation location) throws DebugException { - try { - final ICDITarget cdiTarget = getCDITarget(); - if (cdiTarget == null) { - return; - } - if (location instanceof ICDIFunctionLocation) { - cdiTarget.setFunctionBreakpoint(ICBreakpointType.TEMPORARY, (ICDIFunctionLocation)location, null, false); - } else if (location instanceof ICDILineLocation) { - cdiTarget.setLineBreakpoint(ICBreakpointType.TEMPORARY, (ICDILineLocation)location, null, false); - } else if (location instanceof ICDIAddressLocation) { - cdiTarget.setAddressBreakpoint(ICBreakpointType.TEMPORARY, (ICDIAddressLocation)location, null, false); - } else { - // ??? - targetRequestFailed("not_a_location", null); //$NON-NLS-1$ - } - } catch (CDIException e) { - targetRequestFailed(e.getMessage(), null); - } - } - - protected IThread getCurrentThread() { - IThread[] threads = getThreads(); - for (int i = 0; i < threads.length; ++i) { - if (((CThread)threads[i]).isCurrent()) - return threads[i]; - } - return null; - } - - protected ISourceLocator getSourceLocator() { - return getLaunch().getSourceLocator(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.IExecFileInfo#isLittleEndian() - */ - @Override - public boolean isLittleEndian() { - if (fIsLittleEndian == null) { - fIsLittleEndian = Boolean.TRUE; - IBinaryObject file; - file = getBinaryFile(); - if (file != null) { - fIsLittleEndian = Boolean.valueOf(file.isLittleEndian()); - } - } - return fIsLittleEndian.booleanValue(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.IExecFileInfo#getExecFile() - */ - @Override - public IBinaryObject getExecFile() { - return getBinaryFile(); - } - - public IBinaryObject getBinaryFile() { - return fBinaryFile; - } - - private void setExecFile(IBinaryObject file) { - fBinaryFile = file; - } - - private void setProject(IProject project) { - fProject = project; - } - - public IProject getProject() { - return fProject; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.IExecFileInfo#getGlobals() - */ - @Override - public IGlobalVariableDescriptor[] getGlobals() throws DebugException { - ICDITarget cdiTarget = getCDITarget(); - // If the backend can give us the globals... - boolean hasCDIGlobals = false; - ArrayList<IGlobalVariableDescriptor> list = new ArrayList<IGlobalVariableDescriptor>(); - if (cdiTarget instanceof ICDITarget2) { - ICDIGlobalVariableDescriptor[] cdiGlobals = ((ICDITarget2) cdiTarget).getGlobalVariables(); - hasCDIGlobals = cdiGlobals != null; - if (hasCDIGlobals) { - for (int i = 0; i < cdiGlobals.length; i++) { - list.add(CVariableFactory.createGlobalVariableDescriptor(cdiGlobals[i].getName(), null)); - } - } - } - // otherwise ask the binary - if (!hasCDIGlobals) { - IBinaryObject file = getBinaryFile(); - if (file != null) { - list.addAll(getCFileGlobals(file)); - } - } - return list.toArray(new IGlobalVariableDescriptor[list.size()]); - } - - private List<IGlobalVariableDescriptor> getCFileGlobals(IBinaryObject file) { - ArrayList<IGlobalVariableDescriptor> list = new ArrayList<IGlobalVariableDescriptor>(); - ISymbol[] symbols = file.getSymbols(); - for (int i = 0; i < symbols.length; ++i) { - if (symbols[i].getType() == ISymbol.VARIABLE) { - list.add(CVariableFactory.createGlobalVariableDescriptor(symbols[i])); - } - } - return list; - } - - protected void setModuleManager(CModuleManager mm) { - fModuleManager = mm; - } - - protected CModuleManager getModuleManager() { - return fModuleManager; - } - - protected void disposeModuleManager() { - fModuleManager.dispose(); - fModuleManager = null; - } - - protected void setSignalManager(CSignalManager sm) { - fSignalManager = sm; - } - - protected CSignalManager getSignalManager() { - return fSignalManager; - } - - protected void disposeSignalManager() { - fSignalManager.dispose(); - } - - protected void saveRegisterGroups() { - fRegisterManager.save(); - } - - protected void disposeRegisterManager() { - fRegisterManager.dispose(); - } - - protected void saveGlobalVariables() { - fGlobalVariableManager.save(); - } - - protected void saveFormats() { - fFormatManager.save(); - } - - protected void disposeGlobalVariableManager() { - fGlobalVariableManager.dispose(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.IResumeWithoutSignal#canResumeWithoutSignal() - */ - @Override - public boolean canResumeWithoutSignal() { - // Check if the configuration supports this!!! - return (canResume() && getCurrentStateInfo() instanceof ICDISignalReceived); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.IResumeWithoutSignal#resumeWithoutSignal() - */ - @Override - public void resumeWithoutSignal() throws DebugException { - if (!canResume()) - return; - final CDebugElementState newState = CDebugElementState.RESUMING; - changeState(newState); - try { - final ICDITarget cdiTarget = getCDITarget(); - if (cdiTarget != null) { - cdiTarget.resume(false); - } - } catch (CDIException e) { - if (getState() == newState) { - restoreOldState(); - } - targetRequestFailed(e.getMessage(), e); - } - } - - public CRegisterManager getRegisterManager() { - // Workaround for bug #309212. gdb 7.0 returns "No registers" error - // at the beginning of the session. - fRegisterManager.initialize(); - return fRegisterManager; - } - - protected void setRegisterManager(CRegisterManager registerManager) { - fRegisterManager = registerManager; - } - - public IRegisterGroup[] getRegisterGroups(CStackFrame frame) throws DebugException { - return getRegisterManager().getRegisterGroups(frame); - } - - protected void disposeSourceManager() { - ISourceLocator locator = getSourceLocator(); - if (locator instanceof IAdaptable) { - IResourceChangeListener listener = ((IAdaptable)locator).getAdapter(IResourceChangeListener.class); - if (listener != null) - CCorePlugin.getWorkspace().removeResourceChangeListener(listener); - } - } - - 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); - } - } - } - } - - protected void saveMemoryBlocks() { - getMemoryBlockRetrieval().save(); - } - - protected void disposeMemoryBlockRetrieval() { - getMemoryBlockRetrieval().dispose(); - } - - protected CBreakpointManager getBreakpointManager() { - return fBreakpointManager; - } - - protected void setBreakpointManager(CBreakpointManager manager) { - fBreakpointManager = manager; - } - - protected void disposeBreakpointManager() { - if (getBreakpointManager() != null) - getBreakpointManager().dispose(); - } - - /* (non-Javadoc) - * @see java.lang.Object#toString() - */ - @Override - public String toString() { - String result = ""; //$NON-NLS-1$ - try { - result = getName(); - } catch (DebugException e) { - } - return result; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.ICDebugTarget#getDisassembly() - */ - @Override - public IDisassembly getDisassembly() throws DebugException { - return fDisassembly; - } - - public DisassemblyRetrieval getDisassemblyRetrieval() { - return fDisassemblyRetrieval; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.ICDebugTarget#getSignals() - */ - @Override - public ICSignal[] getSignals() throws DebugException { - CSignalManager sm = getSignalManager(); - if (sm != null) { - return sm.getSignals(); - } - return new ICSignal[0]; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.ICDebugTarget#hasSignals() - */ - @Override - public boolean hasSignals() throws DebugException { - CSignalManager sm = getSignalManager(); - if (sm != null) { - return (sm.getSignals().length > 0); - } - return false; - } - - private void createDisassembly() { - this.fDisassembly = new Disassembly(this); - this.fDisassemblyRetrieval = new DisassemblyRetrieval(this); - } - - private void disposeDisassembly() { - if (fDisassembly != null) - fDisassembly.dispose(); - fDisassembly = null; - if (fDisassemblyRetrieval != null) - fDisassemblyRetrieval.dispose(); - fDisassemblyRetrieval = null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.IBreakpointTarget#getBreakpointAddress(org.eclipse.cdt.debug.core.model.ICLineBreakpoint) - */ - @Override - public IAddress getBreakpointAddress(ICLineBreakpoint breakpoint) throws DebugException { - return (getBreakpointManager() != null) ? getBreakpointManager().getBreakpointAddress(breakpoint) : getAddressFactory().getZero(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.ISteppingModeTarget#enableInstructionStepping(boolean) - */ - @Override - public void enableInstructionStepping(boolean enabled) { - fPreferences.setValue(PREF_INSTRUCTION_STEPPING_MODE, enabled); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.ISteppingModeTarget#isInstructionSteppingEnabled() - */ - @Override - public boolean isInstructionSteppingEnabled() { - return fPreferences.getBoolean(PREF_INSTRUCTION_STEPPING_MODE); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.ISteppingModeTarget#supportsInstructionStepping() - */ - @Override - public boolean supportsInstructionStepping() { - return getConfiguration().supportsInstructionStepping(); - } - - private void initializePreferences() { - fPreferences = new Preferences(); - fPreferences.setDefault(PREF_INSTRUCTION_STEPPING_MODE, CDebugCorePlugin.getDefault().getPluginPreferences().getBoolean(ICDebugConstants.PREF_INSTRUCTION_STEP_MODE_ON)); - } - - private void disposePreferences() { - if (fPreferences != null) { - // persist current instruction stepping mode - CDebugCorePlugin.getDefault().getPluginPreferences().setValue(ICDebugConstants.PREF_INSTRUCTION_STEP_MODE_ON, fPreferences.getBoolean(PREF_INSTRUCTION_STEPPING_MODE)); - CDebugCorePlugin.getDefault().savePluginPreferences(); - } - fPreferences = null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.ITargetProperties#addPropertyChangeListener(org.eclipse.core.runtime.Preferences.IPropertyChangeListener) - */ - @Override - public void addPropertyChangeListener(IPropertyChangeListener listener) { - if (fPreferences != null) - fPreferences.addPropertyChangeListener(listener); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.ITargetProperties#removePropertyChangeListener(org.eclipse.core.runtime.Preferences.IPropertyChangeListener) - */ - @Override - public void removePropertyChangeListener(IPropertyChangeListener listener) { - if (fPreferences != null) - fPreferences.removePropertyChangeListener(listener); - } - - protected CGlobalVariableManager getGlobalVariableManager() { - return fGlobalVariableManager; - } - - private void setGlobalVariableManager(CGlobalVariableManager globalVariableManager) { - fGlobalVariableManager = globalVariableManager; - } - - protected CSettingsManager getFormatManager() { - return fFormatManager; - } - - private void setFormatManager(CSettingsManager formatManager) { - fFormatManager = formatManager; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.ICDebugTarget#isPostMortem() - */ - @Override - public boolean isPostMortem() { - return false; - } - - public IAddressFactory getAddressFactory() { - if (fAddressFactory == null) { - // Ask CDI plug-in for the default AddressFactory. - final ICDITarget cdiTarget = getCDITarget(); - if (cdiTarget instanceof ICDIAddressFactoryManagement) { - fAddressFactory = ((ICDIAddressFactoryManagement) cdiTarget).getAddressFactory(); - } - // And if that doesn't work, use the one from the file. - if (fAddressFactory == null) { - if (getExecFile() != null && getProject() != null) { - IBinaryObject file = getBinaryFile(); - if (file != null) { - fAddressFactory = file.getAddressFactory(); - } - } - } - - // As a last resort, fallback to 64 bit address factory - if (fAddressFactory == null) { - fAddressFactory = new Addr64Factory(); - } - } - return fAddressFactory; - } - - private CMemoryBlockRetrievalExtension getMemoryBlockRetrieval() { - return fMemoryBlockRetrieval; - } - - private void setMemoryBlockRetrieval(CMemoryBlockRetrievalExtension memoryBlockRetrieval) { - fMemoryBlockRetrieval = memoryBlockRetrieval; - } - - private void changeState(CDebugElementState state) { - setState(state); - Iterator<CThread> it = getThreadList().iterator(); - while (it.hasNext()) { - it.next().setState(state); - } - } - - protected void restoreOldState() { - restoreState(); - Iterator<CThread> it = getThreadList().iterator(); - while (it.hasNext()) { - it.next().restoreState(); - } - } - - private void handleSymbolsLoaded(ICDISharedLibrary library) { - getModuleManager().symbolsLoaded(library); - } - - public ICGlobalVariable createGlobalVariable(IGlobalVariableDescriptor info) throws DebugException { - ICDIVariableDescriptor vo = null; - try { - final ICDITarget cdiTarget = getCDITarget(); - if (cdiTarget != null) { - vo = cdiTarget.getGlobalVariableDescriptors(info.getPath().lastSegment(), null, info.getName()); - } - } catch (CDIException e) { - throw new DebugException(new Status(IStatus.ERROR, CDIDebugModel.getPluginIdentifier(), DebugException.TARGET_REQUEST_FAILED, e.getMessage(), null)); - } - return CVariableFactory.createGlobalVariable(this, info, vo); - } - - @Override - public void sourceContainersChanged(ISourceLookupDirector director) { - setSourceLookupPath(director.getSourceContainers()); - } - - private void setSourceLookupPath(ISourceContainer[] containers) { - // LinkedHashSet allows quick lookup and deterministic ordering. We need - // the former to efficiently prevent infinite recursion - LinkedHashSet<String> list = new LinkedHashSet<String>(containers.length); - - getSourceLookupPath(list, containers); - try { - final ICDITarget cdiTarget = getCDITarget(); - if (cdiTarget != null) { - cdiTarget.setSourcePaths(list.toArray(new String[list.size()])); - } - } catch (CDIException e) { - CDebugCorePlugin.log(e); - } - } - - private void getSourceLookupPath(LinkedHashSet<String> list, ISourceContainer[] containers) { - for (ISourceContainer container : containers) { - String pathToAdd = null; - - if (container instanceof CProjectSourceContainer) { - IProject project = ((CProjectSourceContainer) container).getProject(); - if (project != null && project.exists()) { - IPath location = project.getLocation(); - if (location != null) { - pathToAdd = location.toPortableString(); - } - } - } else if (container instanceof ProjectSourceContainer) { // For backward compatibility - IProject project = ((ProjectSourceContainer) container).getProject(); - if (project != null && project.exists()) { - IPath location = project.getLocation(); - if (location != null) { - pathToAdd = location.toPortableString(); - } - } - } else if (container instanceof FolderSourceContainer) { - IContainer folderContainer = ((FolderSourceContainer) container).getContainer(); - if (folderContainer != null && folderContainer.exists()) { - IPath location = folderContainer.getLocation(); - if (location != null) { - pathToAdd = location.toPortableString(); - } - } - } if (container instanceof DirectorySourceContainer) { - File dir = ((DirectorySourceContainer) container).getDirectory(); - if (dir != null && dir.exists()) { - IPath path = new Path(dir.getAbsolutePath()); - pathToAdd = path.toPortableString(); - } - } - - if (pathToAdd != null) { - // 291912. Avoid infinite recursion - if (list.contains(pathToAdd)) { - continue; - } - - list.add(pathToAdd); - } - - if (container.isComposite()) { - try { - getSourceLookupPath(list, container.getSourceContainers()); - } catch (CoreException e) { - CDebugCorePlugin.log(e.getStatus()); - } - } - } - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.ICDebugTarget#getRegisterDescriptors() - */ - @Override - public IRegisterDescriptor[] getRegisterDescriptors() throws DebugException { - return getRegisterManager().getAllRegisterDescriptors(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.ICDebugTarget#addUserDefinedRegisterGroup(java.lang.String, org.eclipse.cdt.debug.core.model.IRegisterDescriptor[]) - */ - @Override - public void addRegisterGroup(String name, IRegisterDescriptor[] descriptors) { - getRegisterManager().addRegisterGroup(name, descriptors); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.ICDebugTarget#removeRegisterGroups(org.eclipse.debug.core.model.IRegisterGroup[]) - */ - @Override - public void removeRegisterGroups(IRegisterGroup[] groups) { - getRegisterManager().removeRegisterGroups(groups); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.ICDebugTarget#modifyRegisterGroup(org.eclipse.cdt.debug.core.model.IPersistableRegisterGroup, org.eclipse.cdt.debug.core.model.IRegisterDescriptor[]) - */ - @Override - public void modifyRegisterGroup(IPersistableRegisterGroup group, IRegisterDescriptor[] descriptors) { - getRegisterManager().modifyRegisterGroup(group, descriptors); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.ICDebugTarget#restoreDefaultRegisterGroups() - */ - @Override - public void restoreDefaultRegisterGroups() { - getRegisterManager().restoreDefaults(); - } - - protected void skipBreakpoints(boolean enabled) { - getBreakpointManager().skipBreakpoints(enabled); - } - - /** - * 'stopExpression' is used solely for the error message if the request - * fails. Where to stop is dictated entirely by 'location' - * @param symbol - */ - private void stopAtLocation(ICDILocation location, String stopExpression) throws DebugException { - try { - setInternalTemporaryBreakpoint(location); - } catch (CoreException e) { - final ICDITarget cdiTarget = getCDITarget(); - boolean isTerminated = cdiTarget != null && cdiTarget.isTerminated(); - if (isTerminated) { - String message = MessageFormat.format(CoreModelMessages.getString("CDebugTarget.0"), new String[]{ stopExpression }); //$NON-NLS-1$ - MultiStatus status = new MultiStatus(CDebugCorePlugin.getUniqueIdentifier(), IStatus.OK, message, null); - status.add(e.getStatus()); - throw new DebugException(status); - } - String message = MessageFormat.format(CoreModelMessages.getString("CDebugTarget.2"), new String[]{ stopExpression, e.getStatus().getMessage() }); //$NON-NLS-1$ - IStatus newStatus = new Status(IStatus.WARNING, e.getStatus().getPlugin(), ICDebugInternalConstants.STATUS_CODE_QUESTION, message, null); - if (!CDebugUtils.question(newStatus, this)) { - throw new DebugException(new Status(IStatus.OK, e.getStatus().getPlugin(), e.getStatus().getCode(), e.getStatus().getMessage(), null)); - } - } - } - - protected void stopAtSymbol(String stopSymbol) throws DebugException { - final ICDITarget cdiTarget = getCDITarget(); - if (cdiTarget != null) { - ICDILocation location = cdiTarget.createFunctionLocation("", stopSymbol); //$NON-NLS-1$ - stopAtLocation(location, stopSymbol); - } - } - - protected void stopAtAddress(IAddress address) throws DebugException { - final ICDITarget cdiTarget = getCDITarget(); - if (cdiTarget != null) { - ICDIAddressLocation location = cdiTarget.createAddressLocation(address.getValue()); - stopAtLocation(location, address.toHexAddressString()); - } - } - - protected void stopInMain() throws DebugException { - String mainSymbol = ICDTLaunchConfigurationConstants.DEBUGGER_STOP_AT_MAIN_SYMBOL_DEFAULT; - try { - final ICDITarget cdiTarget = getCDITarget(); - if (cdiTarget != null) { - mainSymbol = getLaunch().getLaunchConfiguration().getAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_STOP_AT_MAIN_SYMBOL, ICDTLaunchConfigurationConstants.DEBUGGER_STOP_AT_MAIN_SYMBOL_DEFAULT); - ICDILocation location = cdiTarget.createFunctionLocation("", mainSymbol); //$NON-NLS-1$ - setInternalTemporaryBreakpoint(location); - } - } catch (CoreException e) { - String message = MessageFormat.format(CoreModelMessages.getString("CDebugTarget.2"), new String[]{ mainSymbol, e.getStatus().getMessage() }); //$NON-NLS-1$ - IStatus newStatus = new Status(IStatus.WARNING, e.getStatus().getPlugin(), ICDebugInternalConstants.STATUS_CODE_QUESTION, message, null); - if (!CDebugUtils.question(newStatus, this)) { - terminate(); - throw new DebugException(new Status(IStatus.OK, e.getStatus().getPlugin(), e.getStatus().getCode(), e.getStatus().getMessage(), null)); - } - } - } - - @Override - public boolean hasModules() throws DebugException { - CModuleManager mm = getModuleManager(); - if (mm != null) - return mm.hasModules(); - return false; - } - - @Override - public ICModule[] getModules() throws DebugException { - CModuleManager mm = getModuleManager(); - if (mm != null) - return mm.getModules(); - return new ICModule[0]; - } - - @Override - public void loadSymbolsForAllModules() throws DebugException { - CModuleManager mm = getModuleManager(); - if (mm != null) - mm.loadSymbolsForAllModules(); - } - - public String getInternalID() { - return internalD; - } -}
\ No newline at end of file diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CDummyStackFrame.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CDummyStackFrame.java deleted file mode 100644 index 02d4c2e4c2f..00000000000 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CDummyStackFrame.java +++ /dev/null @@ -1,296 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2012 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 - *******************************************************************************/ -package org.eclipse.cdt.debug.internal.core.model; - -import org.eclipse.cdt.debug.core.model.IDummyStackFrame; -import org.eclipse.debug.core.DebugException; -import org.eclipse.debug.core.model.IRegisterGroup; -import org.eclipse.debug.core.model.IStackFrame; -import org.eclipse.debug.core.model.IThread; -import org.eclipse.debug.core.model.IVariable; - -/** - * Implementation of the dummy stack frame. - */ -public class CDummyStackFrame extends CDebugElement implements IStackFrame, IDummyStackFrame { - - /** - * Containing thread. - */ - private CThread fThread; - - /** - * Constructor for CDummyStackFrame. - * - * @param target - */ - public CDummyStackFrame( CThread thread ) { - super( (CDebugTarget)thread.getDebugTarget() ); - setThread( thread ); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.debug.core.model.IStackFrame#getThread() - */ - @Override - public IThread getThread() { - return fThread; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.debug.core.model.IStackFrame#getVariables() - */ - @Override - public IVariable[] getVariables() throws DebugException { - return new IVariable[0]; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.debug.core.model.IStackFrame#hasVariables() - */ - @Override - public boolean hasVariables() throws DebugException { - return false; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.debug.core.model.IStackFrame#getLineNumber() - */ - @Override - public int getLineNumber() throws DebugException { - return 0; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.debug.core.model.IStackFrame#getCharStart() - */ - @Override - public int getCharStart() throws DebugException { - return 0; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.debug.core.model.IStackFrame#getCharEnd() - */ - @Override - public int getCharEnd() throws DebugException { - return 0; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.debug.core.model.IStackFrame#getName() - */ - @Override - public String getName() throws DebugException { - return "..."; //$NON-NLS-1$ - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.debug.core.model.IStackFrame#getRegisterGroups() - */ - @Override - public IRegisterGroup[] getRegisterGroups() throws DebugException { - return new IRegisterGroup[0]; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.debug.core.model.IStackFrame#hasRegisterGroups() - */ - @Override - public boolean hasRegisterGroups() throws DebugException { - return false; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.debug.core.model.IStep#canStepInto() - */ - @Override - public boolean canStepInto() { - return false; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.debug.core.model.IStep#canStepOver() - */ - @Override - public boolean canStepOver() { - return false; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.debug.core.model.IStep#canStepReturn() - */ - @Override - public boolean canStepReturn() { - return false; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.debug.core.model.IStep#isStepping() - */ - @Override - public boolean isStepping() { - return false; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.debug.core.model.IStep#stepInto() - */ - @Override - public void stepInto() throws DebugException { - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.debug.core.model.IStep#stepOver() - */ - @Override - public void stepOver() throws DebugException { - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.debug.core.model.IStep#stepReturn() - */ - @Override - public void stepReturn() throws DebugException { - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.debug.core.model.ISuspendResume#canResume() - */ - @Override - public boolean canResume() { - return false; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.debug.core.model.ISuspendResume#canSuspend() - */ - @Override - public boolean canSuspend() { - return false; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.debug.core.model.ISuspendResume#isSuspended() - */ - @Override - public boolean isSuspended() { - return false; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.debug.core.model.ISuspendResume#resume() - */ - @Override - public void resume() throws DebugException { - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.debug.core.model.ISuspendResume#suspend() - */ - @Override - public void suspend() throws DebugException { - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.debug.core.model.ITerminate#canTerminate() - */ - @Override - public boolean canTerminate() { - return false; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.debug.core.model.ITerminate#isTerminated() - */ - @Override - public boolean isTerminated() { - return false; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.debug.core.model.ITerminate#terminate() - */ - @Override - public void terminate() throws DebugException { - } - - /** - * Sets the containing thread. - * - * @param thread the containing thread - */ - protected void setThread( CThread thread ) { - fThread = thread; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.core.runtime.IAdaptable#getAdapter(Class) - */ - @Override - public Object getAdapter( Class adapter ) { - if ( adapter.equals( IDummyStackFrame.class ) ) - return this; - if ( adapter.equals( IStackFrame.class ) ) - return this; - return super.getAdapter( adapter ); - } -} diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CExpression.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CExpression.java deleted file mode 100644 index 0caca05201e..00000000000 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CExpression.java +++ /dev/null @@ -1,264 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2012 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 - * Ling Wang (Nokia) - 126262 - *******************************************************************************/ -package org.eclipse.cdt.debug.internal.core.model; - -import org.eclipse.cdt.debug.core.CDebugCorePlugin; -import org.eclipse.cdt.debug.core.ICDebugConstants; -import org.eclipse.cdt.debug.core.cdi.CDIException; -import org.eclipse.cdt.debug.core.cdi.event.ICDIChangedEvent; -import org.eclipse.cdt.debug.core.cdi.event.ICDIEvent; -import org.eclipse.cdt.debug.core.cdi.event.ICDIResumedEvent; -import org.eclipse.cdt.debug.core.cdi.model.ICDIExpression; -import org.eclipse.cdt.debug.core.cdi.model.ICDIObject; -import org.eclipse.cdt.debug.core.cdi.model.ICDITarget; -import org.eclipse.cdt.debug.core.cdi.model.ICDIValue; -import org.eclipse.cdt.debug.core.cdi.model.ICDIVariable; -import org.eclipse.cdt.debug.core.cdi.model.ICDIVariableDescriptor; -import org.eclipse.cdt.debug.core.cdi.model.type.ICDIArrayValue; -import org.eclipse.cdt.debug.core.model.CVariableFormat; -import org.eclipse.cdt.debug.core.model.ICStackFrame; -import org.eclipse.cdt.debug.core.model.ICType; -import org.eclipse.cdt.debug.core.model.ICValue; -import org.eclipse.debug.core.DebugException; -import org.eclipse.debug.core.model.IExpression; -import org.eclipse.debug.core.model.IValue; - -/** - * Represents an expression in the CDI model. - */ -public class CExpression extends CLocalVariable implements IExpression { - - private String fText; - - private ICDIExpression fCDIExpression; - - private CStackFrame fStackFrame; - - private IValue fValue = CValueFactory.NULL_VALUE; - - private ICType fType; - - /** - * Constructor for CExpression. - */ - public CExpression( CStackFrame frame, ICDIExpression cdiExpression, ICDIVariableDescriptor varObject ) { - super( frame, varObject ); - setFormat( CVariableFormat.getFormat( CDebugCorePlugin.getDefault().getPluginPreferences().getInt( ICDebugConstants.PREF_DEFAULT_EXPRESSION_FORMAT ) ) ); - fText = cdiExpression.getExpressionText(); - fCDIExpression = cdiExpression; - fStackFrame = frame; - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.IExpression#getExpressionText() - */ - @Override - public String getExpressionText() { - return fText; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.cdi.event.ICDIEventListener#handleDebugEvents(org.eclipse.cdt.debug.core.cdi.event.ICDIEvent[]) - */ - @Override - public void handleDebugEvents( ICDIEvent[] events ) { - for( int i = 0; i < events.length; i++ ) { - ICDIEvent event = events[i]; - ICDIObject source = event.getSource(); - - if ( event instanceof ICDIResumedEvent ) { - if ( source != null ) { - ICDITarget cdiTarget = source.getTarget(); - if ( getCDITarget().equals( cdiTarget ) ) { - setChanged( false ); - resetValue(); - } - } - } - - if ( event instanceof ICDIChangedEvent ) { - // If a variable is changed (by user or program), - // we should re-evaluate expressions. - // Though it's better we check if the changed variable - // is part of the expression, the effort required is not - // worth the gain. - // This is partial fix to bug 126262. It makes CDT behavior - // in line with JDT. - // The remaining problem (with both CDT & JDT) is: - // Due to platform bug, the change will not show up in - // Expression View until the view is redrawn (e.g. after stepping, - // or when the view is uncovered from background). In other words, - // if the Expression View is at the front (not covered) when the - // variable is changed, the change won't be reflected in the view. - if ( source instanceof ICDIVariable) { - setChanged( false ); - resetValue(); - } - } - } - super.handleDebugEvents( events ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.ICVariable#isEnabled() - */ - @Override - public boolean isEnabled() { - return true; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.ICVariable#canEnableDisable() - */ - @Override - public boolean canEnableDisable() { - return true; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.internal.core.model.CVariable#isBookkeepingEnabled() - */ - @Override - protected boolean isBookkeepingEnabled() { - return false; - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.IExpression#getValue() - */ - @Override - public IValue getValue() { - CStackFrame frame = (CStackFrame)getStackFrame(); - try { - return getValue( frame ); - } - catch( DebugException e ) { - } - return null; - } - - protected synchronized IValue getValue( CStackFrame context ) throws DebugException { - if ( fValue.equals( CValueFactory.NULL_VALUE ) ) { - if ( context.isSuspended() ) { - try { - ICDIValue value = fCDIExpression.getValue( context.getCDIStackFrame() ); - if ( value != null ) { - if ( value instanceof ICDIArrayValue ) { - ICType type = null; - try { - type = new CType( value.getType() ); - } - catch( CDIException e ) { - // ignore and use default type - } - if ( type != null && type.isArray() ) { - int[] dims = type.getArrayDimensions(); - if ( dims.length > 0 && dims[0] > 0 ) - fValue = CValueFactory.createIndexedValue( this, (ICDIArrayValue)value, 0, dims[0] ); - } - } - else { - fValue = CValueFactory.createValue( this, value ); - } - } - } - catch( CDIException e ) { - targetRequestFailed( e.getMessage(), null ); - } - } - } - return fValue; - } - - @Override - protected ICStackFrame getStackFrame() { - return fStackFrame; - } - - @Override - protected void resetValue() { - if ( fValue instanceof AbstractCValue ) { - ((AbstractCValue)fValue).reset(); - - // We can't just reset the value and toss the reference we've been - // holding. Those things have a dispose() method and that needs to be - // called when there is no further use for it (so debugger-engine - // objects tied to the value can be freed). We return the AbstractCValue - // as an IValue to the platform, which means the platform certainly - // isn't going to dispose of it (there is no IValue.dispose method). - // Notice that we call AbstractCValue.dispose in our dispose method - // above. So, naturally, we need to do the same here. But then what is - // the purpose of calling AbstractCValue.reset() if we just dispose of - // the object, anyway? This whole thing seems a bit screwy. We should - // either be holding on to the AbstractCValue and resetting it, or just - // discarding it. The reset above doesn't hurt, but it sure seems - // pointless. - ((AbstractCValue) fValue).dispose(); - } - fValue = CValueFactory.NULL_VALUE; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.internal.core.model.AbstractCVariable#getExpressionString() - */ - @Override - public String getExpressionString() throws DebugException { - return getExpressionText(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.internal.core.model.AbstractCVariable#dispose() - */ - @Override - public void dispose() { - if ( fCDIExpression != null ) { - try { - fCDIExpression.dispose(); - fCDIExpression = null; - } - catch( CDIException e ) { - } - } - if ( fValue instanceof AbstractCValue ) { - ((AbstractCValue)fValue).dispose(); - fValue = CValueFactory.NULL_VALUE; - } - internalDispose( true ); - setDisposed( true ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.ICVariable#getType() - */ - @Override - public ICType getType() throws DebugException { - if ( isDisposed() ) - return null; - if ( fType == null ) { - synchronized( this ) { - if ( fType == null ) { - fType = ((ICValue)fValue).getType(); - } - } - } - return fType; - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.IVariable#getReferenceTypeName() - */ - @Override - public String getReferenceTypeName() throws DebugException { - ICType type = getType(); - return ( type != null ) ? type.getName() : ""; //$NON-NLS-1$ - } -} diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CFloatingPointValue.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CFloatingPointValue.java deleted file mode 100644 index 83ffacbf0d8..00000000000 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CFloatingPointValue.java +++ /dev/null @@ -1,44 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2006 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 - *******************************************************************************/ -package org.eclipse.cdt.debug.internal.core.model; - -import org.eclipse.cdt.debug.core.cdi.CDIException; -import org.eclipse.cdt.debug.core.cdi.model.ICDIValue; -import org.eclipse.cdt.debug.core.cdi.model.type.ICDIDoubleValue; -import org.eclipse.cdt.debug.core.cdi.model.type.ICDIFloatValue; - -/** - * Represents a value of a float or double variable type. - */ -public class CFloatingPointValue extends CValue { - - private Number fFloatingPointValue; - - /** - * Constructor for CFloatingPointValue. - */ - public CFloatingPointValue( CVariable parent, ICDIValue cdiValue ) { - super( parent, cdiValue ); - } - - public Number getFloatingPointValue() throws CDIException { - if ( fFloatingPointValue == null ) { - ICDIValue cdiValue = getUnderlyingValue(); - if ( cdiValue instanceof ICDIDoubleValue ) { - fFloatingPointValue = new Double( ((ICDIDoubleValue)cdiValue).doubleValue() ); - } - else if ( cdiValue instanceof ICDIFloatValue ) { - fFloatingPointValue = new Float( ((ICDIFloatValue)cdiValue).floatValue() ); - } - } - return fFloatingPointValue; - } -} diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CGlobalValue.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CGlobalValue.java deleted file mode 100644 index 230c8f0c1fe..00000000000 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CGlobalValue.java +++ /dev/null @@ -1,43 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2012 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 - *******************************************************************************/ -package org.eclipse.cdt.debug.internal.core.model; - -import org.eclipse.cdt.debug.core.cdi.model.ICDIValue; -import org.eclipse.debug.core.DebugException; - -public class CGlobalValue extends CValue -{ - private Boolean fHasChildren = null; - - - /** - * Constructor for CGlobalValue. - * @param parent - * @param cdiValue - */ - public CGlobalValue( CVariable parent, ICDIValue cdiValue ) - { - super( parent, cdiValue ); - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.IValue#hasVariables() - */ - @Override - public boolean hasVariables() throws DebugException - { - if ( fHasChildren == null ) - { - fHasChildren = Boolean.valueOf( super.hasVariables() ); - } - return fHasChildren.booleanValue(); - } -} diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CGlobalVariable.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CGlobalVariable.java deleted file mode 100644 index 9be52411c45..00000000000 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CGlobalVariable.java +++ /dev/null @@ -1,413 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2012 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 - *******************************************************************************/ -package org.eclipse.cdt.debug.internal.core.model; - -import org.eclipse.cdt.debug.core.cdi.CDIException; -import org.eclipse.cdt.debug.core.cdi.event.ICDIEvent; -import org.eclipse.cdt.debug.core.cdi.event.ICDIResumedEvent; -import org.eclipse.cdt.debug.core.cdi.model.ICDIArgumentDescriptor; -import org.eclipse.cdt.debug.core.cdi.model.ICDIGlobalVariableDescriptor; -import org.eclipse.cdt.debug.core.cdi.model.ICDIObject; -import org.eclipse.cdt.debug.core.cdi.model.ICDITarget; -import org.eclipse.cdt.debug.core.cdi.model.ICDITargetConfiguration2; -import org.eclipse.cdt.debug.core.cdi.model.ICDIValue; -import org.eclipse.cdt.debug.core.cdi.model.ICDIVariable; -import org.eclipse.cdt.debug.core.cdi.model.ICDIVariableDescriptor; -import org.eclipse.cdt.debug.core.cdi.model.type.ICDIArrayValue; -import org.eclipse.cdt.debug.core.cdi.model.type.ICDIType; -import org.eclipse.cdt.debug.core.model.ICGlobalVariable; -import org.eclipse.cdt.debug.core.model.ICType; -import org.eclipse.cdt.debug.core.model.ICValue; -import org.eclipse.cdt.debug.core.model.IGlobalVariableDescriptor; -import org.eclipse.debug.core.DebugException; - -/** - * Represents a global variable. - */ -public class CGlobalVariable extends CVariable implements ICGlobalVariable { - - private class InternalVariable implements IInternalVariable { - - /** - * The enclosing <code>CVariable</code> instance. - */ - private CVariable fVariable; - - /** - * The CDI variable object this variable is based on. - */ - private ICDIVariableDescriptor fCDIVariableObject; - - /** - * The underlying CDI variable. - */ - private ICDIVariable fCDIVariable; - - /** - * The type of this variable. - */ - private CType fType; - - /** - * The expression used to eveluate the value of this variable. - */ - private String fQualifiedName; - - /** - * The cache of the current value. - */ - private ICValue fValue = CValueFactory.NULL_VALUE; - - /** - * The change flag. - */ - private boolean fChanged = false; - - /** - * Constructor for InternalVariable. - */ - InternalVariable( CVariable var, ICDIVariableDescriptor varObject ) { - setVariable( var ); - setCDIVariableObject( varObject ); - setCDIVariable( (varObject instanceof ICDIVariable) ? (ICDIVariable)varObject : null ); - } - - @Override - public IInternalVariable createShadow( int start, int length ) throws DebugException { - IInternalVariable iv = null; - try { - iv = new InternalVariable( getVariable(), getCDIVariableObject().getVariableDescriptorAsArray( start, length ) ); - } - catch( CDIException e ) { - requestFailed( e.getMessage(), null ); - } - return iv; - } - - @Override - public IInternalVariable createShadow( String type ) throws DebugException { - IInternalVariable iv = null; - try { - iv = new InternalVariable( getVariable(), getCDIVariableObject().getVariableDescriptorAsType( type ) ); - } - catch( CDIException e ) { - requestFailed( e.getMessage(), null ); - } - return iv; - } - - private synchronized ICDIVariable getCDIVariable() throws DebugException { - if ( fCDIVariable == null ) { - try { - fCDIVariable = getCDITarget().createGlobalVariable( (ICDIGlobalVariableDescriptor)getCDIVariableObject() ); - } - catch( CDIException e ) { - requestFailed( e.getMessage(), null ); - } - } - return fCDIVariable; - } - - private void setCDIVariable( ICDIVariable variable ) { - fCDIVariable = variable; - } - - private ICDIVariableDescriptor getCDIVariableObject() { - if ( fCDIVariable != null ) { - return fCDIVariable; - } - return fCDIVariableObject; - } - - private void setCDIVariableObject( ICDIVariableDescriptor variableObject ) { - fCDIVariableObject = variableObject; - } - - @Override - public String getQualifiedName() throws DebugException { - if ( fQualifiedName == null ) { - try { - fQualifiedName = (fCDIVariableObject != null) ? fCDIVariableObject.getQualifiedName() : null; - } - catch( CDIException e ) { - requestFailed( e.getMessage(), null ); - } - } - return fQualifiedName; - } - - @Override - public CType getType() throws DebugException { - if ( fType == null ) { - ICDIVariableDescriptor varObject = getCDIVariableObject(); - if ( varObject != null ) { - synchronized( this ) { - if ( fType == null ) { - try { - fType = new CType( varObject.getType() ); - } - catch( CDIException e ) { - requestFailed( e.getMessage(), null ); - } - } - } - } - } - return fType; - } - - private synchronized void invalidate( boolean destroy ) { - try { - if ( destroy && fCDIVariable != null ) - fCDIVariable.dispose(); - } - catch( CDIException e ) { - logError( e.getMessage() ); - } - invalidateValue(); - setCDIVariable( null ); - if ( fType != null ) - fType.dispose(); - fType = null; - } - - @Override - public void dispose( boolean destroy ) { - invalidate( destroy ); - } - - @Override - public boolean isSameVariable( ICDIVariable cdiVar ) { - return ( fCDIVariable != null ) ? fCDIVariable.equals( cdiVar ) : false; - } - - @Override - public int sizeof() { - if ( getCDIVariableObject() != null ) { - try { - return getCDIVariableObject().sizeof(); - } - catch( CDIException e ) { - } - } - return 0; - } - - @Override - public boolean isArgument() { - return ( getCDIVariableObject() instanceof ICDIArgumentDescriptor ); - } - - @Override - public void setValue( String expression ) throws DebugException { - ICDIVariable cdiVariable = null; - try { - cdiVariable = getCDIVariable(); - if ( cdiVariable != null ) - cdiVariable.setValue( expression ); - else - requestFailed( CoreModelMessages.getString( "CModificationVariable.0" ), null ); //$NON-NLS-1$ - } - catch( CDIException e ) { - targetRequestFailed( e.getMessage(), null ); - } - } - - @Override - public synchronized ICValue getValue() throws DebugException { - if ( fValue.equals( CValueFactory.NULL_VALUE ) ) { - ICDIVariable var = getCDIVariable(); - if ( var != null ) { - try { - ICDIValue cdiValue = var.getValue(); - if ( cdiValue != null ) { - ICDIType cdiType = cdiValue.getType(); - if ( cdiValue instanceof ICDIArrayValue && cdiType != null ) { - ICType type = new CType( cdiType ); - if ( type.isArray() ) { - int[] dims = type.getArrayDimensions(); - if ( dims.length > 0 && dims[0] > 0 ) - fValue = CValueFactory.createIndexedValue( getVariable(), (ICDIArrayValue)cdiValue, 0, dims[0] ); - } - } - else { - fValue = CValueFactory.createValue( getVariable(), cdiValue ); - } - } - if (getCDITarget().getConfiguration() instanceof ICDITargetConfiguration2 && - ((ICDITargetConfiguration2)getCDITarget().getConfiguration()).supportsRuntimeTypeIdentification()) - fType = null; // When the debugger supports RTTI getting a new value may also mean a new type. - } - catch( CDIException e ) { - requestFailed( e.getMessage(), e ); - } - } - } - return fValue; - } - - @Override - public void invalidateValue() { - if ( fValue instanceof AbstractCValue ) { - ((AbstractCValue)fValue).dispose(); - fValue = CValueFactory.NULL_VALUE; - } - } - - @Override - public boolean isChanged() { - return fChanged; - } - - @Override - public synchronized void setChanged( boolean changed ) { - if ( changed ) { - invalidateValue(); - } - if ( fValue instanceof AbstractCValue ) { - ((AbstractCValue)fValue).setChanged( changed ); - } - fChanged = changed; - } - - @Override - public synchronized void preserve() { - setChanged( false ); - if ( fValue instanceof AbstractCValue ) { - ((AbstractCValue)fValue).preserve(); - } - } - - CVariable getVariable() { - return fVariable; - } - - private void setVariable( CVariable variable ) { - fVariable = variable; - } - - @Override - public void resetValue() { - if ( fValue instanceof AbstractCValue ) { - ((AbstractCValue)fValue).reset(); - } - } - - @Override - public boolean isEditable() throws DebugException { - ICDIVariable var = getCDIVariable(); - if ( var != null ) { - try { - return var.isEditable(); - } - catch( CDIException e ) { - } - } - return false; - } - - /** - * Compares the underlying variable objects. - * @see java.lang.Object#equals(java.lang.Object) - */ - @Override - public boolean equals( Object obj ) { - if ( obj instanceof InternalVariable ) { - return getCDIVariableObject().equals( ((InternalVariable)obj).getCDIVariableObject() ); - } - return false; - } - - @Override - public boolean isSameDescriptor( ICDIVariableDescriptor desc ) { - return getCDIVariableObject().equals( desc ); - } - - @Override - public ICDIObject getCdiObject() { - return fCDIVariable; - } - } - - /** - * Will be null for a child of a global (array member, struct field, etc) - */ - private IGlobalVariableDescriptor fDescriptor; - - /** - * Constructor for CGlobalVariable. - */ - protected CGlobalVariable( CDebugElement parent, IGlobalVariableDescriptor descriptor, ICDIVariableDescriptor cdiVariableObject ) { - super( parent, cdiVariableObject ); - fDescriptor = descriptor; - } - - /** - * Constructor for CGlobalVariable. - */ - protected CGlobalVariable( CDebugElement parent, IGlobalVariableDescriptor descriptor, ICDIVariableDescriptor cdiVariableObject, String message ) { - super( parent, cdiVariableObject, message ); - fDescriptor = descriptor; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.ICVariable#canEnableDisable() - */ - @Override - public boolean canEnableDisable() { - return true; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.cdi.event.ICDIEventListener#handleDebugEvents(org.eclipse.cdt.debug.core.cdi.event.ICDIEvent[]) - */ - @Override - public void handleDebugEvents( ICDIEvent[] events ) { - for( int i = 0; i < events.length; i++ ) { - ICDIEvent event = events[i]; - if ( event instanceof ICDIResumedEvent ) { - ICDIObject source = event.getSource(); - if ( source != null ) { - ICDITarget cdiTarget = source.getTarget(); - if ( getCDITarget().equals( cdiTarget ) ) { - setChanged( false ); - } - } - } - } - super.handleDebugEvents( events ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.ICGlobalVariable#getDescriptor() - */ - @Override - public IGlobalVariableDescriptor getDescriptor() { - return fDescriptor; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.internal.core.model.AbstractCVariable#dispose() - */ - @Override - public void dispose() { - internalDispose( true ); - setDisposed( true ); - } - - @Override - protected void createOriginal( ICDIVariableDescriptor vo ) { - if ( vo != null ) { - setName( vo.getName() ); - setOriginal( new InternalVariable( this, vo ) ); - } - } -} diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CIndexedValue.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CIndexedValue.java deleted file mode 100644 index f04ae203fb1..00000000000 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CIndexedValue.java +++ /dev/null @@ -1,315 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2012 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 - * Mathias Kunter - Support for octal number format (bug 370462) - *******************************************************************************/ -package org.eclipse.cdt.debug.internal.core.model; - -import java.math.BigInteger; -import java.util.HashMap; -import java.util.Map; - -import org.eclipse.cdt.core.IAddress; -import org.eclipse.cdt.core.IAddressFactory; -import org.eclipse.cdt.debug.core.cdi.CDIException; -import org.eclipse.cdt.debug.core.cdi.model.ICDIVariable; -import org.eclipse.cdt.debug.core.cdi.model.type.ICDIArrayValue; -import org.eclipse.cdt.debug.core.cdi.model.type.ICDIPointerValue; -import org.eclipse.cdt.debug.core.cdi.model.type.ICDIType; -import org.eclipse.cdt.debug.core.model.CVariableFormat; -import org.eclipse.cdt.debug.core.model.ICType; -import org.eclipse.cdt.utils.Addr32; -import org.eclipse.cdt.utils.Addr64; -import org.eclipse.debug.core.DebugException; -import org.eclipse.debug.core.model.IIndexedValue; -import org.eclipse.debug.core.model.IVariable; - -/** - * A value containing an array of variables. - */ -public class CIndexedValue extends AbstractCValue implements IIndexedValue { - - /** - * The underlying CDI value. - */ - private ICDIArrayValue fCDIValue; - - /** - * Child variables. Only the variables from loaded partitions will be held. - * Use map instead of a java array to scale for large number of children. - */ - private Map<Integer, IVariable> fVariables; - - /** - * The index of the first variable contained in this value. - */ - private int fOffset; - - /** - * The number of entries in this indexed collection. - */ - private int fSize; - - /** - * The type of this value. - */ - private ICType fType; - - /** - * Constructor for CIndexedValue. - */ - public CIndexedValue( AbstractCVariable parent, ICDIArrayValue cdiValue, int offset, int size ) { - super( parent ); - fVariables = new HashMap<Integer, IVariable>(getPreferredPartitionSize()); - fCDIValue = cdiValue; - fOffset = offset; - fSize = size; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.internal.core.model.AbstractCValue#setChanged(boolean) - */ - @Override - protected void setChanged( boolean changed ) { - for (IVariable var : fVariables.values()) { - ((AbstractCVariable)var).setChanged( changed ); - } - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.internal.core.model.AbstractCValue#dispose() - */ - @Override - public void dispose() { - for (IVariable var : fVariables.values()) { - ((AbstractCVariable)var).dispose(); - } - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.internal.core.model.AbstractCValue#reset() - */ - @Override - protected void reset() { - for (IVariable var : fVariables.values()) { - ((AbstractCVariable)var).resetValue(); - } - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.internal.core.model.AbstractCValue#preserve() - */ - @Override - protected void preserve() { - resetStatus(); - for (IVariable var : fVariables.values()) { - ((AbstractCVariable)var).preserve(); - } - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.ICValue#getType() - */ - @Override - public ICType getType() throws DebugException { - if ( fType == null ) { - synchronized( this ) { - if ( fType == null ) { - try { - ICDIType cdiType = getCDIValue().getType(); - if ( cdiType != null ) - fType = new CType( cdiType ); - } - catch( CDIException e ) { - targetRequestFailed( e.getMessage(), null ); - } - } - } - } - return fType; - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.IValue#getReferenceTypeName() - */ - @Override - public String getReferenceTypeName() throws DebugException { - ICType type = getType(); - return ( type != null ) ? type.getName() : ""; //$NON-NLS-1$ - } - - /** - * Please note that this function returns the address of the array, not the - * contents of the array, as long as the underlying ICDIArrayValue is an - * instance of ICDIPointerValue. Otherwise, it returns an empty string. - * - * @see org.eclipse.debug.core.model.IValue#getValueString() - */ - @Override - public String getValueString() throws DebugException { - if ( fCDIValue instanceof ICDIPointerValue ) { - try { - IAddressFactory factory = ((CDebugTarget)getDebugTarget()).getAddressFactory(); - BigInteger pv = ((ICDIPointerValue)fCDIValue).pointerValue(); - if ( pv == null ) - return ""; //$NON-NLS-1$ - IAddress address = factory.createAddress( pv ); - if ( address == null ) - return ""; //$NON-NLS-1$ - CVariableFormat format = getParentVariable().getFormat(); - if ( CVariableFormat.NATURAL.equals( format ) || CVariableFormat.HEXADECIMAL.equals( format ) ) - return address.toHexAddressString(); - else if ( CVariableFormat.DECIMAL.equals( format ) ) - return address.toString(); - else if ( CVariableFormat.OCTAL.equals( format ) ) { - // Using the instanceof operator here to avoid API change - // Add IAddress.toOctalAddressString() in a future CDT release - if (address instanceof Addr32) { - return ((Addr32)address).toOctalAddressString(); - } else if (address instanceof Addr64) { - return ((Addr64)address).toOctalAddressString(); - } else { - // Fall back to hexadecimal address format - return address.toHexAddressString(); - } - } else if ( CVariableFormat.BINARY.equals( format ) ) - return address.toBinaryAddressString(); - return null; - } catch (CDIException e) { - requestFailed( e.getMessage(), null ); - } - } - return ""; //$NON-NLS-1$ - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.IValue#isAllocated() - */ - @Override - public boolean isAllocated() throws DebugException { - return true; - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.IValue#getVariables() - */ - @Override - public IVariable[] getVariables() throws DebugException { - return getVariables0( getInitialOffset(), getSize() ); - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.IValue#hasVariables() - */ - @Override - public boolean hasVariables() throws DebugException { - return getSize() > 0; - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.IIndexedValue#getVariable(int) - */ - @Override - public IVariable getVariable( int offset ) throws DebugException { - if ( offset >= getSize() ) { - requestFailed( CoreModelMessages.getString( "CIndexedValue.0" ), null ); //$NON-NLS-1$ - } - return getVariables0( offset, 1 )[0]; - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.IIndexedValue#getVariables(int, int) - */ - @Override - public IVariable[] getVariables( int offset, int length ) throws DebugException { - if ( offset >= getSize() ) { - requestFailed( CoreModelMessages.getString( "CIndexedValue.1" ), null ); //$NON-NLS-1$ - } - if ( (offset + length - 1) >= getSize() ) { - requestFailed( CoreModelMessages.getString( "CIndexedValue.2" ), null ); //$NON-NLS-1$ - } - return getVariables0( offset, length ); - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.IIndexedValue#getSize() - */ - @Override - public int getSize() throws DebugException { - return getSize0(); - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.IIndexedValue#getInitialOffset() - */ - @Override - public int getInitialOffset() { - return fOffset; - } - - protected ICDIArrayValue getCDIValue() { - return fCDIValue; - } - - private int getPartitionSize( int index ) { - int psize = getPreferredPartitionSize(); - int size = getSize0(); - int pcount = size/psize + 1; - if ( pcount - 1 < index ) - return 0; - return ( pcount - 1 == index ) ? size % psize : psize; - } - - private int getPartitionIndex( int offset ) { - return offset / getPreferredPartitionSize(); - } - - private int getPreferredPartitionSize() { - return 100; - } - - private IVariable[] getVariables0( int offset, int length ) throws DebugException { - IVariable[] result = new IVariable[length]; - int firstIndex = getPartitionIndex( offset ); - int lastIndex = getPartitionIndex( offset + Math.max( length - 1, 0 ) ); - for ( int i = firstIndex; i <= lastIndex; ++i ) { - synchronized( this ) { - if ( !isPartitionLoaded( i ) ) { - loadPartition( i ); - } - } - } - for (int i = 0; i < length; i++) { - result[i] = fVariables.get( offset + i ); - } - return result; - } - - private boolean isPartitionLoaded( int index ) { - return fVariables.containsKey(index * getPreferredPartitionSize()); - } - - private void loadPartition( int index ) throws DebugException { - int prefSize = getPreferredPartitionSize(); - int psize = getPartitionSize( index ); - ICDIVariable[] cdiVars = new ICDIVariable[0]; - try { - cdiVars = getCDIValue().getVariables( index * prefSize, psize ); - } - catch( CDIException e ) { - requestFailed( e.getMessage(), null ); - } - for( int i = 0; i < cdiVars.length; ++i ) - fVariables.put(i + index * prefSize, CVariableFactory.createLocalVariable( this, cdiVars[i] )); - } - - private int getSize0() { - return fSize; - } -} diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CLocalVariable.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CLocalVariable.java deleted file mode 100644 index cfb67a2978f..00000000000 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CLocalVariable.java +++ /dev/null @@ -1,353 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2012 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 - *******************************************************************************/ -package org.eclipse.cdt.debug.internal.core.model; - -import org.eclipse.cdt.debug.core.cdi.CDIException; -import org.eclipse.cdt.debug.core.cdi.model.ICDIArgumentDescriptor; -import org.eclipse.cdt.debug.core.cdi.model.ICDILocalVariableDescriptor; -import org.eclipse.cdt.debug.core.cdi.model.ICDIObject; -import org.eclipse.cdt.debug.core.cdi.model.ICDITargetConfiguration2; -import org.eclipse.cdt.debug.core.cdi.model.ICDIValue; -import org.eclipse.cdt.debug.core.cdi.model.ICDIVariable; -import org.eclipse.cdt.debug.core.cdi.model.ICDIVariableDescriptor; -import org.eclipse.cdt.debug.core.cdi.model.type.ICDIArrayValue; -import org.eclipse.cdt.debug.core.cdi.model.type.ICDIType; -import org.eclipse.cdt.debug.core.model.ICType; -import org.eclipse.cdt.debug.core.model.ICValue; -import org.eclipse.debug.core.DebugException; - - -public class CLocalVariable extends CVariable { - - private class InternalVariable implements IInternalVariable { - - /** - * The enclosing <code>CVariable</code> instance. - */ - private CVariable fVariable; - - /** - * The CDI variable object this variable is based on. - */ - private ICDIVariableDescriptor fCDIVariableObject; - - /** - * The underlying CDI variable. - */ - private ICDIVariable fCDIVariable; - - /** - * The type of this variable. - */ - private CType fType; - - /** - * The expression used to eveluate the value of this variable. - */ - private String fQualifiedName; - - /** - * The cache of the current value. - */ - private ICValue fValue = CValueFactory.NULL_VALUE; - - /** - * The change flag. - */ - private boolean fChanged = false; - - /** - * Constructor for InternalVariable. - */ - InternalVariable( CVariable var, ICDIVariableDescriptor varObject ) { - setVariable( var ); - setCDIVariableObject( varObject ); - setCDIVariable( (varObject instanceof ICDIVariable) ? (ICDIVariable)varObject : null ); - } - - @Override - public IInternalVariable createShadow( int start, int length ) throws DebugException { - IInternalVariable iv = null; - try { - iv = new InternalVariable( getVariable(), getCDIVariableObject().getVariableDescriptorAsArray( start, length ) ); - } - catch( CDIException e ) { - requestFailed( e.getMessage(), null ); - } - return iv; - } - - @Override - public IInternalVariable createShadow( String type ) throws DebugException { - IInternalVariable iv = null; - try { - iv = new InternalVariable( getVariable(), getCDIVariableObject().getVariableDescriptorAsType( type ) ); - } - catch( CDIException e ) { - requestFailed( e.getMessage(), null ); - } - return iv; - } - - private synchronized ICDIVariable getCDIVariable() throws DebugException { - if ( fCDIVariable == null ) { - try { - fCDIVariable = ((CStackFrame)getStackFrame()).getCDIStackFrame().createLocalVariable( (ICDILocalVariableDescriptor)getCDIVariableObject() ); - } - catch( CDIException e ) { - requestFailed( e.getMessage(), null ); - } - } - return fCDIVariable; - } - - private void setCDIVariable( ICDIVariable variable ) { - fCDIVariable = variable; - } - - private ICDIVariableDescriptor getCDIVariableObject() { - if ( fCDIVariable != null ) { - return fCDIVariable; - } - return fCDIVariableObject; - } - - private void setCDIVariableObject( ICDIVariableDescriptor variableObject ) { - fCDIVariableObject = variableObject; - } - - @Override - public String getQualifiedName() throws DebugException { - if ( fQualifiedName == null ) { - try { - fQualifiedName = (fCDIVariableObject != null) ? fCDIVariableObject.getQualifiedName() : null; - } - catch( CDIException e ) { - requestFailed( e.getMessage(), null ); - } - } - return fQualifiedName; - } - - @Override - public CType getType() throws DebugException { - if ( fType == null ) { - ICDIVariableDescriptor varObject = getCDIVariableObject(); - if ( varObject != null ) { - synchronized( this ) { - if ( fType == null ) { - try { - fType = new CType( varObject.getType() ); - } - catch( CDIException e ) { - requestFailed( e.getMessage(), null ); - } - } - } - } - } - return fType; - } - - private synchronized void invalidate( boolean destroy ) { - try { - if ( destroy && fCDIVariable != null ) - fCDIVariable.dispose(); - } - catch( CDIException e ) { - logError( e.getMessage() ); - } - invalidateValue(); - setCDIVariable( null ); - if ( fType != null ) - fType.dispose(); - fType = null; - } - - @Override - public void dispose( boolean destroy ) { - invalidate( destroy ); - } - - @Override - public boolean isSameVariable( ICDIVariable cdiVar ) { - return ( fCDIVariable != null ) ? fCDIVariable.equals( cdiVar ) : false; - } - - @Override - public int sizeof() { - if ( getCDIVariableObject() != null ) { - try { - return getCDIVariableObject().sizeof(); - } - catch( CDIException e ) { - } - } - return 0; - } - - @Override - public boolean isArgument() { - return ( getCDIVariableObject() instanceof ICDIArgumentDescriptor ); - } - - @Override - public void setValue( String expression ) throws DebugException { - ICDIVariable cdiVariable = null; - try { - cdiVariable = getCDIVariable(); - if ( cdiVariable != null ) - cdiVariable.setValue( expression ); - else - requestFailed( CoreModelMessages.getString( "CModificationVariable.0" ), null ); //$NON-NLS-1$ - } - catch( CDIException e ) { - targetRequestFailed( e.getMessage(), null ); - } - } - - @Override - public synchronized ICValue getValue() throws DebugException { - if ( fValue.equals( CValueFactory.NULL_VALUE ) ) { - ICDIVariable var = getCDIVariable(); - if ( var != null ) { - try { - ICDIValue cdiValue = var.getValue(); - if ( cdiValue != null ) { - ICDIType cdiType = cdiValue.getType(); - if ( cdiValue instanceof ICDIArrayValue && cdiType != null ) { - ICType type = new CType( cdiType ); - if ( type.isArray() ) { - int[] dims = type.getArrayDimensions(); - if ( dims.length > 0 && dims[0] > 0 ) - fValue = CValueFactory.createIndexedValue( getVariable(), (ICDIArrayValue)cdiValue, 0, dims[0] ); - } - } - else { - fValue = CValueFactory.createValue( getVariable(), cdiValue ); - } - } - if (getCDITarget().getConfiguration() instanceof ICDITargetConfiguration2 && - ((ICDITargetConfiguration2)getCDITarget().getConfiguration()).supportsRuntimeTypeIdentification()) - fType = null; // When the debugger supports RTTI getting a new value may also mean a new type. - } - catch( CDIException e ) { - requestFailed( e.getMessage(), e ); - } - } - } - return fValue; - } - - @Override - public void invalidateValue() { - if ( fValue instanceof AbstractCValue ) { - ((AbstractCValue)fValue).dispose(); - fValue = CValueFactory.NULL_VALUE; - } - } - - @Override - public boolean isChanged() { - return fChanged; - } - - @Override - public synchronized void setChanged( boolean changed ) { - if ( changed ) { - invalidateValue(); - } - if ( fValue instanceof AbstractCValue ) { - ((AbstractCValue)fValue).setChanged( changed ); - } - fChanged = changed; - } - - @Override - public synchronized void preserve() { - setChanged( false ); - if ( fValue instanceof AbstractCValue ) { - ((AbstractCValue)fValue).preserve(); - } - } - - CVariable getVariable() { - return fVariable; - } - - private void setVariable( CVariable variable ) { - fVariable = variable; - } - - @Override - public void resetValue() { - if ( fValue instanceof AbstractCValue ) { - ((AbstractCValue)fValue).reset(); - } - } - - @Override - public boolean isEditable() throws DebugException { - ICDIVariable var = getCDIVariable(); - if ( var != null ) { - try { - return var.isEditable(); - } - catch( CDIException e ) { - } - } - return false; - } - - /** - * Compares the underlying variable objects. - * @see java.lang.Object#equals(java.lang.Object) - */ - @Override - public boolean equals( Object obj ) { - if ( obj instanceof InternalVariable ) { - return getCDIVariableObject().equals( ((InternalVariable)obj).getCDIVariableObject() ); - } - return false; - } - - @Override - public boolean isSameDescriptor( ICDIVariableDescriptor desc ) { - return getCDIVariableObject().equals( desc ); - } - @Override - public ICDIObject getCdiObject() { - return fCDIVariable; - } - } - - /** - * Constructor for CLocalVariable. - */ - public CLocalVariable( CDebugElement parent, ICDIVariableDescriptor cdiVariableObject, String errorMessage ) { - super( parent, cdiVariableObject, errorMessage ); - } - - /** - * Constructor for CLocalVariable. - */ - public CLocalVariable( CDebugElement parent, ICDIVariableDescriptor cdiVariableObject ) { - super( parent, cdiVariableObject ); - } - - @Override - protected void createOriginal( ICDIVariableDescriptor vo ) { - if ( vo != null ) { - setName( vo.getName() ); - setOriginal( new InternalVariable( this, vo ) ); - } - } -} diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CMemoryBlockExtension.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CMemoryBlockExtension.java deleted file mode 100644 index 9f4fb6d0697..00000000000 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CMemoryBlockExtension.java +++ /dev/null @@ -1,604 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2015 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 - *******************************************************************************/ -package org.eclipse.cdt.debug.internal.core.model; - -import java.math.BigInteger; -import java.util.Arrays; -import java.util.HashSet; -import java.util.Set; - -import org.eclipse.cdt.debug.core.CDebugCorePlugin; -import org.eclipse.cdt.debug.core.cdi.CDIException; -import org.eclipse.cdt.debug.core.cdi.ICDISession; -import org.eclipse.cdt.debug.core.cdi.event.ICDIEvent; -import org.eclipse.cdt.debug.core.cdi.event.ICDIEventListener; -import org.eclipse.cdt.debug.core.cdi.event.ICDIMemoryChangedEvent; -import org.eclipse.cdt.debug.core.cdi.event.ICDIRestartedEvent; -import org.eclipse.cdt.debug.core.cdi.event.ICDIResumedEvent; -import org.eclipse.cdt.debug.core.cdi.model.ICDIMemoryBlock; -import org.eclipse.cdt.debug.core.cdi.model.ICDIMemoryBlockManagement2; -import org.eclipse.cdt.debug.core.cdi.model.ICDIMemorySpaceEncoder; -import org.eclipse.cdt.debug.core.cdi.model.ICDIMemorySpaceManagement; -import org.eclipse.cdt.debug.core.cdi.model.ICDIObject; -import org.eclipse.cdt.debug.core.cdi.model.ICDITarget; -import org.eclipse.cdt.debug.core.model.IExecFileInfo; -import org.eclipse.cdt.debug.core.model.provisional.IMemorySpaceAwareMemoryBlock; -import org.eclipse.cdt.debug.internal.core.CMemoryBlockRetrievalExtension; -import org.eclipse.debug.core.DebugEvent; -import org.eclipse.debug.core.DebugException; -import org.eclipse.debug.core.DebugPlugin; -import org.eclipse.debug.core.model.IMemoryBlockRetrieval; -import org.eclipse.debug.core.model.MemoryByte; - -/** - * Represents a memory block in the CDI model. - */ -public class CMemoryBlockExtension extends CDebugElement implements IMemorySpaceAwareMemoryBlock, ICDIEventListener { - - /** - * The address expression this memory block is based on. - */ - private String fExpression; - - /** - * The base address of this memory block. - */ - private BigInteger fBaseAddress; - - /** - * The memory space identifier; will be null for backends that - * don't require memory space support - */ - private String fMemorySpaceID; - - /** - * The underlying CDI memory block. - */ - private ICDIMemoryBlock fCDIBlock; - - /** - * The memory bytes values. - */ - private MemoryByte[] fBytes = null; - - private Set<BigInteger> fChanges = new HashSet<BigInteger>(); - - /** - * is fWordSize available? - */ - private boolean fHaveWordSize; - - /** - * The number of bytes per address. - */ - private int fWordSize; - - - /** - * Constructor - */ - public CMemoryBlockExtension( CDebugTarget target, String expression, BigInteger baseAddress ) { - this(target, expression, baseAddress, null); - } - - /** - * Constructor that takes a memory space identifier - */ - @SuppressWarnings("deprecation") - public CMemoryBlockExtension( CDebugTarget target, String expression, BigInteger baseAddress, String memorySpaceID ) { - super( target ); - - fBaseAddress = baseAddress; - fMemorySpaceID = memorySpaceID; - - if (memorySpaceID == null) { - fExpression = expression; - } - else { - assert memorySpaceID.length() > 0; - ICDITarget cdiTarget = target.getCDITarget(); - if (cdiTarget instanceof ICDIMemorySpaceEncoder) { - // new interface - fExpression = ((ICDIMemorySpaceEncoder)cdiTarget).encodeAddress(expression, memorySpaceID); - } - else if (cdiTarget instanceof ICDIMemorySpaceManagement) { - // old interface - fExpression = ((ICDIMemorySpaceManagement)target.getCDITarget()).addressToString(baseAddress, memorySpaceID); - } - - if (fExpression == null) { - // If the backend supports memory spaces, it should implement ICDIMemorySpaceManagement - // Even if it does, it may choose to use our built-in encoding/decoding - fExpression = CMemoryBlockRetrievalExtension.encodeAddressDefault(expression, memorySpaceID); - } - } - - } - - /** - * Constructor that takes the addressable size - */ - public CMemoryBlockExtension( CDebugTarget target, String expression, BigInteger baseAddress, int wordSize ) { - this( target, expression, baseAddress, wordSize, null ); - } - - /** - * Constructor that takes the addressable size and a memory space identifier - */ - public CMemoryBlockExtension( CDebugTarget target, String expression, BigInteger baseAddress, int wordSize, String memorySpaceID ) { - super( target ); - fExpression = expression; - fBaseAddress = baseAddress; - fWordSize= wordSize; - fHaveWordSize= true; - fMemorySpaceID = memorySpaceID; - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.IMemoryBlockExtension#getExpression() - */ - @Override - public String getExpression() { - return fExpression; - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.IMemoryBlockExtension#getBigBaseAddress() - */ - @Override - public BigInteger getBigBaseAddress() { - return fBaseAddress; - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.IMemoryBlockExtension#getAddressSize() - */ - @Override - public int getAddressSize() { - return ((CDebugTarget)getDebugTarget()).getAddressFactory().createAddress( getBigBaseAddress() ).getSize(); - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.IMemoryBlockExtension#getAddressableSize() - */ - @Override - public int getAddressableSize() throws DebugException { - if (!fHaveWordSize) { - synchronized (this) { - if (!fHaveWordSize) { - ICDIMemoryBlock block= getCDIBlock(); - if (block == null) { - try { - // create a CDI block of an arbitrary size so we can call into - // the backend to determine the memory's addressable size - setCDIBlock( block= createCDIBlock( fBaseAddress, 100 )); - } - catch( CDIException e ) { - targetRequestFailed( e.getMessage(), null ); - } - } - if (block != null) { - fWordSize= block.getWordSize(); - fHaveWordSize= true; - } - } - } - } - return fWordSize; - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.IMemoryBlockExtension#supportBaseAddressModification() - */ - @Override - public boolean supportBaseAddressModification() { - return true; - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.IMemoryBlockExtension#setBaseAddress(java.math.BigInteger) - */ - @Override - public void setBaseAddress( BigInteger address ) throws DebugException { - BigInteger current = fBaseAddress; - if (current == address || (current != null && current.equals(address))) { - return; // optimization - } - fBaseAddress = address; - fireChangeEvent(DebugEvent.STATE); - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.IMemoryBlockExtension#getBytesFromOffset(java.math.BigInteger, long) - */ - @Override - public MemoryByte[] getBytesFromOffset( BigInteger unitOffset, long addressableUnits ) throws DebugException { - return getBytesFromAddress(unitOffset.add(getBigBaseAddress()) , addressableUnits); - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.IMemoryBlockExtension#getBytesFromAddress(java.math.BigInteger, long) - */ - @Override - public MemoryByte[] getBytesFromAddress( BigInteger address, long length ) throws DebugException { - ICDIMemoryBlock cdiBlock = getCDIBlock(); - if ( fBytes == null || cdiBlock == null || - cdiBlock.getStartAddress().compareTo( address ) > 0 || - cdiBlock.getStartAddress().add( BigInteger.valueOf( cdiBlock.getLength()/cdiBlock.getWordSize() ) ).compareTo( address.add( BigInteger.valueOf( length ) ) ) < 0 ) { - synchronized( this ) { - byte[] bytes = null; - try { - cdiBlock = getCDIBlock(); - if ( cdiBlock == null || - cdiBlock.getStartAddress().compareTo( address ) > 0 || - cdiBlock.getStartAddress().add( BigInteger.valueOf( cdiBlock.getLength()/cdiBlock.getWordSize() ) ).compareTo( address.add( BigInteger.valueOf( length ) ) ) < 0 ) { - if ( cdiBlock != null ) { - disposeCDIBlock(); - fBytes = null; - } - setCDIBlock( cdiBlock = createCDIBlock( address, length ) ); - } - bytes = getCDIBlock().getBytes(); - } - catch( CDIException e ) { - targetRequestFailed( e.getMessage(), null ); - } - if (bytes != null) { - fBytes = new MemoryByte[bytes.length]; - for ( int i = 0; i < bytes.length; ++i ) { - fBytes[i] = createMemoryByte( bytes[i], getCDIBlock().getFlags( i ), hasChanged( getRealBlockAddress().add( BigInteger.valueOf( i ) ) ) ); - } - } - } - } - MemoryByte[] result = new MemoryByte[0]; - if ( fBytes != null && cdiBlock != null ) { - int offset = address.subtract( getRealBlockAddress() ).intValue(); - int offsetInBytes = offset * cdiBlock.getWordSize(); - long lengthInBytes = length * cdiBlock.getWordSize(); - if ( offset >= 0 ) { - int size = ( fBytes.length - offsetInBytes >= lengthInBytes ) ? (int)lengthInBytes : fBytes.length - offsetInBytes; - if ( size > 0 ) { - result = new MemoryByte[size]; - System.arraycopy( fBytes, offsetInBytes, result, 0, size ); - } - } - } - return result; - } - - private boolean isBigEndian() { - IExecFileInfo info = getDebugTarget().getAdapter( IExecFileInfo.class ); - if ( info != null ) { - return !info.isLittleEndian(); - } - return false; - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.IMemoryBlockExtension#getMemoryBlockRetrieval() - */ - @Override - public IMemoryBlockRetrieval getMemoryBlockRetrieval() { - return getDebugTarget().getAdapter( IMemoryBlockRetrieval.class ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.cdi.event.ICDIEventListener#handleDebugEvents(org.eclipse.cdt.debug.core.cdi.event.ICDIEvent[]) - */ - @Override - public void handleDebugEvents( ICDIEvent[] events ) { - for( int i = 0; i < events.length; i++ ) { - ICDIEvent event = events[i]; - ICDIObject source = event.getSource(); - if ( source == null ) - continue; - if ( source.getTarget().equals( getCDITarget() ) ) { - if ( event instanceof ICDIResumedEvent || event instanceof ICDIRestartedEvent ) { - resetChanges(); - } - else if ( event instanceof ICDIMemoryChangedEvent ) { - if ( source instanceof ICDIMemoryBlock && source.equals( getCDIBlock() ) ) { - handleChangedEvent( (ICDIMemoryChangedEvent)event ); - } - } - } - } - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.IMemoryBlock#getStartAddress() - */ - @Override - public long getStartAddress() { - return 0; - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.IMemoryBlock#getLength() - */ - @Override - public long getLength() { - return 0; - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.IMemoryBlock#getBytes() - */ - @Override - public byte[] getBytes() throws DebugException { - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.IMemoryBlock#supportsValueModification() - */ - @Override - public boolean supportsValueModification() { - return true; - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.IMemoryBlock#setValue(long, byte[]) - */ - @Override - public void setValue( long offset, byte[] bytes ) throws DebugException { - setValue( BigInteger.valueOf( offset ), bytes ); - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.IMemoryBlockExtension#setValue(java.math.BigInteger, byte[]) - */ - @Override - public void setValue( BigInteger offset, byte[] bytes ) throws DebugException { - ICDIMemoryBlock block = getCDIBlock(); - if ( block != null ) { - BigInteger base = getBigBaseAddress(); - BigInteger real = getRealBlockAddress(); - long realOffset = base.add( offset ).subtract( real ).longValue(); - try { - block.setValue( realOffset, bytes ); - } - catch( CDIException e ) { - targetRequestFailed( e.getDetailMessage(), null ); - } - } - } - - private ICDIMemoryBlock createCDIBlock( BigInteger address, long length) throws CDIException { - ICDIMemoryBlock block = null; - CDebugTarget target = (CDebugTarget)getDebugTarget(); - ICDITarget cdiTarget = target.getCDITarget(); - if ((fMemorySpaceID != null) && (cdiTarget instanceof ICDIMemoryBlockManagement2)) { - block = ((ICDIMemoryBlockManagement2)cdiTarget).createMemoryBlock(address, fMemorySpaceID, (int)length); - } else { - // Note that CDI clients should ignore the word size - // parameter. It has been deprecated in 4.0. We continue to - // pass in 1 as has always been the case to maintain backwards - // compatibility. - block = cdiTarget.createMemoryBlock( address.toString(), (int)length, 1); - } - block.setFrozen( false ); - getCDISession().getEventManager().addEventListener( this ); - return block; - } - - private void disposeCDIBlock() { - ICDIMemoryBlock block = getCDIBlock(); - if ( block != null ) { - try { - ((CDebugTarget)getDebugTarget()).getCDITarget().removeBlocks( new ICDIMemoryBlock[]{ block }); - } - catch( CDIException e ) { - DebugPlugin.log( e ); - } - setCDIBlock( null ); - getCDISession().getEventManager().removeEventListener( this ); - } - } - - private ICDIMemoryBlock getCDIBlock() { - return fCDIBlock; - } - - private void setCDIBlock( ICDIMemoryBlock cdiBlock ) { - fCDIBlock = cdiBlock; - } - - private BigInteger getRealBlockAddress() { - ICDIMemoryBlock block = getCDIBlock(); - return ( block != null ) ? block.getStartAddress() : BigInteger.ZERO; - } - - private long getBlockSize() { - ICDIMemoryBlock block = getCDIBlock(); - return ( block != null ) ? block.getLength() : 0; - } - - private void handleChangedEvent( ICDIMemoryChangedEvent event ) { - ICDIMemoryBlock block = getCDIBlock(); - if ( block != null && fBytes != null ) { - MemoryByte[] memBytes = fBytes.clone(); - try { - BigInteger start = getRealBlockAddress(); - long length = block.getLength(); - byte[] newBytes = block.getBytes(); - BigInteger[] addresses = event.getAddresses(); - saveChanges( addresses ); - for ( int i = 0; i < addresses.length; ++i ) { - fChanges.add( addresses[i] ); - int addressableSize = fCDIBlock.getWordSize(); // # of bytes per address - if ( addresses[i].compareTo( start ) >= 0 && addresses[i].compareTo( start.add( BigInteger.valueOf( length / addressableSize ) ) ) < 0 ) { - int index = addressableSize * addresses[i].subtract( start ).intValue(); - int end = Math.min(Math.min(index + addressableSize, memBytes.length), newBytes.length); - for (index = Math.max(index, 0) ; index < end; index++ ) { - memBytes[index].setChanged( true ); - memBytes[index].setValue( newBytes[index] ); - } - } - } - fBytes = memBytes; - fireChangeEvent( DebugEvent.CONTENT ); - } - catch( CDIException e ) { - DebugPlugin.log( e ); - } - } - } - - private void saveChanges( BigInteger[] addresses ) { - fChanges.addAll( Arrays.asList( addresses ) ); - } - - private boolean hasChanged( BigInteger address ) { - return fChanges.contains( address ); - } - - private void resetChanges() { - if ( fBytes != null ) { - BigInteger[] changes = fChanges.toArray( new BigInteger[fChanges.size()] ); - for ( int i = 0; i < changes.length; ++i ) { - BigInteger real = getRealBlockAddress(); - if ( real.compareTo( changes[i] ) <= 0 && real.add( BigInteger.valueOf( getBlockSize() ) ).compareTo( changes[i] ) > 0 ) { - int index = changes[i].subtract( real ).intValue(); - if ( index >= 0 && index < fBytes.length ) { - fBytes[index].setChanged( false ); - } - } - } - } - fChanges.clear(); - fireChangeEvent( DebugEvent.CONTENT ); - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.IMemoryBlockExtension#supportsChangeManagement() - */ - @Override - public boolean supportsChangeManagement() { - return true; - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.IMemoryBlockExtension#connect(java.lang.Object) - */ - @Override - public void connect( Object object ) { - // TODO Auto-generated method stub - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.IMemoryBlockExtension#disconnect(java.lang.Object) - */ - @Override - public void disconnect( Object object ) { - // TODO Auto-generated method stub - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.IMemoryBlockExtension#getConnections() - */ - @Override - public Object[] getConnections() { - // TODO Auto-generated method stub - return new Object[0]; - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.IMemoryBlockExtension#dispose() - */ - @Override - public void dispose() { - fChanges.clear(); - ICDIMemoryBlock cdiBlock = getCDIBlock(); - if ( cdiBlock != null ) { - try { - ((CDebugTarget)getDebugTarget()).getCDITarget().removeBlocks( new ICDIMemoryBlock[] {cdiBlock} ); - } - catch( CDIException e ) { - CDebugCorePlugin.log( e ); - } - fCDIBlock = null; - } - final ICDISession cdiSession = getCDISession(); - if (cdiSession != null) { - cdiSession.getEventManager().removeEventListener( this ); - } - } - - /* (non-Javadoc) - * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class) - */ - @Override - @SuppressWarnings("rawtypes") - public Object getAdapter( Class adapter ) { - if ( IMemoryBlockRetrieval.class.equals( adapter ) ) - return getMemoryBlockRetrieval(); - return super.getAdapter( adapter ); - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.IMemoryBlockExtension#getMemoryBlockStartAddress() - */ - @Override - public BigInteger getMemoryBlockStartAddress() throws DebugException { - return null; // return null to mean not bounded ... according to the spec - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.IMemoryBlockExtension#getMemoryBlockEndAddress() - */ - @Override - public BigInteger getMemoryBlockEndAddress() throws DebugException { - return null;// return null to mean not bounded ... according to the spec - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.IMemoryBlockExtension#getBigLength() - */ - @Override - public BigInteger getBigLength() throws DebugException { - ICDIMemoryBlock block = getCDIBlock(); - if ( block != null ) { - BigInteger length = new BigInteger( Long.toHexString( block.getLength() ), 16 ); - return length; - } - return BigInteger.ZERO; - } - - private MemoryByte createMemoryByte( byte value, byte cdiFlags, boolean changed ) { - byte flags = 0; - if ( (cdiFlags & ICDIMemoryBlock.VALID) != 0 ) { - flags |= MemoryByte.HISTORY_KNOWN | MemoryByte.ENDIANESS_KNOWN; - if ( (cdiFlags & ICDIMemoryBlock.READ_ONLY) != 0 ) { - flags |= MemoryByte.READABLE; - } - else { - flags |= MemoryByte.READABLE | MemoryByte.WRITABLE; - } - if ( isBigEndian() ) { - flags |= MemoryByte.BIG_ENDIAN; - } - if ( changed ) - flags |= MemoryByte.CHANGED; - } - return new MemoryByte( value, flags ); - } - - - /** - * @see org.eclipse.cdt.debug.core.model.provisional.IMemorySpaceAwareMemoryBlock#getMemorySpaceID() - */ - @Override - public String getMemorySpaceID() { - return fMemorySpaceID; - } -} diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CModule.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CModule.java deleted file mode 100644 index 8789fe5c727..00000000000 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CModule.java +++ /dev/null @@ -1,314 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2012 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 - *******************************************************************************/ -package org.eclipse.cdt.debug.internal.core.model; - -import java.math.BigInteger; -import com.ibm.icu.text.MessageFormat; - -import org.eclipse.cdt.core.IAddress; -import org.eclipse.cdt.core.IAddressFactory; -import org.eclipse.cdt.core.IBinaryParser.IBinaryFile; -import org.eclipse.cdt.core.IBinaryParser.IBinaryObject; -import org.eclipse.cdt.core.model.CModelException; -import org.eclipse.cdt.core.model.CoreModel; -import org.eclipse.cdt.core.model.IBinary; -import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.cdt.core.model.ICProject; -import org.eclipse.cdt.core.model.ISourceRoot; -import org.eclipse.cdt.debug.core.CDebugCorePlugin; -import org.eclipse.cdt.debug.core.cdi.CDIException; -import org.eclipse.cdt.debug.core.cdi.model.ICDIObject; -import org.eclipse.cdt.debug.core.cdi.model.ICDISharedLibrary; -import org.eclipse.cdt.debug.core.model.ICModule; -import org.eclipse.cdt.internal.core.model.Binary; -import org.eclipse.cdt.internal.core.model.CModelManager; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IWorkspaceRoot; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Path; -import org.eclipse.debug.core.DebugException; - -/** - * The CDI based implementation of <code>ICModule</code>. - * - * This implementation is experimental and needs to be changed when - * the CDI level support is available. - */ -public class CModule extends CDebugElement implements ICModule { - - private int fType = 0; - - private Binary fBinary; - - private ICDIObject fCDIObject; - - private IPath fImageName; - - private IPath fSymbolsFileName; - - public static CModule createExecutable( CDebugTarget target, IPath path ) { - // TODO Add support for executables to CDI. - return new CModule( EXECUTABLE, target, path ); - } - - public static CModule createSharedLibrary( CDebugTarget target, ICDISharedLibrary lib ) { - return new CModule( SHARED_LIBRARY, target, lib ); - } - - /** - * Constructor for CModule. Used for the program. - */ - private CModule( int type, CDebugTarget target, IPath path ) { - super( target ); - fType = type; - fBinary = createBinary(path); - fCDIObject = null; - fImageName = path; - fSymbolsFileName = path; - } - - /** - * Constructor for CModule. Used for shared libraries. - */ - private CModule( int type, CDebugTarget target, ICDIObject cdiObject ) { - super( target ); - fType = type; - if ( cdiObject instanceof ICDISharedLibrary ) { - ICDISharedLibrary cdiSharedLib = (ICDISharedLibrary)cdiObject; - fBinary = 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()) { - file = null; - } - - // In case this is an external resource see if we can find - // a file for it. - if (file == null) { - IFile[] files = root.findFilesForLocation(path); - if (files.length > 0) { - file = files[0]; - } - } - - if (file != null) { - ICProject cproject = CoreModel.getDefault().create(file.getProject()); - IPath resourcePath = file.getParent().getFullPath(); - - try { - ICElement cfolder = cproject.findElement(resourcePath); - - // Check if folder is a source root and use that instead - ISourceRoot sourceRoot = cproject.findSourceRoot(resourcePath); - if (sourceRoot != null) - cfolder = sourceRoot; - - IBinaryFile bin = CModelManager.getDefault().createBinaryFile(file); - if (bin != null) { - return new Binary(cfolder, file, (IBinaryObject)bin); - } - } catch (CModelException e) { - CDebugCorePlugin.log(e); - } - } - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.ICModule#getType() - */ - @Override - public int getType() { - return fType; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.ICModule#getName() - */ - @Override - public String getName() { - return fImageName.lastSegment().toString(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.ICModule#getImageName() - */ - @Override - public IPath getImageName() { - return fImageName; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.ICModule#getSymbolsFileName() - */ - @Override - public IPath getSymbolsFileName() { - return fSymbolsFileName; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.ICModule#setSymbolsFileName(org.eclipse.core.runtime.IPath) - */ - @Override - public void setSymbolsFileName( IPath symbolsFile ) throws DebugException { - loadSymbolsFromFile( symbolsFile ); - fSymbolsFileName = symbolsFile; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.ICModule#getBaseAddress() - */ - @Override - public IAddress getBaseAddress() { - return ( fCDIObject instanceof ICDISharedLibrary ) ? getAddressFactory().createAddress( ((ICDISharedLibrary)fCDIObject).getStartAddress() ) : getAddressFactory().getZero(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.ICModule#getSize() - */ - @Override - public long getSize() { - long result = 0; - if ( fCDIObject instanceof ICDISharedLibrary ) { - BigInteger start = ((ICDISharedLibrary)fCDIObject).getStartAddress(); - BigInteger end = ((ICDISharedLibrary)fCDIObject).getEndAddress(); - if ( end.compareTo( start ) > 0 ) - result = end.subtract( start ).longValue(); - } - return result; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.ICModule#areSymbolsLoaded() - */ - @Override - public boolean areSymbolsLoaded() { - if (fCDIObject instanceof ICDISharedLibrary) - return ((ICDISharedLibrary)fCDIObject).areSymbolsLoaded(); - - if (fBinary != null) - return fBinary.hasDebug(); - - return false; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.ICModule#canLoadSymbols() - */ - @Override - public boolean canLoadSymbols() { - return ( getDebugTarget().isSuspended() && !areSymbolsLoaded() ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.ICModule#loadSymbols() - */ - @Override - public void loadSymbols() throws DebugException { - loadSymbolsFromFile( getSymbolsFileName() ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.ICModule#getPlatform() - */ - @Override - public String getPlatform() { - return ( fBinary != null ) ? fBinary.getCPU() : CoreModelMessages.getString( "CModule.1" ); //$NON-NLS-1$ - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.ICModule#isLittleEndian() - */ - @Override - public boolean isLittleEndian() { - return ( fBinary != null ) ? fBinary.isLittleEndian() : ((CDebugTarget)getDebugTarget()).isLittleEndian(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.ICModule#getAddressFactory() - */ - @Override - public IAddressFactory getAddressFactory() { - return ((CDebugTarget)getDebugTarget()).getAddressFactory(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.ICModule#getCPU() - */ - @Override - public String getCPU() { - return ( fBinary != null ) ? fBinary.getCPU() : null; - } - - /* (non-Javadoc) - * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class) - */ - @Override - public Object getAdapter( Class adapter ) { - if ( ICElement.class.equals( adapter ) ) { - return getCElement(); - } - if ( IBinary.class.equals( adapter ) && getCElement() instanceof IBinary ) { - return getCElement(); - } - return super.getAdapter( adapter ); - } - - public void dispose() { - - } - - public boolean equals( ICDIObject cdiObject ) { - return ( fCDIObject != null ) ? fCDIObject.equals( cdiObject ) : false; - } - - protected ICElement getCElement() { - return fBinary; - } - - private void loadSymbolsFromFile(IPath path) throws DebugException { - if (fCDIObject instanceof ICDISharedLibrary) { - if (path == null || path.isEmpty()) { - requestFailed(CoreModelMessages.getString("CModule.2"), null); //$NON-NLS-1$ - } else { - if (path.equals(getSymbolsFileName())) { - try { - ((ICDISharedLibrary) fCDIObject).loadSymbols(); - } catch (CDIException e) { - targetRequestFailed(e.getMessage(), null); - } - } else { - String message = MessageFormat.format( // - CoreModelMessages.getString("CModule.5"), //$NON-NLS-1$ - new Object[] { path.toString() }); - targetRequestFailed(message, null); - } - } - } - } -} diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CModuleManager.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CModuleManager.java deleted file mode 100644 index 5b85e37526c..00000000000 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CModuleManager.java +++ /dev/null @@ -1,169 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2012 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 - *******************************************************************************/ -package org.eclipse.cdt.debug.internal.core.model; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Iterator; - -import org.eclipse.cdt.debug.core.CDIDebugModel; -import org.eclipse.cdt.debug.core.cdi.model.ICDIObject; -import org.eclipse.cdt.debug.core.cdi.model.ICDISharedLibrary; -import org.eclipse.cdt.debug.core.model.ICDebugTarget; -import org.eclipse.cdt.debug.core.model.ICModule; -import org.eclipse.cdt.debug.core.model.IModuleRetrieval; -import org.eclipse.cdt.debug.internal.core.ICDebugInternalConstants; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.MultiStatus; -import org.eclipse.core.runtime.PlatformObject; -import org.eclipse.core.runtime.Status; -import org.eclipse.debug.core.DebugEvent; -import org.eclipse.debug.core.DebugException; - -/** - * Manages the modules loaded on this debug target. - */ -public class CModuleManager extends PlatformObject implements IModuleRetrieval { - - /** - * The debug target associated with this manager. - */ - private CDebugTarget fDebugTarget; - - /** - * The collection of the shared libraries loaded on this target. - */ - private ArrayList fModules; - - /** - * Constructor for CModuleManager. - */ - public CModuleManager( CDebugTarget target ) { - fDebugTarget = target; - fModules = new ArrayList( 5 ); - } - - @Override - public boolean hasModules() throws DebugException { - return !fModules.isEmpty(); - } - - @Override - public ICModule[] getModules() throws DebugException { - return (ICModule[])fModules.toArray( new ICModule[fModules.size()] ); - } - - @Override - public void loadSymbolsForAllModules() throws DebugException { - MultiStatus ms = new MultiStatus( CDIDebugModel.getPluginIdentifier(), ICDebugInternalConstants.STATUS_CODE_ERROR, CoreModelMessages.getString( "CModuleManager.0" ), null ); //$NON-NLS-1$ - Iterator it = fModules.iterator(); - while( it.hasNext() ) { - ICModule module = (ICModule)it.next(); - try { - module.loadSymbols(); - } - catch( DebugException e ) { - ms.add( new Status( IStatus.ERROR, CDIDebugModel.getPluginIdentifier(), ICDebugInternalConstants.STATUS_CODE_ERROR, e.getMessage(), e ) ); - } - } - if ( !ms.isOK() ) { - throw new DebugException( ms ); - } - } - - public void loadSymbols( ICModule[] modules ) throws DebugException { - MultiStatus ms = new MultiStatus( CDIDebugModel.getPluginIdentifier(), ICDebugInternalConstants.STATUS_CODE_ERROR, CoreModelMessages.getString( "CModuleManager.1" ), null ); //$NON-NLS-1$ - for ( int i = 0; i < modules.length; ++i ) { - try { - modules[i].loadSymbols(); - } - catch( DebugException e ) { - ms.add( new Status( IStatus.ERROR, CDIDebugModel.getPluginIdentifier(), ICDebugInternalConstants.STATUS_CODE_ERROR, e.getMessage(), e ) ); - } - } - if ( !ms.isOK() ) { - throw new DebugException( ms ); - } - } - - public void dispose() { - Iterator it = fModules.iterator(); - while( it.hasNext() ) { - ((CModule)it.next()).dispose(); - } - fModules.clear(); - } - - protected CDebugTarget getDebugTarget() { - return fDebugTarget; - } - - protected void addModules( ICModule[] modules ) { - fModules.addAll( Arrays.asList( modules ) ); - } - - protected void removeModules( ICModule[] modules ) { - fModules.removeAll( Arrays.asList( modules ) ); - } - - public void sharedLibraryLoaded( ICDISharedLibrary cdiLibrary ) { - CModule library = null; - synchronized( fModules ) { - if ( find( cdiLibrary ) == null ) { - library = CModule.createSharedLibrary( getDebugTarget(), cdiLibrary ); - fModules.add( library ); - } - } - if ( library != null ) - library.fireCreationEvent(); - } - - public void sharedLibraryUnloaded( ICDISharedLibrary cdiLibrary ) { - CModule library = null; - synchronized( fModules ) { - library = find( cdiLibrary ); - if ( library != null ) { - fModules.remove( library ); - } - } - if ( library != null ) { - library.dispose(); - library.fireTerminateEvent(); - } - } - - public void symbolsLoaded( ICDIObject cdiObject ) { - CModule module = find( cdiObject ); - if ( module != null ) { - module.fireChangeEvent( DebugEvent.STATE ); - } - } - - private CModule find( ICDIObject cdiObject ) { - Iterator it = fModules.iterator(); - while( it.hasNext() ) { - CModule module = (CModule)it.next(); - if ( module.equals( cdiObject ) ) - return module; - } - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.core.runtime.PlatformObject#getAdapter(java.lang.Class) - */ - @Override - public Object getAdapter( Class adapter ) { - if ( adapter.equals( ICDebugTarget.class ) ) - return getDebugTarget(); - return super.getAdapter( adapter ); - } -} diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CRegister.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CRegister.java deleted file mode 100644 index 30da4afef57..00000000000 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CRegister.java +++ /dev/null @@ -1,451 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2012 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 - * ARM Limited - https://bugs.eclipse.org/bugs/show_bug.cgi?id=186981 - *******************************************************************************/ -package org.eclipse.cdt.debug.internal.core.model; - -import org.eclipse.cdt.debug.core.CDebugCorePlugin; -import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants; -import org.eclipse.cdt.debug.core.ICDebugConstants; -import org.eclipse.cdt.debug.core.cdi.CDIException; -import org.eclipse.cdt.debug.core.cdi.event.ICDIEvent; -import org.eclipse.cdt.debug.core.cdi.event.ICDIMemoryChangedEvent; -import org.eclipse.cdt.debug.core.cdi.event.ICDIResumedEvent; -import org.eclipse.cdt.debug.core.cdi.model.ICDIArgumentDescriptor; -import org.eclipse.cdt.debug.core.cdi.model.ICDIObject; -import org.eclipse.cdt.debug.core.cdi.model.ICDIRegister; -import org.eclipse.cdt.debug.core.cdi.model.ICDIRegisterDescriptor; -import org.eclipse.cdt.debug.core.cdi.model.ICDITarget; -import org.eclipse.cdt.debug.core.cdi.model.ICDITargetConfiguration3; -import org.eclipse.cdt.debug.core.cdi.model.ICDIValue; -import org.eclipse.cdt.debug.core.cdi.model.ICDIVariable; -import org.eclipse.cdt.debug.core.cdi.model.ICDIVariableDescriptor; -import org.eclipse.cdt.debug.core.cdi.model.type.ICDIArrayValue; -import org.eclipse.cdt.debug.core.cdi.model.type.ICDIType; -import org.eclipse.cdt.debug.core.model.CVariableFormat; -import org.eclipse.cdt.debug.core.model.ICRegister; -import org.eclipse.cdt.debug.core.model.ICStackFrame; -import org.eclipse.cdt.debug.core.model.ICType; -import org.eclipse.cdt.debug.core.model.ICValue; -import org.eclipse.cdt.debug.core.model.IRegisterDescriptor; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.debug.core.DebugException; -import org.eclipse.debug.core.model.IRegisterGroup; - -/** - * Represents a register in the CDI model. - */ -public class CRegister extends CVariable implements ICRegister { - - private class InternalVariable implements IInternalVariable { - - /** - * The enclosing <code>CVariable</code> instance. - */ - private CVariable fVariable; - - /** - * The CDI variable object this variable is based on. - */ - private ICDIVariableDescriptor fCDIVariableObject; - - /** - * The underlying CDI register. - */ - private ICDIRegister fCDIRegister; - - /** - * The type of this variable. - */ - private CType fType; - - /** - * The expression used to eveluate the value of this variable. - */ - private String fQualifiedName; - - /** - * The cache of the current value. - */ - private ICValue fValue = CValueFactory.NULL_VALUE; - - /** - * The change flag. - */ - private boolean fChanged = false; - - /** - * Constructor for InternalVariable. - */ - InternalVariable( CVariable var, ICDIVariableDescriptor varObject ) { - setVariable( var ); - setCDIVariableObject( varObject ); - setCDIRegister( (varObject instanceof ICDIRegister) ? (ICDIRegister)varObject : null ); - } - - @Override - public IInternalVariable createShadow( int start, int length ) throws DebugException { - IInternalVariable iv = null; - try { - iv = new InternalVariable( getVariable(), getCDIVariableObject().getVariableDescriptorAsArray( start, length ) ); - } - catch( CDIException e ) { - requestFailed( e.getMessage(), null ); - } - return iv; - } - - @Override - public IInternalVariable createShadow( String type ) throws DebugException { - IInternalVariable iv = null; - try { - iv = new InternalVariable( getVariable(), getCDIVariableObject().getVariableDescriptorAsType( type ) ); - } - catch( CDIException e ) { - requestFailed( e.getMessage(), null ); - } - return iv; - } - - private synchronized ICDIRegister getCDIRegister() throws DebugException { - if ( fCDIRegister == null ) { - try { - fCDIRegister = getCDITarget().createRegister( (ICDIRegisterDescriptor)getCDIVariableObject() ); - } - catch( CDIException e ) { - requestFailed( e.getMessage(), null ); - } - } - return fCDIRegister; - } - - private void setCDIRegister( ICDIRegister register ) { - fCDIRegister = register; - } - - private ICDIVariableDescriptor getCDIVariableObject() { - if ( fCDIRegister != null ) { - return fCDIRegister; - } - return fCDIVariableObject; - } - - private void setCDIVariableObject( ICDIVariableDescriptor variableObject ) { - fCDIVariableObject = variableObject; - } - - @Override - public String getQualifiedName() throws DebugException { - if ( fQualifiedName == null ) { - try { - fQualifiedName = (fCDIVariableObject != null) ? fCDIVariableObject.getQualifiedName() : null; - } - catch( CDIException e ) { - requestFailed( e.getMessage(), null ); - } - } - return fQualifiedName; - } - - @Override - public CType getType() throws DebugException { - if ( fType == null ) { - ICDIVariableDescriptor varObject = getCDIVariableObject(); - if ( varObject != null ) { - synchronized( this ) { - if ( fType == null ) { - try { - fType = new CType( varObject.getType() ); - } - catch( CDIException e ) { - requestFailed( e.getMessage(), null ); - } - } - } - } - } - return fType; - } - - private synchronized void invalidate( boolean destroy ) { - try { - if ( destroy && fCDIRegister != null ) - fCDIRegister.dispose(); - } - catch( CDIException e ) { - logError( e.getMessage() ); - } - invalidateValue(); - setCDIRegister( null ); - if ( fType != null ) - fType.dispose(); - fType = null; - } - - @Override - public void dispose( boolean destroy ) { - invalidate( destroy ); - } - - @Override - public boolean isSameVariable( ICDIVariable cdiVar ) { - return ( fCDIRegister != null ) ? fCDIRegister.equals( cdiVar ) : false; - } - - @Override - public int sizeof() { - if ( getCDIVariableObject() != null ) { - try { - return getCDIVariableObject().sizeof(); - } - catch( CDIException e ) { - } - } - return 0; - } - - @Override - public boolean isArgument() { - return ( getCDIVariableObject() instanceof ICDIArgumentDescriptor ); - } - - @Override - public void setValue( String expression ) throws DebugException { - ICDIRegister cdiRegister = null; - try { - cdiRegister = getCDIRegister(); - if ( cdiRegister != null ) - cdiRegister.setValue( expression ); - else - requestFailed( CoreModelMessages.getString( "CModificationVariable.0" ), null ); //$NON-NLS-1$ - } - catch( CDIException e ) { - targetRequestFailed( e.getMessage(), null ); - } - } - - @Override - public synchronized ICValue getValue() throws DebugException { - CStackFrame frame = getCurrentStackFrame(); - if ( frame == null || frame.isDisposed() ) - fValue = CValueFactory.NULL_VALUE; - else if ( fValue.equals( CValueFactory.NULL_VALUE ) ) { - ICDIRegister reg = getCDIRegister(); - if ( reg != null ) { - try { - ICDIValue cdiValue = reg.getValue( getCurrentStackFrame().getCDIStackFrame() ); - if ( cdiValue != null ) { - ICDIType cdiType = cdiValue.getType(); - if ( cdiValue instanceof ICDIArrayValue && cdiType != null ) { - ICType type = new CType( cdiType ); - if ( type.isArray() ) { - int[] dims = type.getArrayDimensions(); - if ( dims.length > 0 && dims[0] > 0 ) - fValue = CValueFactory.createIndexedValue( getVariable(), (ICDIArrayValue)cdiValue, 0, dims[0] ); - } - } - else { - fValue = CValueFactory.createValue( getVariable(), cdiValue ); - } - } - } - catch( CDIException e ) { - requestFailed( e.getMessage(), e ); - } - } - } - return fValue; - } - - @Override - public void invalidateValue() { - if ( fValue instanceof AbstractCValue ) { - ((AbstractCValue)fValue).dispose(); - fValue = CValueFactory.NULL_VALUE; - } - } - - @Override - public boolean isChanged() { - return fChanged; - } - - @Override - public synchronized void setChanged( boolean changed ) { - if ( changed ) { - invalidateValue(); - } - if ( fValue instanceof AbstractCValue ) { - ((AbstractCValue)fValue).setChanged( changed ); - } - fChanged = changed; - } - - @Override - public synchronized void preserve() { - setChanged( false ); - if ( fValue instanceof AbstractCValue ) { - ((AbstractCValue)fValue).preserve(); - } - } - - CVariable getVariable() { - return fVariable; - } - - private void setVariable( CVariable variable ) { - fVariable = variable; - } - - @Override - public void resetValue() { - if ( fValue instanceof AbstractCValue ) { - ((AbstractCValue)fValue).reset(); - } - } - - @Override - public boolean isEditable() throws DebugException { - ICDIRegister reg = getCDIRegister(); - if ( reg != null && reg.getTarget().getConfiguration().supportsRegisterModification() ) { - try { - return reg.isEditable(); - } - catch( CDIException e ) { - } - } - return false; - } - /** - * Compares the underlying variable objects. - * @see java.lang.Object#equals(java.lang.Object) - */ - @Override - public boolean equals( Object obj ) { - if ( obj instanceof InternalVariable ) { - return getCDIVariableObject().equals( ((InternalVariable)obj).getCDIVariableObject() ); - } - return false; - } - - @Override - public boolean isSameDescriptor( ICDIVariableDescriptor desc ) { - return getCDIVariableObject().equals( desc ); - } - - @Override - public ICDIObject getCdiObject() { - return fCDIRegister; - } - } - - /** - * Constructor for CRegister. - */ - protected CRegister( CRegisterGroup parent, IRegisterDescriptor descriptor ) { - super( parent, ((CRegisterDescriptor)descriptor).getCDIDescriptor() ); - setFormat( CVariableFormat.getFormat( CDebugCorePlugin.getDefault().getPluginPreferences().getInt( ICDebugConstants.PREF_DEFAULT_REGISTER_FORMAT ) ) ); - setInitialFormat(); - } - - /** - * Constructor for CRegister. - */ - protected CRegister( CRegisterGroup parent, IRegisterDescriptor descriptor, String message ) { - super( parent, ((CRegisterDescriptor)descriptor).getCDIDescriptor(), message ); - setFormat( CVariableFormat.getFormat( CDebugCorePlugin.getDefault().getPluginPreferences().getInt( ICDebugConstants.PREF_DEFAULT_REGISTER_FORMAT ) ) ); - setInitialFormat(); - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.IRegister#getRegisterGroup() - */ - @Override - public IRegisterGroup getRegisterGroup() throws DebugException { - return (IRegisterGroup)getParent(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.internal.core.model.CVariable#isBookkeepingEnabled() - */ - @Override - protected boolean isBookkeepingEnabled() { - boolean result = false; - try { - result = getLaunch().getLaunchConfiguration().getAttribute( ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_ENABLE_REGISTER_BOOKKEEPING, false ); - } - catch( CoreException e ) { - } - return result; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.ICVariable#canEnableDisable() - */ - @Override - public boolean canEnableDisable() { - return true; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.cdi.event.ICDIEventListener#handleDebugEvents(org.eclipse.cdt.debug.core.cdi.event.ICDIEvent[]) - */ - @Override - public void handleDebugEvents( ICDIEvent[] events ) { - for( int i = 0; i < events.length; i++ ) { - ICDIEvent event = events[i]; - ICDIObject source = event.getSource(); - if (source != null) { - ICDITarget cdiTarget = source.getTarget(); - if ( event instanceof ICDIResumedEvent ) { - if ( getCDITarget().equals( cdiTarget ) ) { - setChanged( false ); - } - } - else if ( event instanceof ICDIMemoryChangedEvent && - cdiTarget.getConfiguration() instanceof ICDITargetConfiguration3 && - ((ICDITargetConfiguration3)cdiTarget.getConfiguration()).needsRegistersUpdated(event)) { - resetValue(); - return; // avoid similar but logic inappropriate for us in CVariable - } - } - } - super.handleDebugEvents( events ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.internal.core.model.AbstractCVariable#dispose() - */ - @Override - public void dispose() { - internalDispose( true ); - setDisposed( true ); - } - - @Override - protected ICStackFrame getStackFrame() { - ICStackFrame frame = super.getStackFrame(); - if (frame == null) - frame = getCurrentStackFrame(); - return frame; - } - - protected CStackFrame getCurrentStackFrame() { - return ((CDebugTarget)getDebugTarget()).getRegisterManager().getCurrentFrame(); - } - - @Override - protected void createOriginal( ICDIVariableDescriptor vo ) { - if ( vo != null ) { - setName( vo.getName() ); - setOriginal( new InternalVariable( this, vo ) ); - } - } -} diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CRegisterDescriptor.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CRegisterDescriptor.java deleted file mode 100644 index 997ed79cffa..00000000000 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CRegisterDescriptor.java +++ /dev/null @@ -1,66 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2012 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 - *******************************************************************************/ -package org.eclipse.cdt.debug.internal.core.model; - -import org.eclipse.cdt.debug.core.cdi.model.ICDIRegisterDescriptor; -import org.eclipse.cdt.debug.core.cdi.model.ICDIRegisterGroup; -import org.eclipse.cdt.debug.core.model.IRegisterDescriptor; - -/** - * A register descriptor. Temporary, need to change the related CDI interfaces. - */ -public class CRegisterDescriptor implements IRegisterDescriptor { - - private String fName; - private String fGroupName; - private ICDIRegisterDescriptor fCDIDescriptor = null; - - /** - * Constructor for CRegisterDescriptor. - */ - public CRegisterDescriptor( String name, String groupName ) { - fName = name; - fGroupName = groupName; - } - - /** - * Constructor for CRegisterDescriptor. - */ - public CRegisterDescriptor( ICDIRegisterGroup group, ICDIRegisterDescriptor desc ) { - fName = desc.getName(); - fGroupName = group.getName(); - fCDIDescriptor = desc; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.IRegisterDescriptor#getName() - */ - @Override - public String getName() { - return fName; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.IRegisterDescriptor#getGroupName() - */ - @Override - public String getGroupName() { - return fGroupName; - } - - public ICDIRegisterDescriptor getCDIDescriptor() { - return fCDIDescriptor; - } - - public void setCDIDescriptor( ICDIRegisterDescriptor descriptor ) { - fCDIDescriptor = descriptor; - } -} diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CRegisterGroup.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CRegisterGroup.java deleted file mode 100644 index 50a22a1971f..00000000000 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CRegisterGroup.java +++ /dev/null @@ -1,279 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2015 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 - *******************************************************************************/ -package org.eclipse.cdt.debug.internal.core.model; - -import java.util.ArrayList; -import org.eclipse.cdt.debug.core.CDebugCorePlugin; -import org.eclipse.cdt.debug.core.model.IEnableDisableTarget; -import org.eclipse.cdt.debug.core.model.IPersistableRegisterGroup; -import org.eclipse.cdt.debug.core.model.IRegisterDescriptor; -import org.eclipse.cdt.debug.internal.core.CRegisterManager; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.debug.core.DebugEvent; -import org.eclipse.debug.core.DebugException; -import org.eclipse.debug.core.DebugPlugin; -import org.eclipse.debug.core.model.IRegister; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.Node; - -/** - * Represents a group of registers. - */ -public class CRegisterGroup extends CDebugElement implements IPersistableRegisterGroup, IEnableDisableTarget { - - private static final String ELEMENT_REGISTER_GROUP = "registerGroup"; //$NON-NLS-1$ - private static final String ATTR_REGISTER_GROUP_NAME = "name"; //$NON-NLS-1$ - private static final String ATTR_REGISTER_GROUP_ENABLED = "enabled"; //$NON-NLS-1$ - - private static final String ELEMENT_REGISTER = "register"; //$NON-NLS-1$ - private static final String ATTR_REGISTER_NAME = "name"; //$NON-NLS-1$ - private static final String ATTR_REGISTER_ORIGINAL_GROUP_NAME = "originalGroupName"; //$NON-NLS-1$ - - private String fName; - - private IRegisterDescriptor[] fRegisterDescriptors; - - private IRegister[] fRegisters; - - private boolean fIsEnabled = true; - - private boolean fDisposed = false; - - /** - * Constructor for CRegisterGroup. - */ - public CRegisterGroup( CDebugTarget target ) { - super( target ); - } - - /** - * Constructor for CRegisterGroup. - */ - public CRegisterGroup( CDebugTarget target, String name, IRegisterDescriptor[] descriptors ) { - super( target ); - fName = name; - fRegisterDescriptors = descriptors; - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.IRegisterGroup#getName() - */ - @Override - public String getName() throws DebugException { - return fName; - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.IRegisterGroup#getRegisters() - */ - @Override - public IRegister[] getRegisters() throws DebugException { - if ( fDisposed ) - return new IRegister[0]; - if ( fRegisters == null ) { - synchronized( this ) { - if ( fRegisters == null ) { - fRegisters = new IRegister[fRegisterDescriptors.length]; - for( int i = 0; i < fRegisters.length; ++i ) { - fRegisters[i] = new CRegister( this, fRegisterDescriptors[i] ); - } - } - } - } - return fRegisters; - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.IRegisterGroup#hasRegisters() - */ - @Override - public boolean hasRegisters() throws DebugException { - return ( fRegisterDescriptors.length > 0 ); - } - - public void dispose() { - fDisposed = true; - invalidate(); - } - - public void targetSuspended() { - if ( fRegisters == null ) { - return; - } - for ( int i = 0; i < fRegisters.length; ++i ) { - if ( fRegisters[i] != null && ((CRegister)fRegisters[i]).hasErrors() ) { - ((CRegister)fRegisters[i]).resetStatus(); - } - } - } - - /* (non-Javadoc) - * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class) - */ - @Override - public Object getAdapter( Class adapter ) { - if ( IEnableDisableTarget.class.equals( adapter ) ) - return this; - return super.getAdapter( adapter ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.IEnableDisableTarget#canEnableDisable() - */ - @Override - public boolean canEnableDisable() { - return true; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.IEnableDisableTarget#isEnabled() - */ - @Override - public boolean isEnabled() { - return fIsEnabled; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.IEnableDisableTarget#setEnabled(boolean) - */ - @Override - public void setEnabled( boolean enabled ) throws DebugException { - if ( fRegisters != null ) { - synchronized( fRegisters ) { - if ( fRegisters != null ) { - for ( int i = 0; i < fRegisters.length; ++i ) { - if ( fRegisters[i] instanceof CRegister ) { - ((CRegister)fRegisters[i]).setEnabled( enabled ); - } - } - } - } - } - fIsEnabled = enabled; - fireChangeEvent( DebugEvent.CONTENT ); - } - - @Override - public String getMemento() throws CoreException { - Document document = DebugPlugin.newDocument(); - Element element = document.createElement( ELEMENT_REGISTER_GROUP ); - element.setAttribute( ATTR_REGISTER_GROUP_NAME, getName() ); - element.setAttribute( ATTR_REGISTER_GROUP_ENABLED, Boolean.valueOf( isEnabled() ).toString() ); - for ( int i = 0; i < fRegisterDescriptors.length; ++i ) { - Element child = document.createElement( ELEMENT_REGISTER ); - child.setAttribute( ATTR_REGISTER_NAME, fRegisterDescriptors[i].getName() ); - child.setAttribute( ATTR_REGISTER_ORIGINAL_GROUP_NAME, fRegisterDescriptors[i].getGroupName() ); - element.appendChild( child ); - } - document.appendChild( element ); - return DebugPlugin.serializeDocument( document ); - } - - @Override - public void initializeFromMemento( String memento ) throws CoreException { - Node node = DebugPlugin.parseDocument( memento ); - if ( node.getNodeType() != Node.ELEMENT_NODE ) { - abort( CoreModelMessages.getString( "CRegisterGroup.0" ), null ); //$NON-NLS-1$ - } - Element element = (Element)node; - if ( !ELEMENT_REGISTER_GROUP.equals( element.getNodeName() ) ) { - abort( CoreModelMessages.getString( "CRegisterGroup.1" ), null ); //$NON-NLS-1$ - } - String groupName = element.getAttribute( ATTR_REGISTER_GROUP_NAME ); - if ( groupName == null || groupName.length() == 0 ) { - abort( CoreModelMessages.getString( "CRegisterGroup.2" ), null ); //$NON-NLS-1$ - } - String e = element.getAttribute( ATTR_REGISTER_GROUP_ENABLED ); - boolean enabled = Boolean.valueOf( e ).booleanValue(); - CRegisterManager rm = getRegisterManager(); - ArrayList list = new ArrayList(); - Node childNode = element.getFirstChild(); - while( childNode != null ) { - if ( childNode.getNodeType() == Node.ELEMENT_NODE ) { - Element child = (Element)childNode; - if ( ELEMENT_REGISTER.equals( child.getNodeName() ) ) { - String name = child.getAttribute( ATTR_REGISTER_NAME ); - String originalGroupName = child.getAttribute( ATTR_REGISTER_ORIGINAL_GROUP_NAME ); - if ( name == null || name.length() == 0 || originalGroupName == null || originalGroupName.length() == 0 ) { - abort( CoreModelMessages.getString( "CRegisterGroup.3" ), null ); //$NON-NLS-1$ - } - else { - IRegisterDescriptor d = rm.findDescriptor( originalGroupName, name ); - if ( d != null ) - list.add( d ); - else - CDebugCorePlugin.log( CoreModelMessages.getString( "CRegisterGroup.4" ) ); //$NON-NLS-1$ - } - } - } - childNode = childNode.getNextSibling(); - } - setName( groupName ); - fRegisterDescriptors = (IRegisterDescriptor[])list.toArray( new IRegisterDescriptor[list.size()] ); - setEnabled( enabled ); - } - - private void abort( String message, Throwable exception ) throws CoreException { - IStatus status = new Status( IStatus.ERROR, CDebugCorePlugin.getUniqueIdentifier(), CDebugCorePlugin.INTERNAL_ERROR, message, exception ); - throw new CoreException( status ); - } - - private void setName( String name ) { - fName = name; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.IPersistableRegisterGroup#setRegisterDescriptors(org.eclipse.cdt.debug.core.model.IRegisterDescriptor[]) - */ - @Override - public void setRegisterDescriptors( IRegisterDescriptor[] registerDescriptors ) { - invalidate(); - fRegisterDescriptors = registerDescriptors; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.IPersistableRegisterGroup#getRegisterDescriptors() - */ - @Override - public IRegisterDescriptor[] getRegisterDescriptors() { - return fRegisterDescriptors; - } - - private CRegisterManager getRegisterManager() { - return getDebugTarget().getAdapter( CRegisterManager.class ); - } - - private void invalidate() { - if ( fRegisters == null ) { - return; - } - for ( int i = 0; i < fRegisters.length; ++i ) { - if ( fRegisters[i] != null ) { - ((CRegister)fRegisters[i]).dispose(); - } - } - fRegisters = null; - } - - public void resetRegisterValues() { - if ( fRegisters == null ) { - return; - } - for ( int i = 0; i < fRegisters.length; ++i ) { - if ( fRegisters[i] != null ) { - ((CRegister)fRegisters[i]).invalidateValue(); - } - } - } -} diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CSignal.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CSignal.java deleted file mode 100644 index 8732a75a1d6..00000000000 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CSignal.java +++ /dev/null @@ -1,148 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2012 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 - *******************************************************************************/ -package org.eclipse.cdt.debug.internal.core.model; - -import org.eclipse.cdt.debug.core.cdi.CDIException; -import org.eclipse.cdt.debug.core.cdi.event.ICDIEvent; -import org.eclipse.cdt.debug.core.cdi.event.ICDIEventListener; -import org.eclipse.cdt.debug.core.cdi.model.ICDISignal; -import org.eclipse.cdt.debug.core.model.ICSignal; -import org.eclipse.debug.core.DebugException; - -/** - * Enter type comment. - * - * @since: Jan 31, 2003 - */ -public class CSignal extends CDebugElement implements ICSignal, ICDIEventListener -{ - private ICDISignal fCDISignal; - - /** - * Constructor for CSignal. - * @param target - */ - public CSignal( CDebugTarget target, ICDISignal cdiSignal ) - { - super( target ); - fCDISignal = cdiSignal; - getCDISession().getEventManager().addEventListener( this ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.ICSignal#getDescription() - */ - @Override - public String getDescription() throws DebugException - { - return getCDISignal().getDescription(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.ICSignal#getName() - */ - @Override - public String getName() throws DebugException - { - return getCDISignal().getName(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.ICSignal#isPassEnabled() - */ - @Override - public boolean isPassEnabled() throws DebugException - { - return !getCDISignal().isIgnore(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.ICSignal#isStopEnabled() - */ - @Override - public boolean isStopEnabled() throws DebugException - { - return getCDISignal().isStopSet(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.ICSignal#setPassEnabled(boolean) - */ - @Override - public void setPassEnabled( boolean enable ) throws DebugException - { - handle( enable, isStopEnabled() ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.ICSignal#setStopEnabled(boolean) - */ - @Override - public void setStopEnabled( boolean enable ) throws DebugException - { - handle( isPassEnabled(), enable ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.cdi.event.ICDIEventListener#handleDebugEvents(ICDIEvent) - */ - @Override - public void handleDebugEvents( ICDIEvent[] events ) - { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.ICSignal#dispose() - */ - public void dispose() - { - getCDISession().getEventManager().removeEventListener( this ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.ICSignal#signal() - */ - @Override - public void signal() throws DebugException - { - try - { - getCDITarget().resume( getCDISignal() ); - } - catch( CDIException e ) - { - targetRequestFailed( e.getMessage(), null ); - } - } - - protected ICDISignal getCDISignal() - { - return fCDISignal; - } - - private void handle( boolean pass, boolean stop ) throws DebugException - { - try - { - getCDISignal().handle( !pass, stop ); - } - catch( CDIException e ) - { - targetRequestFailed( e.getMessage(), null ); - } - } - - @Override - public boolean canModify() { - // TODO add canModify method to ICDISignal - return true; - } -} diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CStackFrame.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CStackFrame.java deleted file mode 100644 index ea38ed259fa..00000000000 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CStackFrame.java +++ /dev/null @@ -1,1049 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2015 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 - *******************************************************************************/ -package org.eclipse.cdt.debug.internal.core.model; - -import java.math.BigInteger; -import com.ibm.icu.text.MessageFormat; -import com.ibm.icu.text.NumberFormat; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.cdt.core.IAddress; -import org.eclipse.cdt.core.IAddressFactory; -import org.eclipse.cdt.debug.core.cdi.CDIException; -import org.eclipse.cdt.debug.core.cdi.ICDILocation; -import org.eclipse.cdt.debug.core.cdi.ICDILocator; -import org.eclipse.cdt.debug.core.cdi.event.ICDIEvent; -import org.eclipse.cdt.debug.core.cdi.event.ICDIEventListener; -import org.eclipse.cdt.debug.core.cdi.model.ICDIDisposable; -import org.eclipse.cdt.debug.core.cdi.model.ICDIExecuteMoveInstructionPointer; -import org.eclipse.cdt.debug.core.cdi.model.ICDIExecuteResume; -import org.eclipse.cdt.debug.core.cdi.model.ICDIExpression; -import org.eclipse.cdt.debug.core.cdi.model.ICDIStackFrame; -import org.eclipse.cdt.debug.core.cdi.model.ICDIThread; -import org.eclipse.cdt.debug.core.cdi.model.ICDIVariableDescriptor; -import org.eclipse.cdt.debug.core.model.ICGlobalVariable; -import org.eclipse.cdt.debug.core.model.ICStackFrame; -import org.eclipse.cdt.debug.core.model.IMoveToAddress; -import org.eclipse.cdt.debug.core.model.IMoveToLine; -import org.eclipse.cdt.debug.core.model.IRestart; -import org.eclipse.cdt.debug.core.model.IResumeAtAddress; -import org.eclipse.cdt.debug.core.model.IResumeAtLine; -import org.eclipse.cdt.debug.core.model.IResumeWithoutSignal; -import org.eclipse.cdt.debug.core.model.IRunToAddress; -import org.eclipse.cdt.debug.core.model.IRunToLine; -import org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocator; -import org.eclipse.cdt.debug.internal.core.CGlobalVariableManager; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.debug.core.DebugException; -import org.eclipse.debug.core.model.IMemoryBlockRetrieval; -import org.eclipse.debug.core.model.IRegisterGroup; -import org.eclipse.debug.core.model.ISourceLocator; -import org.eclipse.debug.core.model.IStackFrame; -import org.eclipse.debug.core.model.IThread; -import org.eclipse.debug.core.model.IValue; -import org.eclipse.debug.core.model.IVariable; - -/** - * Proxy to a stack frame on the target. - */ -public class CStackFrame extends CDebugElement implements ICStackFrame, IRestart, IResumeWithoutSignal, IMoveToAddress, IMoveToLine, ICDIEventListener { - - /** - * Underlying CDI stack frame. - */ - private ICDIStackFrame fCDIStackFrame; - - /** - * The last (previous) CDI stack frame. - */ - private ICDIStackFrame fLastCDIStackFrame; - - /** - * Containing thread. - */ - private CThread fThread; - - /** - * List of visible variable (includes arguments). - */ - private List fVariables; - - /** - * Whether the variables need refreshing - */ - private boolean fRefreshVariables = true; - - /** - * List of watch expressions evaluating in the context of this frame. - */ - private List fExpressions; - - /** - * Need this flag to prevent evaluations on disposed frames. - */ - private boolean fIsDisposed = false; - - /** - * Constructor for CStackFrame. - */ - public CStackFrame( CThread thread, ICDIStackFrame cdiFrame ) { - super( (CDebugTarget)thread.getDebugTarget() ); - setCDIStackFrame( cdiFrame ); - setThread( thread ); - getCDISession().getEventManager().addEventListener( this ); - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.IStackFrame#getThread() - */ - @Override - public IThread getThread() { - return fThread; - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.IStackFrame#getVariables() - */ - @Override - public IVariable[] getVariables() throws DebugException { - if ( isDisposed() ) { - return new IVariable[0]; - } - ICGlobalVariable[] globals = getGlobals(); - List vars = getVariables0(); - List all = new ArrayList( globals.length + vars.size() ); - all.addAll( Arrays.asList( globals ) ); - all.addAll( vars ); - return (IVariable[])all.toArray( new IVariable[all.size()] ); - } - - protected synchronized List getVariables0() throws DebugException { - if ( isDisposed() ) { - return Collections.EMPTY_LIST; - } - CThread thread = (CThread)getThread(); - if ( thread.isSuspended() ) { - if ( fVariables == null ) { - List vars = getAllCDIVariableObjects(); - fVariables = new ArrayList( vars.size() ); - Iterator it = vars.iterator(); - while( it.hasNext() ) { - fVariables.add( CVariableFactory.createLocalVariable( this, (ICDIVariableDescriptor)it.next() ) ); - } - } - else if ( refreshVariables() ) { - updateVariables(); - } - setRefreshVariables( false ); - } - return ( fVariables != null ) ? fVariables : Collections.EMPTY_LIST; - } - - /** - * Incrementally updates this stack frame's variables. - */ - protected void updateVariables() throws DebugException { - List locals = getAllCDIVariableObjects(); - Iterator<CVariable> it = fVariables.iterator(); - while (it.hasNext()) { - CVariable var = it.next(); - ICDIVariableDescriptor varObject = findVariable(locals, var); - if (varObject != null && !var.isDisposed()) - locals.remove(varObject); - else { - // ensure variable is unregistered from event listener - var.dispose(); - it.remove(); - } - } - // add any new locals - Iterator newOnes = locals.iterator(); - while( newOnes.hasNext() ) { - fVariables.add( CVariableFactory.createLocalVariable( this, (ICDIVariableDescriptor)newOnes.next() ) ); - } - } - - /** - * Sets the containing thread. - * - * @param thread the containing thread - */ - protected void setThread( CThread thread ) { - fThread = thread; - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.IStackFrame#hasVariables() - */ - @Override - public boolean hasVariables() throws DebugException { - return ( isDisposed() ) ? false : (getVariables0().size() > 0 || getGlobals().length > 0); - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.IStackFrame#getLineNumber() - */ - @Override - public int getLineNumber() throws DebugException { - if ( isSuspended() ) { - ISourceLocator locator = ((CDebugTarget)getDebugTarget()).getSourceLocator(); - if ( locator != null && locator instanceof IAdaptable && ((IAdaptable)locator).getAdapter( ICSourceLocator.class ) != null ) - return ((IAdaptable)locator).getAdapter( ICSourceLocator.class ).getLineNumber( this ); - - final ICDIStackFrame cdiFrame = getCDIStackFrame(); - if ( cdiFrame != null && cdiFrame.getLocator() != null ) - return cdiFrame.getLocator().getLineNumber(); - } - return -1; - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.IStackFrame#getCharStart() - */ - @Override - public int getCharStart() throws DebugException { - return -1; - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.IStackFrame#getCharEnd() - */ - @Override - public int getCharEnd() throws DebugException { - return -1; - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.IStackFrame#getName() - */ - @Override - public String getName() throws DebugException { - final ICDIStackFrame cdiFrame = getCDIStackFrame(); - if (cdiFrame == null) { - return ""; //$NON-NLS-1$ - } - - ICDILocator locator = cdiFrame.getLocator(); - String func = ""; //$NON-NLS-1$ - String file = ""; //$NON-NLS-1$ - String line = ""; //$NON-NLS-1$ - if ( locator.getFunction() != null && locator.getFunction().trim().length() > 0 ) - func += locator.getFunction() + "() "; //$NON-NLS-1$ - if ( locator.getFile() != null && locator.getFile().trim().length() > 0 ) { - file = locator.getFile(); - if ( locator.getLineNumber() != 0 ) { - line = NumberFormat.getInstance().format( new Integer( locator.getLineNumber() ) ); - } - } - else { - return func; - } - return MessageFormat.format( CoreModelMessages.getString( "CStackFrame.0" ), new String[]{ func, file, line } ); //$NON-NLS-1$ - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.IStackFrame#getRegisterGroups() - */ - @Override - public IRegisterGroup[] getRegisterGroups() throws DebugException { - return ( isDisposed() ) ? new IRegisterGroup[0] : ((CDebugTarget)getDebugTarget()).getRegisterGroups( this ); - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.IStackFrame#hasRegisterGroups() - */ - @Override - public boolean hasRegisterGroups() throws DebugException { - return ( isDisposed() ) ? false : ((CDebugTarget)getDebugTarget()).getRegisterGroups( this ).length > 0; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.cdi.event.ICDIEventListener#handleDebugEvents(org.eclipse.cdt.debug.core.cdi.event.ICDIEvent[]) - */ - @Override - public void handleDebugEvents( ICDIEvent[] events ) { - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.IStep#canStepInto() - */ - @Override - public boolean canStepInto() { - try { - return exists() /*&& isTopStackFrame()*/ && getThread().canStepInto(); - } - catch( DebugException e ) { - logError( e ); - return false; - } - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.IStep#canStepOver() - */ - @Override - public boolean canStepOver() { - try { - return exists() && getThread().canStepOver(); - } - catch( DebugException e ) { - logError( e ); - } - return false; - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.IStep#canStepReturn() - */ - @Override - public boolean canStepReturn() { - try { - if ( !exists() ) { - return false; - } - List frames = ((CThread)getThread()).computeStackFrames(); - if ( frames != null && !frames.isEmpty() ) { - boolean bottomFrame = this.equals( frames.get( frames.size() - 1 ) ); - return !bottomFrame && getThread().canStepReturn(); - } - } - catch( DebugException e ) { - logError( e ); - } - return false; - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.IStep#isStepping() - */ - @Override - public boolean isStepping() { - return getThread().isStepping(); - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.IStep#stepInto() - */ - @Override - public void stepInto() throws DebugException { - if ( canStepInto() ) { - getThread().stepInto(); - } - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.IStep#stepOver() - */ - @Override - public void stepOver() throws DebugException { - if ( canStepOver() ) { - getThread().stepOver(); - } - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.IStep#stepReturn() - */ - @Override - public void stepReturn() throws DebugException { - if ( canStepReturn() ) { - getThread().stepReturn(); - } - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.ISuspendResume#canResume() - */ - @Override - public boolean canResume() { - return getThread().canResume(); - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.ISuspendResume#canSuspend() - */ - @Override - public boolean canSuspend() { - return getThread().canSuspend(); - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.ISuspendResume#isSuspended() - */ - @Override - public boolean isSuspended() { - return getThread().isSuspended(); - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.ISuspendResume#resume() - */ - @Override - public void resume() throws DebugException { - getThread().resume(); - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.ISuspendResume#suspend() - */ - @Override - public void suspend() throws DebugException { - getThread().suspend(); - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.ITerminate#canTerminate() - */ - @Override - public boolean canTerminate() { - boolean exists = false; - try { - exists = exists(); - } - catch( DebugException e ) { - logError( e ); - } - return exists && getThread().canTerminate() || getDebugTarget().canTerminate(); - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.ITerminate#isTerminated() - */ - @Override - public boolean isTerminated() { - return getThread().isTerminated(); - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.ITerminate#terminate() - */ - @Override - public void terminate() throws DebugException { - if ( getThread().canTerminate() ) { - getThread().terminate(); - } - else { - getDebugTarget().terminate(); - } - } - - /** - * Returns the underlying CDI stack frame that this model object is a proxy to. - * - * @return the underlying CDI stack frame - */ - protected ICDIStackFrame getCDIStackFrame() { - return fCDIStackFrame; - } - - /** - * Sets the underlying CDI stack frame. Called by a thread when incrementally updating after a step has completed. - * - * @param frame the underlying stack frame - */ - protected void setCDIStackFrame( ICDIStackFrame frame ) { - if ( frame != null ) { - fLastCDIStackFrame = frame; - } - else { - fLastCDIStackFrame = fCDIStackFrame; - } - fCDIStackFrame = frame; - setRefreshVariables( true ); - } - - /** - * The underlying stack frame that existed before the current underlying stack frame. Used only so that equality can be checked on stack frame after the new - * one has been set. - */ - protected ICDIStackFrame getLastCDIStackFrame() { - return fLastCDIStackFrame; - } - - /** - * Helper method for computeStackFrames(). For the purposes of detecting if an underlying stack frame needs to be disposed, stack frames are equal if the - * frames are equal and the locations are equal. - */ - protected static boolean equalFrame( ICDIStackFrame frameOne, ICDIStackFrame frameTwo ) { - if ( frameOne == null || frameTwo == null ) - return false; - ICDILocator loc1 = frameOne.getLocator(); - ICDILocator loc2 = frameTwo.getLocator(); - if ( loc1 == null || loc2 == null ) - return false; - if ( loc1.getFile() != null && loc1.getFile().length() > 0 && loc2.getFile() != null && loc2.getFile().length() > 0 && loc1.getFile().equals( loc2.getFile() ) ) { - if ( loc1.getFunction() != null && loc1.getFunction().length() > 0 && loc2.getFunction() != null && loc2.getFunction().length() > 0 && loc1.getFunction().equals( loc2.getFunction() ) ) - return true; - } - if ( (loc1.getFile() == null || loc1.getFile().length() < 1) && (loc2.getFile() == null || loc2.getFile().length() < 1) ) { - if ( loc1.getFunction() != null && loc1.getFunction().length() > 0 && loc2.getFunction() != null && loc2.getFunction().length() > 0 && loc1.getFunction().equals( loc2.getFunction() ) ) - return true; - } - if ( (loc1.getFile() == null || loc1.getFile().length() < 1) && (loc2.getFile() == null || loc2.getFile().length() < 1) && (loc1.getFunction() == null || loc1.getFunction().length() < 1) && (loc2.getFunction() == null || loc2.getFunction().length() < 1) ) { - if ( loc1.getAddress() == loc2.getAddress() ) - return true; - } - return false; - } - - protected boolean exists() throws DebugException { - return ((CThread)getThread()).computeStackFrames().indexOf( this ) != -1; - } - - /** - * @see IAdaptable#getAdapter(Class) - */ - @Override - public Object getAdapter( Class adapter ) { - if ( adapter == IRunToLine.class ) { - return this; - } - if ( adapter == IRunToAddress.class ) { - return this; - } - if ( adapter == IResumeAtLine.class ) { - return this; - } - if ( adapter == IResumeAtAddress.class ) { - return this; - } - if ( adapter == IMoveToLine.class ) { - return this; - } - if ( adapter == IMoveToAddress.class ) { - return this; - } - if ( adapter == CStackFrame.class ) { - return this; - } - if ( adapter == ICStackFrame.class ) { - return this; - } - if ( adapter == IStackFrame.class ) { - return this; - } - if ( adapter == ICDIStackFrame.class ) { - return getCDIStackFrame(); - } - if ( adapter == IMemoryBlockRetrieval.class ) { - return getDebugTarget().getAdapter( adapter ); - } - return super.getAdapter( adapter ); - } - - protected void dispose() { - setDisposed( true ); - getCDISession().getEventManager().removeEventListener( this ); - disposeAllVariables(); - disposeExpressions(); - - final ICDIStackFrame cdiFrame = getCDIStackFrame(); - setCDIStackFrame(null); - if (cdiFrame instanceof ICDIDisposable) { - ((ICDIDisposable)cdiFrame).dispose(); - } - } - - /** - * Retrieves local variables in this stack frame. Returns an empty list if there are no local variables. - * - */ - protected List getCDILocalVariableObjects() throws DebugException { - List list = new ArrayList(); - try { - final ICDIStackFrame cdiFrame = getCDIStackFrame(); - if (cdiFrame != null) { - list.addAll( Arrays.asList( cdiFrame.getLocalVariableDescriptors( ) ) ); - } - } - catch( CDIException e ) { - targetRequestFailed( e.getMessage(), null ); - } - return list; - } - - /** - * Retrieves arguments in this stack frame. Returns an empty list if there are no arguments. - * - */ - protected List getCDIArgumentObjects() throws DebugException { - List list = new ArrayList(); - try { - final ICDIStackFrame cdiFrame = getCDIStackFrame(); - if (cdiFrame != null) { - list.addAll( Arrays.asList( cdiFrame.getArgumentDescriptors() ) ); - } - } - catch( CDIException e ) { - targetRequestFailed( e.getMessage(), null ); - } - return list; - } - - protected List getAllCDIVariableObjects() throws DebugException { - List list = new ArrayList(); - list.addAll( getCDIArgumentObjects() ); - list.addAll( getCDILocalVariableObjects() ); - return list; - } - - protected boolean isTopStackFrame() throws DebugException { - IStackFrame tos = getThread().getTopStackFrame(); - return tos != null && tos.equals( this ); - } - - protected void disposeAllVariables() { - if ( fVariables == null ) - return; - Iterator it = fVariables.iterator(); - while( it.hasNext() ) { - ((CVariable)it.next()).dispose(); - } - fVariables.clear(); - fVariables = null; - } - - protected void disposeExpressions() { - if ( fExpressions != null ) { - Iterator it = fExpressions.iterator(); - while( it.hasNext() ) { - ((CExpression)it.next()).dispose(); - } - fExpressions.clear(); - } - fExpressions = null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.ICStackFrame#getAddress() - */ - @Override - public IAddress getAddress() { - IAddressFactory factory = ((CDebugTarget)getDebugTarget()).getAddressFactory(); - final ICDIStackFrame cdiFrame = getCDIStackFrame(); - return cdiFrame != null ? factory.createAddress( cdiFrame.getLocator().getAddress() ) : null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.ICStackFrame#getFile() - */ - @Override - public String getFile() { - final ICDIStackFrame cdiFrame = getCDIStackFrame(); - return cdiFrame != null ? cdiFrame.getLocator().getFile() : ""; //$NON-NLS-1$ - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.ICStackFrame#getFunction() - */ - @Override - public String getFunction() { - final ICDIStackFrame cdiFrame = getCDIStackFrame(); - return cdiFrame != null ? cdiFrame.getLocator().getFunction() : ""; //$NON-NLS-1$ - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.ICStackFrame#getLevel() - */ - @Override - public int getLevel() { - final ICDIStackFrame cdiFrame = getCDIStackFrame(); - return cdiFrame != null ? cdiFrame.getLevel() : -1; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.ICStackFrame#getFrameLineNumber() - */ - @Override - public int getFrameLineNumber() { - final ICDIStackFrame cdiFrame = getCDIStackFrame(); - return cdiFrame != null ? cdiFrame.getLocator().getLineNumber() : -1; - } - - protected synchronized void preserve() { - preserveVariables(); - preserveExpressions(); - } - - private void preserveVariables() { - if ( fVariables == null ) - return; - Iterator it = fVariables.iterator(); - while( it.hasNext() ) { - AbstractCVariable av = (AbstractCVariable)it.next(); - av.preserve(); - } - } - - private void preserveExpressions() { - if ( fExpressions == null ) - return; - Iterator it = fExpressions.iterator(); - while( it.hasNext() ) { - CExpression exp = (CExpression)it.next(); - exp.preserve(); - } - } - - protected ICDIVariableDescriptor findVariable( List list, CVariable var ) { - Iterator it = list.iterator(); - while( it.hasNext() ) { - ICDIVariableDescriptor newVarObject = (ICDIVariableDescriptor)it.next(); - if ( var.sameVariable( newVarObject ) ) - return newVarObject; - } - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.IRestart#canRestart() - */ - @Override - public boolean canRestart() { - return getDebugTarget() instanceof IRestart && ((IRestart)getDebugTarget()).canRestart(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.IRestart#restart() - */ - @Override - public void restart() throws DebugException { - if ( canRestart() ) { - ((IRestart)getDebugTarget()).restart(); - } - } - - public void setRefreshVariables( boolean refresh ) { - fRefreshVariables = refresh; - } - - private boolean refreshVariables() { - return fRefreshVariables; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.IResumeWithoutSignal#canResumeWithoutSignal() - */ - @Override - public boolean canResumeWithoutSignal() { - return (getDebugTarget() instanceof IResumeWithoutSignal && ((IResumeWithoutSignal)getDebugTarget()).canResumeWithoutSignal()); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.IResumeWithoutSignal#resumeWithoutSignal() - */ - @Override - public void resumeWithoutSignal() throws DebugException { - if ( canResumeWithoutSignal() ) { - ((IResumeWithoutSignal)getDebugTarget()).resumeWithoutSignal(); - } - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.ICStackFrame#evaluateExpression(java.lang.String) - */ - @Override - public IValue evaluateExpression( String expressionText ) throws DebugException { - if ( !isDisposed() ) { - CExpression expression = getExpression( expressionText ); - if ( expression != null ) { - return expression.getValue( this ); - } - } - return null; - } - - private ICGlobalVariable[] getGlobals() { - CGlobalVariableManager gvm = ((CDebugTarget)getDebugTarget()).getGlobalVariableManager(); - if ( gvm != null ) { - return gvm.getGlobals(); - } - return new ICGlobalVariable[0]; - } - - /* (non-Javadoc) - * @see java.lang.Object#toString() - */ - @Override - public String toString() { - try { - return getName(); - } - catch( DebugException e ) { - return e.getLocalizedMessage(); - } - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.ICStackFrame#evaluateExpressionToString(java.lang.String) - */ - @Override - public String evaluateExpressionToString( String expression ) throws DebugException { - try { - final ICDIStackFrame cdiFrame = getCDIStackFrame(); - if (cdiFrame != null) { - return getCDITarget().evaluateExpressionToString( cdiFrame, expression ); - } - } - catch( CDIException e ) { - targetRequestFailed( e.getMessage(), null ); - } - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.ICStackFrame#canEvaluate() - */ - @Override - public boolean canEvaluate() { - CDebugTarget target = ((CDebugTarget)getDebugTarget()); - return target.supportsExpressionEvaluation() && isSuspended(); - } - - protected void doStepReturn() throws DebugException { - try { - final ICDIStackFrame cdiFrame = getCDIStackFrame(); - if (cdiFrame != null) { - cdiFrame.stepReturn(); - } - } - catch( CDIException e ) { - targetRequestFailed( e.getMessage(), null ); - } - } - - private synchronized CExpression getExpression( String expressionText ) throws DebugException { - if ( isDisposed() ) { - return null; - } - if ( fExpressions == null ) { - fExpressions = new ArrayList( 5 ); - } - CExpression expression = null; - Iterator it = fExpressions.iterator(); - while( it.hasNext() ) { - expression = (CExpression)it.next(); - if ( expression.getExpressionText().compareTo( expressionText ) == 0 ) { - return expression; - } - } - try { - ICDIExpression cdiExpression = ((CDebugTarget)getDebugTarget()).getCDITarget().createExpression( expressionText ); - expression = new CExpression( this, cdiExpression, null ); - fExpressions.add( expression ); - } - catch( CDIException e ) { - targetRequestFailed( e.getMessage(), null ); - } - return expression; - } - - protected boolean isDisposed() { - return fIsDisposed; - } - - private synchronized void setDisposed( boolean isDisposed ) { - fIsDisposed = isDisposed; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.IRunToLine#canRunToLine(org.eclipse.core.resources.IFile, int) - */ - @Override - public boolean canRunToLine( IFile file, int lineNumber ) { - return ((CThread)getThread()).canRunToLine( file, lineNumber ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.IRunToLine#runToLine(org.eclipse.core.resources.IFile, int, boolean) - */ - @Override - public void runToLine( IFile file, int lineNumber, boolean skipBreakpoints ) throws DebugException { - if ( !canRunToLine( file, lineNumber ) ) - return; - ((CThread)getThread()).runToLine( file, lineNumber, skipBreakpoints ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.IRunToLine#canRunToLine(java.lang.String, int) - */ - @Override - public boolean canRunToLine( String fileName, int lineNumber ) { - return ((CThread)getThread()).canRunToLine( fileName, lineNumber ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.IRunToLine#runToLine(java.lang.String, int, boolean) - */ - @Override - public void runToLine( String fileName, int lineNumber, boolean skipBreakpoints ) throws DebugException { - if ( !canRunToLine( fileName, lineNumber ) ) - return; - ((CThread)getThread()).runToLine( fileName, lineNumber, skipBreakpoints ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.IRunToAddress#canRunToAddress(org.eclipse.cdt.core.IAddress) - */ - @Override - public boolean canRunToAddress( IAddress address ) { - return getThread().canResume(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.IRunToAddress#runToAddress(org.eclipse.cdt.core.IAddress, boolean) - */ - @Override - public void runToAddress( IAddress address, boolean skipBreakpoints ) throws DebugException { - if ( !canRunToAddress( address ) ) - return; - if ( skipBreakpoints ) { - ((CDebugTarget)getDebugTarget()).skipBreakpoints( true ); - } - ICDILocation location = getCDITarget().createAddressLocation( new BigInteger( address.toString() ) ); - try { - getCDIThread().stepUntil( location ); - } - catch( CDIException e ) { - if ( skipBreakpoints ) { - ((CDebugTarget)getDebugTarget()).skipBreakpoints( false ); - } - targetRequestFailed( e.getMessage(), e ); - } - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.IResumeAtLine#canResumeAtLine(org.eclipse.core.resources.IFile, int) - */ - @Override - public boolean canResumeAtLine( IFile file, int lineNumber ) { - return getThread().canResume(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.IResumeAtLine#resumeAtLine(org.eclipse.core.resources.IFile, int) - */ - @Override - public void resumeAtLine( IFile file, int lineNumber ) throws DebugException { - if ( !canResumeAtLine( file, lineNumber ) ) - return; - resumeAtLine( file.getLocation().lastSegment(), lineNumber ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.IResumeAtLine#canResumeAtLine(java.lang.String, int) - */ - @Override - public boolean canResumeAtLine( String fileName, int lineNumber ) { - return getThread().canResume(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.IResumeAtLine#resumeAtLine(java.lang.String, int) - */ - @Override - public void resumeAtLine( String fileName, int lineNumber ) throws DebugException { - if ( !canResumeAtLine( fileName, lineNumber ) ) - return; - - ICDILocation location = getCDITarget().createLineLocation( fileName, lineNumber ); - try { - ICDIExecuteResume resumer = getCDIThread(); - resumer.resume(location); - } - catch( CDIException e ) { - targetRequestFailed( e.getMessage(), e ); - } - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.IResumeAtAddress#canResumeAtAddress(org.eclipse.cdt.core.IAddress) - */ - @Override - public boolean canResumeAtAddress( IAddress address ) { - return getThread().canResume(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.IResumeAtAddress#resumeAtAddress(org.eclipse.cdt.core.IAddress) - */ - @Override - public void resumeAtAddress( IAddress address ) throws DebugException { - if ( !canResumeAtAddress( address ) ) - return; - ICDILocation location = getCDITarget().createAddressLocation( new BigInteger( address.toString() ) ); - try { - getCDIThread().resume( location ); - } - catch( CDIException e ) { - targetRequestFailed( e.getMessage(), e ); - } - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.IMoveToAddress#canMoveToAddress(org.eclipse.cdt.core.IAddress) - */ - @Override - public boolean canMoveToAddress(IAddress address) { - return getThread().isSuspended() && (getCDIThread() instanceof ICDIExecuteMoveInstructionPointer); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.IMoveToAddress#moveToAddress(org.eclipse.cdt.core.IAddress) - */ - @Override - public void moveToAddress(IAddress address) throws DebugException { - if ( !canMoveToAddress( address ) ) - return; - ICDILocation location = getCDITarget().createAddressLocation( new BigInteger( address.toString() ) ); - ICDIExecuteMoveInstructionPointer mover = (ICDIExecuteMoveInstructionPointer)getCDIThread(); - try { - mover.moveInstructionPointer( location); - } - catch( CDIException e ) { - targetRequestFailed( e.getMessage(), e ); - } - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.IMoveToLine#canMoveToLine(java.lang.String, int) - */ - @Override - public boolean canMoveToLine(String fileName, int lineNumber) { - return getThread().isSuspended() && (getCDIThread() instanceof ICDIExecuteMoveInstructionPointer); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.IMoveToLine#moveToLine(java.lang.String, int) - */ - @Override - public void moveToLine(String fileName, int lineNumber) throws DebugException { - if ( !canMoveToLine( fileName, lineNumber ) ) - return; - ICDILocation location= getCDITarget().createLineLocation( fileName, lineNumber ); - ICDIExecuteMoveInstructionPointer mover = (ICDIExecuteMoveInstructionPointer)getCDIThread(); - try { - mover.moveInstructionPointer( location ); - } - catch( CDIException e ) { - targetRequestFailed( e.getMessage(), e ); - } - } - - private ICDIThread getCDIThread() { - return ((CThread)getThread()).getCDIThread(); - } -} diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CThread.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CThread.java deleted file mode 100644 index 726c3bfeddd..00000000000 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CThread.java +++ /dev/null @@ -1,1101 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2015 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 - * Stefan Bylund (Enea, steby@enea.se) - patch for bug 155464 - * Ken Ryall (Nokia) - Support for breakpoint actions (bug 118308) - * Ling Wang (Nokia) - Bug 176077 - * Denis Pilat (ST) - Bug 205017 - *******************************************************************************/ -package org.eclipse.cdt.debug.internal.core.model; - -import com.ibm.icu.text.MessageFormat; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.cdt.debug.core.CDebugCorePlugin; -import org.eclipse.cdt.debug.core.cdi.CDIException; -import org.eclipse.cdt.debug.core.cdi.ICDIBreakpointHit; -import org.eclipse.cdt.debug.core.cdi.ICDIEndSteppingRange; -import org.eclipse.cdt.debug.core.cdi.ICDILocation; -import org.eclipse.cdt.debug.core.cdi.ICDISessionObject; -import org.eclipse.cdt.debug.core.cdi.ICDISignalReceived; -import org.eclipse.cdt.debug.core.cdi.ICDIWatchpointTrigger; -import org.eclipse.cdt.debug.core.cdi.event.ICDIChangedEvent; -import org.eclipse.cdt.debug.core.cdi.event.ICDIDestroyedEvent; -import org.eclipse.cdt.debug.core.cdi.event.ICDIDisconnectedEvent; -import org.eclipse.cdt.debug.core.cdi.event.ICDIEvent; -import org.eclipse.cdt.debug.core.cdi.event.ICDIEventListener; -import org.eclipse.cdt.debug.core.cdi.event.ICDIResumedEvent; -import org.eclipse.cdt.debug.core.cdi.event.ICDISuspendedEvent; -import org.eclipse.cdt.debug.core.cdi.model.ICDIDisposable; -import org.eclipse.cdt.debug.core.cdi.model.ICDIObject; -import org.eclipse.cdt.debug.core.cdi.model.ICDIStackFrame; -import org.eclipse.cdt.debug.core.cdi.model.ICDITargetConfiguration; -import org.eclipse.cdt.debug.core.cdi.model.ICDITargetConfiguration2; -import org.eclipse.cdt.debug.core.cdi.model.ICDIThread; -import org.eclipse.cdt.debug.core.model.CDebugElementState; -import org.eclipse.cdt.debug.core.model.ICDebugElementStatus; -import org.eclipse.cdt.debug.core.model.ICStackFrame; -import org.eclipse.cdt.debug.core.model.ICThread; -import org.eclipse.cdt.debug.core.model.IDummyStackFrame; -import org.eclipse.cdt.debug.core.model.IMoveToAddress; -import org.eclipse.cdt.debug.core.model.IMoveToLine; -import org.eclipse.cdt.debug.core.model.IRestart; -import org.eclipse.cdt.debug.core.model.IResumeAtAddress; -import org.eclipse.cdt.debug.core.model.IResumeAtLine; -import org.eclipse.cdt.debug.core.model.IResumeWithoutSignal; -import org.eclipse.cdt.debug.core.model.IRunToAddress; -import org.eclipse.cdt.debug.core.model.IRunToLine; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.debug.core.DebugEvent; -import org.eclipse.debug.core.DebugException; -import org.eclipse.debug.core.model.IBreakpoint; -import org.eclipse.debug.core.model.IMemoryBlockRetrieval; -import org.eclipse.debug.core.model.IStackFrame; - -/** - * A thread in a C/C++ debug model. - */ -public class CThread extends CDebugElement implements ICThread, IRestart, IResumeWithoutSignal, ICDIEventListener { - - private final static int MAX_STACK_DEPTH = 100; - - /** - * Underlying CDI thread. - */ - private ICDIThread fCDIThread; - - /** - * Collection of stack frames - */ - private ArrayList fStackFrames; - - /** - * Whether children need to be refreshed. Set to <code>true</code> when stack frames are re-used on the next suspend. - */ - private boolean fRefreshChildren = true; - - /** - * The debug configuration of this session. - */ - private ICDITargetConfiguration fConfig; - - /** - * Whether this thread is current. - */ - private boolean fIsCurrent = false; - - /** - * The depth of the current stack. - */ - private int fLastStackDepth = 0; - - /** - * Whether this thread is disposed. - */ - private boolean fDisposed = false; - - /** - * Constructor for CThread. - */ - public CThread( CDebugTarget target, ICDIThread cdiThread ) { - super( target ); - setState( cdiThread.isSuspended() ? CDebugElementState.SUSPENDED : CDebugElementState.RESUMED ); - setCDIThread( cdiThread ); - fConfig = getCDITarget().getConfiguration(); - initialize(); - getCDISession().getEventManager().addEventListener( this ); - } - - protected void initialize() { - fStackFrames = new ArrayList(); - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.IThread#getStackFrames() - */ - @Override - public IStackFrame[] getStackFrames() throws DebugException { - List list = Collections.EMPTY_LIST; - try { - list = computeStackFrames(); - } - catch( DebugException e ) { - setStatus( ICDebugElementStatus.ERROR, e.getStatus().getMessage() ); - throw e; - } - return (IStackFrame[])list.toArray( new IStackFrame[list.size()] ); - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.IThread#hasStackFrames() - */ - @Override - public boolean hasStackFrames() throws DebugException { - // Always return true to postpone the stack frames request. - // But not if the thread is already resumed. This fixes flickering in the Debug View. - if (getState().equals( CDebugElementState.RESUMED )) - return false; - - return true; - } - - /** - * @see computeStackFrames() - * - * @param refreshChildren whether or not this method should request new stack frames from the target - */ - protected synchronized List computeStackFrames( boolean refreshChildren ) throws DebugException { - if ( isSuspended() ) { - if ( isTerminated() ) { - fStackFrames = new ArrayList(); - } - else if ( refreshChildren ) { - // Remove dummy frame - if ( fStackFrames.size() > 0 ) { - Object frame = fStackFrames.get( fStackFrames.size() - 1 ); - if ( frame instanceof IDummyStackFrame ) { - fStackFrames.remove( frame ); - } - } - // Retrieve stack frames from the backend - int depth = getStackDepth(); - if ( depth >= getMaxStackDepth() ) - depth = getMaxStackDepth() - 1; - ICDIStackFrame[] frames = ( depth != 0 ) ? getCDIStackFrames( 0, depth - 1 ) : new ICDIStackFrame[0]; - - // Safety precaution in case getting the stack frames failed to get us as many as it said - depth = frames.length; - - if ( fStackFrames.isEmpty() ) { - if ( frames.length > 0 ) { - addStackFrames( frames, 0, frames.length, false ); - } - } - else { - int diff = depth - getLastStackDepth(); - int offset = ( diff > 0 ) ? frames.length - diff : 0; - int length = ( diff > 0 ) ? diff : -diff; - if (offset < 0 || !compareStackFrames( frames, fStackFrames, offset, length ) ) { - // replace all frames - disposeStackFrames( 0, fStackFrames.size() ); - addStackFrames( frames, 0, frames.length, false ); - } - if ( diff < 0 ) { - // stepping out of the last frame - disposeStackFrames( 0, getLastStackDepth() - depth ); - if ( frames.length > 0 ) { - updateStackFrames( frames, 0, fStackFrames, fStackFrames.size() ); - if ( fStackFrames.size() < frames.length ) { - addStackFrames( frames, fStackFrames.size(), frames.length - fStackFrames.size(), true ); - } - } - } - else if ( diff > 0 ) { - // stepping into a new frame - disposeStackFrames( frames.length - depth + getLastStackDepth(), depth - getLastStackDepth() ); - addStackFrames( frames, 0, depth - getLastStackDepth(), false ); - updateStackFrames( frames, depth - getLastStackDepth(), fStackFrames, frames.length - depth + getLastStackDepth() ); - } - else { // diff == 0 - if ( depth != 0 ) { - // we are in the same frame - updateStackFrames( frames, 0, fStackFrames, frames.length ); - } - } - } - if ( depth > getMaxStackDepth() ) { - fStackFrames.add( new CDummyStackFrame( this ) ); - } - setLastStackDepth( depth ); - setRefreshChildren( false ); - } - } - return fStackFrames; - } - - /** - * Compares the lists of the old and new frames. - * - * @param newFrames the array of the new frames - * @param oldFrames the list of the old frames - * @param offset the offset in the new frames array - * @param length the number of frames to compare - * - * @return <code>true</code> if all frames are same - */ - private boolean compareStackFrames( ICDIStackFrame[] newFrames, List oldFrames, int offset, int length ) { - if (offset<0) return false; - int index = offset; - Iterator it = oldFrames.iterator(); - while( it.hasNext() && index < newFrames.length ) { - CStackFrame frame = (CStackFrame)it.next(); - if ( !frame.getCDIStackFrame().equals( newFrames[index++] ) ) - return false; - } - return true; - } - - /** - * Retrieves and returns all underlying stack frames - * - * @return list of <code>StackFrame</code> - * @exception DebugException if this method fails. Reasons include: - * <ul> - * </ul> - */ - protected ICDIStackFrame[] getCDIStackFrames() throws DebugException { - return new ICDIStackFrame[0]; - } - - /** - * Retrieves and returns underlying stack frames between <code>lowFrame<code/> - * and <code>highFrame<code/>. - * - * @return list of <code>StackFrame</code> - * @exception DebugException if this method fails. Reasons include: - * <ul> - * </ul> - */ - protected ICDIStackFrame[] getCDIStackFrames( int lowFrame, int highFrame ) throws DebugException { - try { - final ICDIThread cdiThread = getCDIThread(); - if (cdiThread != null) { - return cdiThread.getStackFrames( lowFrame, highFrame ); - } - } - catch( CDIException e ) { - setStatus( ICDebugElementStatus.WARNING, MessageFormat.format( CoreModelMessages.getString( "CThread.0" ), new String[]{ e.getMessage() } ) ); //$NON-NLS-1$ - targetRequestFailed( e.getMessage(), null ); - } - return new ICDIStackFrame[0]; - } - - /** - * Replaces the underlying stack frame objects in the preserved frames list with the current underlying stack frames. - * - * @param newFrames list of current underlying <code>ICDIStackFrame</code>s. Frames from this list are assigned to the underlying frames in the - * <code>oldFrames</code> list. - * @param offset the offset in the lists at which to start replacing the old underlying frames - * @param oldFrames list of preserved frames, of type <code>CStackFrame</code> - * @param length the number of frames to replace - */ - protected void updateStackFrames( ICDIStackFrame[] newFrames, int offset, List oldFrames, int length ) throws DebugException { - for( int i = 0; i < length; i++ ) { - CStackFrame frame = (CStackFrame)oldFrames.get( offset ); - frame.setCDIStackFrame( newFrames[offset] ); - offset++; - } - } - - protected void addStackFrames( ICDIStackFrame[] newFrames, int startIndex, int length, boolean append ) { - if ( newFrames.length >= startIndex + length ) { - for( int i = 0; i < length; ++i ) { - if ( append ) - fStackFrames.add( new CStackFrame( this, newFrames[startIndex + i] ) ); - else - fStackFrames.add( i, new CStackFrame( this, newFrames[startIndex + i] ) ); - } - } - } - - /** - * Returns this thread's current stack frames as a list, computing them if required. Returns an empty collection if this thread is not currently suspended, - * or this thread is terminated. This method should be used internally to get the current stack frames, instead of calling <code>#getStackFrames()</code>, - * which makes a copy of the current list. - * <p> - * Before a thread is resumed a call must be made to one of: - * <ul> - * <li><code>preserveStackFrames()</code></li> - * <li><code>disposeStackFrames()</code></li> - * </ul> - * If stack frames are disposed before a thread is resumed, stack frames are completely re-computed on the next call to this method. If stack frames are to - * be preserved, this method will attempt to re-use any stack frame objects which represent the same stack frame as on the previous suspend. Stack frames - * are cached until a subsequent call to preserve or dispose stack frames. - * </p> - * - * @return list of <code>IStackFrame</code> - * @exception DebugException if this method fails. Reasons include: - * <ul> - * </ul> - */ - public synchronized List computeStackFrames() throws DebugException { - return computeStackFrames( refreshChildren() ); - } - - /** - * @see CThread#computeStackFrames() - * - * This method differs from computeStackFrames() in that it always requests new stack frames from the target. As this is an expensive operation, this method - * should only be used by clients who know for certain that the stack frames on the target have changed. - */ - public List computeNewStackFrames() throws DebugException { - return computeStackFrames( true ); - } - - /** - * Helper method for <code>#computeStackFrames()</code> to create all underlying stack frames. - * - * @exception DebugException if this method fails. Reasons include: - * <ul> - * </ul> - */ - protected List createAllStackFrames( int depth, ICDIStackFrame[] frames ) throws DebugException { - List list = new ArrayList( frames.length ); - for( int i = 0; i < frames.length; ++i ) { - list.add( new CStackFrame( this, frames[i] ) ); - } - if ( depth > frames.length ) { - list.add( new CDummyStackFrame( this ) ); - } - return list; - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.IThread#getPriority() - */ - @Override - public int getPriority() throws DebugException { - return 0; - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.IThread#getTopStackFrame() - */ - @Override - public IStackFrame getTopStackFrame() throws DebugException { - List c = computeStackFrames(); - return (c.isEmpty()) ? null : (IStackFrame)c.get( 0 ); - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.IThread#getName() - */ - @Override - public String getName() throws DebugException { - final ICDIThread cdiThread = getCDIThread(); - return cdiThread != null ? cdiThread.toString() : ""; //$NON-NLS-1$ - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.IThread#getBreakpoints() - */ - @Override - public IBreakpoint[] getBreakpoints() { - List list = new ArrayList( 1 ); - if ( isSuspended() ) { - IBreakpoint bkpt = null; - if ( getCurrentStateInfo() instanceof ICDIBreakpointHit ) - bkpt = ((CDebugTarget)getDebugTarget()).getBreakpointManager().getBreakpoint( ((ICDIBreakpointHit)getCurrentStateInfo()).getBreakpoint() ); - else if ( getCurrentStateInfo() instanceof ICDIWatchpointTrigger ) - bkpt = ((CDebugTarget)getDebugTarget()).getBreakpointManager().getBreakpoint( ((ICDIWatchpointTrigger)getCurrentStateInfo()).getWatchpoint() ); - if ( bkpt != null ) - list.add( bkpt ); - } - return (IBreakpoint[])list.toArray( new IBreakpoint[list.size()] ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.cdi.event.ICDIEventListener#handleDebugEvents(org.eclipse.cdt.debug.core.cdi.event.ICDIEvent[]) - */ - @Override - public void handleDebugEvents( ICDIEvent[] events ) { - if ( isDisposed() ) - return; - for( int i = 0; i < events.length; i++ ) { - ICDIEvent event = events[i]; - ICDIObject source = event.getSource(); - final ICDIThread cdiThread = getCDIThread(); - if ( source instanceof ICDIThread && cdiThread != null && source.equals( cdiThread ) ) { - if ( event instanceof ICDISuspendedEvent ) { - handleSuspendedEvent( (ICDISuspendedEvent)event ); - } - else if ( event instanceof ICDIResumedEvent ) { - handleResumedEvent( (ICDIResumedEvent)event ); - } - else if ( event instanceof ICDIDestroyedEvent ) { - handleTerminatedEvent( (ICDIDestroyedEvent)event ); - } - else if ( event instanceof ICDIDisconnectedEvent ) { - handleDisconnectedEvent( (ICDIDisconnectedEvent)event ); - } - else if ( event instanceof ICDIChangedEvent ) { - handleChangedEvent( (ICDIChangedEvent)event ); - } - } - } - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.ISuspendResume#canResume() - */ - @Override - public boolean canResume() { - return ( fConfig.supportsResume() && isSuspended() ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.IRunToLine#canRunToLine(org.eclipse.core.resources.IFile, int) - */ - @Override - public boolean canRunToLine( IFile file, int lineNumber ) { - return canRunToLine( file.getLocation().lastSegment(), lineNumber ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.IRunToLine#canRunToLine(java.lang.String, int) - */ - @Override - public boolean canRunToLine( String fileName, int lineNumber ) { - return canResume(); - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.ISuspendResume#canSuspend() - */ - @Override - public boolean canSuspend() { - CDebugElementState state = getState(); - return ( fConfig.supportsSuspend() && (state.equals( CDebugElementState.RESUMED ) || state.equals( CDebugElementState.STEPPED )) ); - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.ISuspendResume#isSuspended() - */ - @Override - public boolean isSuspended() { - return getState().equals( CDebugElementState.SUSPENDED ); - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.ISuspendResume#resume() - */ - @Override - public void resume() throws DebugException { - if ( !canResume() ) - return; - CDebugElementState oldState = getState(); - setState( CDebugElementState.RESUMING ); - try { - final ICDIThread cdiThread = getCDIThread(); - if (cdiThread != null) { - cdiThread.resume( false ); - } - } - catch( CDIException e ) { - setState( oldState ); - targetRequestFailed( e.getMessage(), null ); - } - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.IRunToLine#runToLine(org.eclipse.core.resources.IFile, int, boolean) - */ - @Override - public void runToLine( IFile file, int lineNumber, boolean skipBreakpoints ) throws DebugException { - runToLine( file.getLocation().lastSegment(), lineNumber, skipBreakpoints ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.IRunToLine#runToLine(java.lang.String, int, boolean) - */ - @Override - public void runToLine( String fileName, int lineNumber, boolean skipBreakpoints ) throws DebugException { - if ( !canRunToLine( fileName, lineNumber ) ) - return; - if ( skipBreakpoints ) { - ((CDebugTarget)getDebugTarget()).skipBreakpoints( true ); - } - CDebugElementState oldState = getState(); - setState( CDebugElementState.RESUMING ); - ICDILocation location = getCDITarget().createLineLocation( fileName, lineNumber ); - - try { - final ICDIThread cdiThread = getCDIThread(); - if (cdiThread != null) { - cdiThread.stepUntil( location ); - } - } - catch( CDIException e ) { - setState( oldState ); - if ( skipBreakpoints ) { - ((CDebugTarget)getDebugTarget()).skipBreakpoints( false ); - } - targetRequestFailed( e.getMessage(), e ); - } - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.ISuspendResume#suspend() - */ - @Override - public void suspend() throws DebugException { - if ( !canSuspend() ) - return; - CDebugElementState oldState = getState(); - setState( CDebugElementState.SUSPENDING ); - try { - final ICDIThread cdiThread = getCDIThread(); - if (cdiThread != null) { - cdiThread.suspend(); - } - } - catch( CDIException e ) { - setState( oldState ); - targetRequestFailed( e.getMessage(), null ); - } - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.IStep#canStepInto() - */ - @Override - public boolean canStepInto() { - return canStep(); - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.IStep#canStepOver() - */ - @Override - public boolean canStepOver() { - return canStep(); - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.IStep#canStepReturn() - */ - @Override - public boolean canStepReturn() { - if ( !fConfig.supportsStepping() || !canResume() ) { - return false; - } - return ( fStackFrames.size() > 1 ); - } - - /** - * Returns whether this thread is in a valid state to step. - * - * @return whether this thread is in a valid state to step - */ - protected boolean canStep() { - if ( !fConfig.supportsStepping() || !isSuspended() ) { - return false; - } - return !fStackFrames.isEmpty(); - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.IStep#isStepping() - */ - @Override - public boolean isStepping() { - return ( getState().equals( CDebugElementState.STEPPING ) ) || ( getState().equals( CDebugElementState.STEPPED ) ); - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.IStep#stepInto() - */ - @Override - public void stepInto() throws DebugException { - if ( !canStepInto() ) - return; - CDebugElementState oldState = getState(); - setState( CDebugElementState.STEPPING ); - try { - final ICDIThread cdiThread = getCDIThread(); - if (cdiThread != null) { - if ( !isInstructionsteppingEnabled() ) { - cdiThread.stepInto( 1 ); - } - else { - cdiThread.stepIntoInstruction( 1 ); - } - } - } - catch( CDIException e ) { - setState( oldState ); - targetRequestFailed( e.getMessage(), null ); - } - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.IStep#stepOver() - */ - @Override - public void stepOver() throws DebugException { - if ( !canStepOver() ) - return; - CDebugElementState oldState = getState(); - setState( CDebugElementState.STEPPING ); - try { - final ICDIThread cdiThread = getCDIThread(); - if (cdiThread != null) { - if ( !isInstructionsteppingEnabled() ) { - cdiThread.stepOver( 1 ); - } - else { - cdiThread.stepOverInstruction( 1 ); - } - } - } - catch( CDIException e ) { - setState( oldState ); - targetRequestFailed( e.getMessage(), null ); - } - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.IStep#stepReturn() - */ - @Override - public void stepReturn() throws DebugException { - if ( !canStepReturn() ) - return; - IStackFrame[] frames = getStackFrames(); - if ( frames.length == 0 ) - return; - CStackFrame f = (CStackFrame)frames[0]; - CDebugElementState oldState = getState(); - setState( CDebugElementState.STEPPING ); - try { - f.doStepReturn(); - } - catch( DebugException e ) { - setState( oldState ); - throw e; - } - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.ITerminate#canTerminate() - */ - @Override - public boolean canTerminate() { - return getDebugTarget().canTerminate(); - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.ITerminate#isTerminated() - */ - @Override - public boolean isTerminated() { - return getDebugTarget().isTerminated(); - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.ITerminate#terminate() - */ - @Override - public void terminate() throws DebugException { - getDebugTarget().terminate(); - } - - /** - * Sets the underlying CDI thread that this model object is a proxy to. - * - * @param thread the underlying CDI thread - */ - protected void setCDIThread( ICDIThread cdiThread ) { - fCDIThread = cdiThread; - } - - /** - * Returns the underlying CDI thread that this model object is a proxy to. - * - * @return the underlying CDI thread - */ - protected ICDIThread getCDIThread() { - return fCDIThread; - } - - /** - * Preserves stack frames to be used on the next suspend event. Iterates through all current stack frames, setting their state as invalid. This method - * should be called before this thread is resumed, when stack frames are to be re-used when it later suspends. - * - * @see computeStackFrames() - */ - protected synchronized void preserveStackFrames() { - Iterator it = fStackFrames.iterator(); - while( it.hasNext() ) { - CStackFrame frame = (((IAdaptable)it.next()).getAdapter( CStackFrame.class )); - if ( frame != null ) { - frame.preserve(); - } - } - setRefreshChildren( true ); - } - - /** - * Disposes stack frames, to be completely re-computed on the next suspend event. This method should be called before this thread is resumed when stack - * frames are not to be re-used on the next suspend. - */ - protected synchronized void disposeStackFrames() { - Iterator it = fStackFrames.iterator(); - while( it.hasNext() ) { - Object obj = it.next(); - if ( obj instanceof CStackFrame ) { - ((CStackFrame)obj).dispose(); - } - } - fStackFrames.clear(); - setLastStackDepth( 0 ); - resetStatus(); - setRefreshChildren( true ); - } - - protected void disposeStackFrames( int index, int length ) { - List removeList = new ArrayList( length ); - Iterator it = fStackFrames.iterator(); - int counter = 0; - while( it.hasNext() ) { - CStackFrame frame = (((IAdaptable)it.next()).getAdapter( CStackFrame.class )); - if ( frame != null && counter >= index && counter < index + length ) { - frame.dispose(); - removeList.add( frame ); - } - ++counter; - } - fStackFrames.removeAll( removeList ); - } - - /** - * Notification this thread has terminated - update state and fire a terminate event. - */ - protected void terminated() { - setState( CDebugElementState.TERMINATED ); - dispose(); - } - - private void handleSuspendedEvent( ICDISuspendedEvent event ) { - if ( !(getState().equals( CDebugElementState.RESUMED ) || - getState().equals( CDebugElementState.STEPPED ) || - getState().equals( CDebugElementState.SUSPENDING )) ) - return; - setState( CDebugElementState.SUSPENDED ); - ICDISessionObject reason = event.getReason(); - setCurrentStateInfo( reason ); - if ( reason instanceof ICDIEndSteppingRange ) { - handleEndSteppingRange( (ICDIEndSteppingRange)reason ); - } - else if ( reason instanceof ICDIBreakpointHit ) { - handleBreakpointHit( (ICDIBreakpointHit)reason ); - } - else if ( reason instanceof ICDISignalReceived ) { - handleSuspendedBySignal( (ICDISignalReceived)reason ); - } - else { - // fireSuspendEvent( DebugEvent.CLIENT_REQUEST ); - // Temporary fix for bug 56520 - fireSuspendEvent( DebugEvent.BREAKPOINT ); - } - } - - private void handleResumedEvent( ICDIResumedEvent event ) { - CDebugElementState state = CDebugElementState.RESUMED; - int detail = DebugEvent.RESUME; - syncWithBackend(); - if ( isCurrent() && event.getType() != ICDIResumedEvent.CONTINUE ) { - preserveStackFrames(); - switch( event.getType() ) { - case ICDIResumedEvent.STEP_INTO: - case ICDIResumedEvent.STEP_INTO_INSTRUCTION: - detail = DebugEvent.STEP_INTO; - break; - case ICDIResumedEvent.STEP_OVER: - case ICDIResumedEvent.STEP_OVER_INSTRUCTION: - detail = DebugEvent.STEP_OVER; - break; - case ICDIResumedEvent.STEP_RETURN: - detail = DebugEvent.STEP_RETURN; - break; - } - state = CDebugElementState.STEPPED; - } - else { - disposeStackFrames(); - fireChangeEvent( DebugEvent.CONTENT ); - } - setCurrent( false ); - setState( state ); - setCurrentStateInfo( null ); - fireResumeEvent( detail ); - } - - private void handleEndSteppingRange( ICDIEndSteppingRange endSteppingRange ) { - fireSuspendEvent( DebugEvent.STEP_END ); - } - - private void handleBreakpointHit( ICDIBreakpointHit breakpointHit ) { - IBreakpoint platformBreakpoint = ((CDebugTarget)getDebugTarget()).getBreakpointManager().getBreakpoint(breakpointHit.getBreakpoint()); - if (platformBreakpoint != null) - CDebugCorePlugin.getDefault().getBreakpointActionManager().executeActions(platformBreakpoint, this); - fireSuspendEvent( DebugEvent.BREAKPOINT ); - } - - private void handleWatchpointHit( ICDIWatchpointTrigger watchPointTrigger ) { - IBreakpoint platformBreakpoint = ((CDebugTarget)getDebugTarget()).getBreakpointManager().getBreakpoint(watchPointTrigger.getWatchpoint()); - if (platformBreakpoint != null) - CDebugCorePlugin.getDefault().getBreakpointActionManager().executeActions(platformBreakpoint, this); - fireSuspendEvent( DebugEvent.BREAKPOINT ); - } - - private void handleSuspendedBySignal( ICDISignalReceived signal ) { - fireSuspendEvent( DebugEvent.CLIENT_REQUEST ); - } - - private void handleTerminatedEvent( ICDIDestroyedEvent event ) { - setState( CDebugElementState.TERMINATED ); - setCurrentStateInfo( null ); - terminated(); - } - - private void handleDisconnectedEvent( ICDIDisconnectedEvent event ) { - setState( CDebugElementState.TERMINATED ); - setCurrentStateInfo( null ); - terminated(); - } - - private void handleChangedEvent( ICDIChangedEvent event ) { - } - - /** - * Cleans up the internal state of this thread. - */ - protected void cleanup() { - getCDISession().getEventManager().removeEventListener( this ); - disposeStackFrames(); - - final ICDIThread cdiThread = getCDIThread(); - setCDIThread(null); - if (cdiThread instanceof ICDIDisposable) { - ((ICDIDisposable)cdiThread).dispose(); - } - } - - private void setRefreshChildren( boolean refresh ) { - fRefreshChildren = refresh; - } - - private boolean refreshChildren() { - return fRefreshChildren; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.IRestart#canRestart() - */ - @Override - public boolean canRestart() { - return getDebugTarget() instanceof IRestart && ((IRestart)getDebugTarget()).canRestart(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.IRestart#restart() - */ - @Override - public void restart() throws DebugException { - if ( canRestart() ) { - ((IRestart)getDebugTarget()).restart(); - } - } - - protected boolean isCurrent() { - return fIsCurrent; - } - - protected void setCurrent( boolean current ) { - boolean c = current; - if ( !c ) { - if ( getCDITarget().getConfiguration() instanceof ICDITargetConfiguration2 - && ((ICDITargetConfiguration2)getCDITarget().getConfiguration()).supportsThreadControl() ) - c = true; // When the debugger can control individual - // threads treat every thread is "current" - } - fIsCurrent = c; - } - - protected int getStackDepth() throws DebugException { - int depth = 0; - try { - final ICDIThread cdiThread = getCDIThread(); - if (cdiThread != null) { - depth = cdiThread.getStackFrameCount(); - } - } - catch( CDIException e ) { - setStatus( ICDebugElementStatus.WARNING, MessageFormat.format( CoreModelMessages.getString( "CThread.1" ), new String[]{ e.getMessage() } ) ); //$NON-NLS-1$ - } - return depth; - } - - protected int getMaxStackDepth() { - return MAX_STACK_DEPTH; - } - - private void setLastStackDepth( int depth ) { - fLastStackDepth = depth; - } - - protected int getLastStackDepth() { - return fLastStackDepth; - } - - /* (non-Javadoc) - * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class) - */ - @Override - public Object getAdapter( Class adapter ) { - if ( adapter.equals( IRunToLine.class ) || - adapter.equals( IRunToAddress.class ) || - adapter.equals( IResumeAtLine.class ) || - adapter.equals( IResumeAtAddress.class ) || - adapter.equals( IMoveToLine.class ) || - adapter.equals( IMoveToAddress.class ) ) { - try { - // Alain: Put a proper fix later. - Object obj = getTopStackFrame(); - if (obj instanceof ICStackFrame) { - return obj; - } - } - catch( DebugException e ) { - // do nothing - } - } - if ( adapter.equals( CDebugElementState.class ) ) - return this; - if ( adapter == ICStackFrame.class ) { - try { - // Alain: Put a proper fix later. - Object obj = getTopStackFrame(); - if (obj instanceof ICStackFrame) { - return obj; - } - } - catch( DebugException e ) { - // do nothing - } - } - if ( adapter == IMemoryBlockRetrieval.class ) { - return getDebugTarget().getAdapter( adapter ); - } - if ( adapter == ICDIThread.class ) { - return getCDIThread(); - } - return super.getAdapter( adapter ); - } - - protected void dispose() { - fDisposed = true; - cleanup(); - } - - protected boolean isDisposed() { - return fDisposed; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.IResumeWithoutSignal#canResumeWithoutSignal() - */ - @Override - public boolean canResumeWithoutSignal() { - return (getDebugTarget() instanceof IResumeWithoutSignal && ((IResumeWithoutSignal)getDebugTarget()).canResumeWithoutSignal()); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.IResumeWithoutSignal#resumeWithoutSignal() - */ - @Override - public void resumeWithoutSignal() throws DebugException { - if ( canResumeWithoutSignal() ) { - ((IResumeWithoutSignal)getDebugTarget()).resumeWithoutSignal(); - } - } - - /* (non-Javadoc) - * @see java.lang.Object#toString() - */ - @Override - public String toString() { - String result = ""; //$NON-NLS-1$ - try { - result = getName(); - } - catch( DebugException e ) { - } - return result; - } - - protected void resumedByTarget( int detail, List events ) { - syncWithBackend(); - if ( isCurrent() && detail != DebugEvent.CLIENT_REQUEST && detail != DebugEvent.UNSPECIFIED ) { - setState( CDebugElementState.STEPPED ); - preserveStackFrames(); - events.add( createResumeEvent( detail ) ); - } - else { - setState( CDebugElementState.RESUMED ); - disposeStackFrames(); - // events.add( createResumeEvent( DebugEvent.CLIENT_REQUEST ) ); FIX FOR 218260 - } - setCurrent( false ); - setCurrentStateInfo( null ); - } - - protected boolean isInstructionsteppingEnabled() { - return ((CDebugTarget)getDebugTarget()).isInstructionSteppingEnabled(); - } - - protected void suspendByTarget( ICDISessionObject reason, ICDIThread suspensionThread ) { - setState( CDebugElementState.SUSPENDED ); - setCurrentStateInfo( null ); - final ICDIThread cdiThread = getCDIThread(); - if ( cdiThread != null && cdiThread.equals( suspensionThread ) ) { - setCurrent( true ); - setCurrentStateInfo( reason ); - if ( reason instanceof ICDIEndSteppingRange ) { - handleEndSteppingRange( (ICDIEndSteppingRange)reason ); - } - else if ( reason instanceof ICDIBreakpointHit ) { - handleBreakpointHit( (ICDIBreakpointHit)reason ); - } - else if ( reason instanceof ICDIWatchpointTrigger ) { - handleWatchpointHit( (ICDIWatchpointTrigger)reason ); - } - else if ( reason instanceof ICDISignalReceived ) { - handleSuspendedBySignal( (ICDISignalReceived)reason ); - } - else { - // fireSuspendEvent( DebugEvent.CLIENT_REQUEST ); - // Temporary fix for bug 56520 - fireSuspendEvent( DebugEvent.BREAKPOINT ); - } - } - } - - private void syncWithBackend() { - ICDIThread cdiThread = getCDIThread(); - if (cdiThread == null) { - return; - } - - ICDIThread currentThread = null; - try { - currentThread = cdiThread.getTarget().getCurrentThread(); - } - catch( CDIException e ) { - // ignore - } - setCurrent( cdiThread.equals( currentThread ) ); - } - -} diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CType.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CType.java deleted file mode 100644 index d85cbc4ec29..00000000000 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CType.java +++ /dev/null @@ -1,148 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2012 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 - *******************************************************************************/ -package org.eclipse.cdt.debug.internal.core.model; - -import org.eclipse.cdt.debug.core.cdi.model.type.ICDIArrayType; -import org.eclipse.cdt.debug.core.cdi.model.type.ICDICharType; -import org.eclipse.cdt.debug.core.cdi.model.type.ICDIDerivedType; -import org.eclipse.cdt.debug.core.cdi.model.type.ICDIFloatingPointType; -import org.eclipse.cdt.debug.core.cdi.model.type.ICDIIntegralType; -import org.eclipse.cdt.debug.core.cdi.model.type.ICDIPointerType; -import org.eclipse.cdt.debug.core.cdi.model.type.ICDIReferenceType; -import org.eclipse.cdt.debug.core.cdi.model.type.ICDIStructType; -import org.eclipse.cdt.debug.core.cdi.model.type.ICDIType; -import org.eclipse.cdt.debug.core.model.ICType; - -/** - * The CDI-based implementation of <code>ICType</code>. - */ -public class CType implements ICType { - - /** - * The underlying CDI type. - */ - private ICDIType fCDIType; - - /** - * Constructor for CType. - */ - public CType( ICDIType cdiType ) { - setCDIType( cdiType ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.ICType#getName() - */ - @Override - public String getName() { - return ( fCDIType != null ) ? fCDIType.getTypeName() : null; - } - - public void dispose() { - fCDIType = null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.ICType#getArrayDimensions() - */ - @Override - public int[] getArrayDimensions() { - int length = 0; - ICDIType type = getCDIType(); - while( type instanceof ICDIArrayType ) { - ++length; - type = ((ICDIDerivedType)type).getComponentType(); - } - int[] dims = new int[length]; - type = getCDIType(); - for (int i = 0; i < length; i++) { - dims[i] = ((ICDIArrayType)type).getDimension(); - type = ((ICDIDerivedType)type).getComponentType(); - } - return dims; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.ICType#isArray() - */ - @Override - public boolean isArray() { - return ( getCDIType() instanceof ICDIArrayType ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.ICType#isCharacter() - */ - @Override - public boolean isCharacter() { - return ( getCDIType() instanceof ICDICharType ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.ICType#isFloatingPointType() - */ - @Override - public boolean isFloatingPointType() { - return ( getCDIType() instanceof ICDIFloatingPointType ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.ICType#isPointer() - */ - @Override - public boolean isPointer() { - return ( getCDIType() instanceof ICDIPointerType ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.ICType#isReference() - */ - @Override - public boolean isReference() { - return ( getCDIType() instanceof ICDIReferenceType ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.ICType#isStructure() - */ - @Override - public boolean isStructure() { - return ( getCDIType() instanceof ICDIStructType ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.ICType#isUnsigned() - */ - @Override - public boolean isUnsigned() { - return ( isIntegralType() ) ? ((ICDIIntegralType)getCDIType()).isUnsigned() : false; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.ICType#isIntegralType() - */ - @Override - public boolean isIntegralType() { - return ( getCDIType() instanceof ICDIIntegralType ); - } - - protected ICDIType getCDIType() { - return fCDIType; - } - - protected void setCDIType( ICDIType type ) { - fCDIType = type; - } - - protected boolean isAggregate() { - return ( isArray() || isStructure() || isPointer() || isReference() ); - } -} diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CValue.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CValue.java deleted file mode 100644 index ffa02991cec..00000000000 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CValue.java +++ /dev/null @@ -1,846 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2012 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 - * Mark Mitchell, CodeSourcery - Bug 136896: View variables in binary format - * Warren Paul (Nokia) - 150860, 150864, 150862, 150863, 217493 - * Ken Ryall (Nokia) - 207675 - * Mathias Kunter - Support for octal number format (bug 370462) -*******************************************************************************/ -package org.eclipse.cdt.debug.internal.core.model; - -import java.math.BigInteger; -import java.nio.ByteBuffer; -import java.nio.charset.CharacterCodingException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import org.eclipse.cdt.core.IAddress; -import org.eclipse.cdt.core.IAddressFactory; -import org.eclipse.cdt.debug.core.CDebugUtils; -import org.eclipse.cdt.debug.core.cdi.CDIException; -import org.eclipse.cdt.debug.core.cdi.ICDIFormat; -import org.eclipse.cdt.debug.core.cdi.ICDIFormattable; -import org.eclipse.cdt.debug.core.cdi.model.ICDITargetConfiguration2; -import org.eclipse.cdt.debug.core.cdi.model.ICDIValue; -import org.eclipse.cdt.debug.core.cdi.model.ICDIVariable; -import org.eclipse.cdt.debug.core.cdi.model.type.ICDIBoolValue; -import org.eclipse.cdt.debug.core.cdi.model.type.ICDICharValue; -import org.eclipse.cdt.debug.core.cdi.model.type.ICDIDoubleValue; -import org.eclipse.cdt.debug.core.cdi.model.type.ICDIFloatValue; -import org.eclipse.cdt.debug.core.cdi.model.type.ICDIIntValue; -import org.eclipse.cdt.debug.core.cdi.model.type.ICDILongLongValue; -import org.eclipse.cdt.debug.core.cdi.model.type.ICDIBigIntegerValue; -import org.eclipse.cdt.debug.core.cdi.model.type.ICDILongValue; -import org.eclipse.cdt.debug.core.cdi.model.type.ICDIPointerValue; -import org.eclipse.cdt.debug.core.cdi.model.type.ICDIReferenceValue; -import org.eclipse.cdt.debug.core.cdi.model.type.ICDIShortValue; -import org.eclipse.cdt.debug.core.cdi.model.type.ICDIWCharValue; -import org.eclipse.cdt.debug.core.model.CVariableFormat; -import org.eclipse.cdt.debug.core.model.ICDebugElementStatus; -import org.eclipse.cdt.debug.core.model.ICStackFrame; -import org.eclipse.cdt.debug.core.model.ICType; -import org.eclipse.cdt.utils.Addr32; -import org.eclipse.cdt.utils.Addr64; -import org.eclipse.debug.core.DebugException; -import org.eclipse.debug.core.model.IVariable; - -/** - * Represents the value of a variable in the CDI model. - */ -public class CValue extends AbstractCValue { - /** - * Cached value. - */ - private String fValueString = null; - - /** - * Underlying CDI value. - */ - private ICDIValue fCDIValue; - - /** - * List of child variables. - */ - private List<AbstractCVariable> fVariables = new ArrayList<AbstractCVariable>(); - - private CType fType; - - /** - * Constructor for CValue. - */ - protected CValue( CVariable parent, ICDIValue cdiValue ) { - super( parent ); - fCDIValue = cdiValue; - } - - /** - * Constructor for CValue. - */ - protected CValue( CVariable parent, String message ) { - super( parent ); - setStatus( ICDebugElementStatus.ERROR, message ); - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.IValue#getReferenceTypeName() - */ - @Override - public String getReferenceTypeName() throws DebugException { - return ( getParentVariable() != null ) ? getParentVariable().getReferenceTypeName() : null; - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.IValue#getValueString() - */ - @Override - public String getValueString() throws DebugException { - if ( fValueString == null && getUnderlyingValue() != null ) { - resetStatus(); - ICStackFrame cframe = getParentVariable().getStackFrame(); - boolean isSuspended = (cframe == null) ? getCDITarget().isSuspended() : cframe.isSuspended(); - if ( isSuspended ) { - try { - fValueString = processUnderlyingValue( getUnderlyingValue() ); - } - catch( CDIException e ) { - setStatus( ICDebugElementStatus.ERROR, e.getMessage() ); - fValueString = e.getLocalizedMessage(); - } - } - } - return fValueString; - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.IValue#isAllocated() - */ - @Override - public boolean isAllocated() throws DebugException { - return true; - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.IValue#getVariables() - */ - @Override - public IVariable[] getVariables() throws DebugException { - List<AbstractCVariable> list = getVariables0(); - return list.toArray( new IVariable[list.size()] ); - } - - protected synchronized List<AbstractCVariable> getVariables0() throws DebugException { - if ( !isAllocated() || !hasVariables() ) - return new ArrayList<AbstractCVariable>(); - if ( fVariables.size() == 0 ) { - try { - List<ICDIVariable> vars = getCDIVariables(); - for (ICDIVariable var : vars) { - if (getParentVariable() instanceof CGlobalVariable) { - fVariables.add(CVariableFactory.createGlobalVariable( - this, - null, - var)); - } - else { - fVariables.add(CVariableFactory.createLocalVariable(this, var)); - } - } - resetStatus(); - } - catch( DebugException e ) { - setStatus( ICDebugElementStatus.ERROR, e.getMessage() ); - } - } - return fVariables; - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.IValue#hasVariables() - */ - @Override - public boolean hasVariables() throws DebugException { - try { - ICDIValue value = getUnderlyingValue(); - if ( value != null ) - return value.getChildrenNumber() > 0; - } - catch( CDIException e ) { - targetRequestFailed( e.getMessage(), null ); - } - return false; - } - - public ICDIValue getUnderlyingValue() { - return fCDIValue; - } - - protected List<ICDIVariable> getCDIVariables() throws DebugException { - ICDIVariable[] vars = null; - try { - ICDIValue value = getUnderlyingValue(); - if ( value != null ) { - vars = value.getVariables(); - } - } - catch( CDIException e ) { - requestFailed( e.getMessage(), e ); - } - - // getVariables should return an empty array instead of null. - if ( vars == null ) { - vars = new ICDIVariable[0]; - } - - return Arrays.asList( vars ); - } - - @Override - protected synchronized void setChanged( boolean changed ) { - if ( changed ) { - fValueString = null; - resetStatus(); - } - else { - if (getCDITarget().getConfiguration() instanceof ICDITargetConfiguration2 && - ((ICDITargetConfiguration2)getCDITarget().getConfiguration()).supportsPassiveVariableUpdate()) - fValueString = null; - } - - for (AbstractCVariable var : fVariables) { - var.setChanged( changed ); - } - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.internal.core.model.AbstractCValue#dispose() - */ - @Override - public void dispose() { - for (AbstractCVariable var : fVariables) { - var.dispose(); - } - } - - private String processUnderlyingValue( ICDIValue cdiValue ) throws CDIException { - if ( cdiValue != null ) { - if ( cdiValue instanceof ICDIBoolValue ) - return getBoolValueString( (ICDIBoolValue)cdiValue ); - if ( cdiValue instanceof ICDICharValue ) - return getCharValueString( (ICDICharValue)cdiValue ); - else if ( cdiValue instanceof ICDIShortValue ) - return getShortValueString( (ICDIShortValue)cdiValue ); - else if ( cdiValue instanceof ICDIIntValue ) - return getIntValueString( (ICDIIntValue)cdiValue ); - else if ( cdiValue instanceof ICDILongValue ) - return getLongValueString( (ICDILongValue)cdiValue ); - else if ( cdiValue instanceof ICDILongLongValue ) - return getLongLongValueString( (ICDILongLongValue)cdiValue ); - else if ( cdiValue instanceof ICDIBigIntegerValue ) - return getBigIntegerValueString( (ICDIBigIntegerValue)cdiValue ); - else if ( cdiValue instanceof ICDIFloatValue ) - return getFloatValueString( (ICDIFloatValue)cdiValue ); - else if ( cdiValue instanceof ICDIDoubleValue ) - return getDoubleValueString( (ICDIDoubleValue)cdiValue ); - else if ( cdiValue instanceof ICDIPointerValue ) - return getPointerValueString( (ICDIPointerValue)cdiValue ); - else if ( cdiValue instanceof ICDIReferenceValue ) - return processUnderlyingValue(((ICDIReferenceValue)cdiValue).referenceValue()); - else if ( cdiValue instanceof ICDIWCharValue ) - return getWCharValueString( (ICDIWCharValue)cdiValue ); - else - return getGenericValueString(cdiValue.getValueString()); - } - return null; - } - - private String getBoolValueString( ICDIBoolValue value ) throws CDIException { - CVariableFormat format = getParentVariable().getFormat(); - if ( CVariableFormat.NATURAL.equals( format ) ) { - short byteValue = value.shortValue(); - if (byteValue == 0) - return "false";//$NON-NLS-1$ - else if (byteValue == 1) - return "true";//$NON-NLS-1$ - else - return Integer.toString( value.shortValue() ); - } - else if ( CVariableFormat.DECIMAL.equals( format ) ) { - return Integer.toString( value.shortValue() ); - } - else if ( CVariableFormat.HEXADECIMAL.equals( format ) ) { - StringBuffer sb = new StringBuffer( "0x" ); //$NON-NLS-1$ - String stringValue = (isUnsigned()) ? Integer.toHexString( value.shortValue() ) : Integer.toHexString( (byte)value.byteValue() ); - sb.append( (stringValue.length() > 2) ? stringValue.substring( stringValue.length() - 2 ) : stringValue ); - return sb.toString(); - } - else if ( CVariableFormat.OCTAL.equals( format ) ) { - StringBuffer sb = new StringBuffer( "0" ); //$NON-NLS-1$ - String stringValue = (isUnsigned()) ? Integer.toOctalString( value.shortValue() ) : Integer.toOctalString( (byte)value.byteValue() ); - stringValue = (stringValue.length() > 3) ? stringValue.substring( stringValue.length() - 3 ) : stringValue; - sb.append( (stringValue.length() == 3 && stringValue.charAt( 0 ) >= '4') ? (char)(stringValue.charAt( 0 ) - 4) + stringValue.substring( 1 ) : stringValue ); - return sb.toString(); - } - else if ( CVariableFormat.BINARY.equals( format ) ) { - StringBuffer sb = new StringBuffer( "0b" ); //$NON-NLS-1$ - String stringValue = (isUnsigned()) ? Integer.toBinaryString( value.shortValue() ) : Integer.toBinaryString( (byte)value.byteValue() ); - sb.append( (stringValue.length() > 8) ? stringValue.substring( stringValue.length() - 8 ) : stringValue ); - return sb.toString(); - } - return null; - } - - private String getCharValueString( ICDICharValue value ) throws CDIException { - CVariableFormat format = getParentVariable().getFormat(); - if ( CVariableFormat.NATURAL.equals( format ) ) { - byte byteValue = (byte)value.byteValue(); - switch (byteValue) { - case '\b': - return "'\\b'"; //$NON-NLS-1$ - case '\t': - return "'\\t'"; //$NON-NLS-1$ - case '\n': - return "'\\n'"; //$NON-NLS-1$ - case '\f': - return "'\\f'"; //$NON-NLS-1$ - case '\r': - return "'\\r'"; //$NON-NLS-1$ - } - - if (Character.isISOControl(byteValue)) - return Byte.toString(byteValue); - else if (byteValue < 0) - return isUnsigned() ? Short.toString(value.shortValue()) : Byte.toString(byteValue); - - return new String( new byte[]{ '\'', byteValue, '\'' } ); - } - else if ( CVariableFormat.DECIMAL.equals( format ) ) { - return (isUnsigned()) ? Integer.toString( value.shortValue() ) : Integer.toString( (byte)value.byteValue() ); - } - else if ( CVariableFormat.HEXADECIMAL.equals( format ) ) { - StringBuffer sb = new StringBuffer( "0x" ); //$NON-NLS-1$ - String stringValue = (isUnsigned()) ? Integer.toHexString( value.shortValue() ) : Integer.toHexString( (byte)value.byteValue() ); - sb.append( (stringValue.length() > 2) ? stringValue.substring( stringValue.length() - 2 ) : stringValue ); - return sb.toString(); - } - else if ( CVariableFormat.OCTAL.equals( format ) ) { - StringBuffer sb = new StringBuffer( "0" ); //$NON-NLS-1$ - String stringValue = (isUnsigned()) ? Integer.toOctalString( value.shortValue() ) : Integer.toOctalString( (byte)value.byteValue() ); - stringValue = (stringValue.length() > 3) ? stringValue.substring( stringValue.length() - 3 ) : stringValue; - sb.append( (stringValue.length() == 3 && stringValue.charAt( 0 ) >= '4') ? (char)(stringValue.charAt( 0 ) - 4) + stringValue.substring( 1 ) : stringValue ); - return sb.toString(); - } - else if ( CVariableFormat.BINARY.equals( format ) ) { - StringBuffer sb = new StringBuffer( "0b" ); //$NON-NLS-1$ - String stringValue = (isUnsigned()) ? Integer.toBinaryString( value.shortValue() ) : Integer.toBinaryString( (byte)value.byteValue() ); - sb.append( (stringValue.length() > 8) ? stringValue.substring( stringValue.length() - 8 ) : stringValue ); - return sb.toString(); - } - return null; - } - - private String getShortValueString( ICDIShortValue value ) throws CDIException { - CVariableFormat format = getParentVariable().getFormat(); - - if (CVariableFormat.NATURAL.equals(format)) { - format = getNaturalFormat(value, CVariableFormat.DECIMAL); - } - - if ( CVariableFormat.DECIMAL.equals( format ) ) { - return (isUnsigned()) ? Integer.toString( value.intValue() ) : Short.toString( value.shortValue() ); - } - else if ( CVariableFormat.HEXADECIMAL.equals( format ) ) { - StringBuffer sb = new StringBuffer( "0x" ); //$NON-NLS-1$ - String stringValue = Integer.toHexString( (isUnsigned()) ? value.intValue() : value.shortValue() ); - sb.append( (stringValue.length() > 4) ? stringValue.substring( stringValue.length() - 4 ) : stringValue ); - return sb.toString(); - } - else if ( CVariableFormat.OCTAL.equals( format ) ) { - StringBuffer sb = new StringBuffer( "0" ); //$NON-NLS-1$ - String stringValue = Integer.toOctalString( (isUnsigned()) ? value.intValue() : value.shortValue() ); - stringValue = (stringValue.length() > 6) ? stringValue.substring( stringValue.length() - 6 ) : stringValue; - sb.append( (stringValue.length() == 6 && stringValue.charAt( 0 ) >= '2') ? (char)((stringValue.charAt( 0 ) - '0') % 2 + '0') + stringValue.substring( 1 ) : stringValue ); - return sb.toString(); - } - else if ( CVariableFormat.BINARY.equals( format ) ) { - StringBuffer sb = new StringBuffer( "0b" ); //$NON-NLS-1$ - String stringValue = Integer.toBinaryString( (isUnsigned()) ? value.intValue() : value.shortValue() ); - sb.append( (stringValue.length() > 16) ? stringValue.substring( stringValue.length() - 16 ) : stringValue ); - return sb.toString(); - } - return null; - } - - private String getIntValueString( ICDIIntValue value ) throws CDIException { - CVariableFormat format = getParentVariable().getFormat(); - - if (CVariableFormat.NATURAL.equals(format)) { - format = getNaturalFormat(value, CVariableFormat.DECIMAL); - } - - if ( CVariableFormat.DECIMAL.equals( format ) ) { - return (isUnsigned()) ? Long.toString( value.longValue() ) : Integer.toString( value.intValue() ); - } - else if ( CVariableFormat.HEXADECIMAL.equals( format ) ) { - StringBuffer sb = new StringBuffer( "0x" ); //$NON-NLS-1$ - String stringValue = (isUnsigned()) ? Long.toHexString( value.longValue() ) : Integer.toHexString( value.intValue() ); - sb.append( (stringValue.length() > 8) ? stringValue.substring( stringValue.length() - 8 ) : stringValue ); - return sb.toString(); - } - else if ( CVariableFormat.OCTAL.equals( format ) ) { - StringBuffer sb = new StringBuffer( "0" ); //$NON-NLS-1$ - String stringValue = (isUnsigned()) ? Long.toOctalString( value.longValue() ) : Integer.toOctalString( value.intValue() ); - stringValue = (stringValue.length() > 11) ? stringValue.substring( stringValue.length() - 11 ) : stringValue; - sb.append( (stringValue.length() == 11 && stringValue.charAt( 0 ) >= '4') ? (char)(stringValue.charAt( 0 ) - 4) + stringValue.substring( 1 ) : stringValue ); - return sb.toString(); - } - else if ( CVariableFormat.BINARY.equals( format ) ) { - StringBuffer sb = new StringBuffer( "0b" ); //$NON-NLS-1$ - String stringValue = (isUnsigned()) ? Long.toBinaryString( value.longValue() ) : Integer.toBinaryString( value.intValue() ); - sb.append( (stringValue.length() > 32) ? stringValue.substring( stringValue.length() - 32 ) : stringValue ); - return sb.toString(); - } - return null; - } - - private String getLongValueString( ICDILongValue value ) throws CDIException { - try { - CVariableFormat format = getParentVariable().getFormat(); - - if (CVariableFormat.NATURAL.equals(format)) { - format = getNaturalFormat(value, CVariableFormat.DECIMAL); - } - - if ( CVariableFormat.DECIMAL.equals( format ) ) { - if ( isUnsigned() ) { - BigInteger bigValue = new BigInteger( value.getValueString() ); - return bigValue.toString(); - } - return Integer.toString( value.intValue() ); - } - else if ( CVariableFormat.HEXADECIMAL.equals( format ) ) { - StringBuffer sb = new StringBuffer( "0x" ); //$NON-NLS-1$ - if ( isUnsigned() ) { - BigInteger bigValue = new BigInteger( value.getValueString() ); - sb.append( bigValue.toString( 16 ) ); - } - else - sb.append( Integer.toHexString( value.intValue() ) ); - return sb.toString(); - } - else if ( CVariableFormat.OCTAL.equals( format ) ) { - StringBuffer sb = new StringBuffer( "0" ); //$NON-NLS-1$ - if ( isUnsigned() ) { - BigInteger bigValue = new BigInteger( value.getValueString() ); - sb.append( bigValue.toString( 8 ) ); - } - else - sb.append( Integer.toOctalString( value.intValue() ) ); - return sb.toString(); - } - else if ( CVariableFormat.BINARY.equals( format ) ) { - StringBuffer sb = new StringBuffer( "0b" ); //$NON-NLS-1$ - if ( isUnsigned() ) { - BigInteger bigValue = new BigInteger( value.getValueString() ); - sb.append( bigValue.toString( 2 ) ); - } - else - sb.append( Integer.toBinaryString( value.intValue() ) ); - return sb.toString(); - } - } - catch( NumberFormatException e ) { - } - return null; - } - - private String getLongLongValueString( ICDILongLongValue value ) throws CDIException { - try { - CVariableFormat format = getParentVariable().getFormat(); - - if (CVariableFormat.NATURAL.equals(format)) { - format = getNaturalFormat(value, CVariableFormat.DECIMAL); - } - - if ( CVariableFormat.DECIMAL.equals( format ) ) { - if ( isUnsigned() ) { - BigInteger bigValue = new BigInteger( value.getValueString() ); - return bigValue.toString(); - } - return Long.toString( value.longValue() ); - } - else if ( CVariableFormat.HEXADECIMAL.equals( format ) ) { - StringBuffer sb = new StringBuffer( "0x" ); //$NON-NLS-1$ - if ( isUnsigned() ) { - BigInteger bigValue = new BigInteger( value.getValueString() ); - sb.append( bigValue.toString( 16 ) ); - } - else - sb.append( Long.toHexString( value.longValue() ) ); - return sb.toString(); - } - else if ( CVariableFormat.OCTAL.equals( format ) ) { - StringBuffer sb = new StringBuffer( "0" ); //$NON-NLS-1$ - if ( isUnsigned() ) { - BigInteger bigValue = new BigInteger( value.getValueString() ); - sb.append( bigValue.toString( 8 ) ); - } - else - sb.append( Long.toOctalString( value.longValue() ) ); - return sb.toString(); - } - else if ( CVariableFormat.BINARY.equals( format ) ) { - StringBuffer sb = new StringBuffer( "0b" ); //$NON-NLS-1$ - if ( isUnsigned() ) { - BigInteger bigValue = new BigInteger( value.getValueString() ); - sb.append( bigValue.toString( 2 ) ); - } - else - sb.append( Long.toBinaryString( value.longValue() ) ); - return sb.toString(); - } - } - catch( NumberFormatException e ) { - } - return null; - } - - private String getGenericValueString(String svalue) throws CDIException { - try { - BigInteger bigValue = new BigInteger(svalue); - CVariableFormat format = getParentVariable().getFormat(); - if (CVariableFormat.NATURAL.equals(format)) { - format = CVariableFormat.DECIMAL; - } - if (CVariableFormat.DECIMAL.equals(format)) { - return svalue; - } else if (CVariableFormat.HEXADECIMAL.equals(format)) { - StringBuffer sb = new StringBuffer("0x"); //$NON-NLS-1$ - if (isUnsigned()) { - sb.append(bigValue.toString(16)); - } else - sb.append(Long.toHexString(bigValue.longValue())); - return sb.toString(); - } else if (CVariableFormat.OCTAL.equals(format)) { - StringBuffer sb = new StringBuffer("0"); //$NON-NLS-1$ - if (isUnsigned()) { - sb.append(bigValue.toString(8)); - } else - sb.append(Long.toOctalString(bigValue.longValue())); - return sb.toString(); - } else if (CVariableFormat.BINARY.equals(format)) { - StringBuffer sb = new StringBuffer("0b"); //$NON-NLS-1$ - if (isUnsigned()) { - sb.append(bigValue.toString(2)); - } else - sb.append(Long.toBinaryString(bigValue.longValue())); - return sb.toString(); - } - } catch (NumberFormatException e) { - } - return svalue; - } - - - private String getFloatValueString( ICDIFloatValue value ) throws CDIException { - float floatValue = value.floatValue(); - if ( Float.isNaN(floatValue) ) - return "NaN"; //$NON-NLS-1$ - if ( Float.isInfinite(floatValue) ) - return "inf"; //$NON-NLS-1$ - - CVariableFormat format = getParentVariable().getFormat(); - if ( CVariableFormat.NATURAL.equals( format ) ) { - return Float.toString( floatValue ); - } - else if ( CVariableFormat.DECIMAL.equals( format ) ) { - return Long.toString( Float.floatToIntBits(floatValue) ); - } - else if ( CVariableFormat.HEXADECIMAL.equals( format ) ) { - StringBuffer sb = new StringBuffer( "0x" ); //$NON-NLS-1$ - String stringValue = Long.toHexString( Float.floatToIntBits(floatValue) ); - sb.append( (stringValue.length() > 8) ? stringValue.substring( stringValue.length() - 8 ) : stringValue ); - return sb.toString(); - } - else if ( CVariableFormat.OCTAL.equals( format ) ) { - StringBuffer sb = new StringBuffer( "0" ); //$NON-NLS-1$ - String stringValue = Long.toOctalString( Float.floatToIntBits(floatValue) ); - stringValue = (stringValue.length() > 11) ? stringValue.substring( stringValue.length() - 11 ) : stringValue; - sb.append( (stringValue.length() == 11 && stringValue.charAt( 0 ) >= '4') ? (char)(stringValue.charAt( 0 ) - 4) + stringValue.substring( 1 ) : stringValue ); - return sb.toString(); - } - else if ( CVariableFormat.BINARY.equals( format ) ) { - StringBuffer sb = new StringBuffer( "0b" ); //$NON-NLS-1$ - String stringValue = Long.toBinaryString( Float.floatToIntBits(floatValue) ); - sb.append( (stringValue.length() > 32) ? stringValue.substring( stringValue.length() - 32 ) : stringValue ); - return sb.toString(); - } - return null; - } - - private String getDoubleValueString( ICDIDoubleValue value ) throws CDIException { - double doubleValue = value.doubleValue(); - if ( Double.isNaN(doubleValue) ) - return "NaN"; //$NON-NLS-1$ - if ( Double.isInfinite(doubleValue) ) - return "inf"; //$NON-NLS-1$ - - CVariableFormat format = getParentVariable().getFormat(); - if ( CVariableFormat.NATURAL.equals( format ) ) { - return Double.toString(doubleValue); - } - else if ( CVariableFormat.DECIMAL.equals( format ) ) { - return Long.toString( Double.doubleToLongBits(doubleValue) ); - } - else if ( CVariableFormat.HEXADECIMAL.equals( format ) ) { - StringBuffer sb = new StringBuffer( "0x" ); //$NON-NLS-1$ - String stringValue = Long.toHexString( Double.doubleToLongBits(doubleValue) ); - sb.append( (stringValue.length() > 16) ? stringValue.substring( stringValue.length() - 16 ) : stringValue ); - return sb.toString(); - } - else if ( CVariableFormat.OCTAL.equals( format ) ) { - StringBuffer sb = new StringBuffer( "0" ); //$NON-NLS-1$ - String stringValue = Long.toOctalString( Double.doubleToLongBits(doubleValue) ); - stringValue = (stringValue.length() > 22) ? stringValue.substring( stringValue.length() - 22 ) : stringValue; - sb.append( (stringValue.length() == 22 && stringValue.charAt( 0 ) >= '2') ? (char)((stringValue.charAt( 0 ) - '0') % 2 + '0') + stringValue.substring( 1 ) : stringValue ); - return sb.toString(); - } - else if ( CVariableFormat.BINARY.equals( format ) ) { - StringBuffer sb = new StringBuffer( "0b" ); //$NON-NLS-1$ - String stringValue = Long.toBinaryString( Double.doubleToLongBits(doubleValue) ); - sb.append( (stringValue.length() > 64) ? stringValue.substring( stringValue.length() - 64 ) : stringValue ); - return sb.toString(); - } - return null; - } - - private String getPointerValueString( ICDIPointerValue value ) throws CDIException { - //TODO:IPF_TODO Workaround to solve incorrect handling of structures referenced by pointers or references - IAddressFactory factory = ((CDebugTarget)getDebugTarget()).getAddressFactory(); - BigInteger pv = value.pointerValue(); - if ( pv == null ) - return ""; //$NON-NLS-1$ - IAddress address = factory.createAddress( pv ); - if ( address == null ) - return ""; //$NON-NLS-1$ - CVariableFormat format = getParentVariable().getFormat(); - if ( CVariableFormat.NATURAL.equals( format ) || CVariableFormat.HEXADECIMAL.equals( format ) ) - return address.toHexAddressString(); - else if ( CVariableFormat.DECIMAL.equals( format ) ) - return address.toString(); - else if ( CVariableFormat.OCTAL.equals( format ) ) { - // Using the instanceof operator here to avoid API change - // Add IAddress.toOctalAddressString() in a future CDT release - if (address instanceof Addr32) { - return ((Addr32)address).toOctalAddressString(); - } else if (address instanceof Addr64) { - return ((Addr64)address).toOctalAddressString(); - } else { - // Fall back to hexadecimal address format - return address.toHexAddressString(); - } - } else if ( CVariableFormat.BINARY.equals( format ) ) - return address.toBinaryAddressString(); - return null; - } - - private String getWCharValueString( ICDIWCharValue value ) throws CDIException { - if ( getParentVariable() instanceof CVariable ) { - int size = ((CVariable)getParentVariable()).sizeof(); - if ( size == 2 ) { - CVariableFormat format = getParentVariable().getFormat(); - if ( CVariableFormat.NATURAL.equals( format ) ) { - ByteBuffer buffer = ByteBuffer.allocate(4); - buffer.putInt(value.intValue()); - buffer.position(2); - String stringValue; - try { - stringValue = new String(CDebugUtils.getCharsetDecoder().decode(buffer).array()); - } catch (CharacterCodingException e) { - stringValue = e.toString(); - } - StringBuffer sb = new StringBuffer("'"); //$NON-NLS-1$ - sb.append(stringValue); - sb.append('\''); - return sb.toString(); - } - else if ( CVariableFormat.DECIMAL.equals( format ) ) { - return (isUnsigned()) ? Integer.toString( value.intValue() ) : Short.toString( value.shortValue() ); - } - else if ( CVariableFormat.HEXADECIMAL.equals( format ) ) { - StringBuffer sb = new StringBuffer( "0x" ); //$NON-NLS-1$ - String stringValue = Integer.toHexString( (isUnsigned()) ? value.intValue() : value.shortValue() ); - sb.append( (stringValue.length() > 4) ? stringValue.substring( stringValue.length() - 4 ) : stringValue ); - return sb.toString(); - } - else if ( CVariableFormat.OCTAL.equals( format ) ) { - StringBuffer sb = new StringBuffer( "0" ); //$NON-NLS-1$ - String stringValue = Integer.toOctalString( (isUnsigned()) ? value.intValue() : value.shortValue() ); - stringValue = (stringValue.length() > 6) ? stringValue.substring( stringValue.length() - 6 ) : stringValue; - sb.append( (stringValue.length() == 6 && stringValue.charAt( 0 ) >= '2') ? (char)((stringValue.charAt( 0 ) - '0') % 2 + '0') + stringValue.substring( 1 ) : stringValue ); - return sb.toString(); - } - else if ( CVariableFormat.BINARY.equals( format ) ) { - StringBuffer sb = new StringBuffer( "0b" ); //$NON-NLS-1$ - String stringValue = Integer.toBinaryString( (isUnsigned()) ? value.intValue() : value.shortValue() ); - sb.append( (stringValue.length() > 16) ? stringValue.substring( stringValue.length() - 16 ) : stringValue ); - return sb.toString(); - } - } - if ( size == 4 ) { - CVariableFormat format = getParentVariable().getFormat(); - if ( CVariableFormat.NATURAL.equals( format ) ) { - ByteBuffer buffer = ByteBuffer.allocate(8); - buffer.putLong(value.longValue()); - buffer.position(4); - String stringValue; - try { - stringValue = new String(CDebugUtils.getCharsetDecoder().decode(buffer).array()); - } catch (CharacterCodingException e) { - stringValue = e.toString(); - } - StringBuffer sb = new StringBuffer("'"); //$NON-NLS-1$ - sb.append(stringValue); - sb.append('\''); - return sb.toString(); - } - else if ( CVariableFormat.DECIMAL.equals( format ) ) { - return (isUnsigned()) ? Long.toString( value.longValue() ) : Integer.toString( value.intValue() ); - } - else if ( CVariableFormat.HEXADECIMAL.equals( format ) ) { - StringBuffer sb = new StringBuffer( "0x" ); //$NON-NLS-1$ - String stringValue = (isUnsigned()) ? Long.toHexString( value.longValue() ) : Integer.toHexString( value.intValue() ); - sb.append( (stringValue.length() > 8) ? stringValue.substring( stringValue.length() - 8 ) : stringValue ); - return sb.toString(); - } - else if ( CVariableFormat.OCTAL.equals( format ) ) { - StringBuffer sb = new StringBuffer( "0" ); //$NON-NLS-1$ - String stringValue = (isUnsigned()) ? Long.toOctalString( value.longValue() ) : Integer.toOctalString( value.intValue() ); - stringValue = (stringValue.length() > 11) ? stringValue.substring( stringValue.length() - 11 ) : stringValue; - sb.append( (stringValue.length() == 11 && stringValue.charAt( 0 ) >= '4') ? (char)(stringValue.charAt( 0 ) - 4) + stringValue.substring( 1 ) : stringValue ); - return sb.toString(); - } - else if ( CVariableFormat.BINARY.equals( format ) ) { - StringBuffer sb = new StringBuffer( "0b" ); //$NON-NLS-1$ - String stringValue = (isUnsigned()) ? Long.toBinaryString( value.longValue() ) : Integer.toBinaryString( value.intValue() ); - sb.append( (stringValue.length() > 32) ? stringValue.substring( stringValue.length() - 32 ) : stringValue ); - return sb.toString(); - } - } - } - return value.getValueString(); - } - - private String getBigIntegerValueString( ICDIBigIntegerValue value ) throws CDIException { - try { - CVariableFormat format = getParentVariable().getFormat(); - - if (CVariableFormat.NATURAL.equals(format)) { - format = getNaturalFormat(value, CVariableFormat.DECIMAL); - } - - if ( CVariableFormat.DECIMAL.equals( format ) ) { - BigInteger bigValue = value.bigIntegerValue(); - return bigValue.toString(10); - } - else if ( CVariableFormat.HEXADECIMAL.equals( format ) ) { - StringBuffer sb = new StringBuffer("0x"); //$NON-NLS-1$ - sb.append(value.bigIntegerValue().toString(16)); - return sb.toString(); - } - else if ( CVariableFormat.OCTAL.equals( format ) ) { - StringBuffer sb = new StringBuffer("0"); //$NON-NLS-1$ - sb.append(value.bigIntegerValue().toString(8)); - return sb.toString(); - } - else if ( CVariableFormat.BINARY.equals( format ) ) { - StringBuffer sb = new StringBuffer("0b"); //$NON-NLS-1$ - sb.append(value.bigIntegerValue().toString(2)); - return sb.toString(); - } - } - catch( NumberFormatException e ) { - } - return null; - } - private boolean isUnsigned() { - boolean result = false; - try { - ICType type = getParentVariable().getType(); - if ( type != null ) - result = type.isUnsigned(); - } - catch( DebugException e ) { - } - return result; - } - - /** - * Invalidates the string cache. - */ - @Override - protected void reset() { - resetStatus(); - fValueString = null; - for (AbstractCVariable var : fVariables) { - var.resetValue(); - } - } - - @Override - public ICType getType() throws DebugException { - ICDIValue cdiValue = getUnderlyingValue(); - if ( fType == null ) { - if ( cdiValue != null ) { - synchronized( this ) { - if ( fType == null ) { - try { - fType = new CType( cdiValue.getType() ); - } - catch( CDIException e ) { - requestFailed( e.getMessage(), null ); - } - } - } - } - } - return fType; -// AbstractCVariable var = getParentVariable(); -// return ( var instanceof CVariable ) ? ((CVariable)var).getType() : null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.internal.core.model.AbstractCValue#preserve() - */ - @Override - protected void preserve() { - setChanged( false ); - resetStatus(); - for (AbstractCVariable var : fVariables) { - var.preserve(); - } - } - - private static CVariableFormat getNaturalFormat(ICDIValue value, CVariableFormat defaultFormat) throws CDIException { - if (value instanceof ICDIFormattable) { - int naturalFormat = ((ICDIFormattable)value).getNaturalFormat(); - switch (naturalFormat) { - case ICDIFormat.DECIMAL: - return CVariableFormat.DECIMAL; - case ICDIFormat.BINARY: - return CVariableFormat.BINARY; - case ICDIFormat.OCTAL: - return CVariableFormat.OCTAL; - case ICDIFormat.HEXADECIMAL: - return CVariableFormat.HEXADECIMAL; - } - } - return defaultFormat; - } -} diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CValueFactory.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CValueFactory.java deleted file mode 100644 index 9db5e6efdbf..00000000000 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CValueFactory.java +++ /dev/null @@ -1,118 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2012 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 - *******************************************************************************/ -package org.eclipse.cdt.debug.internal.core.model; - -import org.eclipse.cdt.debug.core.CDebugCorePlugin; -import org.eclipse.cdt.debug.core.cdi.model.ICDIValue; -import org.eclipse.cdt.debug.core.cdi.model.type.ICDIArrayValue; -import org.eclipse.cdt.debug.core.cdi.model.type.ICDIFloatingPointValue; -import org.eclipse.cdt.debug.core.model.CDebugElementState; -import org.eclipse.cdt.debug.core.model.ICStackFrame; -import org.eclipse.cdt.debug.core.model.ICType; -import org.eclipse.cdt.debug.core.model.ICValue; -import org.eclipse.debug.core.DebugException; -import org.eclipse.debug.core.ILaunch; -import org.eclipse.debug.core.model.IDebugTarget; -import org.eclipse.debug.core.model.IVariable; - -/** - * The value factory for variable and expressions. - */ -public class CValueFactory { - - static public final ICValue NULL_VALUE = new ICValue() { - - @Override - public String getReferenceTypeName() throws DebugException { - return ""; //$NON-NLS-1$ - } - - @Override - public String getValueString() throws DebugException { - return ""; //$NON-NLS-1$ - } - - @Override - public boolean isAllocated() throws DebugException { - return true; - } - - @Override - public IVariable[] getVariables() throws DebugException { - return new IVariable[0]; - } - - @Override - public boolean hasVariables() throws DebugException { - return false; - } - - @Override - public String getModelIdentifier() { - return CDebugCorePlugin.getUniqueIdentifier(); - } - - @Override - public IDebugTarget getDebugTarget() { - return null; - } - - @Override - public ILaunch getLaunch() { - return null; - } - - @Override - public Object getAdapter( Class adapter ) { - return null; - } - - @Override - public ICType getType() throws DebugException { - return null; - } - - @Override - public String evaluateAsExpression( ICStackFrame frame ) { - return ""; //$NON-NLS-1$ - } - - @Override - public CDebugElementState getState() { - return CDebugElementState.UNDEFINED; - } - - @Override - public Object getCurrentStateInfo() { - return null; - } - - }; - - static public CValue createValue( CVariable parent, ICDIValue cdiValue ) { - if ( cdiValue instanceof ICDIFloatingPointValue ) { - return new CFloatingPointValue( parent, cdiValue ); - } - return new CValue( parent, cdiValue ); - } - - static public CIndexedValue createIndexedValue( AbstractCVariable parent, ICDIArrayValue cdiValue, int start, int length ) { - return new CIndexedValue( parent, cdiValue, start, length ); - } - - static public CValue createGlobalValue( CVariable parent, ICDIValue cdiValue ) { - return new CGlobalValue( parent, cdiValue ); - } - - static public ICValue createValueWithError( CVariable parent, String message ) { - return new CValue( parent, message ); - } -} diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CVariable.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CVariable.java deleted file mode 100644 index d905acaa68f..00000000000 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CVariable.java +++ /dev/null @@ -1,941 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2012 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 - *******************************************************************************/ -package org.eclipse.cdt.debug.internal.core.model; - -import com.ibm.icu.text.MessageFormat; - -import org.eclipse.cdt.debug.core.CDebugCorePlugin; -import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants; -import org.eclipse.cdt.debug.core.ICDebugConstants; -import org.eclipse.cdt.debug.core.ICWatchpointTarget; -import org.eclipse.cdt.debug.core.cdi.event.ICDIChangedEvent; -import org.eclipse.cdt.debug.core.cdi.event.ICDIDestroyedEvent; -import org.eclipse.cdt.debug.core.cdi.event.ICDIEvent; -import org.eclipse.cdt.debug.core.cdi.event.ICDIEventListener; -import org.eclipse.cdt.debug.core.cdi.event.ICDIMemoryChangedEvent; -import org.eclipse.cdt.debug.core.cdi.event.ICDIResumedEvent; -import org.eclipse.cdt.debug.core.cdi.model.ICDIObject; -import org.eclipse.cdt.debug.core.cdi.model.ICDITarget; -import org.eclipse.cdt.debug.core.cdi.model.ICDITargetConfiguration; -import org.eclipse.cdt.debug.core.cdi.model.ICDITargetConfiguration2; -import org.eclipse.cdt.debug.core.cdi.model.ICDITargetConfiguration3; -import org.eclipse.cdt.debug.core.cdi.model.ICDIVariable; -import org.eclipse.cdt.debug.core.cdi.model.ICDIVariableDescriptor; -import org.eclipse.cdt.debug.core.model.CVariableFormat; -import org.eclipse.cdt.debug.core.model.ICDebugElementStatus; -import org.eclipse.cdt.debug.core.model.ICType; -import org.eclipse.cdt.debug.core.model.ICValue; -import org.eclipse.cdt.debug.internal.core.CSettingsManager; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.debug.core.DebugEvent; -import org.eclipse.debug.core.DebugException; -import org.eclipse.debug.core.DebugPlugin; -import org.eclipse.debug.core.model.IValue; - -/** - * A thin wrapper over the CVariable for injection into the CDI event manager's - * listener collection. We used to directly inject the CVariable, but that's - * problematic since CVariable overrides the equals() method to base the - * decision on the internal variable object. So if two CVariables were added to - * the listener list for the same underlying value, trying to later remove one - * of the listeners had a 50/50 chance of removing the wrong one. - * - * How can you end up with two CVariables for the same internal variable on the - * listener list? Easy. - * 1. View a register in the Registers view. - * 2. Create a custom register group that contains the same register. - * 3. Expand the custom register group - * 4. Remove the custom register group - * Step 4 removed the wrong CVariable from the listener list. - * - */ -class VariableEventListener implements ICDIEventListener { - private CVariable fVar; - public VariableEventListener(CVariable var) { - fVar = var; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.cdi.event.ICDIEventListener#handleDebugEvents(org.eclipse.cdt.debug.core.cdi.event.ICDIEvent[]) - */ - @Override - public void handleDebugEvents(ICDIEvent[] events) { - fVar.handleDebugEvents(events); - } -} - -/** - * Represents a variable in the CDI model. - */ -public abstract class CVariable extends AbstractCVariable implements ICDIEventListener, ICWatchpointTarget { - - interface IInternalVariable { - IInternalVariable createShadow( int start, int length ) throws DebugException; - IInternalVariable createShadow( String type ) throws DebugException; - CType getType() throws DebugException; - String getQualifiedName() throws DebugException; - ICValue getValue() throws DebugException; - void setValue( String expression ) throws DebugException; - boolean isChanged(); - void setChanged( boolean changed ); - void dispose( boolean destroy ); - boolean isSameDescriptor( ICDIVariableDescriptor desc ); - boolean isSameVariable( ICDIVariable cdiVar ); - void resetValue(); - boolean isEditable() throws DebugException; - boolean isArgument(); - int sizeof(); - void invalidateValue(); - void preserve(); - - // Note: the CDI object association can change; e.g., if a "Cast to Type" - // or "Display as Array" is done on the element. - ICDIObject getCdiObject(); - } - - /** - * Whether this variable is currently enabled. - */ - private boolean fIsEnabled = true; - - /** - * The original internal variable. - */ - private IInternalVariable fOriginal; - - /** - * The shadow internal variable used for casting. - */ - private IInternalVariable fShadow; - - /** - * The name of this variable. - */ - private String fName; - - /** - * The current format of this variable. - */ - private CVariableFormat fFormat = CVariableFormat.getFormat( CDebugCorePlugin.getDefault().getPluginPreferences().getInt( ICDebugConstants.PREF_DEFAULT_VARIABLE_FORMAT ) ); - - /** - * Whether this variable has been disposed. - */ - private boolean fIsDisposed = false; - - /** - * Thin wrapper for instertion into the CDI event manager's listener list - */ - private VariableEventListener fEventListenerWrapper; - - /** - * Constructor for CVariable. - */ - protected CVariable( CDebugElement parent, ICDIVariableDescriptor cdiVariableObject ) { - super( parent ); - fEventListenerWrapper = new VariableEventListener(this); - if ( cdiVariableObject != null ) { - setName( cdiVariableObject.getName() ); - createOriginal( cdiVariableObject ); - } - fIsEnabled = ( parent instanceof AbstractCValue ) ? ((AbstractCValue)parent).getParentVariable().isEnabled() : !isBookkeepingEnabled(); - getCDISession().getEventManager().addEventListener( fEventListenerWrapper ); - if ( cdiVariableObject != null ) { - setInitialFormat(); - } - } - - /** - * Constructor for CVariable. - */ - protected CVariable( CDebugElement parent, ICDIVariableDescriptor cdiVariableObject, String errorMessage ) { - super( parent ); - fEventListenerWrapper = new VariableEventListener(this); - if ( cdiVariableObject != null ) { - setName( cdiVariableObject.getName() ); - createOriginal( cdiVariableObject ); - } - fIsEnabled = !isBookkeepingEnabled(); - setStatus( ICDebugElementStatus.ERROR, MessageFormat.format( CoreModelMessages.getString( "CVariable.1" ), new String[]{ errorMessage } ) ); //$NON-NLS-1$ - getCDISession().getEventManager().addEventListener( fEventListenerWrapper ); - if ( cdiVariableObject != null ) { - setInitialFormat(); - } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.debug.core.model.ICVariable#getType() - */ - @Override - public ICType getType() throws DebugException { - if ( isDisposed() ) - return null; - IInternalVariable iv = getCurrentInternalVariable(); - return ( iv != null ) ? iv.getType() : null; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.debug.core.model.ICVariable#isEnabled() - */ - @Override - public boolean isEnabled() { - return fIsEnabled; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.debug.core.model.ICVariable#setEnabled(boolean) - */ - @Override - public void setEnabled( boolean enabled ) throws DebugException { - // Debugger engines that use active variable objects will benefit - // performance-wise if we dispose the internal variable when it's - // disabled by the user (it will automatically get lazily recreated if - // it's ever needed again). Engines using passive variables probably - // won't, so we can defer the dispose until we have no use for the - // variable altogether. - boolean disposeVariable = true; - ICDITargetConfiguration configuration = getParent().getCDITarget().getConfiguration(); - if (configuration instanceof ICDITargetConfiguration2) { - disposeVariable = !((ICDITargetConfiguration2)configuration).supportsPassiveVariableUpdate(); - } - if (disposeVariable) { - IInternalVariable iv = getOriginal(); - if ( iv != null ) - iv.dispose( true ); - iv = getShadow(); - if ( iv != null ) - iv.dispose( true ); - } - fIsEnabled = enabled; - fireChangeEvent( DebugEvent.STATE ); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.debug.core.model.ICVariable#canEnableDisable() - */ - @Override - public boolean canEnableDisable() { - return !( getParent() instanceof IValue ); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.debug.core.model.ICVariable#isArgument() - */ - @Override - public boolean isArgument() { - IInternalVariable iv = getOriginal(); - return ( iv != null ) ? iv.isArgument() : false; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.debug.core.model.IVariable#getValue() - */ - @Override - public IValue getValue() throws DebugException { - if ( !isDisposed() && isEnabled() ) { - IInternalVariable iv = getCurrentInternalVariable(); - if ( iv != null ) { - try { - return iv.getValue(); - } - catch( DebugException e ) { - setStatus( ICDebugElementStatus.ERROR, e.getMessage() ); - } - } - } - return CValueFactory.NULL_VALUE; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.debug.core.model.IVariable#getName() - */ - @Override - public String getName() throws DebugException { - return fName; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.debug.core.model.IVariable#getReferenceTypeName() - */ - @Override - public String getReferenceTypeName() throws DebugException { - ICType type = getType(); - return ( type != null ) ? type.getName() : ""; //$NON-NLS-1$ - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.debug.core.model.IVariable#hasValueChanged() - */ - @Override - public boolean hasValueChanged() throws DebugException { - if ( isDisposed() ) - return false; - IInternalVariable iv = getCurrentInternalVariable(); - return ( iv != null ) ? iv.isChanged() : false; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.debug.core.model.IFormatSupport#supportsFormatting() - */ - @Override - public boolean supportsFormatting() { - return true; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.debug.core.model.IFormatSupport#getFormat() - */ - @Override - public CVariableFormat getFormat() { - return fFormat; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.debug.core.model.IFormatSupport#changeFormat(org.eclipse.cdt.debug.core.model.CVariableFormat) - */ - @Override - public void changeFormat( CVariableFormat format ) throws DebugException { - setFormat( format ); - storeFormat( format ); - resetValue(); - } - - /* - * (non-Javadoc) - * Allow this operation only for the pointer types (???). - * - * @see org.eclipse.cdt.debug.core.model.ICastToArray#canCastToArray() - */ - @Override - public boolean canCastToArray() { - ICType type; - try { - type = getType(); - return ( getOriginal() != null && isEnabled() && type != null && type.isPointer() ); - } - catch( DebugException e ) { - } - return false; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.debug.core.model.ICastToArray#castToArray(int, int) - */ - @Override - public void castToArray( int startIndex, int length ) throws DebugException { - IInternalVariable current = getCurrentInternalVariable(); - if ( current != null ) { - IInternalVariable newVar = current.createShadow( startIndex, length ); - if ( getShadow() != null ) - getShadow().dispose( true ); - setShadow( newVar ); - // If casting of variable to a type or array causes an error, the status - // of the variable is set to "error" and it can't be reset by subsequent castings. - resetValue(); - storeCastToArray( startIndex, length ); - } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.debug.core.model.IValueModification#setValue(java.lang.String) - */ - @Override - public void setValue( String expression ) throws DebugException { - IInternalVariable iv = getCurrentInternalVariable(); - if ( iv != null ) { - String newExpression = processExpression( expression ); - iv.setValue( newExpression ); - } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.debug.core.model.IValueModification#setValue(org.eclipse.debug.core.model.IValue) - */ - @Override - public void setValue( IValue value ) throws DebugException { - notSupported( CoreModelMessages.getString( "CVariable.3" ) ); //$NON-NLS-1$ - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.debug.core.model.IValueModification#supportsValueModification() - */ - @Override - public boolean supportsValueModification() { - try { - return fIsEnabled ? getCurrentInternalVariable().isEditable() : false; - } - catch( DebugException e ) { - } - return false; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.debug.core.model.IValueModification#verifyValue(java.lang.String) - */ - @Override - public boolean verifyValue( String expression ) throws DebugException { - return true; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.debug.core.model.IValueModification#verifyValue(org.eclipse.debug.core.model.IValue) - */ - @Override - public boolean verifyValue( IValue value ) throws DebugException { - return value.getDebugTarget().equals( getDebugTarget() ); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.debug.core.model.ICastToType#canCast() - */ - @Override - public boolean canCast() { - return ( getOriginal() != null && isEnabled() ); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.debug.core.model.ICastToType#getCurrentType() - */ - @Override - public String getCurrentType() { - String typeName = ""; //$NON-NLS-1$ - try { - typeName = getReferenceTypeName(); - } - catch( DebugException e ) { - } - return typeName; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.debug.core.model.ICastToType#cast(java.lang.String) - */ - @Override - public void cast( String type ) throws DebugException { - IInternalVariable current = getCurrentInternalVariable(); - if ( current != null ) { - IInternalVariable newVar = current.createShadow( type ); - if ( getShadow() != null ) - getShadow().dispose( true ); - setShadow( newVar ); - // If casting of variable to a type or array causes an error, the status - // of the variable is set to "error" and it can't be reset by subsequent castings. - resetValue(); - storeCast(type); - } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.debug.core.model.ICastToType#restoreOriginal() - */ - @Override - public void restoreOriginal() throws DebugException { - IInternalVariable oldVar = getShadow(); - setShadow( null ); - if ( oldVar != null ) - oldVar.dispose( true ); - IInternalVariable iv = getOriginal(); - if ( iv != null ) - iv.invalidateValue(); - // If casting of variable to a type or array causes an error, the status - // of the variable is set to "error" and it can't be reset by subsequent castings. - resetValue(); - forgetCast(); - forgetCastToArray(); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.debug.core.model.ICastToType#isCasted() - */ - @Override - public boolean isCasted() { - return ( getShadow() != null ); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.debug.core.cdi.event.ICDIEventListener#handleDebugEvents(org.eclipse.cdt.debug.core.cdi.event.ICDIEvent[]) - */ - @Override - public void handleDebugEvents( ICDIEvent[] events ) { - IInternalVariable iv = getCurrentInternalVariable(); - if ( iv == null ) - return; - for( int i = 0; i < events.length; i++ ) { - ICDIEvent event = events[i]; - ICDIObject source = event.getSource(); - if ( source == null ) - continue; - ICDITarget target = source.getTarget(); - if ( target.equals( getCDITarget() ) ) { - if ( event instanceof ICDIMemoryChangedEvent && - target.getConfiguration() instanceof ICDITargetConfiguration3 && - ((ICDITargetConfiguration3)target.getConfiguration()).needsVariablesUpdated(event)) { - resetValue(); - } - else if ( event instanceof ICDIChangedEvent ) { - if ( source instanceof ICDIVariable && iv.isSameVariable( (ICDIVariable)source ) ) { - handleChangedEvent( (ICDIChangedEvent)event ); - } - } - else if ( event instanceof ICDIResumedEvent ) { - handleResumedEvent( (ICDIResumedEvent)event ); - } - else if (event instanceof ICDIDestroyedEvent - && iv.getCdiObject() == source) { - dispose(); - fireChangeEvent(DebugEvent.STATE); - } - } - } - } - - private void handleResumedEvent( ICDIResumedEvent event ) { - boolean changed = false; - if ( hasErrors() ) { - resetStatus(); - changed = true; - IInternalVariable iv = getCurrentInternalVariable(); - if ( iv != null ) - iv.invalidateValue(); - } - if ( changed ) - fireChangeEvent( DebugEvent.STATE ); - } - - private void handleChangedEvent( ICDIChangedEvent event ) { - IInternalVariable iv = getCurrentInternalVariable(); - if ( iv != null ) { - iv.setChanged( true ); - fireChangeEvent( DebugEvent.STATE ); - } - } - - private IInternalVariable getCurrentInternalVariable() { - if ( getShadow() != null ) - return getShadow(); - return getOriginal(); - } - - private IInternalVariable getOriginal() { - return fOriginal; - } - - protected void setOriginal( IInternalVariable original ) { - fOriginal = original; - } - - private IInternalVariable getShadow() { - return fShadow; - } - - private void setShadow( IInternalVariable shadow ) { - fShadow = shadow; - } - - protected boolean isBookkeepingEnabled() { - boolean result = false; - try { - result = getLaunch().getLaunchConfiguration().getAttribute( ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_ENABLE_VARIABLE_BOOKKEEPING, false ); - } - catch( CoreException e ) { - } - return result; - } - - abstract protected void createOriginal( ICDIVariableDescriptor vo ); - - protected boolean hasErrors() { - return !isOK(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.internal.core.model.AbstractCVariable#setChanged(boolean) - */ - @Override - protected void setChanged( boolean changed ) { - IInternalVariable iv = getCurrentInternalVariable(); - if ( iv != null ) { - iv.setChanged( changed ); - } - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.internal.core.model.AbstractCVariable#resetValue() - */ - @Override - protected void resetValue() { - IInternalVariable iv = getCurrentInternalVariable(); - if ( iv != null ) { - resetStatus(); - iv.resetValue(); - fireChangeEvent( DebugEvent.STATE ); - } - } - - private String processExpression( String oldExpression ) { - return oldExpression; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.internal.core.model.AbstractCVariable#dispose() - */ - @Override - public void dispose() { - // Hack: do not destroy local variables - internalDispose( false ); - setDisposed( true ); - } - - public int sizeof() { - IInternalVariable iv = getCurrentInternalVariable(); - return ( iv != null ) ? iv.sizeof() : -1; - } - - /** - * Compares the original internal variables. - * @see java.lang.Object#equals(java.lang.Object) - */ - @Override - public boolean equals( Object obj ) { - if ( obj instanceof CVariable ) { - // A disposed copy can be stored in the viewer. - // false should be returned to force the viewer to - // replace it by a new variable. See bug #115385 - if ( isDisposed() != ((CVariable)obj).isDisposed() ) - return false; - IInternalVariable iv = getOriginal(); - return ( iv != null ) ? iv.equals( ((CVariable)obj).getOriginal() ) : false; - } - return false; - } - - protected boolean sameVariable( ICDIVariableDescriptor vo ) { - IInternalVariable iv = getOriginal(); - return ( iv != null && iv.isSameDescriptor( vo ) ); - } - - protected void setFormat( CVariableFormat format ) { - fFormat = format; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.ICVariable#getExpressionString() - */ - @Override - public String getExpressionString() throws DebugException { - IInternalVariable iv = getCurrentInternalVariable(); - return ( iv != null ) ? iv.getQualifiedName() : null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.internal.core.model.AbstractCVariable#preserve() - */ - @Override - protected void preserve() { - resetStatus(); - IInternalVariable iv = getCurrentInternalVariable(); - if ( iv != null ) - iv.preserve(); - } - - protected void internalDispose( boolean destroy ) { - getCDISession().getEventManager().removeEventListener( fEventListenerWrapper ); - IInternalVariable iv = getOriginal(); - if ( iv != null ) - iv.dispose( destroy ); - iv = getShadow(); - if ( iv != null ) - iv.dispose( destroy ); - } - - protected boolean isDisposed() { - return fIsDisposed; - } - - protected void setDisposed( boolean isDisposed ) { - fIsDisposed = isDisposed; - } - - protected void invalidateValue() { - resetStatus(); - IInternalVariable iv = getCurrentInternalVariable(); - if ( iv != null ) - iv.invalidateValue(); - } - - protected void setName( String name ) { - fName = name; - } - - public ICDIObject getCdiObject() { - IInternalVariable iv = getCurrentInternalVariable(); - if ( iv != null ) { - return iv.getCdiObject(); - } - return null; - } - - protected CSettingsManager getFormatManager() { - return ((CDebugTarget) getDebugTarget()).getFormatManager(); - } - - /** - * used to concatenate multiple names to a single identifier - */ - private final static String NAME_PART_SEPARATOR = "-"; //$NON-NLS-1$ - - /** - * suffix used to identify format informations - */ - private final static String FORMAT_SUFFIX = NAME_PART_SEPARATOR + "(format)"; //$NON-NLS-1$ - - /** - * suffix used to identify cast settings - */ - private final static String CAST_SUFFIX = NAME_PART_SEPARATOR + "(cast)"; //$NON-NLS-1$ - - /** - * suffix used to identify cast to array settings - */ - private final static String CAST_TO_ARRAY_SUFFIX = NAME_PART_SEPARATOR + "(cast_to_array)"; //$NON-NLS-1$ - - /** retrieve the identification for this variable. - * @return a string identifying this variable, to be used to store settings - * @throws DebugException - */ - String getVariableID() throws DebugException { - return getName(); // TODO: better identification if multiple variables have the same name - } - - /** helper to generate a string id used to persist the settings. - * @param next_obj next object to encode into the id - * @param buf contains the id of the part encoded so far. - * @throws DebugException - */ - static private void buildPesistID( CDebugElement next_obj, StringBuffer buf ) throws DebugException { - if ( next_obj instanceof CVariable ) { - CVariable cVariableParent = (CVariable) next_obj; - buf.append( NAME_PART_SEPARATOR ); - buf.append( cVariableParent.getVariableID() ); - buildPesistID( cVariableParent.getParent(), buf ); - } else if ( next_obj instanceof CStackFrame ) { - buf.append(NAME_PART_SEPARATOR); - // TODO: better identification if multiple functions have the same name (say for static functions) - buf.append( ((CStackFrame)next_obj ).getFunction() ); - } else if ( next_obj instanceof CDebugTarget ) { - // global, we use a root NAME_PART_SEPARATOR as indicator of that - buf.append( NAME_PART_SEPARATOR ); - } else if ( next_obj instanceof AbstractCValue ) { - // index or indirection. - AbstractCValue av = (AbstractCValue) next_obj; - buildPesistID( av.getParentVariable(), buf ); - } - } - - /** returns an string used to identify this variable - * @return - * @throws DebugException - */ - private final String getPersistID() throws DebugException { - StringBuffer id = new StringBuffer(); - id.append( getVariableID() ); - buildPesistID( getParent(), id ); - return id.toString(); - } - - /** stores the given format - * @param format the format to be used for this variable - */ - protected void storeFormat( CVariableFormat format ) { - try { - String formatString = Integer.toString( format.getFormatNumber() ); - - getFormatManager().putValue( getPersistID() + FORMAT_SUFFIX, formatString ); - } catch ( DebugException e ) { - // if we do not get the name, we use the default format, no reason for the creation to fail too. - DebugPlugin.log( e ); - } - } - - /** stores the cast information. - * @param type the type to be displayed instead - */ - protected void storeCast( String type ) { - try { - String id = getPersistID() + CAST_SUFFIX; - getFormatManager().putValue( id, type ); - } catch ( DebugException e ) { - DebugPlugin.log( e ); - } - } - - /** drops the cast information. - */ - protected void forgetCast() { - try { - String id = getPersistID() + CAST_SUFFIX; - getFormatManager().removeValue( id ); - } catch ( DebugException e ) { - DebugPlugin.log( e ); - } - } - - /** stores the cast array information. - * @param startIndex the first item to be displayed in the cast array operation - * @param length the number of elements to display - */ - protected void storeCastToArray(int startIndex, int length) { - try { - // we persist the information in a (startIndex):(Length) format. - String content = Integer.toString( startIndex ) + ":" + Integer.toString( length ); //$NON-NLS-1$ - getFormatManager().putValue( getPersistID() + CAST_TO_ARRAY_SUFFIX, content ); - } catch ( DebugException e ) { - DebugPlugin.log( e ); - } - } - - /** drops previously stored cast array information. - */ - protected void forgetCastToArray() { - try { - String id = getPersistID() + CAST_TO_ARRAY_SUFFIX; - getFormatManager().removeValue( id ); - } catch ( DebugException e ) { - DebugPlugin.log( e ); - } - } - - /** - * restore the format stored previously for this variable. - * Only sets explicitly retrieved formats in order to maintain defaults. - */ - protected void setInitialFormat() { - try { - String persistID= getPersistID(); - String stringFormat = getFormatManager().getValue( persistID + FORMAT_SUFFIX ); - if ( stringFormat != null ) { - try { - CVariableFormat format = CVariableFormat.getFormat( Integer.parseInt( stringFormat ) ); - setFormat( format ); - } catch ( NumberFormatException e ) { - DebugPlugin.log( e ); - } - } - - if ( canCast() ) { - String castString = getFormatManager().getValue( persistID + CAST_SUFFIX ); - if ( castString != null ) { - cast( castString ); - } - } - if ( canCastToArray() ) { - String castToArrayString = getFormatManager().getValue( persistID + CAST_TO_ARRAY_SUFFIX ); - if (castToArrayString != null) { - int index = castToArrayString.indexOf( ':' ); - if ( index > 0 ) { - try { - int beg = Integer.parseInt( castToArrayString.substring( 0, index ) ); - int num = Integer.parseInt( castToArrayString.substring( index + 1 ) ); - castToArray( beg, num ); - } catch ( NumberFormatException e ) { - DebugPlugin.log( e ); - } - } else { - DebugPlugin.logMessage( "did not find expected : for cast to array", null ); //$NON-NLS-1$ - } - } - } - } catch ( DebugException e ) { - DebugPlugin.log( e ); - // we drop (and log) the exception here. - // even if the initial setup fails, we still want the complete creation to be successful - } - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.internal.core.IWatchpointTarget#getExpression() - */ - @Override - public String getExpression() { - try { - return getExpressionString(); - } catch (DebugException e) { - return ""; //$NON-NLS-1$ - } - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.internal.core.IWatchpointTarget#getSize() - */ - @Override - public void getSize(ICWatchpointTarget.GetSizeRequest request) { - // CDI has synchronous APIs, so this is easy... - request.setSize(sizeof()); - request.done(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.internal.core.IWatchpointTarget#canCreateWatchpoint(org.eclipse.cdt.debug.internal.core.IWatchpointTarget.CanCreateWatchpointRequest) - */ - @Override - public void canSetWatchpoint(ICWatchpointTarget.CanCreateWatchpointRequest request) { - // CDI has synchronous APIs, so this is easy... - request.setCanCreate(sizeof() > 0); - request.done(); - } -} diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CVariableFactory.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CVariableFactory.java deleted file mode 100644 index 1dd3f640f7b..00000000000 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CVariableFactory.java +++ /dev/null @@ -1,84 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2012 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 - *******************************************************************************/ -package org.eclipse.cdt.debug.internal.core.model; - -import com.ibm.icu.text.MessageFormat; - -import org.eclipse.cdt.core.IBinaryParser.ISymbol; -import org.eclipse.cdt.core.model.IBinaryModule; -import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.cdt.debug.core.cdi.model.ICDIVariableDescriptor; -import org.eclipse.cdt.debug.core.model.IGlobalVariableDescriptor; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Path; - -/** - * Provides factory methods for the variable types. - */ -public class CVariableFactory { - - public static CLocalVariable createLocalVariable( CDebugElement parent, ICDIVariableDescriptor cdiVariableObject ) { - return new CLocalVariable( parent, cdiVariableObject ); - } - - public static CLocalVariable createLocalVariableWithError( CDebugElement parent, ICDIVariableDescriptor cdiVariableObject, String message ) { - return new CLocalVariable( parent, cdiVariableObject, message ); - } - - public static IGlobalVariableDescriptor createGlobalVariableDescriptor( final String name, final IPath path ) { - - return new IGlobalVariableDescriptor() { - - @Override - public String getName() { - return name; - } - - @Override - public IPath getPath() { - return ( path != null ) ? path : new Path( "" ); //$NON-NLS-1$ - } - - @Override - public String toString() { - return MessageFormat.format( "{0}::{1}", new String[] { getPath().toOSString(), getName() } ); //$NON-NLS-1$ - } - - @Override - public boolean equals( Object obj ) { - if ( !(obj instanceof IGlobalVariableDescriptor) ) - return false; - IGlobalVariableDescriptor d = (IGlobalVariableDescriptor)obj; - return ( getName().compareTo( d.getName() ) == 0 && getPath().equals( d.getPath() ) ); - } - }; - } - - public static IGlobalVariableDescriptor createGlobalVariableDescriptor( final org.eclipse.cdt.core.model.IVariable var ) { - IPath path = new Path( "" ); //$NON-NLS-1$ - ICElement parent = var.getParent(); - if ( parent instanceof IBinaryModule ) { - path = ((IBinaryModule)parent).getPath(); - } - return createGlobalVariableDescriptor( var.getElementName(), path ); - } - - public static IGlobalVariableDescriptor createGlobalVariableDescriptor( ISymbol symbol ) { - return createGlobalVariableDescriptor( symbol.getName(), symbol.getFilename() ); - } - - /** - * @param descriptor can be null if creating a child for a global - */ - public static CGlobalVariable createGlobalVariable( CDebugElement parent, IGlobalVariableDescriptor descriptor, ICDIVariableDescriptor cdiVariableObject ) { - return new CGlobalVariable( parent, descriptor, cdiVariableObject ); - } -} diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/Disassembly.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/Disassembly.java deleted file mode 100644 index 58b571f6482..00000000000 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/Disassembly.java +++ /dev/null @@ -1,228 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2015 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 - * oyvind.harboe@zylin.com - http://bugs.eclipse.org/250638 - *******************************************************************************/ -package org.eclipse.cdt.debug.internal.core.model; - -import java.math.BigInteger; -import java.util.ArrayList; -import org.eclipse.cdt.core.IAddress; -import org.eclipse.cdt.core.IAddressFactory; -import org.eclipse.cdt.debug.core.CDebugCorePlugin; -import org.eclipse.cdt.debug.core.ICDebugConstants; -import org.eclipse.cdt.debug.core.cdi.CDIException; -import org.eclipse.cdt.debug.core.cdi.event.ICDIEvent; -import org.eclipse.cdt.debug.core.cdi.event.ICDIEventListener; -import org.eclipse.cdt.debug.core.cdi.event.ICDIMemoryChangedEvent; -import org.eclipse.cdt.debug.core.cdi.model.ICDIInstruction; -import org.eclipse.cdt.debug.core.cdi.model.ICDIMixedInstruction; -import org.eclipse.cdt.debug.core.cdi.model.ICDITarget; -import org.eclipse.cdt.debug.core.model.ICStackFrame; -import org.eclipse.cdt.debug.core.model.IDisassembly; -import org.eclipse.cdt.debug.core.model.IDisassemblyBlock; -import org.eclipse.cdt.debug.core.model.IExecFileInfo; -import org.eclipse.debug.core.DebugEvent; -import org.eclipse.debug.core.DebugException; - -/** - * CDI implementation of IDisassembly - */ -public class Disassembly extends CDebugElement implements IDisassembly, ICDIEventListener { - - final static private int DISASSEMBLY_BLOCK_SIZE = 100; - - private DisassemblyBlock[] fBlocks = new DisassemblyBlock[1]; - - /** - * Constructor for Disassembly. - * - * @param target - */ - public Disassembly( CDebugTarget target ) { - super( target ); - getCDISession().getEventManager().addEventListener( this ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.IDisassembly#getDisassemblyBlock(org.eclipse.cdt.debug.core.model.ICStackFrame) - */ - @Override - public IDisassemblyBlock getDisassemblyBlock( ICStackFrame frame ) throws DebugException { - if ( fBlocks[0] == null || !fBlocks[0].contains( frame ) ) { - fBlocks[0] = createBlock( frame ); - } - return fBlocks[0]; - } - - private DisassemblyBlock createBlock( ICStackFrame frame ) throws DebugException { - ICDITarget target = getDebugTarget().getAdapter( ICDITarget.class ); - if ( target != null ) { - String fileName = frame.getFile(); - int lineNumber = frame.getLineNumber(); - ICDIMixedInstruction[] mixedInstrs = new ICDIMixedInstruction[0]; - IAddress address = frame.getAddress(); - if (address==null) - return null; - if ( fileName != null && fileName.length() > 0 ) { - try { - mixedInstrs = target.getMixedInstructions( fileName, - lineNumber, - CDebugCorePlugin.getDefault().getPluginPreferences().getInt( ICDebugConstants.PREF_MAX_NUMBER_OF_INSTRUCTIONS ) ); - } - catch( CDIException e ) { - // ignore and try to get disassembly without source - } - } - // Double check if debugger returns correct address range. - if ( mixedInstrs.length == 0 || - !containsAddress( mixedInstrs, address ) ) { - try { - BigInteger addr = new BigInteger( address.toString() ); - ICDIInstruction[] instructions = getFunctionInstructions( target.getInstructions( addr, addr.add( BigInteger.valueOf( DISASSEMBLY_BLOCK_SIZE ) ) ) ); - return DisassemblyBlock.create( this, instructions ); - } - catch( CDIException e ) { - targetRequestFailed( e.getMessage(), e ); - } - } - else { - return DisassemblyBlock.create( this, mixedInstrs ); - } - } - return null; - } - - @Override - public IDisassemblyBlock getDisassemblyBlock( IAddress address ) throws DebugException { - fBlocks[0] = createBlock( address, null); - return fBlocks[0]; - } - - public IDisassemblyBlock getDisassemblyBlock( IAddress startAddress, IAddress endAddress ) throws DebugException { - fBlocks[0] = createBlock( startAddress, endAddress ); - return fBlocks[0]; - } - - private DisassemblyBlock createBlock( IAddress startAddress, IAddress endAddress) throws DebugException { - ICDITarget target = getDebugTarget().getAdapter( ICDITarget.class ); - if ( target != null ) { - ICDIMixedInstruction[] mixedInstrs = new ICDIMixedInstruction[0]; - if ( mixedInstrs.length == 0 || - !containsAddress( mixedInstrs, startAddress ) ) { - try { - BigInteger startAddr = new BigInteger( startAddress.toString() ); - BigInteger endAddr = null; - if (endAddress != null) { - endAddr = new BigInteger( endAddress.toString() ); - } else { - endAddr = startAddr.add( BigInteger.valueOf( - CDebugCorePlugin.getDefault().getPluginPreferences().getInt(ICDebugConstants.PREF_MAX_NUMBER_OF_INSTRUCTIONS))); - } - mixedInstrs = target.getMixedInstructions( startAddr, endAddr); - return DisassemblyBlock.create( this, mixedInstrs ); - } - catch( CDIException e ) { - targetRequestFailed( e.getMessage(), e ); - } - } - else { - return DisassemblyBlock.create( this, mixedInstrs ); - } - } - return null; - } - - - private boolean containsAddress( ICDIMixedInstruction[] mi, IAddress address ) { - for( int i = 0; i < mi.length; ++i ) { - ICDIInstruction[] instructions = mi[i].getInstructions(); - for ( int j = 0; j < instructions.length; ++j ) { - if ( address.getValue().equals( instructions[j].getAdress() ) ) - return true; - } - } - return false; - } - - private ICDIInstruction[] getFunctionInstructions( ICDIInstruction[] rawInstructions ) { - if ( rawInstructions.length > 0 && rawInstructions[0].getFuntionName() != null && rawInstructions[0].getFuntionName().length() > 0 ) { - ArrayList list = new ArrayList( rawInstructions.length ); - list.add( rawInstructions[0] ); - for( int i = 1; i < rawInstructions.length; ++i ) { - if ( rawInstructions[0].getFuntionName().equals( rawInstructions[i].getFuntionName() ) ) { - list.add( rawInstructions[i] ); - } - } - return (ICDIInstruction[])list.toArray( new ICDIInstruction[list.size()] ); - } - return rawInstructions; - } - - public void dispose() { - getCDISession().getEventManager().removeEventListener( this ); - CDebugCorePlugin.getDefault().getDisassemblyContextService().unregister( this ); - for ( int i = 0; i < fBlocks.length; ++i ) - if ( fBlocks[i] != null ) { - fBlocks[i].dispose(); - fBlocks[i] = null; - } - } - - /* (non-Javadoc) - * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class) - */ - @Override - public Object getAdapter( Class adapter ) { - if ( IExecFileInfo.class.equals( adapter ) ) - return getDebugTarget().getAdapter( adapter ); - return super.getAdapter( adapter ); - } - - public void reset() { - for ( int i = 0; i < fBlocks.length; ++i ) - if ( fBlocks[i] != null ) { - fBlocks[i].dispose(); - fBlocks[i] = null; - } - fireChangeEvent( DebugEvent.CONTENT ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.IDisassembly#getAddressFactory() - */ - @Override - public IAddressFactory getAddressFactory() { - return ((CDebugTarget)getDebugTarget()).getAddressFactory(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.cdi.event.ICDIEventListener#handleDebugEvents(org.eclipse.cdt.debug.core.cdi.event.ICDIEvent[]) - */ - @Override - public void handleDebugEvents( ICDIEvent[] events ) { - boolean update = false; - for ( int i = 0; i < events.length; ++i ) { - if ( events[i] instanceof ICDIMemoryChangedEvent ) { - BigInteger[] addresses = ((ICDIMemoryChangedEvent)events[i]).getAddresses(); - for ( int j = 0; j < addresses.length; ++j ) { - IAddress address = getAddressFactory().createAddress( addresses[j] ); - for ( int k = 0; k < fBlocks.length; ++k ) { - if ( fBlocks[k] != null && fBlocks[k].contains( address ) ) { - update = true; - break; - } - } - } - } - } - if ( update ) - reset(); - } -} diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/DisassemblyBlock.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/DisassemblyBlock.java deleted file mode 100644 index f5a09f7417d..00000000000 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/DisassemblyBlock.java +++ /dev/null @@ -1,244 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2015 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 - * Mike Caraman (Frescale) - https://bugs.eclipse.org/bugs/show_bug.cgi?id=210863 - *******************************************************************************/ -package org.eclipse.cdt.debug.internal.core.model; - -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileReader; -import java.io.IOException; -import java.io.LineNumberReader; - -import org.eclipse.cdt.core.IAddress; -import org.eclipse.cdt.core.IAddressFactory; -import org.eclipse.cdt.core.model.ITranslationUnit; -import org.eclipse.cdt.debug.core.cdi.model.ICDIInstruction; -import org.eclipse.cdt.debug.core.cdi.model.ICDIMixedInstruction; -import org.eclipse.cdt.debug.core.model.IAsmInstruction; -import org.eclipse.cdt.debug.core.model.IAsmSourceLine; -import org.eclipse.cdt.debug.core.model.ICStackFrame; -import org.eclipse.cdt.debug.core.model.IDisassembly; -import org.eclipse.cdt.debug.core.model.IDisassemblyBlock; -import org.eclipse.cdt.debug.core.model.IExecFileInfo; -import org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocator; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IStorage; -import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.debug.core.model.ISourceLocator; -import org.eclipse.debug.core.sourcelookup.ISourceLookupDirector; - -/** - * CDI-based implementation of <code>IDisassemblyBlock</code>. - */ -public class DisassemblyBlock implements IDisassemblyBlock, IAdaptable { - - private IDisassembly fDisassembly; - - private Object fSourceElement; - - private IAsmSourceLine[] fSourceLines; - - private IAddress fStartAddress = null; - - private IAddress fEndAddress = null; - - private boolean fMixedMode = false; - - /** - * Constructor for DisassemblyBlock. - */ - private DisassemblyBlock( IDisassembly disassembly ) { - fDisassembly = disassembly; - } - - public static DisassemblyBlock create( IDisassembly disassembly, ICDIMixedInstruction[] instructions ) { - DisassemblyBlock block = new DisassemblyBlock( disassembly ); - ISourceLocator locator = disassembly.getDebugTarget().getLaunch().getSourceLocator(); - IAddressFactory factory = ((CDebugTarget)disassembly.getDebugTarget()).getAddressFactory(); - block.initialize( factory, locator, instructions ); - return block; - } - - public static DisassemblyBlock create( IDisassembly disassembly, ICDIInstruction[] instructions ) { - DisassemblyBlock block = new DisassemblyBlock( disassembly ); - IAddressFactory factory = ((CDebugTarget)disassembly.getDebugTarget()).getAddressFactory(); - block.initialize( factory, instructions ); - return block; - } - - private void initialize( IAddressFactory factory, ICDIInstruction[] instructions ) { - setMixedMode( false ); - createSourceLines( factory, instructions ); - initializeAddresses(); - } - - private void initialize( IAddressFactory factory, ISourceLocator locator, ICDIMixedInstruction[] mi ) { - setMixedMode( true ); - createSourceLines( factory, locator, mi ); - initializeAddresses(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.IDisassemblyBlock#getDisassembly() - */ - @Override - public IDisassembly getDisassembly() { - return fDisassembly; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.IDisassemblyBlock#getModuleFile() - */ - @Override - public String getModuleFile() { - IDisassembly d = getDisassembly(); - if ( d != null ) { - IExecFileInfo info = d.getAdapter( IExecFileInfo.class ); - if ( info != null && info.getExecFile() != null ) { - return info.getExecFile().getPath().toOSString(); - } - } - return ""; //$NON-NLS-1$ - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.IDisassemblyBlock#getSourceElement() - */ - @Override - public Object getSourceElement() { - return fSourceElement; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.IDisassemblyBlock#contains(org.eclipse.cdt.debug.core.model.ICStackFrame) - */ - @Override - public boolean contains( ICStackFrame frame ) { - if ( !getDisassembly().getDebugTarget().equals( frame.getDebugTarget() ) ) - return false; - if ( fStartAddress == null || fEndAddress == null ) - return false; - IAddress address = frame.getAddress(); // will return null if frame was disposed - return (address != null && address.compareTo( fStartAddress ) >= 0 && address.compareTo( fEndAddress ) <= 0); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.debug.core.model.IDisassemblyBlock#getSourceLines() - */ - @Override - public IAsmSourceLine[] getSourceLines() { - return fSourceLines; - } - - /* (non-Javadoc) - * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class) - */ - @Override - public Object getAdapter( Class adapter ) { - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.IDisassemblyBlock#isMixedMode() - */ - @Override - public boolean isMixedMode() { - return fMixedMode; - } - - public void dispose() { - } - - private void createSourceLines( IAddressFactory factory, ISourceLocator locator, ICDIMixedInstruction[] mi ) { - IAsmSourceLine[] result = new IAsmSourceLine[mi.length]; - LineNumberReader reader = null; - if ( result.length > 0 && locator != null ) { - String fileName = mi[0].getFileName(); - Object element = null; - if ( locator instanceof ISourceLookupDirector ) { - element = ((ISourceLookupDirector)locator).getSourceElement( fileName ); - } - if ( locator instanceof ICSourceLocator ) { - element = ((ICSourceLocator)locator).findSourceElement( fileName ); - } - fSourceElement = element; - File file = null; - if ( element instanceof IFile ) { - file = ((IFile)element).getLocation().toFile(); - } - else if ( element instanceof ITranslationUnit ) { - file = ((ITranslationUnit)element).getLocation().toFile(); - } - else if ( element instanceof IStorage ) { - file = ((IStorage)element).getFullPath().toFile(); - } - if ( file != null ) { - try { - reader = new LineNumberReader( new FileReader( file ) ); - } - catch( FileNotFoundException e ) { - } - } - } - for ( int i = 0; i < result.length; ++i ) { - String text = null; - boolean failed = false; - int lineNumber = mi[i].getLineNumber(); - if ( reader != null ) { - while( reader.getLineNumber() + 1 < lineNumber ) { - try { - if ( reader.readLine() == null ) { - // break if the end of file is reached (see bug #123745) - failed = true; - break; - } - } - catch( IOException e ) { - } - } - if ( !failed && reader.getLineNumber() + 1 == lineNumber ) { - try { - text = reader.readLine() + '\n'; - } - catch( IOException e ) { - } - } - } - result[i] = new AsmSourceLine( factory, text, lineNumber, mi[i].getInstructions() ); - } - fSourceLines = result; - } - - private void createSourceLines( IAddressFactory factory, ICDIInstruction[] instructions ) { - fSourceLines = new IAsmSourceLine[] { new AsmSourceLine( factory, "", instructions ) }; //$NON-NLS-1$ - } - - private void initializeAddresses() { - for ( int i = 0; i < fSourceLines.length; ++i ) { - IAsmInstruction[] instr = fSourceLines[i].getInstructions(); - if ( instr.length > 0 ) { - if ( fStartAddress == null ) - fStartAddress = instr[0].getAdress(); - fEndAddress = instr[instr.length - 1].getAdress(); - } - } - } - - private void setMixedMode( boolean mixedMode ) { - this.fMixedMode = mixedMode; - } - - protected boolean contains( IAddress address ) { - return ( address.compareTo( fStartAddress ) >= 0 && address.compareTo( fEndAddress ) <= 0 ); - } -} diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/DisassemblyInstruction.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/DisassemblyInstruction.java deleted file mode 100644 index 982af00a252..00000000000 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/DisassemblyInstruction.java +++ /dev/null @@ -1,103 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2012 ARM Limited 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: - * ARM Limited - Initial API and implementation - *******************************************************************************/ - -package org.eclipse.cdt.debug.internal.core.model; - -import java.math.BigInteger; - -import org.eclipse.cdt.core.IAddress; -import org.eclipse.cdt.debug.core.cdi.model.ICDIInstruction; -import org.eclipse.cdt.debug.core.model.IDisassemblyInstruction; - -public class DisassemblyInstruction extends CDebugElement implements IDisassemblyInstruction { - - private ICDIInstruction fCDIInstruction; - private IAddress fAddress; - - public DisassemblyInstruction( CDebugTarget target, BigInteger baseElement, ICDIInstruction instruction ) { - super( target ); - fCDIInstruction = instruction; - fAddress = target.getAddressFactory().createAddress( fCDIInstruction.getAdress() ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.IAsmInstruction#getAdress() - */ - @Override - public IAddress getAdress() { - return fAddress; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.IAsmInstruction#getArguments() - */ - @Override - public String getArguments() { - return fCDIInstruction.getArgs(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.IAsmInstruction#getFunctionName() - */ - @Override - public String getFunctionName() { - return fCDIInstruction.getFuntionName(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.IAsmInstruction#getInstructionText() - */ - @Override - public String getInstructionText() { - return fCDIInstruction.getInstruction(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.IAsmInstruction#getOffset() - */ - @Override - public long getOffset() { - return fCDIInstruction.getOffset(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.IAsmInstruction#getOpcode() - */ - @Override - public String getOpcode() { - return fCDIInstruction.getOpcode(); - } - - /* (non-Javadoc) - * @see java.lang.Object#equals(java.lang.Object) - */ - @Override - public boolean equals( Object obj ) { - if ( obj == this ) - return true; - if ( !(obj instanceof IDisassemblyInstruction) ) - return false; - IDisassemblyInstruction instr = (IDisassemblyInstruction)obj; - if ( !instr.getAdress().equals( getAdress() ) ) - return false; - if ( instr.getOffset() != getOffset() ) - return false; - if ( instr.getFunctionName().compareTo( getFunctionName() ) != 0 ) - return false; - if ( instr.getOpcode().compareTo( getOpcode() ) != 0 ) - return false; - if ( instr.getArguments().compareTo( getArguments() ) != 0 ) - return false; - if ( instr.getInstructionText().compareTo( getInstructionText() ) != 0 ) - return false; - return true; - } -} diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/DisassemblyRetrieval.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/DisassemblyRetrieval.java deleted file mode 100644 index 16d4411a896..00000000000 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/DisassemblyRetrieval.java +++ /dev/null @@ -1,327 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2015 ARM Limited 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: - * ARM Limited - Initial API and implementation - *******************************************************************************/ - -package org.eclipse.cdt.debug.internal.core.model; - -import java.math.BigInteger; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import org.eclipse.cdt.core.IAddress; -import org.eclipse.cdt.core.IAddressFactory; -import org.eclipse.cdt.debug.core.CDebugCorePlugin; -import org.eclipse.cdt.debug.core.cdi.CDIException; -import org.eclipse.cdt.debug.core.cdi.event.ICDIBreakpointMovedEvent; -import org.eclipse.cdt.debug.core.cdi.event.ICDIBreakpointProblemEvent; -import org.eclipse.cdt.debug.core.cdi.event.ICDIChangedEvent; -import org.eclipse.cdt.debug.core.cdi.event.ICDICreatedEvent; -import org.eclipse.cdt.debug.core.cdi.event.ICDIDestroyedEvent; -import org.eclipse.cdt.debug.core.cdi.event.ICDIEvent; -import org.eclipse.cdt.debug.core.cdi.event.ICDIEventListener; -import org.eclipse.cdt.debug.core.cdi.model.ICDIInstruction; -import org.eclipse.cdt.debug.core.cdi.model.ICDILocationBreakpoint; -import org.eclipse.cdt.debug.core.cdi.model.ICDIMixedInstruction; -import org.eclipse.cdt.debug.core.cdi.model.ICDITarget; -import org.eclipse.cdt.debug.core.model.ICStackFrame; -import org.eclipse.cdt.debug.core.model.IDisassemblyInstruction; -import org.eclipse.cdt.debug.core.model.IDisassemblyLine; -import org.eclipse.core.runtime.Assert; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.debug.core.DebugEvent; -import org.eclipse.debug.core.DebugException; - -public class DisassemblyRetrieval extends CDebugElement implements ICDIEventListener { - - public static final int FLAGS_SHOW_INSTRUCTIONS = 0x1; - public static final int FLAGS_SHOW_SOURCE = 0x2; - - private Object fInput = null; - private BigInteger fBaseElement = null; - private int fCurrentOffset = 0; - private int fFlags = 0; - private IDisassemblyLine[] fLines; - - public DisassemblyRetrieval( CDebugTarget target ) { - super( target ); - fLines = new IDisassemblyLine[0]; - CDebugCorePlugin.getDefault().getDisassemblyContextService().register( this ); - getCDISession().getEventManager().addEventListener( this ); - } - - public void dispose() { - getCDISession().getEventManager().removeEventListener( this ); - CDebugCorePlugin.getDefault().getDisassemblyContextService().unregister( this ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.cdi.event.ICDIEventListener#handleDebugEvents(org.eclipse.cdt.debug.core.cdi.event.ICDIEvent[]) - */ - @Override - public void handleDebugEvents( ICDIEvent[] events ) { - for ( ICDIEvent event : events ) { - Object source = event.getSource(); - if ( (event instanceof ICDICreatedEvent - || event instanceof ICDIChangedEvent - || event instanceof ICDIDestroyedEvent - || event instanceof ICDIBreakpointMovedEvent - || event instanceof ICDIBreakpointProblemEvent ) - && source instanceof ICDILocationBreakpoint ) { - BigInteger address = ((ICDILocationBreakpoint)source).getLocator().getAddress(); - if ( address != null ) { - int index = getIndexForAddress( address, fLines ); - if ( index >= 0 ) { - fireEvent( new DebugEvent( fLines[index], DebugEvent.CHANGE, DebugEvent.STATE ) ); - } - if ( event instanceof ICDIBreakpointMovedEvent ) { - address = ((ICDIBreakpointMovedEvent)event).getNewLocation().getAddress(); - if ( address != null ) { - index = getIndexForAddress( address, fLines ); - if ( index >= 0 ) { - fireEvent( new DebugEvent( fLines[index], DebugEvent.CHANGE, DebugEvent.STATE ) ); - } - } - } - } - } - } - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.IDisassemblyRetrieval#getInput() - */ - public Object getInput() { - return fInput; - } - - public BigInteger getBaseElement() { - return fBaseElement; - } - - public int getCurrentOffset() { - return fCurrentOffset; - } - - public IDisassemblyLine[] getLines() { - return fLines; - } - - public void changeBase( Object input, int offset, int flags ) throws DebugException { - if ( input instanceof ICStackFrame ) { - fInput = input; - ICStackFrame frame = (ICStackFrame)input; - IAddress frameAddress = frame.getAddress(); - BigInteger address = (frameAddress != null) ? frameAddress.getValue() : BigInteger.valueOf(0); - if ( !containsAddress( address, fLines ) ) { - fCurrentOffset = 0; - reset(); - } - else if ( flags != fFlags ) { - reset(); - } - else { - fCurrentOffset += getDistance( fBaseElement, address ); - } - fFlags = flags; - fBaseElement = address; - } - } - - public void retrieveDisassembly( Object input, Object base, int offset, int lineCount, boolean reveal, int flags ) throws DebugException { - fFlags = flags; - boolean showSource = ( (flags & FLAGS_SHOW_SOURCE) != 0 ); - List<IDisassemblyLine> lines = new ArrayList<IDisassemblyLine>( lineCount ); - BigInteger startAddress = getCurrentStartAddress(); - BigInteger address = null; - if ( startAddress != null ) { - if ( getCurrentOffset() > offset ) { - // scrolling up - address = startAddress.subtract( BigInteger.valueOf( getMinInstructionSize() * (getCurrentOffset() - offset) ) ); - } - else if ( getCurrentOffset() < offset ) { - // scrolling down - IDisassemblyInstruction next = getNextInstruction( startAddress, fLines ); - if ( next != null ) - address = next.getAdress().getValue(); - } - else { - address = startAddress; - } - } - if ( address == null ) - address = fBaseElement; - lines.addAll( Arrays.asList( disassembleDown( address, lineCount, showSource ) ) ); - fLines = lines.toArray( new IDisassemblyLine[lines.size()] ); - fCurrentOffset = offset; - } - - private boolean containsAddress( BigInteger address, IDisassemblyLine[] lines ) { - return ( getIndexForAddress( address, lines ) >= 0 ); - } - - public void reset() { - fLines = new IDisassemblyLine[0]; - } - - private int getDistance( BigInteger address1, BigInteger address2 ) { - int index1 = getIndexForAddress( address1, fLines ); - Assert.isTrue( index1 >=0 ); - int index2 = getIndexForAddress( address2, fLines ); - Assert.isTrue( index2 >=0 ); - return index2 - index1; - } - - private int getIndexForAddress( BigInteger address, IDisassemblyLine[] lines ) { - for ( int i = 0; i < lines.length; ++i ) { - if ( lines[i] instanceof IDisassemblyInstruction && - address.compareTo( ((IDisassemblyInstruction)lines[i]).getAdress().getValue() ) == 0 ) - return i; - } - return -1; - } - - private BigInteger getCurrentStartAddress() { - for ( IDisassemblyLine l : fLines ) { - if ( l instanceof IDisassemblyInstruction ) - return ((IDisassemblyInstruction)l).getAdress().getValue(); - } - return null; - } - - private IDisassemblyLine[] disassembleDown( BigInteger address, int lineCount, boolean mixed ) throws DebugException { - BigInteger startAddress = address; - IDisassemblyLine[] lines = new IDisassemblyLine[0]; - BigInteger endAddress = startAddress; - if ( lines.length < lineCount && endAddress.compareTo( getGlobalEndAddress() ) < 0 ) { - endAddress = address.add( BigInteger.valueOf( lineCount * getMaxInstructionSize() ) ); - if ( endAddress.compareTo( getGlobalEndAddress() ) > 0 ) - endAddress = getGlobalEndAddress(); - lines = disassemble( address, endAddress, mixed ); - IDisassemblyInstruction firstInstruction = getFirstInstruction( lines ); - IDisassemblyInstruction lastInstruction = getLastInstruction( lines ); - if ( firstInstruction != null && lastInstruction != null ) { - if ( startAddress.compareTo( firstInstruction.getAdress().getValue() ) < 0 ) { - lines = appendLines( disassemble( startAddress, firstInstruction.getAdress().getValue(), mixed ), lines ); - } - startAddress = lastInstruction.getAdress().getValue(); - if ( startAddress.compareTo( endAddress ) < 0 ) { - IDisassemblyLine[] extraLines = new IDisassemblyLine[0]; - while( extraLines.length == 0 && endAddress.compareTo( getGlobalEndAddress() ) < 0 ) { - endAddress = endAddress.add( BigInteger.valueOf( getMaxInstructionSize() ) ); - extraLines = disassemble( startAddress, endAddress, mixed ); - } - lines = appendLines( lines, extraLines ); - } - } - } - int size = Math.min( lineCount, lines.length ); - IDisassemblyLine[] result = new IDisassemblyLine[size]; - int start = getIndexForAddress( address, lines ); - if ( start != -1 ) { - System.arraycopy( lines, start, result, 0, size ); - } - return result; - } - - private IDisassemblyLine[] disassemble( BigInteger startAddress, BigInteger endAddress, boolean mixed ) throws DebugException { - List<IDisassemblyLine> list = new ArrayList<IDisassemblyLine>(); - ICDITarget cdiTarget = getDebugTarget().getAdapter( ICDITarget.class ); - try { - ICDIMixedInstruction[] mixedInstructions = null; - ICDIInstruction[] asmInstructions = null; - if ( mixed ) { - mixedInstructions = cdiTarget.getMixedInstructions( startAddress, endAddress ); - if ( mixedInstructions.length == 0 - || mixedInstructions.length == 1 - && mixedInstructions[0].getInstructions().length == 0 ) { - mixedInstructions = null; - } - } - if ( mixedInstructions == null ) { - asmInstructions = cdiTarget.getInstructions( startAddress, endAddress ); - } - if ( mixedInstructions != null ) { - for ( ICDIMixedInstruction mi : mixedInstructions ) { - ICDIInstruction[] instructions = mi.getInstructions(); - if ( instructions.length > 0 ) { - list.add( new DisassemblySourceLine( (CDebugTarget)getDebugTarget(), fBaseElement, mi ) ); - for ( ICDIInstruction i : instructions ) { - list.add( new DisassemblyInstruction( (CDebugTarget)getDebugTarget(), fBaseElement, i ) ); - } - } - } - } - else if ( asmInstructions != null ) { - for ( ICDIInstruction i : asmInstructions ) { - list.add( new DisassemblyInstruction( (CDebugTarget)getDebugTarget(), fBaseElement, i ) ); - } - } - } - catch( CDIException exc ) { - throw new DebugException( new Status( IStatus.ERROR, "dummy", exc.getDetailMessage(), exc ) ); //$NON-NLS-1$ - } - return list.toArray( new IDisassemblyLine[list.size()] ); - } - - private int getMaxInstructionSize() { - return 4; - } - - private int getMinInstructionSize() { - return 1; - } - - private IDisassemblyInstruction getNextInstruction( BigInteger address, IDisassemblyLine[] lines ) { - int index = getIndexForAddress( address, lines ); - if ( index == -1 || index == lines.length - 1 ) - return null; - for ( int i = index + 1; i < lines.length; ++i ) { - if ( lines[i] instanceof IDisassemblyInstruction ) - return (IDisassemblyInstruction)lines[i]; - } - return null; - } - - private IDisassemblyInstruction getFirstInstruction( IDisassemblyLine[] lines ) { - for ( IDisassemblyLine l : lines ) { - if ( l instanceof IDisassemblyInstruction ) - return (IDisassemblyInstruction)l; - } - return null; - } - - private IDisassemblyInstruction getLastInstruction( IDisassemblyLine[] lines ) { - for ( int i = lines.length - 1; i >= 0; --i ) { - if ( lines[i] instanceof IDisassemblyInstruction ) - return (IDisassemblyInstruction)lines[i]; - } - return null; - } - - private BigInteger getGlobalEndAddress() { - return getAddressFactory().getMax().getValue(); - } - - private IAddressFactory getAddressFactory() { - return ((CDebugTarget)getDebugTarget()).getAddressFactory(); - } - - private IDisassemblyLine[] appendLines( IDisassemblyLine[] lines1, IDisassemblyLine[] lines2 ) { - List<IDisassemblyLine> list = new ArrayList<IDisassemblyLine>( lines1.length + lines2.length ); - list.addAll( Arrays.asList( lines1 ) ); - for ( IDisassemblyLine l : lines2 ) { - if ( !list.contains( l ) ) - list.add( l ); - } - return list.toArray( new IDisassemblyLine[list.size()] ); - } -} diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/DisassemblySourceLine.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/DisassemblySourceLine.java deleted file mode 100644 index 5b503d86074..00000000000 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/DisassemblySourceLine.java +++ /dev/null @@ -1,86 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2012 ARM Limited 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: - * ARM Limited - Initial API and implementation - *******************************************************************************/ - -package org.eclipse.cdt.debug.internal.core.model; - -import java.io.File; -import java.math.BigInteger; - -import org.eclipse.cdt.debug.core.cdi.model.ICDIMixedInstruction; -import org.eclipse.cdt.debug.core.model.IAsmInstruction; -import org.eclipse.cdt.debug.core.model.IDisassemblySourceLine; - -public class DisassemblySourceLine extends CDebugElement implements IDisassemblySourceLine { - - private BigInteger fBaseElement; - private ICDIMixedInstruction fCDIMixedInstruction; - - public DisassemblySourceLine( CDebugTarget target, BigInteger baseElement, ICDIMixedInstruction mixedInstruction ) { - super( target ); - fBaseElement = baseElement; - fCDIMixedInstruction = mixedInstruction; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.IDisassemblySourceLine#getFile() - */ - @Override - public File getFile() { - String name = fCDIMixedInstruction.getFileName(); - if ( name != null && name.length() > 0 ) { - return new File( name ); - } - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.IAsmSourceLine#getInstructions() - */ - @Override - public IAsmInstruction[] getInstructions() { - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.IAsmSourceLine#getLineNumber() - */ - @Override - public int getLineNumber() { - return fCDIMixedInstruction.getLineNumber(); - } - - public BigInteger getBaseAddress() { - return fBaseElement; - } - - /* (non-Javadoc) - * @see java.lang.Object#toString() - */ - @Override - public String toString() { - return fCDIMixedInstruction.getFileName() + ' ' + getLineNumber(); - } - - /* (non-Javadoc) - * @see java.lang.Object#equals(java.lang.Object) - */ - @Override - public boolean equals( Object obj ) { - if ( !(obj instanceof IDisassemblySourceLine) ) - return false; - IDisassemblySourceLine other = (IDisassemblySourceLine)obj; - if ( !getFile().equals( other.getFile() ) ) - return false; - if ( getLineNumber() != other.getLineNumber() ) - return false; - return true; - } -} diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CSourceLookupParticipant.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CSourceLookupParticipant.java index c9bde9be8e2..b86e9e5bfad 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CSourceLookupParticipant.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CSourceLookupParticipant.java @@ -19,16 +19,11 @@ import java.util.Collections; import java.util.HashMap; import java.util.Map; -import org.eclipse.cdt.debug.core.cdi.ICDIBreakpointHit; -import org.eclipse.cdt.debug.core.model.ICDebugTarget; -import org.eclipse.cdt.debug.core.model.ICStackFrame; import org.eclipse.cdt.debug.core.sourcelookup.AbsolutePathSourceContainer; import org.eclipse.cdt.debug.core.sourcelookup.ISourceLookupChangeListener; -import org.eclipse.cdt.debug.internal.core.CBreakpointManager; import org.eclipse.cdt.debug.internal.core.ListenerList; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IAdaptable; import org.eclipse.debug.core.model.IBreakpoint; import org.eclipse.debug.core.model.IDebugElement; import org.eclipse.debug.core.sourcelookup.AbstractSourceLookupParticipant; @@ -64,13 +59,6 @@ public class CSourceLookupParticipant extends AbstractSourceLookupParticipant { if (object instanceof String) { return (String)object; } - if (object instanceof IAdaptable) { - ICStackFrame frame = ((IAdaptable)object).getAdapter(ICStackFrame.class); - if (frame != null) { - String name = frame.getFile(); - return (name != null && name.trim().length() > 0) ? name : null; - } - } return null; } @@ -87,30 +75,7 @@ public class CSourceLookupParticipant extends AbstractSourceLookupParticipant { // Workaround for cases when the stack frame doesn't contain the source file name String name = null; IBreakpoint breakpoint = null; - if (object instanceof IAdaptable) { - ICStackFrame frame = ((IAdaptable)object).getAdapter(ICStackFrame.class); - if (frame != null) { - name = frame.getFile().trim(); - if (name == null || name.length() == 0) - { - if (object instanceof IDebugElement) - results = new Object[] { new CSourceNotFoundElement((IDebugElement) object, ((IDebugElement) object).getLaunch().getLaunchConfiguration(), name) }; - else - results = new Object[] { gfNoSource }; - fCachedResults.put(object, results); - return results; - } - } - // See if findSourceElements(...) is the result of a Breakpoint Hit Event - ICDebugTarget target = ((IAdaptable)object).getAdapter(ICDebugTarget.class); - if (target != null) { - CBreakpointManager bmanager = target.getAdapter(CBreakpointManager.class); - Object stateInfo = target.getCurrentStateInfo(); - if (bmanager != null && stateInfo instanceof ICDIBreakpointHit) { - breakpoint = bmanager.getBreakpoint(((ICDIBreakpointHit)stateInfo).getBreakpoint()); - } - } - } else if (object instanceof String) { + if (object instanceof String) { name = (String)object; } diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CSourceManager.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CSourceManager.java index 3d10e11a694..31c34841d96 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CSourceManager.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CSourceManager.java @@ -13,14 +13,11 @@ package org.eclipse.cdt.debug.internal.core.sourcelookup; import org.eclipse.cdt.debug.core.model.ICStackFrame; import org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocation; import org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocator; -import org.eclipse.cdt.debug.internal.core.model.CDebugTarget; -import org.eclipse.cdt.debug.internal.core.model.Disassembly; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResourceChangeListener; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.debug.core.DebugException; import org.eclipse.debug.core.ILaunch; import org.eclipse.debug.core.ILaunchConfiguration; import org.eclipse.debug.core.model.IPersistableSourceLocator; @@ -33,7 +30,6 @@ import org.eclipse.debug.core.model.IStackFrame; public class CSourceManager implements ICSourceLocator, IPersistableSourceLocator, IAdaptable { private ISourceLocator fSourceLocator = null; private ILaunch fLaunch = null; - private CDebugTarget fDebugTarget = null; /** * Constructor for CSourceManager. @@ -75,17 +71,6 @@ public class CSourceManager implements ICSourceLocator, IPersistableSourceLocato public void setSourceLocations(ICSourceLocation[] locations) { if (getCSourceLocator() != null) { getCSourceLocator().setSourceLocations(locations); - CDebugTarget target = getDebugTarget(); - if (target != null) { - Disassembly d = null; - try { - d = (Disassembly)target.getDisassembly(); - } catch (DebugException e) { - } - if (d != null) { - d.reset(); - } - } } } @@ -203,14 +188,6 @@ public class CSourceManager implements ICSourceLocator, IPersistableSourceLocato return (getCSourceLocator() != null) ? getCSourceLocator().getProject() : null; } - public void setDebugTarget(CDebugTarget target) { - fDebugTarget = target; - } - - protected CDebugTarget getDebugTarget() { - return fDebugTarget; - } - /* * (non-Javadoc) * @see org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocator#setSearchForDuplicateFiles(boolean) |