~ubuntu-branches/debian/sid/eclipse-cdt/sid

« back to all changes in this revision

Viewing changes to dsf/org.eclipse.cdt.dsf.ui/src/org/eclipse/cdt/dsf/debug/internal/ui/actions/RunToLine.java

  • Committer: Package Import Robot
  • Author(s): Jakub Adam
  • Date: 2011-10-06 21:15:04 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20111006211504-8dutmljjih0zikfv
Tags: 8.0.1-1
* New upstream release.
* Split the JNI packages into a separate architecture dependent
  package and made eclipse-cdt architecture independent.
* Install JNI libraries into multiarch aware location
* Bumped Standards-Version to 3.9.2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
7
 * 
 
8
 * Contributors:
 
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;
 
13
 
 
14
import java.util.concurrent.ExecutionException;
 
15
import java.util.concurrent.RejectedExecutionException;
 
16
 
 
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;
 
33
 
 
34
/**
 
35
 * Implements the CDT's run to line interface.  This interface is called by CDT's
 
36
 * {@link IRunToLineTarget} implementation.
 
37
 * 
 
38
 * @since 2.1
 
39
 */
 
40
public class RunToLine implements IRunToLine, IRunToAddress {
 
41
 
 
42
    private final IExecutionDMContext fContext;
 
43
 
 
44
    public RunToLine(IExecutionDMContext context) {
 
45
        fContext = context;
 
46
    }
 
47
    
 
48
    public boolean canRunToLine(final IFile file, final int lineNumber) {
 
49
        return canRunToLine(file.getLocation().makeAbsolute().toOSString(), lineNumber);
 
50
     }
 
51
 
 
52
    public boolean canRunToLine(final String fileName, final int lineNumber) {
 
53
        DsfSession session = DsfSession.getSession(fContext.getSessionId());
 
54
        if (session != null && session.isActive()) {
 
55
            try {
 
56
                Query<Boolean> query = new Query<Boolean>() {
 
57
                    @Override
 
58
                    protected void execute(DataRequestMonitor<Boolean> rm) {
 
59
                        DsfServicesTracker tracker = 
 
60
                            new DsfServicesTracker(DsfUIPlugin.getBundleContext(), fContext.getSessionId());
 
61
                        
 
62
                        IRunControl2 runControl = tracker.getService(IRunControl2.class);
 
63
                        if (runControl != null) {
 
64
                            runControl.canRunToLine(fContext, fileName, lineNumber, rm);
 
65
                        } else {
 
66
                            rm.setData(false);
 
67
                            rm.done();
 
68
                        }
 
69
                        tracker.dispose();
 
70
                    }
 
71
                };
 
72
                session.getExecutor().execute(query);
 
73
                return query.get();
 
74
            } catch (RejectedExecutionException e) {
 
75
            } catch (InterruptedException e) {
 
76
            } catch (ExecutionException e) {
 
77
            }
 
78
        }
 
79
        return false;
 
80
    }
 
81
 
 
82
    public void runToLine(IFile file, int lineNumber, boolean skipBreakpoints) throws DebugException {
 
83
        runToLine(file.getLocation().makeAbsolute().toOSString(), lineNumber, skipBreakpoints);
 
84
    }
 
85
    
 
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;
 
90
            try {
 
91
                Query<Object> query = new Query<Object>() {
 
92
                    @Override
 
93
                    protected void execute(final DataRequestMonitor<Object> rm) {
 
94
                        DsfServicesTracker tracker = 
 
95
                            new DsfServicesTracker(DsfUIPlugin.getBundleContext(), fContext.getSessionId());
 
96
                        
 
97
                        IRunControl2 runControl = tracker.getService(IRunControl2.class);
 
98
                        if (runControl != null) {
 
99
                                runControl.runToLine(
 
100
                                fContext, fileName, lineNumber, skipBreakpoints, rm);
 
101
                        } else {
 
102
                            rm.setStatus(new Status(IStatus.ERROR, DsfUIPlugin.PLUGIN_ID, IDsfStatusConstants.NOT_SUPPORTED, "IRunControl2 service not available", null)); //$NON-NLS-1$
 
103
                            rm.done();
 
104
                        }
 
105
                        tracker.dispose();
 
106
                    }
 
107
                };
 
108
                session.getExecutor().execute(query);
 
109
                query.get();
 
110
            } catch (RejectedExecutionException e) {
 
111
                exception = e;
 
112
            } catch (InterruptedException e) {
 
113
                exception = e;
 
114
            } catch (ExecutionException e) {
 
115
                exception = e;
 
116
            }
 
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$
 
119
            }
 
