1
/*******************************************************************************
2
* Copyright (c) 2009, 2010 Wind River Systems and others.
3
* All rights reserved. This program and the accompanying materials
4
* are made available under the terms of the Eclipse Public License v1.0
5
* which accompanies this distribution, and is available at
6
* http://www.eclipse.org/legal/epl-v10.html
9
* Wind River Systems - initial API and implementation
10
* Ericsson - Added support for IRunToAddress for DSF DisassemblyView (302324)
11
*******************************************************************************/
12
package org.eclipse.cdt.dsf.debug.internal.ui.actions;
14
import java.util.concurrent.ExecutionException;
15
import java.util.concurrent.RejectedExecutionException;
17
import org.eclipse.cdt.core.IAddress;
18
import org.eclipse.cdt.debug.core.model.IRunToAddress;
19
import org.eclipse.cdt.debug.core.model.IRunToLine;
20
import org.eclipse.cdt.dsf.concurrent.DataRequestMonitor;
21
import org.eclipse.cdt.dsf.concurrent.IDsfStatusConstants;
22
import org.eclipse.cdt.dsf.concurrent.Query;
23
import org.eclipse.cdt.dsf.debug.service.IRunControl2;
24
import org.eclipse.cdt.dsf.debug.service.IRunControl.IExecutionDMContext;
25
import org.eclipse.cdt.dsf.internal.ui.DsfUIPlugin;
26
import org.eclipse.cdt.dsf.service.DsfServicesTracker;
27
import org.eclipse.cdt.dsf.service.DsfSession;
28
import org.eclipse.core.resources.IFile;
29
import org.eclipse.core.runtime.IStatus;
30
import org.eclipse.core.runtime.Status;
31
import org.eclipse.debug.core.DebugException;
32
import org.eclipse.debug.ui.actions.IRunToLineTarget;
35
* Implements the CDT's run to line interface. This interface is called by CDT's
36
* {@link IRunToLineTarget} implementation.
40
public class RunToLine implements IRunToLine, IRunToAddress {
42
private final IExecutionDMContext fContext;
44
public RunToLine(IExecutionDMContext context) {
48
public boolean canRunToLine(final IFile file, final int lineNumber) {
49
return canRunToLine(file.getLocation().makeAbsolute().toOSString(), lineNumber);
52
public boolean canRunToLine(final String fileName, final int lineNumber) {
53
DsfSession session = DsfSession.getSession(fContext.getSessionId());
54
if (session != null && session.isActive()) {
56
Query<Boolean> query = new Query<Boolean>() {
58
protected void execute(DataRequestMonitor<Boolean> rm) {
59
DsfServicesTracker tracker =
60
new DsfServicesTracker(DsfUIPlugin.getBundleContext(), fContext.getSessionId());
62
IRunControl2 runControl = tracker.getService(IRunControl2.class);
63
if (runControl != null) {
64
runControl.canRunToLine(fContext, fileName, lineNumber, rm);
72
session.getExecutor().execute(query);
74
} catch (RejectedExecutionException e) {
75
} catch (InterruptedException e) {
76
} catch (ExecutionException e) {
82
public void runToLine(IFile file, int lineNumber, boolean skipBreakpoints) throws DebugException {
83
runToLine(file.getLocation().makeAbsolute().toOSString(), lineNumber, skipBreakpoints);
86
public void runToLine(final String fileName, final int lineNumber, final boolean skipBreakpoints) throws DebugException {
87
DsfSession session = DsfSession.getSession(fContext.getSessionId());
88
if (session != null && session.isActive()) {
89
Throwable exception = null;
91
Query<Object> query = new Query<Object>() {
93
protected void execute(final DataRequestMonitor<Object> rm) {
94
DsfServicesTracker tracker =
95
new DsfServicesTracker(DsfUIPlugin.getBundleContext(), fContext.getSessionId());
97
IRunControl2 runControl = tracker.getService(IRunControl2.class);
98
if (runControl != null) {
100
fContext, fileName, lineNumber, skipBreakpoints, rm);
102
rm.setStatus(new Status(IStatus.ERROR, DsfUIPlugin.PLUGIN_ID, IDsfStatusConstants.NOT_SUPPORTED, "IRunControl2 service not available", null)); //$NON-NLS-1$
108
session.getExecutor().execute(query);
110
} catch (RejectedExecutionException e) {
112
} catch (InterruptedException e) {
114
} catch (ExecutionException e) {
117
if (exception != null) {
118
throw new DebugException(new Status(IStatus.ERROR, DsfUIPlugin.PLUGIN_ID, DebugException.REQUEST_FAILED, "Failed executing run to line", exception)); //$NON-NLS-1$
121
throw new DebugException(new Status(IStatus.ERROR, DsfUIPlugin.PLUGIN_ID, DebugException.REQUEST_FAILED, "Debug session is not active", null)); //$NON-NLS-1$
125
public boolean canRunToAddress(final IAddress address) {
126
DsfSession session = DsfSession.getSession(fContext.getSessionId());
127
if (session != null && session.isActive()) {
129
Query<Boolean> query = new Query<Boolean>() {
131
protected void execute(DataRequestMonitor<Boolean> rm) {
132
DsfServicesTracker tracker =
133
new DsfServicesTracker(DsfUIPlugin.getBundleContext(), fContext.getSessionId());
135
IRunControl2 runControl = tracker.getService(IRunControl2.class);
136
if (runControl != null) {
137
runControl.canRunToAddress(fContext, address, rm);
145
session.getExecutor().execute(query);
147
} catch (RejectedExecutionException e) {
148
} catch (InterruptedException e) {
149
} catch (ExecutionException e) {
155
public void runToAddress(final IAddress address, final boolean skipBreakpoints) throws DebugException {
156
DsfSession session = DsfSession.getSession(fContext.getSessionId());
157
if (session != null && session.isActive()) {
158
Throwable exception = null;
160
Query<Object> query = new Query<Object>() {
162
protected void execute(final DataRequestMonitor<Object> rm) {
163
DsfServicesTracker tracker =
164
new DsfServicesTracker(DsfUIPlugin.getBundleContext(), fContext.getSessionId());
166
IRunControl2 runControl = tracker.getService(IRunControl2.class);
167
if (runControl != null) {
168
runControl.runToAddress(fContext, address, skipBreakpoints, rm);
170
rm.setStatus(new Status(IStatus.ERROR, DsfUIPlugin.PLUGIN_ID, IDsfStatusConstants.NOT_SUPPORTED, "IRunControl2 service not available", null)); //$NON-NLS-1$
176
session.getExecutor().execute(query);
178
} catch (RejectedExecutionException e) {
180
} catch (InterruptedException e) {
182
} catch (ExecutionException e) {
185
if (exception != null) {
186
throw new DebugException(new Status(IStatus.ERROR, DsfUIPlugin.PLUGIN_ID, DebugException.REQUEST_FAILED, "Failed executing run to line", exception)); //$NON-NLS-1$
189
throw new DebugException(new Status(IStatus.ERROR, DsfUIPlugin.PLUGIN_ID, DebugException.REQUEST_FAILED, "Debug session is not active", null)); //$NON-NLS-1$