diff --git a/dsf/org.eclipse.cdt.tests.dsf/META-INF/MANIFEST.MF b/dsf/org.eclipse.cdt.tests.dsf/META-INF/MANIFEST.MF
index e44670aa588..2f93d176480 100644
--- a/dsf/org.eclipse.cdt.tests.dsf/META-INF/MANIFEST.MF
+++ b/dsf/org.eclipse.cdt.tests.dsf/META-INF/MANIFEST.MF
@@ -14,5 +14,6 @@ Require-Bundle: org.eclipse.core.runtime,
org.junit4,
org.eclipse.ui,
org.eclipse.cdt.dsf.ui,
- org.eclipse.cdt.examples.dsf.pda;bundle-version="2.0.0"
+ org.eclipse.cdt.examples.dsf.pda;bundle-version="2.0.0",
+ org.eclipse.cdt.core;bundle-version="5.2.0"
Bundle-RequiredExecutionEnvironment: J2SE-1.5
diff --git a/dsf/org.eclipse.cdt.tests.dsf/plugin.xml b/dsf/org.eclipse.cdt.tests.dsf/plugin.xml
index ba839803701..4b4d7a573fc 100644
--- a/dsf/org.eclipse.cdt.tests.dsf/plugin.xml
+++ b/dsf/org.eclipse.cdt.tests.dsf/plugin.xml
@@ -15,4 +15,22 @@
id="org.eclipse.cdt.tests.dsf.model.ModelTestView">
+
+
+
+
+
+
+
+
+
+
diff --git a/dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/DsfTestPlugin.java b/dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/DsfTestPlugin.java
index 742f1dda5cf..8fcab24f16b 100644
--- a/dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/DsfTestPlugin.java
+++ b/dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/DsfTestPlugin.java
@@ -10,6 +10,9 @@
*******************************************************************************/
package org.eclipse.cdt.tests.dsf;
+import org.eclipse.cdt.dsf.concurrent.RequestMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
@@ -66,4 +69,10 @@ public class DsfTestPlugin extends AbstractUIPlugin {
return fgBundleContext;
}
+ public static void failRequest(RequestMonitor rm, int code, String message) {
+ rm.setStatus(new Status(IStatus.ERROR, PLUGIN_ID, code, message, null));
+ rm.done();
+ }
+
+
}
diff --git a/dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/ServiceEventWaitor.java b/dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/ServiceEventWaitor.java
new file mode 100644
index 00000000000..9357d0a8d67
--- /dev/null
+++ b/dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/ServiceEventWaitor.java
@@ -0,0 +1,104 @@
+/*******************************************************************************
+ * Copyright (c) 2007 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:
+ * Ericsson - Initial Implementation
+ *******************************************************************************/
+package org.eclipse.cdt.tests.dsf;
+
+import org.eclipse.cdt.dsf.service.DsfServiceEventHandler;
+import org.eclipse.cdt.dsf.service.DsfSession;
+
+/*
+ * This class provides a way to wait for an asynchronous ServerEvent
+ * to occur. The user of this class specifies which event is of
+ * interest using the proper constructor or the registerForEvent() method.
+ * waitForEvent() can then be called to block until the event occurs or
+ * the timeout elapses.
+ *
+ * Note that if the event occurs after regsiterForEvent() is called but
+ * before waitForEvent() is called, waitForEvent() will return immediatly
+ * since it will know the event has already occured.
+ */
+
+public class ServiceEventWaitor {
+ /*
+ * Indicates we will wait forever. Otherwise the time specified
+ * is in milliseconds.
+ */
+ public final static int WAIT_FOREVER = 0 ;
+
+ /* The type of event to wait for */
+ private Class fEventTypeClass;
+ private DsfSession fSession;
+ private V fEvent;
+
+
+ /* Empty contructor. registerForEvent() should be called when
+ * this constructor is used.
+ */
+ public ServiceEventWaitor(DsfSession session) {
+ fSession = session;
+ }
+
+ /* Contructor that takes the eventClass as parameter. This is a shortcut
+ * that avoids calling registerForEvent()
+ */
+ public ServiceEventWaitor(DsfSession session, Class eventClass) {
+ this(session);
+ registerForEvent(eventClass);
+ }
+
+ /* Specify which event to wait for, and add ourselves as
+ * a listener with the session
+ */
+ public void registerForEvent(Class eventClass) {
+ fEventTypeClass = eventClass;
+ fEvent = null;
+ fSession.addServiceEventListener(this, null);
+ }
+
+ @Override
+ protected void finalize() throws Throwable {
+ super.finalize();
+ if (fEventTypeClass != null) fSession.removeServiceEventListener(this);
+ }
+
+ /* Block until 'timeout' or the previously specified event has been
+ * received. The reason we don's specify the event as a parameter
+ * is that we must be ready for the event to occur event before
+ * this method is called.
+ */
+ public synchronized V waitForEvent(int timeout) throws Exception {
+ if (fEventTypeClass == null) {
+ throw new Exception("Event to wait for has not been specified!");
+ }
+ // The event might have already been received
+ if (fEvent != null) return fEvent;
+
+ wait(timeout);
+
+ if (fEvent == null) {
+ throw new Exception("Timed out waiting for ServiceEvent: " + fEventTypeClass.getName());
+ }
+ return fEvent;
+ }
+
+ /*
+ * Listen to all possible events by having the base class be the parameter.
+ * and then igure out if that event is the one we were waiting for.
+ */
+ @DsfServiceEventHandler
+ public void eventDispatched(V event) {
+ if (fEventTypeClass.isAssignableFrom(event.getClass())) {
+ synchronized(this) {
+ fEvent = event;
+ notifyAll();
+ }
+ }
+ }
+}
diff --git a/dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/breakpoints/BreakpointMediatorTests.java b/dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/breakpoints/BreakpointMediatorTests.java
new file mode 100644
index 00000000000..b8a91f7ce4f
--- /dev/null
+++ b/dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/breakpoints/BreakpointMediatorTests.java
@@ -0,0 +1,179 @@
+/*******************************************************************************
+ * Copyright (c) 2006 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.tests.dsf.breakpoints;
+
+import java.lang.reflect.Constructor;
+import java.util.concurrent.ExecutionException;
+
+import org.eclipse.cdt.dsf.concurrent.DsfRunnable;
+import org.eclipse.cdt.dsf.concurrent.RequestMonitor;
+import org.eclipse.cdt.dsf.concurrent.Sequence;
+import org.eclipse.cdt.dsf.debug.service.BreakpointsMediator2;
+import org.eclipse.cdt.dsf.debug.service.IBreakpointAttributeTranslator2;
+import org.eclipse.cdt.dsf.service.DsfSession;
+import org.eclipse.cdt.dsf.service.IDsfService;
+import org.eclipse.cdt.tests.dsf.ServiceEventWaitor;
+import org.eclipse.cdt.tests.dsf.TestDsfExecutor;
+import org.eclipse.cdt.tests.dsf.breakpoints.DsfTestBreakpoints.BreakpointsAddedEvent;
+import org.eclipse.cdt.tests.dsf.breakpoints.DsfTestBreakpoints.BreakpointsTargetDMContext;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+public class BreakpointMediatorTests {
+ TestDsfExecutor fExecutor;
+ DsfSession fSession;
+ DsfTestBreakpoints fBreakpoints;
+ BreakpointsMediator2 fMediator;
+ IBreakpointAttributeTranslator2 fTranslator;
+ BreakpointsTargetDMContext fTargetContext;
+
+ abstract private class InitializeServiceStep extends Sequence.Step {
+ Class fServiceClass;
+
+ InitializeServiceStep(Class serviceClass) {
+ fServiceClass = serviceClass;
+ }
+
+ @Override
+ public void execute(RequestMonitor requestMonitor) {
+ try {
+ Constructor c = fServiceClass.getConstructor(new Class[] {DsfSession.class});
+ V service = c.newInstance(new Object[] {fSession});
+ setService(service);
+ service.initialize(requestMonitor);
+ } catch (Exception e) {
+ Assert.fail("Unexpected exception"); //$NON-NLS-1$
+ }
+ }
+
+ protected void setService(V service) {}
+ }
+
+ private class ShutdownServiceStep extends Sequence.Step {
+ IDsfService fService;
+
+ ShutdownServiceStep(IDsfService service) {
+ fService = service;
+ }
+
+ @Override
+ public void execute(RequestMonitor requestMonitor) {
+ fService.shutdown(requestMonitor);
+ }
+ }
+
+ @Before public void start() throws ExecutionException, InterruptedException {
+ fExecutor = new TestDsfExecutor();
+
+ Sequence seq = new Sequence(fExecutor) {
+ @Override
+ public Step[] getSteps() {
+ return new Step[] {
+ // Create session
+ new Sequence.Step() {
+ @Override
+ public void execute(RequestMonitor rm) {
+ fSession = DsfSession.startSession(fExecutor, "org.eclipse.cdt.dsf.tests"); //$NON-NLS-1$
+ rm.done();
+ }
+ },
+
+ // Initialize breakpoints service
+ new InitializeServiceStep(DsfTestBreakpoints.class) {
+ @Override
+ protected void setService(DsfTestBreakpoints service) {
+ fBreakpoints = service;
+ }
+ },
+
+ // Initialize breakpoint mediator
+ new Sequence.Step() {
+ @Override
+ public void execute(RequestMonitor rm) {
+ fTranslator = new DsfTestBreakpointAttributeTranslator2();
+ fMediator = new BreakpointsMediator2(fSession, fTranslator);
+ fMediator.initialize(rm);
+ }
+ },
+
+ // Start tracking breakpoints
+ new Sequence.Step() {
+ @Override
+ public void execute(RequestMonitor rm) {
+ fTargetContext = new BreakpointsTargetDMContext(fSession.getId());
+ fMediator.startTrackingBreakpoints(fTargetContext, rm);
+ }
+ },
+ };
+ }
+ };
+
+ fExecutor.execute(seq);
+ seq.get();
+ }
+
+ @After public void shutdown() throws ExecutionException, InterruptedException {
+ Sequence seq = new Sequence(fExecutor) {
+ @Override
+ public Step[] getSteps() {
+ return new Step[] {
+ // Stop tracking breakpoints
+ new Sequence.Step() {
+ @Override
+ public void execute(RequestMonitor rm) {
+ fMediator.stopTrackingBreakpoints(fTargetContext, rm);
+ fTargetContext = null;
+ }
+ },
+
+ // Shutdown services
+ new ShutdownServiceStep(fMediator),
+ new ShutdownServiceStep(fBreakpoints),
+
+ // Shutdown session
+ new Sequence.Step() {
+ @Override
+ public void execute(RequestMonitor rm) {
+ DsfSession.endSession(fSession);
+ rm.done();
+ }
+ },
+ };
+ }
+ };
+
+ fExecutor.execute(seq);
+ seq.get();
+
+ fExecutor.submit(new DsfRunnable() { public void run() {
+ fExecutor.shutdown();
+ }}).get();
+ if (fExecutor.exceptionsCaught()) {
+ Throwable[] exceptions = fExecutor.getExceptions();
+ throw new ExecutionException(exceptions[0]);
+ }
+ fExecutor = null;
+ }
+
+ @Test
+ public void singleServiceTest() throws Exception {
+
+ ServiceEventWaitor waitor = new ServiceEventWaitor(fSession, BreakpointsAddedEvent.class);
+
+ new DsfTestBreakpoint();
+
+ waitor.waitForEvent(50000);
+ }
+
+
+}
diff --git a/dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/breakpoints/DsfTestBreakpoint.java b/dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/breakpoints/DsfTestBreakpoint.java
new file mode 100644
index 00000000000..355cee9daf9
--- /dev/null
+++ b/dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/breakpoints/DsfTestBreakpoint.java
@@ -0,0 +1,73 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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.tests.dsf.breakpoints;
+
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IWorkspaceRunnable;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.debug.core.DebugPlugin;
+import org.eclipse.debug.core.model.Breakpoint;
+import org.eclipse.debug.core.model.IBreakpoint;
+
+/**
+ * Test breakpoint.
+ */
+public class DsfTestBreakpoint extends Breakpoint {
+
+ public static final String DSF_TEST_BREAKPOINT_MODEL_ID = "dsfTest";
+ public static final String ATTR_IDE_PREFIX = DSF_TEST_BREAKPOINT_MODEL_ID + ".ide.";
+
+ public static final String ATTR_ID = ATTR_IDE_PREFIX + "id";
+ public static final String ATTR_NUM_TARGET_BREAKPOINTS = ATTR_IDE_PREFIX + "numTargetBreakpoints";
+ public static final String ATTR_TRANSLATED = ATTR_IDE_PREFIX + "translated";
+ public static final String ATTR_UNTRANSLATED = ATTR_IDE_PREFIX + "untranslated";
+ public static final String ATTR_UPDATABLE = ATTR_IDE_PREFIX + "updatable";
+
+ public static int fgIdCounter = 0;
+
+ public DsfTestBreakpoint() throws CoreException {
+ this(true, 1, "", "", "");
+ }
+
+ public DsfTestBreakpoint(final boolean enabled, final int numTargetBPs, final String translated,
+ final String untranslated, final String updatable)
+ throws CoreException
+ {
+ final IResource resource = ResourcesPlugin.getWorkspace().getRoot();
+ IWorkspaceRunnable runnable = new IWorkspaceRunnable() {
+ public void run(IProgressMonitor monitor) throws CoreException {
+ IMarker marker = resource.createMarker("org.eclipse.cdt.tests.dsf.markerType.breakpoint");
+ setMarker(marker);
+ marker.setAttribute(IBreakpoint.ENABLED, enabled);
+ marker.setAttribute(DsfTestBreakpoint.ATTR_ID, fgIdCounter++);
+ marker.setAttribute(DsfTestBreakpoint.ATTR_NUM_TARGET_BREAKPOINTS, numTargetBPs);
+ marker.setAttribute(DsfTestBreakpoint.ATTR_TRANSLATED, translated);
+ marker.setAttribute(DsfTestBreakpoint.ATTR_UNTRANSLATED, untranslated);
+ marker.setAttribute(DsfTestBreakpoint.ATTR_UPDATABLE, updatable);
+ }
+ };
+ run(getMarkerRule(resource), runnable);
+ DebugPlugin.getDefault().getBreakpointManager().addBreakpoint(this);
+ }
+
+ public Integer getID() throws CoreException {
+ return (Integer)ensureMarker().getAttribute(ATTR_ID);
+ }
+
+ public String getModelIdentifier() {
+ return DSF_TEST_BREAKPOINT_MODEL_ID;
+ }
+
+
+}
diff --git a/dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/breakpoints/DsfTestBreakpointAttributeTranslator2.java b/dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/breakpoints/DsfTestBreakpointAttributeTranslator2.java
new file mode 100644
index 00000000000..ea76a625ef1
--- /dev/null
+++ b/dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/breakpoints/DsfTestBreakpointAttributeTranslator2.java
@@ -0,0 +1,104 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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.tests.dsf.breakpoints;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.cdt.dsf.concurrent.DataRequestMonitor;
+import org.eclipse.cdt.dsf.debug.service.BreakpointsMediator2;
+import org.eclipse.cdt.dsf.debug.service.IBreakpointAttributeTranslator2;
+import org.eclipse.cdt.dsf.debug.service.BreakpointsMediator2.BreakpointEventType;
+import org.eclipse.cdt.dsf.debug.service.BreakpointsMediator2.ITargetBreakpointInfo;
+import org.eclipse.cdt.dsf.debug.service.IBreakpoints.IBreakpointsTargetDMContext;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.debug.core.model.IBreakpoint;
+
+/**
+ *
+ */
+public class DsfTestBreakpointAttributeTranslator2 implements IBreakpointAttributeTranslator2 {
+
+ public void initialize(BreakpointsMediator2 mediator) {
+ }
+
+ public void dispose() {
+ }
+
+ public boolean supportsBreakpoint(IBreakpoint bp) {
+ return DsfTestBreakpoint.DSF_TEST_BREAKPOINT_MODEL_ID.equals(bp.getModelIdentifier());
+ }
+
+ public void resolveBreakpoint(IBreakpointsTargetDMContext context, IBreakpoint breakpoint,
+ Map bpAttrs, DataRequestMonitor>> drm)
+ {
+ Integer num = (Integer)bpAttrs.get(DsfTestBreakpoint.ATTR_NUM_TARGET_BREAKPOINTS);
+ if (num == null) {
+ num = new Integer(1);
+ }
+ List