120
        } else {
 
121
            throw new DebugException(new Status(IStatus.ERROR, DsfUIPlugin.PLUGIN_ID, DebugException.REQUEST_FAILED, "Debug session is not active", null)); //$NON-NLS-1$            
 
122
        }
 
123
    }
 
124
    
 
125
        public boolean canRunToAddress(final IAddress address) {
 
126
        DsfSession session = DsfSession.getSession(fContext.getSessionId());
 
127
        if (session != null && session.isActive()) {
 
128
            try {
 
129
                Query<Boolean> query = new Query<Boolean>() {
 
130
                    @Override
 
131
                    protected void execute(DataRequestMonitor<Boolean> rm) {
 
132
                        DsfServicesTracker tracker = 
 
133
                            new DsfServicesTracker(DsfUIPlugin.getBundleContext(), fContext.getSessionId());
 
134
                        
 
135
                        IRunControl2 runControl = tracker.getService(IRunControl2.class);
 
136
                        if (runControl != null) {
 
137
                            runControl.canRunToAddress(fContext, address, rm);
 
138
                        } else {
 
139
                            rm.setData(false);
 
140
                            rm.done();
 
141
                        }
 
142
                        tracker.dispose();
 
143
                    }
 
144
                };
 
145
                session.getExecutor().execute(query);
 
146
                return query.get();
 
147
            } catch (RejectedExecutionException e) {
 
148
            } catch (InterruptedException e) {
 
149
            } catch (ExecutionException e) {
 
150
            }
 
151
        }
 
152
        return false;
 
153
    }
 
154
 
 
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;
 
159
            try {
 
160
                Query<Object> query = new Query<Object>() {
 
161
                    @Override
 
162
                    protected void execute(final DataRequestMonitor<Object> rm) {
 
163
                        DsfServicesTracker tracker = 
 
164
                            new DsfServicesTracker(DsfUIPlugin.getBundleContext(), fContext.getSessionId());
 
165
                        
 
166
                        IRunControl2 runControl = tracker.getService(IRunControl2.class);
 
167
                        if (runControl != null) {
 
168
                                runControl.runToAddress(fContext, address, skipBreakpoints, rm);
 
169
                        } else {
 
170
                            rm.setStatus(new Status(IStatus.ERROR, DsfUIPlugin.PLUGIN_ID, IDsfStatusConstants.NOT_SUPPORTED, "IRunControl2 service not available", null)); //$NON-NLS-1$
 
171
                            rm.done();
 
172
                        }
 
173
                        tracker.dispose();
 
174
                    }
 
175
                };
 
176
                session.getExecutor().execute(query);
 
177
                query.get();
 
178
            } catch (RejectedExecutionException e) {
 
179
                exception = e;
 
180
            } catch (InterruptedException e) {
 
181
                exception = e;
 
182
            } catch (ExecutionException e) {
 
183
                exception = e;
 
184
            }
 
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$
 
187
            }
 
188
        } else {
 
189
            throw new DebugException(new Status(IStatus.ERROR, DsfUIPlugin.PLUGIN_ID, DebugException.REQUEST_FAILED, "Debug session is not active", null)); //$NON-NLS-1$            
 
190
        }
 
191
    }
 
192
  }