1
/*******************************************************************************
2
* Copyright (c) 2008 ARM Limited 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
* ARM Limited - Initial API and implementation
10
*******************************************************************************/
12
package org.eclipse.cdt.debug.internal.ui.sourcelookup;
14
import org.eclipse.cdt.debug.core.model.ICStackFrame;
15
import org.eclipse.cdt.debug.internal.ui.disassembly.editor.DisassemblyEditorManager;
16
import org.eclipse.cdt.debug.ui.CDebugUIPlugin;
17
import org.eclipse.core.runtime.IProgressMonitor;
18
import org.eclipse.core.runtime.IStatus;
19
import org.eclipse.core.runtime.Platform;
20
import org.eclipse.core.runtime.Status;
21
import org.eclipse.core.runtime.jobs.Job;
22
import org.eclipse.debug.core.DebugException;
23
import org.eclipse.debug.core.ILaunch;
24
import org.eclipse.debug.core.model.IDebugTarget;
25
import org.eclipse.debug.core.model.IRegisterGroup;
26
import org.eclipse.debug.core.model.IStackFrame;
27
import org.eclipse.debug.core.model.IThread;
28
import org.eclipse.debug.core.model.IVariable;
29
import org.eclipse.debug.ui.sourcelookup.ISourceDisplay;
30
import org.eclipse.ui.IEditorPart;
31
import org.eclipse.ui.IWorkbenchPage;
32
import org.eclipse.ui.progress.UIJob;
34
public class SourceDisplayAdapter implements ISourceDisplay {
36
class DelegatingStackFrame implements IStackFrame {
38
private ICStackFrame fDelegate;
40
DelegatingStackFrame( ICStackFrame delegate ) {
46
* @see org.eclipse.debug.core.model.IStackFrame#getCharEnd()
48
public int getCharEnd() throws DebugException {
49
return fDelegate.getCharEnd();
53
* @see org.eclipse.debug.core.model.IStackFrame#getCharStart()
55
public int getCharStart() throws DebugException {
56
return fDelegate.getCharStart();
60
* @see org.eclipse.debug.core.model.IStackFrame#getLineNumber()
62
public int getLineNumber() throws DebugException {
63
return fDelegate.getLineNumber();
67
* @see org.eclipse.debug.core.model.IStackFrame#getName()
69
public String getName() throws DebugException {
70
return fDelegate.getName();
74
* @see org.eclipse.debug.core.model.IStackFrame#getRegisterGroups()
76
public IRegisterGroup[] getRegisterGroups() throws DebugException {
77
return fDelegate.getRegisterGroups();
81
* @see org.eclipse.debug.core.model.IStackFrame#getThread()
83
public IThread getThread() {
84
return fDelegate.getThread();
88
* @see org.eclipse.debug.core.model.IStackFrame#getVariables()
90
public IVariable[] getVariables() throws DebugException {
91
return fDelegate.getVariables();
95
* @see org.eclipse.debug.core.model.IStackFrame#hasRegisterGroups()
97
public boolean hasRegisterGroups() throws DebugException {
98
return fDelegate.hasRegisterGroups();
102
* @see org.eclipse.debug.core.model.IStackFrame#hasVariables()
104
public boolean hasVariables() throws DebugException {
105
return fDelegate.hasVariables();
109
* @see org.eclipse.debug.core.model.IDebugElement#getDebugTarget()
111
public IDebugTarget getDebugTarget() {
112
return fDelegate.getDebugTarget();
116
* @see org.eclipse.debug.core.model.IDebugElement#getLaunch()
118
public ILaunch getLaunch() {
119
return fDelegate.getLaunch();
123
* @see org.eclipse.debug.core.model.IDebugElement#getModelIdentifier()
125
public String getModelIdentifier() {
126
return fDelegate.getModelIdentifier();
130
* @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
132
@SuppressWarnings("unchecked")
133
public Object getAdapter( Class adapter ) {
134
if ( ICStackFrame.class.equals( adapter ) )
136
return fDelegate.getAdapter( adapter );
140
* @see org.eclipse.debug.core.model.IStep#canStepInto()
142
public boolean canStepInto() {
143
return fDelegate.canStepInto();
147
* @see org.eclipse.debug.core.model.IStep#canStepOver()
149
public boolean canStepOver() {
150
return fDelegate.canStepOver();
154
* @see org.eclipse.debug.core.model.IStep#canStepReturn()
156
public boolean canStepReturn() {
157
return fDelegate.canStepReturn();
161
* @see org.eclipse.debug.core.model.IStep#isStepping()
163
public boolean isStepping() {
164
return fDelegate.isStepping();
168
* @see org.eclipse.debug.core.model.IStep#stepInto()
170
public void stepInto() throws DebugException {
171
fDelegate.stepInto();
175
* @see org.eclipse.debug.core.model.IStep#stepOver()
177
public void stepOver() throws DebugException {
178
fDelegate.stepOver();
182
* @see org.eclipse.debug.core.model.IStep#stepReturn()
184
public void stepReturn() throws DebugException {
185
fDelegate.stepReturn();
189
* @see org.eclipse.debug.core.model.ISuspendResume#canResume()
191
public boolean canResume() {
192
return fDelegate.canResume();
196
* @see org.eclipse.debug.core.model.ISuspendResume#canSuspend()
198
public boolean canSuspend() {
199
return fDelegate.canSuspend();
203
* @see org.eclipse.debug.core.model.ISuspendResume#isSuspended()
205
public boolean isSuspended() {
206
return fDelegate.isSuspended();
210
* @see org.eclipse.debug.core.model.ISuspendResume#resume()
212
public void resume() throws DebugException {
217
* @see org.eclipse.debug.core.model.ISuspendResume#suspend()
219
public void suspend() throws DebugException {
224
* @see org.eclipse.debug.core.model.ITerminate#canTerminate()
226
public boolean canTerminate() {
227
return fDelegate.canTerminate();
231
* @see org.eclipse.debug.core.model.ITerminate#isTerminated()
233
public boolean isTerminated() {
234
return fDelegate.isTerminated();
238
* @see org.eclipse.debug.core.model.ITerminate#terminate()
240
public void terminate() throws DebugException {
241
fDelegate.terminate();
247
* @see org.eclipse.debug.ui.sourcelookup.ISourceDisplay#displaySource(java.lang.Object, org.eclipse.ui.IWorkbenchPage, boolean)
249
public void displaySource( Object element, IWorkbenchPage page, boolean forceSourceLookup ) {
250
if ( element instanceof ICStackFrame ) {
251
ICStackFrame frame = (ICStackFrame)element;
252
if ( isDisplayDisassembly( frame, page ) ) {
253
displayDisassembly( page, frame );
256
DelegatingStackFrame delegatingFrame = new DelegatingStackFrame( (ICStackFrame)element );
257
ISourceDisplay sd = (ISourceDisplay)Platform.getAdapterManager().getAdapter( delegatingFrame, ISourceDisplay.class );
259
sd.displaySource( element, page, forceSourceLookup );
264
private boolean isDisplayDisassembly( ICStackFrame frame, IWorkbenchPage page ) {
265
// always go to the disassembly window if it is already open
266
IEditorPart editor = getDisassemblyEditorManager().findEditor( page, frame );
267
return ( editor != null );
270
protected DisassemblyEditorManager getDisassemblyEditorManager() {
271
return CDebugUIPlugin.getDefault().getDisassemblyEditorManager();
274
private void displayDisassembly( final IWorkbenchPage page, final Object debugContext ) {
275
Job uijob = new UIJob( "Display Disassembly Job" ) { //$NON-NLS-1$
278
* @see org.eclipse.ui.progress.UIJob#runInUIThread(org.eclipse.core.runtime.IProgressMonitor)
281
public IStatus runInUIThread( IProgressMonitor monitor ) {
283
getDisassemblyEditorManager().openEditor( page, debugContext );
285
catch( DebugException e ) {
286
return e.getStatus();
288
return Status.OK_STATUS;
292
uijob.setSystem( true );