From e9d5637ecaed1cee93df613d107360e7777cfc36 Mon Sep 17 00:00:00 2001 From: Jonah Graham Date: Tue, 22 Dec 2015 21:36:54 +0000 Subject: [PATCH] Bug 483234: Add a command example to the example plug-in A new command, ShowVersionHandler, has been added to the plug-in to demonstrate all the pieces that need to be put in place to connect a command to a DSF session. Change-Id: Iefde0ba144c12ce2e580da7717b390258c0d3675 Signed-off-by: Jonah Graham --- .../.classpath | 2 +- .../.settings/org.eclipse.jdt.core.prefs | 7 +- .../META-INF/MANIFEST.MF | 2 +- .../icons/sample.gif | Bin 0 -> 983 bytes .../plugin.xml | 110 ++++++++++++++ .../dsf/gdb/GdbExtendedAdapterFactory.java | 10 +- .../dsf/gdb/GdbExtendedSessionAdapters.java | 14 ++ .../gdb/actions/GdbShowVersionHandler.java | 142 ++++++++++++++++++ .../dsf/gdb/commands/IShowVersionHandler.java | 18 +++ .../dsf/gdb/commands/ShowVersionHandler.java | 22 +++ .../dsf/gdb/service/GDBExtendedService.java | 5 + .../gdb/service/IGDBExtendedFunctions.java | 5 + .../META-INF/MANIFEST.MF | 3 +- 13 files changed, 328 insertions(+), 12 deletions(-) create mode 100644 dsf-gdb/org.eclipse.cdt.examples.dsf.gdb/icons/sample.gif create mode 100644 dsf-gdb/org.eclipse.cdt.examples.dsf.gdb/src/org/eclipse/cdt/examples/dsf/gdb/actions/GdbShowVersionHandler.java create mode 100644 dsf-gdb/org.eclipse.cdt.examples.dsf.gdb/src/org/eclipse/cdt/examples/dsf/gdb/commands/IShowVersionHandler.java create mode 100644 dsf-gdb/org.eclipse.cdt.examples.dsf.gdb/src/org/eclipse/cdt/examples/dsf/gdb/commands/ShowVersionHandler.java diff --git a/dsf-gdb/org.eclipse.cdt.examples.dsf.gdb/.classpath b/dsf-gdb/org.eclipse.cdt.examples.dsf.gdb/.classpath index 098194ca4b7..eca7bdba8f0 100644 --- a/dsf-gdb/org.eclipse.cdt.examples.dsf.gdb/.classpath +++ b/dsf-gdb/org.eclipse.cdt.examples.dsf.gdb/.classpath @@ -1,6 +1,6 @@ - + diff --git a/dsf-gdb/org.eclipse.cdt.examples.dsf.gdb/.settings/org.eclipse.jdt.core.prefs b/dsf-gdb/org.eclipse.cdt.examples.dsf.gdb/.settings/org.eclipse.jdt.core.prefs index 625b641ae3b..52b8b289faa 100644 --- a/dsf-gdb/org.eclipse.cdt.examples.dsf.gdb/.settings/org.eclipse.jdt.core.prefs +++ b/dsf-gdb/org.eclipse.cdt.examples.dsf.gdb/.settings/org.eclipse.jdt.core.prefs @@ -1,9 +1,8 @@ -#Tue Jun 24 11:04:03 PDT 2008 eclipse.preferences.version=1 org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=1.7 +org.eclipse.jdt.core.compiler.compliance=1.8 org.eclipse.jdt.core.compiler.debug.lineNumber=generate org.eclipse.jdt.core.compiler.debug.localVariable=generate org.eclipse.jdt.core.compiler.debug.sourceFile=generate @@ -67,4 +66,4 @@ org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disa org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning -org.eclipse.jdt.core.compiler.source=1.7 +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/dsf-gdb/org.eclipse.cdt.examples.dsf.gdb/META-INF/MANIFEST.MF b/dsf-gdb/org.eclipse.cdt.examples.dsf.gdb/META-INF/MANIFEST.MF index 3cad61e9758..0a01d9cae10 100644 --- a/dsf-gdb/org.eclipse.cdt.examples.dsf.gdb/META-INF/MANIFEST.MF +++ b/dsf-gdb/org.eclipse.cdt.examples.dsf.gdb/META-INF/MANIFEST.MF @@ -16,7 +16,7 @@ Require-Bundle: org.eclipse.ui, org.eclipse.cdt.ui, org.eclipse.cdt.debug.core, org.eclipse.cdt.debug.ui -Bundle-RequiredExecutionEnvironment: JavaSE-1.7 +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Bundle-ActivationPolicy: lazy Bundle-Vendor: Eclipse CDT Export-Package: org.eclipse.cdt.examples.dsf.gdb;x-internal:=true, diff --git a/dsf-gdb/org.eclipse.cdt.examples.dsf.gdb/icons/sample.gif b/dsf-gdb/org.eclipse.cdt.examples.dsf.gdb/icons/sample.gif new file mode 100644 index 0000000000000000000000000000000000000000..34fb3c9d8cb7d489681b7f7aee4bdcd7eaf53610 GIT binary patch literal 983 zcmZ?wbhEHb6krfw_|CxKYUg-n!?izO{@9*?jxd%4aX0yzy`dymabz zw#(eg=y~&N&n)dZv2xzduG}5lraiApo3(c4*{Ylg5#|$JO_EEZ<^|a2`Z*=9ns7DV zy=TR&gYw*7f%auV?ip3tvjRPmcdoho{K?x$_vR?C#t5&<;~V}S*>OMCr>h}%%bLZ9 zmo3`hYEwTICo-TTCZwgTsC&VjZRgJ1eE#fBa^%9R zmmfWS@;bnyJ27HWY}kxYzv(Hl>yu;FCPlAEh+34Muq-8Rb6C)<8qA3{r2e5 z`$vyngh#H=FWlqqvnapfc5%(!sQ4v?r7J61-&eJNEN^;KTK}T7{#i-gJh%G*9vcYdwv_*~xdw!Gz4Va?T!sXyyF@8?w<>X`X=#j%uHV4GRvj@+tE@ zQ%F!a)GKcn^~8abN>4la1UNXVL;{ZWi)lEwyeatDu%Lr6;aASiLrXXW zQm# + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dsf-gdb/org.eclipse.cdt.examples.dsf.gdb/src/org/eclipse/cdt/examples/dsf/gdb/GdbExtendedAdapterFactory.java b/dsf-gdb/org.eclipse.cdt.examples.dsf.gdb/src/org/eclipse/cdt/examples/dsf/gdb/GdbExtendedAdapterFactory.java index 7aa3322336e..45eabe20e93 100644 --- a/dsf-gdb/org.eclipse.cdt.examples.dsf.gdb/src/org/eclipse/cdt/examples/dsf/gdb/GdbExtendedAdapterFactory.java +++ b/dsf-gdb/org.eclipse.cdt.examples.dsf.gdb/src/org/eclipse/cdt/examples/dsf/gdb/GdbExtendedAdapterFactory.java @@ -4,7 +4,7 @@ * 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 *******************************************************************************/ @@ -19,8 +19,8 @@ import org.eclipse.debug.core.ILaunch; @SuppressWarnings("restriction") @ThreadSafe public class GdbExtendedAdapterFactory extends GdbAdapterFactory { - @Override - protected GdbSessionAdapters createGdbSessionAdapters(ILaunch launch, DsfSession session) { - return new GdbExtendedSessionAdapters(launch, session, getAdapterList()); - } + @Override + protected GdbSessionAdapters createGdbSessionAdapters(ILaunch launch, DsfSession session) { + return new GdbExtendedSessionAdapters(launch, session, getAdapterList()); + } } diff --git a/dsf-gdb/org.eclipse.cdt.examples.dsf.gdb/src/org/eclipse/cdt/examples/dsf/gdb/GdbExtendedSessionAdapters.java b/dsf-gdb/org.eclipse.cdt.examples.dsf.gdb/src/org/eclipse/cdt/examples/dsf/gdb/GdbExtendedSessionAdapters.java index 6b3a39e9a8a..5e5f8c7544f 100644 --- a/dsf-gdb/org.eclipse.cdt.examples.dsf.gdb/src/org/eclipse/cdt/examples/dsf/gdb/GdbExtendedSessionAdapters.java +++ b/dsf-gdb/org.eclipse.cdt.examples.dsf.gdb/src/org/eclipse/cdt/examples/dsf/gdb/GdbExtendedSessionAdapters.java @@ -10,9 +10,13 @@ *******************************************************************************/ package org.eclipse.cdt.examples.dsf.gdb; +import java.util.List; + import org.eclipse.cdt.dsf.gdb.internal.ui.GdbSessionAdapters; import org.eclipse.cdt.dsf.service.DsfSession; import org.eclipse.cdt.examples.dsf.gdb.actions.DsfExtendedTerminateCommand; +import org.eclipse.cdt.examples.dsf.gdb.actions.GdbShowVersionHandler; +import org.eclipse.cdt.examples.dsf.gdb.commands.IShowVersionHandler; import org.eclipse.cdt.examples.dsf.gdb.viewmodel.GdbExtendedViewModelAdapter; import org.eclipse.debug.core.ILaunch; import org.eclipse.debug.core.commands.ITerminateHandler; @@ -34,7 +38,17 @@ public class GdbExtendedSessionAdapters extends GdbSessionAdapters { if (IViewerInputProvider.class.equals(adapterType)) { return (T)new GdbExtendedViewModelAdapter(session, getSteppingController()); } + if (IShowVersionHandler.class.equals(adapterType)) { + return (T)new GdbShowVersionHandler(session); + } return super.createModelAdapter(adapterType, launch, session); } + + @Override + protected List> getModelAdapters() { + List> modelAdapters = super.getModelAdapters(); + modelAdapters.add(IShowVersionHandler.class); + return modelAdapters; + } } diff --git a/dsf-gdb/org.eclipse.cdt.examples.dsf.gdb/src/org/eclipse/cdt/examples/dsf/gdb/actions/GdbShowVersionHandler.java b/dsf-gdb/org.eclipse.cdt.examples.dsf.gdb/src/org/eclipse/cdt/examples/dsf/gdb/actions/GdbShowVersionHandler.java new file mode 100644 index 00000000000..4e0619dd110 --- /dev/null +++ b/dsf-gdb/org.eclipse.cdt.examples.dsf.gdb/src/org/eclipse/cdt/examples/dsf/gdb/actions/GdbShowVersionHandler.java @@ -0,0 +1,142 @@ +/******************************************************************************* + * Copyright (c) 2015 Kichwa Coders 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: + * Jonah Graham (Kichwa Coders) - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.cdt.examples.dsf.gdb.actions; + +import java.util.Optional; + +import org.eclipse.cdt.dsf.concurrent.DataRequestMonitor; +import org.eclipse.cdt.dsf.concurrent.DsfExecutor; +import org.eclipse.cdt.dsf.concurrent.DsfRunnable; +import org.eclipse.cdt.dsf.concurrent.RequestMonitor; +import org.eclipse.cdt.dsf.datamodel.DMContexts; +import org.eclipse.cdt.dsf.debug.service.command.ICommandControlService.ICommandControlDMContext; +import org.eclipse.cdt.dsf.service.DsfServicesTracker; +import org.eclipse.cdt.dsf.service.DsfSession; +import org.eclipse.cdt.dsf.ui.viewmodel.datamodel.IDMVMContext; +import org.eclipse.cdt.examples.dsf.gdb.GDBExamplePlugin; +import org.eclipse.cdt.examples.dsf.gdb.commands.IShowVersionHandler; +import org.eclipse.cdt.examples.dsf.gdb.service.IGDBExtendedFunctions; +import org.eclipse.debug.core.commands.IDebugCommandRequest; +import org.eclipse.debug.core.commands.IEnabledStateRequest; + +public class GdbShowVersionHandler implements IShowVersionHandler { + private final DsfExecutor fExecutor; + private final DsfServicesTracker fTracker; + + public GdbShowVersionHandler(DsfSession session) { + fExecutor = session.getExecutor(); + fTracker = new DsfServicesTracker(GDBExamplePlugin.getBundleContext(), session.getId()); + } + + public void dispose() { + fTracker.dispose(); + } + + private Optional getContext(final IDebugCommandRequest request) { + if (request.getElements().length != 1 || !(request.getElements()[0] instanceof IDMVMContext)) { + return Optional.empty(); + } + + final IDMVMContext context = (IDMVMContext) request.getElements()[0]; + ICommandControlDMContext controlDmc = DMContexts.getAncestorOfType(context.getDMContext(), + ICommandControlDMContext.class); + if (controlDmc != null) + return Optional.of(controlDmc); + return Optional.empty(); + } + + @Override + public void canExecute(final IEnabledStateRequest request) { + final Optional context = getContext(request); + if (!context.isPresent()) { + request.setEnabled(false); + request.done(); + return; + } + + fExecutor.execute(new DsfRunnable() { + @Override + public void run() { + final IGDBExtendedFunctions funcService = fTracker.getService(IGDBExtendedFunctions.class); + if (funcService == null) { + request.setEnabled(false); + request.done(); + } else { + funcService.canGetVersion(context.get(), new DataRequestMonitor(fExecutor, null) { + @Override + protected void handleCompleted() { + if (!isSuccess()) { + request.setEnabled(false); + } else { + request.setEnabled(getData()); + } + request.done(); + } + }); + } + } + }); + + } + + @Override + public boolean execute(final IDebugCommandRequest request) { + final Optional context = getContext(request); + if (!context.isPresent()) { + request.done(); + return false; + } + + fExecutor.execute(new DsfRunnable() { + @Override + public void run() { + final IGDBExtendedFunctions funcService = fTracker.getService(IGDBExtendedFunctions.class); + if (funcService == null) { + request.done(); + } else { + funcService.getVersion(context.get(), new DataRequestMonitor(fExecutor, null) { + @Override + protected void handleCompleted() { + String str; + if (isSuccess()) { + str = "======= GDB version: " + getData() + " ======="; //$NON-NLS-1$ //$NON-NLS-2$ + } else { + str = "Could not obtain GDB version. Error: " + //$NON-NLS-1$ + getStatus(); + } + funcService.notify(context.get(), str, new RequestMonitor(fExecutor, null) { + @Override + protected void handleCompleted() { + request.done(); + } + }); + } + }); + } + } + }); + + /* + * Return true so that the show version pop-up command is immediately + * reenabled, this allows users to run the command multiple times + * without any other operations in between. There is a small chance the + * command may be issued again while it is still running, however with + * this particular command it is very fast so that is unlikely. In + * addition for this command no harm comes if it is issued twice. + * + * Most commands return false here because they need to be reenabled by + * some operation. For example continue would only be reenabled by the + * state change in the backend to being suspended again. + */ + return true; + } +} \ No newline at end of file diff --git a/dsf-gdb/org.eclipse.cdt.examples.dsf.gdb/src/org/eclipse/cdt/examples/dsf/gdb/commands/IShowVersionHandler.java b/dsf-gdb/org.eclipse.cdt.examples.dsf.gdb/src/org/eclipse/cdt/examples/dsf/gdb/commands/IShowVersionHandler.java new file mode 100644 index 00000000000..e196e7ef8e6 --- /dev/null +++ b/dsf-gdb/org.eclipse.cdt.examples.dsf.gdb/src/org/eclipse/cdt/examples/dsf/gdb/commands/IShowVersionHandler.java @@ -0,0 +1,18 @@ +/******************************************************************************* + * Copyright (c) 2015 Kichwa Coders 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: + * Jonah Graham (Kichwa Coders) - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.cdt.examples.dsf.gdb.commands; + +import org.eclipse.debug.core.commands.IDebugCommandHandler; + +public interface IShowVersionHandler extends IDebugCommandHandler { + +} diff --git a/dsf-gdb/org.eclipse.cdt.examples.dsf.gdb/src/org/eclipse/cdt/examples/dsf/gdb/commands/ShowVersionHandler.java b/dsf-gdb/org.eclipse.cdt.examples.dsf.gdb/src/org/eclipse/cdt/examples/dsf/gdb/commands/ShowVersionHandler.java new file mode 100644 index 00000000000..5ea7d4fbf53 --- /dev/null +++ b/dsf-gdb/org.eclipse.cdt.examples.dsf.gdb/src/org/eclipse/cdt/examples/dsf/gdb/commands/ShowVersionHandler.java @@ -0,0 +1,22 @@ +/******************************************************************************* + * Copyright (c) 2015 Kichwa Coders 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: + * Jonah Graham (Kichwa Coders) - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.cdt.examples.dsf.gdb.commands; + +import org.eclipse.debug.ui.actions.DebugCommandHandler; + +public class ShowVersionHandler extends DebugCommandHandler { + + @Override + protected Class getCommandType() { + return IShowVersionHandler.class; + } +} diff --git a/dsf-gdb/org.eclipse.cdt.examples.dsf.gdb/src/org/eclipse/cdt/examples/dsf/gdb/service/GDBExtendedService.java b/dsf-gdb/org.eclipse.cdt.examples.dsf.gdb/src/org/eclipse/cdt/examples/dsf/gdb/service/GDBExtendedService.java index c8dca46ff11..a81430376dc 100644 --- a/dsf-gdb/org.eclipse.cdt.examples.dsf.gdb/src/org/eclipse/cdt/examples/dsf/gdb/service/GDBExtendedService.java +++ b/dsf-gdb/org.eclipse.cdt.examples.dsf.gdb/src/org/eclipse/cdt/examples/dsf/gdb/service/GDBExtendedService.java @@ -118,4 +118,9 @@ public class GDBExtendedService extends AbstractDsfService implements IGDBExtend NOT_SUPPORTED, "Not supported", null)); //$NON-NLS-1$ } } + + @Override + public void canGetVersion(ICommandControlDMContext ctx, DataRequestMonitor rm) { + rm.done(fCommandFactory instanceof GdbExtendedCommandFactory_6_8); + } } diff --git a/dsf-gdb/org.eclipse.cdt.examples.dsf.gdb/src/org/eclipse/cdt/examples/dsf/gdb/service/IGDBExtendedFunctions.java b/dsf-gdb/org.eclipse.cdt.examples.dsf.gdb/src/org/eclipse/cdt/examples/dsf/gdb/service/IGDBExtendedFunctions.java index 318f8fa3cea..1cb4f160e94 100644 --- a/dsf-gdb/org.eclipse.cdt.examples.dsf.gdb/src/org/eclipse/cdt/examples/dsf/gdb/service/IGDBExtendedFunctions.java +++ b/dsf-gdb/org.eclipse.cdt.examples.dsf.gdb/src/org/eclipse/cdt/examples/dsf/gdb/service/IGDBExtendedFunctions.java @@ -27,4 +27,9 @@ public interface IGDBExtendedFunctions extends IDsfService { */ void getVersion(ICommandControlDMContext ctx, DataRequestMonitor rm); + /** + * Can get the version of the debugger + */ + void canGetVersion(ICommandControlDMContext ctx, DataRequestMonitor rm); + } diff --git a/dsf/org.eclipse.cdt.dsf.ui/META-INF/MANIFEST.MF b/dsf/org.eclipse.cdt.dsf.ui/META-INF/MANIFEST.MF index 39a907f9f87..39a87443d5d 100644 --- a/dsf/org.eclipse.cdt.dsf.ui/META-INF/MANIFEST.MF +++ b/dsf/org.eclipse.cdt.dsf.ui/META-INF/MANIFEST.MF @@ -72,7 +72,8 @@ Export-Package: org.eclipse.cdt.dsf.debug.internal.ui;x-internal:=true, x-friends:="org.eclipse.cdt.dsf.gdb.ui, org.eclipse.cdt.examples.dsf, org.eclipse.cdt.examples.dsf.pda.ui, - org.eclipse.cdt.debug.edc.ui", + org.eclipse.cdt.debug.edc.ui, + org.eclipse.cdt.examples.dsf.gdb", org.eclipse.cdt.dsf.ui.viewmodel.properties; x-friends:="org.eclipse.cdt.dsf.gdb.ui, org.eclipse.cdt.examples.dsf,