cdt/cdt_6_0_x/org.eclipse.cdt.dsf.ui/src/org/eclipse/cdt/dsf/debug/internal/ui/disassembly/DisassemblyPart.java
author l12wang
Thu, 28 Jan 2010 17:33:54 -0600
changeset 131 6cbf17faf712
parent 37 c2bce6dd59e7
permissions -rw-r--r--
Fixed a NPE. Note it's already fixed in CDT head.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
     1
/*******************************************************************************
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
     2
 * Copyright (c) 2007, 2009 Wind River Systems and others.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
     3
 * All rights reserved. This program and the accompanying materials
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
     4
 * are made available under the terms of the Eclipse Public License v1.0
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
     5
 * which accompanies this distribution, and is available at
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
     6
 * http://www.eclipse.org/legal/epl-v10.html
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
     7
 * 
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
     8
 * Contributors:
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
     9
 *     Wind River Systems - initial API and implementation
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    10
 *******************************************************************************/
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    11
package org.eclipse.cdt.dsf.debug.internal.ui.disassembly;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    12
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    13
import java.io.File;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    14
import java.math.BigInteger;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    15
import java.util.ArrayList;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    16
import java.util.HashMap;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    17
import java.util.Iterator;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    18
import java.util.LinkedList;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    19
import java.util.List;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    20
import java.util.ListIterator;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    21
import java.util.Map;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    22
import java.util.concurrent.ExecutionException;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    23
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    24
import org.eclipse.cdt.core.IAddress;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    25
import org.eclipse.cdt.debug.core.CDIDebugModel;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    26
import org.eclipse.cdt.debug.core.model.ICBreakpoint;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    27
import org.eclipse.cdt.debug.core.model.ICBreakpointType;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    28
import org.eclipse.cdt.dsf.concurrent.DataRequestMonitor;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    29
import org.eclipse.cdt.dsf.concurrent.DsfExecutor;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    30
import org.eclipse.cdt.dsf.concurrent.DsfRunnable;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    31
import org.eclipse.cdt.dsf.concurrent.Query;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    32
import org.eclipse.cdt.dsf.datamodel.DMContexts;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    33
import org.eclipse.cdt.dsf.datamodel.IDMContext;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    34
import org.eclipse.cdt.dsf.debug.internal.ui.disassembly.actions.AbstractDisassemblyAction;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    35
import org.eclipse.cdt.dsf.debug.internal.ui.disassembly.actions.ActionGotoAddress;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    36
import org.eclipse.cdt.dsf.debug.internal.ui.disassembly.actions.ActionGotoProgramCounter;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    37
import org.eclipse.cdt.dsf.debug.internal.ui.disassembly.actions.ActionGotoSymbol;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    38
import org.eclipse.cdt.dsf.debug.internal.ui.disassembly.actions.ActionOpenPreferences;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    39
import org.eclipse.cdt.dsf.debug.internal.ui.disassembly.actions.TextOperationAction;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    40
import org.eclipse.cdt.dsf.debug.internal.ui.disassembly.model.Addr2Line;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    41
import org.eclipse.cdt.dsf.debug.internal.ui.disassembly.model.AddressRangePosition;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    42
import org.eclipse.cdt.dsf.debug.internal.ui.disassembly.model.BreakpointsAnnotationModel;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    43
import org.eclipse.cdt.dsf.debug.internal.ui.disassembly.model.DisassemblyDocument;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    44
import org.eclipse.cdt.dsf.debug.internal.ui.disassembly.model.DisassemblyPosition;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    45
import org.eclipse.cdt.dsf.debug.internal.ui.disassembly.model.ErrorPosition;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    46
import org.eclipse.cdt.dsf.debug.internal.ui.disassembly.model.LabelPosition;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    47
import org.eclipse.cdt.dsf.debug.internal.ui.disassembly.model.SourceFileInfo;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    48
import org.eclipse.cdt.dsf.debug.internal.ui.disassembly.model.SourcePosition;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    49
import org.eclipse.cdt.dsf.debug.internal.ui.disassembly.preferences.DisassemblyPreferenceConstants;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    50
import org.eclipse.cdt.dsf.debug.internal.ui.disassembly.presentation.DisassemblyIPAnnotation;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    51
import org.eclipse.cdt.dsf.debug.internal.ui.disassembly.util.HSL;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    52
import org.eclipse.cdt.dsf.debug.service.IDisassembly;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    53
import org.eclipse.cdt.dsf.debug.service.IExpressions;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    54
import org.eclipse.cdt.dsf.debug.service.IFormattedValues;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    55
import org.eclipse.cdt.dsf.debug.service.IInstruction;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    56
import org.eclipse.cdt.dsf.debug.service.IMixedInstruction;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    57
import org.eclipse.cdt.dsf.debug.service.IRunControl;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    58
import org.eclipse.cdt.dsf.debug.service.ISourceLookup;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    59
import org.eclipse.cdt.dsf.debug.service.IStack;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    60
import org.eclipse.cdt.dsf.debug.service.IDisassembly.IDisassemblyDMContext;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    61
import org.eclipse.cdt.dsf.debug.service.IExpressions.IExpressionDMContext;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    62
import org.eclipse.cdt.dsf.debug.service.IFormattedValues.FormattedValueDMContext;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    63
import org.eclipse.cdt.dsf.debug.service.IFormattedValues.FormattedValueDMData;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    64
import org.eclipse.cdt.dsf.debug.service.IRunControl.IExecutionDMContext;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    65
import org.eclipse.cdt.dsf.debug.service.IRunControl.IExitedDMEvent;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    66
import org.eclipse.cdt.dsf.debug.service.IRunControl.IResumedDMEvent;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    67
import org.eclipse.cdt.dsf.debug.service.IRunControl.ISuspendedDMEvent;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    68
import org.eclipse.cdt.dsf.debug.service.ISourceLookup.ISourceLookupDMContext;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    69
import org.eclipse.cdt.dsf.debug.service.IStack.IFrameDMContext;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    70
import org.eclipse.cdt.dsf.debug.service.IStack.IFrameDMData;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    71
import org.eclipse.cdt.dsf.internal.ui.DsfUIPlugin;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    72
import org.eclipse.cdt.dsf.service.DsfServiceEventHandler;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    73
import org.eclipse.cdt.dsf.service.DsfServicesTracker;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    74
import org.eclipse.cdt.dsf.service.DsfSession;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    75
import org.eclipse.cdt.dsf.service.DsfSession.SessionEndedListener;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    76
import org.eclipse.cdt.dsf.ui.viewmodel.datamodel.IDMVMContext;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    77
import org.eclipse.cdt.internal.ui.dnd.TextViewerDragAdapter;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    78
import org.eclipse.cdt.utils.Addr64;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    79
import org.eclipse.core.resources.IFile;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    80
import org.eclipse.core.resources.IMarker;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    81
import org.eclipse.core.resources.IResource;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    82
import org.eclipse.core.resources.IStorage;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    83
import org.eclipse.core.resources.ResourcesPlugin;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    84
import org.eclipse.core.runtime.CoreException;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    85
import org.eclipse.core.runtime.IAdaptable;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    86
import org.eclipse.core.runtime.IPath;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    87
import org.eclipse.core.runtime.IStatus;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    88
import org.eclipse.core.runtime.ListenerList;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    89
import org.eclipse.core.runtime.Platform;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    90
import org.eclipse.core.runtime.Status;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    91
import org.eclipse.debug.core.DebugPlugin;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    92
import org.eclipse.debug.core.IBreakpointManager;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    93
import org.eclipse.debug.core.model.IBreakpoint;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    94
import org.eclipse.debug.core.model.ISuspendResume;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    95
import org.eclipse.debug.core.sourcelookup.containers.LocalFileStorage;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    96
import org.eclipse.debug.ui.DebugUITools;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    97
import org.eclipse.debug.ui.actions.IRunToLineTarget;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    98
import org.eclipse.debug.ui.actions.IToggleBreakpointsTarget;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    99
import org.eclipse.jface.action.Action;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   100
import org.eclipse.jface.action.GroupMarker;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   101
import org.eclipse.jface.action.IAction;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   102
import org.eclipse.jface.action.IMenuListener;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   103
import org.eclipse.jface.action.IMenuManager;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   104
import org.eclipse.jface.action.IToolBarManager;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   105
import org.eclipse.jface.action.MenuManager;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   106
import org.eclipse.jface.action.Separator;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   107
import org.eclipse.jface.commands.ActionHandler;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   108
import org.eclipse.jface.dialogs.ErrorDialog;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   109
import org.eclipse.jface.preference.IPreferenceStore;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   110
import org.eclipse.jface.preference.PreferenceConverter;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   111
import org.eclipse.jface.resource.JFaceResources;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   112
import org.eclipse.jface.text.BadLocationException;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   113
import org.eclipse.jface.text.BadPositionCategoryException;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   114
import org.eclipse.jface.text.IFindReplaceTarget;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   115
import org.eclipse.jface.text.IRegion;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   116
import org.eclipse.jface.text.ITextOperationTarget;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   117
import org.eclipse.jface.text.ITextPresentationListener;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   118
import org.eclipse.jface.text.ITextSelection;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   119
import org.eclipse.jface.text.ITextViewerExtension;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   120
import org.eclipse.jface.text.IViewportListener;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   121
import org.eclipse.jface.text.Position;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   122
import org.eclipse.jface.text.Region;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   123
import org.eclipse.jface.text.TextPresentation;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   124
import org.eclipse.jface.text.source.Annotation;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   125
import org.eclipse.jface.text.source.AnnotationModel;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   126
import org.eclipse.jface.text.source.AnnotationRulerColumn;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   127
import org.eclipse.jface.text.source.CompositeRuler;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   128
import org.eclipse.jface.text.source.IAnnotationAccess;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   129
import org.eclipse.jface.text.source.IAnnotationModel;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   130
import org.eclipse.jface.text.source.IAnnotationModelExtension;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   131
import org.eclipse.jface.text.source.IOverviewRuler;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   132
import org.eclipse.jface.text.source.ISharedTextColors;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   133
import org.eclipse.jface.text.source.ISourceViewer;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   134
import org.eclipse.jface.text.source.IVerticalRuler;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   135
import org.eclipse.jface.text.source.IVerticalRulerColumn;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   136
import org.eclipse.jface.text.source.IVerticalRulerExtension;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   137
import org.eclipse.jface.text.source.IVerticalRulerInfo;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   138
import org.eclipse.jface.text.source.OverviewRuler;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   139
import org.eclipse.jface.text.source.SourceViewerConfiguration;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   140
import org.eclipse.jface.util.IPropertyChangeListener;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   141
import org.eclipse.jface.util.PropertyChangeEvent;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   142
import org.eclipse.jface.viewers.ISelection;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   143
import org.eclipse.jface.viewers.ISelectionChangedListener;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   144
import org.eclipse.jface.viewers.SelectionChangedEvent;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   145
import org.eclipse.swt.SWT;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   146
import org.eclipse.swt.custom.StyleRange;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   147
import org.eclipse.swt.custom.StyledText;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   148
import org.eclipse.swt.dnd.DND;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   149
import org.eclipse.swt.dnd.DragSource;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   150
import org.eclipse.swt.dnd.DropTarget;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   151
import org.eclipse.swt.dnd.FileTransfer;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   152
import org.eclipse.swt.dnd.TextTransfer;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   153
import org.eclipse.swt.dnd.Transfer;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   154
import org.eclipse.swt.events.MouseAdapter;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   155
import org.eclipse.swt.events.MouseEvent;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   156
import org.eclipse.swt.graphics.Color;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   157
import org.eclipse.swt.graphics.Font;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   158
import org.eclipse.swt.graphics.FontData;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   159
import org.eclipse.swt.graphics.Point;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   160
import org.eclipse.swt.graphics.RGB;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   161
import org.eclipse.swt.graphics.Rectangle;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   162
import org.eclipse.swt.layout.FillLayout;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   163
import org.eclipse.swt.widgets.Composite;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   164
import org.eclipse.swt.widgets.Control;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   165
import org.eclipse.swt.widgets.Display;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   166
import org.eclipse.swt.widgets.Menu;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   167
import org.eclipse.ui.IActionBars;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   168
import org.eclipse.ui.IPartListener2;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   169
import org.eclipse.ui.IWorkbenchActionConstants;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   170
import org.eclipse.ui.IWorkbenchCommandConstants;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   171
import org.eclipse.ui.IWorkbenchPart;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   172
import org.eclipse.ui.IWorkbenchPartReference;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   173
import org.eclipse.ui.IWorkbenchPartSite;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   174
import org.eclipse.ui.PlatformUI;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   175
import org.eclipse.ui.actions.ActionFactory;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   176
import org.eclipse.ui.contexts.IContextActivation;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   177
import org.eclipse.ui.contexts.IContextService;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   178
import org.eclipse.ui.editors.text.EditorsUI;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   179
import org.eclipse.ui.handlers.IHandlerActivation;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   180
import org.eclipse.ui.handlers.IHandlerService;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   181
import org.eclipse.ui.ide.IGotoMarker;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   182
import org.eclipse.ui.part.WorkbenchPart;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   183
import org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstants;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   184
import org.eclipse.ui.texteditor.AnnotationPreference;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   185
import org.eclipse.ui.texteditor.ChainedPreferenceStore;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   186
import org.eclipse.ui.texteditor.DefaultMarkerAnnotationAccess;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   187
import org.eclipse.ui.texteditor.ITextEditorActionConstants;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   188
import org.eclipse.ui.texteditor.IUpdate;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   189
import org.eclipse.ui.texteditor.MarkerAnnotationPreferences;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   190
import org.eclipse.ui.texteditor.SimpleMarkerAnnotation;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   191
import org.eclipse.ui.texteditor.SourceViewerDecorationSupport;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   192
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   193
/**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   194
 * DisassemblyPart
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   195
 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   196
@SuppressWarnings("restriction")
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   197
public abstract class DisassemblyPart extends WorkbenchPart implements IDisassemblyPart, IViewportListener, ITextPresentationListener, SessionEndedListener {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   198
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   199
	private final static boolean DEBUG = "true".equals(Platform.getDebugOption("org.eclipse.cdt.dsf.ui/debug/disassembly"));  //$NON-NLS-1$//$NON-NLS-2$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   200
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   201
	/**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   202
	 * Annotation model attachment key for breakpoint annotations.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   203
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   204
	private final static String BREAKPOINT_ANNOTATIONS= "breakpoints"; //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   205
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   206
	private final static BigInteger PC_UNKNOWN = BigInteger.valueOf(-1);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   207
	private final static BigInteger PC_RUNNING = BigInteger.valueOf(-2);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   208
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   209
	/** Preference key for highlighting current line. */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   210
	private final static String CURRENT_LINE = AbstractDecoratedTextEditorPreferenceConstants.EDITOR_CURRENT_LINE;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   211
	/** Preference key for highlight color of current line. */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   212
	private final static String CURRENT_LINE_COLOR = AbstractDecoratedTextEditorPreferenceConstants.EDITOR_CURRENT_LINE_COLOR;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   213
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   214
	/** The width of the vertical ruler. */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   215
	protected final static int VERTICAL_RULER_WIDTH = 12;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   216
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   217
	/** High water mark for cache */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   218
	private final static int fgHighWaterMark = 500;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   219
	/** Low water mark for cache */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   220
	private final static int fgLowWaterMark = 100;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   221
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   222
	private static final String COMMAND_ID_GOTO_ADDRESS = "org.eclipse.cdt.dsf.debug.ui.disassembly.commands.gotoAddress"; //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   223
	private static final String COMMAND_ID_GOTO_PC = "org.eclipse.cdt.dsf.debug.ui.disassembly.commands.gotoPC"; //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   224
	private static final String COMMAND_ID_GOTO_SYMBOL = "org.eclipse.cdt.dsf.debug.ui.disassembly.commands.gotoSymbol"; //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   225
//	private static final String COMMAND_ID_TOGGLE_BREAKPOINT = "org.eclipse.debug.ui.commands.ToggleBreakpoint"; //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   226
//	private static final String COMMAND_ID_RUN_TO_LINE = "org.eclipse.debug.ui.commands.RunToLine"; //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   227
//	private static final String COMMAND_ID_TOGGLE_STEPPING_MODE = "org.eclipse.cdt.dsf.debug.ui.debug.ui.menu.showDisassemblyAction"; //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   228
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   229
	private static final String KEY_BINDING_CONTEXT_DISASSEMBLY = "org.eclipse.cdt.dsf.debug.ui.disassembly.context"; //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   230
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   231
	protected DisassemblyViewer fViewer;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   232
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   233
	protected AbstractDisassemblyAction fActionGotoPC;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   234
	protected AbstractDisassemblyAction fActionGotoAddress;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   235
	private AbstractDisassemblyAction fActionGotoSymbol;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   236
	private AbstractDisassemblyAction fActionToggleBreakpoint;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   237
	protected AbstractDisassemblyAction fActionToggleSource;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   238
	private AbstractDisassemblyAction fActionToggleFunctionColumn;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   239
	private AbstractDisassemblyAction fActionToggleSymbols;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   240
	private AbstractDisassemblyAction fActionRefreshView;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   241
	private Action fActionOpenPreferences;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   242
	private AbstractDisassemblyAction fActionToggleAddressColumn;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   243
	private AbstractDisassemblyAction fActionToggleBreakpointEnablement;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   244
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   245
	protected DisassemblyDocument fDocument;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   246
	private IAnnotationAccess fAnnotationAccess;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   247
	private AnnotationRulerColumn fAnnotationRulerColumn;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   248
	private MarkerAnnotationPreferences fAnnotationPreferences;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   249
	private IPreferenceStore fPreferenceStore;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   250
	private IOverviewRuler fOverviewRuler;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   251
	private final ListenerList fRulerContextMenuListeners= new ListenerList(ListenerList.IDENTITY);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   252
	private SourceViewerDecorationSupport fDecorationSupport;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   253
	private Font fFont;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   254
	private IVerticalRuler fVerticalRuler;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   255
	private IFindReplaceTarget fFindReplaceTarget;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   256
	private IPropertyChangeListener fPropertyChangeListener= new PropertyChangeListener();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   257
	private Color fInstructionColor;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   258
	private Color fErrorColor;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   259
	private Color fSourceColor;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   260
	private Color fLabelColor;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   261
	private Control fRedrawControl;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   262
	private RGB fPCAnnotationRGB;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   263
	private Composite fComposite;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   264
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   265
	private DropTarget fDropTarget;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   266
	private DragSource fDragSource;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   267
	private TextViewerDragAdapter fDragSourceAdapter;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   268
	private DisassemblyDropAdapter fDropTargetAdapter;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   269
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   270
	private FunctionOffsetRulerColumn fOpcodeRulerColumn;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   271
	private AddressRulerColumn fAddressRulerColumn;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   272
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   273
	private BigInteger fStartAddress;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   274
	private BigInteger fEndAddress;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   275
	private int fAddressSize= 32;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   276
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   277
	private volatile boolean fUpdatePending;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   278
	private BigInteger fPCAddress;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   279
	private BigInteger fGotoAddressPending= PC_UNKNOWN;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   280
	private BigInteger fFocusAddress= PC_UNKNOWN;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   281
	private int fBufferZone;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   282
	private IExecutionDMContext fTargetContext;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   283
	private String fDebugSessionId;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   284
	private int fTargetFrame;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   285
	private DisassemblyIPAnnotation fPCAnnotation;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   286
	private DisassemblyIPAnnotation fSecondaryPCAnnotation;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   287
	private boolean fPCAnnotationUpdatePending;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   288
	private ArrayList<BigInteger> fPendingPCUpdates = new ArrayList<BigInteger>(5);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   289
	private Position fScrollPos;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   290
	private int fScrollLine;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   291
	private Position fFocusPos;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   292
	private BigInteger fFrameAddress= PC_UNKNOWN;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   293
	protected Map<String, Action> fGlobalActions = new HashMap<String, Action>();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   294
	private List<Action> fSelectionActions = new ArrayList<Action>();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   295
	private List<AbstractDisassemblyAction> fStateDependentActions = new ArrayList<AbstractDisassemblyAction>();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   296
	private boolean fSourceOnlyMode;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   297
	private boolean fShowSource;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   298
	private boolean fShowOpcodes;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   299
	private boolean fShowSymbols;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   300
	private Map<String, Object> fFile2Storage = new HashMap<String, Object>();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   301
	private boolean fShowDisassembly;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   302
	private LinkedList<AddressRangePosition> fPCHistory = new LinkedList<AddressRangePosition>();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   303
	private int fPCHistorySizeMax = 4;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   304
	private boolean fGotoFramePending;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   305
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   306
	private String fPCAnnotationColorKey;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   307
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   308
	private ArrayList<Runnable> fRunnableQueue = new ArrayList<Runnable>();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   309
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   310
	protected IPartListener2 fPartListener =
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   311
		new IPartListener2() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   312
			public void partActivated(IWorkbenchPartReference partRef) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   313
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   314
			public void partBroughtToTop(IWorkbenchPartReference partRef) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   315
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   316
			public void partClosed(IWorkbenchPartReference partRef) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   317
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   318
			public void partDeactivated(IWorkbenchPartReference partRef) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   319
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   320
			public void partOpened(IWorkbenchPartReference partRef) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   321
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   322
			public void partHidden(IWorkbenchPartReference partRef) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   323
				if (partRef.getPart(false) == DisassemblyPart.this) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   324
					setActive(false);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   325
				}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   326
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   327
			public void partVisible(IWorkbenchPartReference partRef) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   328
				if (partRef.getPart(false) == DisassemblyPart.this) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   329
					setActive(true);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   330
				}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   331
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   332
			public void partInputChanged(IWorkbenchPartReference partRef) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   333
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   334
		};
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   335
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   336
	private boolean fActive = true;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   337
	private boolean fDoPendingPosted;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   338
	private boolean fUpdateBeforeFocus;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   339
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   340
	private boolean fRefreshAll;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   341
	private IMarker fGotoMarkerPending;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   342
	private boolean fUpdateTitlePending;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   343
	private boolean fRefreshViewPending;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   344
	private boolean fUpdateSourcePending;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   345
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   346
	private ArrayList<IHandlerActivation> fHandlerActivations;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   347
	private IContextActivation fContextActivation;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   348
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   349
	private DsfServicesTracker fServicesTracker;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   350
	private IFrameDMContext fTargetFrameContext;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   351
	protected IFrameDMData fTargetFrameData;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   352
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   353
	
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   354
	private final class ActionRefreshView extends AbstractDisassemblyAction {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   355
		public ActionRefreshView() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   356
			super(DisassemblyPart.this);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   357
			setText(DisassemblyMessages.Disassembly_action_RefreshView_label);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   358
			setImageDescriptor(DisassemblyImageRegistry.getImageDescriptor(DisassemblyImageRegistry.ICON_Refresh_enabled));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   359
			setDisabledImageDescriptor(DisassemblyImageRegistry.getImageDescriptor(DisassemblyImageRegistry.ICON_Refresh_disabled));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   360
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   361
		@Override
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   362
		public void run() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   363
			refreshView(10);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   364
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   365
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   366
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   367
	private final class ActionToggleAddressColumn extends AbstractDisassemblyAction {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   368
		ActionToggleAddressColumn () {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   369
			super(DisassemblyPart.this);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   370
			setText(DisassemblyMessages.Disassembly_action_ShowAddresses_label);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   371
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   372
		@Override
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   373
		public void run() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   374
			IPreferenceStore store = DsfUIPlugin.getDefault().getPreferenceStore();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   375
			store.setValue(DisassemblyPreferenceConstants.SHOW_ADDRESS_RULER, !isAddressRulerVisible());
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   376
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   377
		@Override
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   378
		public void update() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   379
			setChecked(isAddressRulerVisible());
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   380
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   381
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   382
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   383
	private final class ActionToggleFunctionColumn extends AbstractDisassemblyAction {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   384
		ActionToggleFunctionColumn() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   385
			super(DisassemblyPart.this);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   386
			setText(DisassemblyMessages.Disassembly_action_ShowFunctionOffsets_label);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   387
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   388
		@Override
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   389
		public void run() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   390
			IPreferenceStore store = DsfUIPlugin.getDefault().getPreferenceStore();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   391
			store.setValue(DisassemblyPreferenceConstants.SHOW_FUNCTION_OFFSETS, !isOpcodeRulerVisible());
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   392
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   393
		@Override
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   394
		public void update() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   395
			setChecked(isOpcodeRulerVisible());
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   396
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   397
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   398
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   399
	private final class ActionToggleBreakpoint extends AbstractDisassemblyAction {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   400
		private IBreakpoint fBreakpoint;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   401
		private int fLine;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   402
		public ActionToggleBreakpoint() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   403
			super(DisassemblyPart.this);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   404
			setText(DisassemblyMessages.Disassembly_action_AddBreakpoint_label);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   405
			setImageDescriptor(DisassemblyImageRegistry.getImageDescriptor(DisassemblyImageRegistry.ICON_ToggleBreakpoint));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   406
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   407
		@Override
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   408
		public void run() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   409
			try {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   410
				if (fBreakpoint != null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   411
					fBreakpoint.delete();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   412
				} else {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   413
					insertBreakpoint(fLine, false);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   414
				}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   415
			} catch (CoreException e) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   416
				DsfUIPlugin.getDefault().getLog().log(e.getStatus());
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   417
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   418
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   419
		@Override
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   420
		public void update() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   421
			super.update();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   422
			if (isEnabled()) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   423
				fLine = fVerticalRuler.getLineOfLastMouseButtonActivity();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   424
				IBreakpoint[] bps = getBreakpointsAtLine(fLine);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   425
				if (bps == null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   426
					fBreakpoint = null;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   427
					setText(DisassemblyMessages.Disassembly_action_AddBreakpoint_label);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   428
				} else {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   429
					fBreakpoint = bps[0];
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   430
					setText(DisassemblyMessages.Disassembly_action_RemoveBreakpoint_label);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   431
				}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   432
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   433
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   434
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   435
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   436
	private final class ActionToggleBreakpointEnablement extends AbstractDisassemblyAction {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   437
		private IBreakpoint fBreakpoint;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   438
		public ActionToggleBreakpointEnablement() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   439
			super(DisassemblyPart.this);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   440
			setText(DisassemblyMessages.Disassembly_action_EnableBreakpoint_label);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   441
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   442
		@Override
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   443
		public void run() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   444
			try {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   445
				fBreakpoint.setEnabled(!fBreakpoint.isEnabled());
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   446
			} catch (CoreException e) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   447
				internalError(e);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   448
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   449
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   450
		@Override
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   451
		public void update() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   452
			super.update();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   453
			if (isEnabled()) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   454
				int line = fVerticalRuler.getLineOfLastMouseButtonActivity();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   455
				IBreakpoint[] bps = getBreakpointsAtLine(line);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   456
				if (bps == null || bps.length == 0) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   457
					setEnabled(false);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   458
				} else {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   459
					fBreakpoint = bps[0];
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   460
					try {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   461
						if (fBreakpoint.isEnabled()) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   462
							setText(DisassemblyMessages.Disassembly_action_DisableBreakpoint_label);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   463
						} else {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   464
							setText(DisassemblyMessages.Disassembly_action_EnableBreakpoint_label);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   465
						}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   466
					} catch (CoreException e) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   467
						setEnabled(false);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   468
					}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   469
				}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   470
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   471
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   472
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   473
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   474
	private final class ActionToggleSource extends AbstractDisassemblyAction {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   475
		public ActionToggleSource() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   476
			super(DisassemblyPart.this);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   477
			setText(DisassemblyMessages.Disassembly_action_ShowSource_label);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   478
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   479
		@Override
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   480
		public void run() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   481
			IPreferenceStore store = DsfUIPlugin.getDefault().getPreferenceStore();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   482
			boolean showSourceEnabled = store.getBoolean(DisassemblyPreferenceConstants.SHOW_SOURCE);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   483
			if (showSourceEnabled == fShowSource) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   484
				store.setValue(DisassemblyPreferenceConstants.SHOW_SOURCE, !fShowSource);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   485
			} else {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   486
				sourceModeChanged(!fShowSource);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   487
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   488
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   489
		@Override
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   490
		public void update() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   491
			super.update();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   492
			if (isEnabled()) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   493
				setEnabled(fShowDisassembly);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   494
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   495
			setChecked(fShowSource);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   496
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   497
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   498
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   499
	private final class ActionToggleSymbols extends AbstractDisassemblyAction {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   500
		public ActionToggleSymbols() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   501
			super(DisassemblyPart.this);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   502
			setText(DisassemblyMessages.Disassembly_action_ShowSymbols_label);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   503
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   504
		@Override
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   505
		public void run() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   506
			IPreferenceStore store = DsfUIPlugin.getDefault().getPreferenceStore();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   507
			store.setValue(DisassemblyPreferenceConstants.SHOW_SYMBOLS, !fShowSymbols);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   508
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   509
		@Override
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   510
		public void update() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   511
			super.update();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   512
			setChecked(fShowSymbols);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   513
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   514
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   515
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   516
	/**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   517
	 * Internal property change listener for handling changes in the
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   518
	 * preferences.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   519
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   520
	class PropertyChangeListener implements IPropertyChangeListener {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   521
		/*
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   522
		 * @see IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent)
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   523
		 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   524
		public void propertyChange(PropertyChangeEvent event) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   525
			handlePreferenceStoreChanged(event);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   526
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   527
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   528
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   529
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   530
	/**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   531
	 * The constructor.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   532
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   533
	public DisassemblyPart() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   534
		fAnnotationPreferences = new MarkerAnnotationPreferences();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   535
		setPreferenceStore(new ChainedPreferenceStore(new IPreferenceStore[] {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   536
			DsfUIPlugin.getDefault().getPreferenceStore(), EditorsUI.getPreferenceStore() }));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   537
		fPCAddress = fFrameAddress = PC_UNKNOWN;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   538
		fTargetFrame = -1;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   539
		fBufferZone = 32;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   540
		fPCAnnotation = new DisassemblyIPAnnotation(true, 0);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   541
		fSecondaryPCAnnotation = new DisassemblyIPAnnotation(false, 0);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   542
        IPreferenceStore prefs = getPreferenceStore();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   543
		fStartAddress = new BigInteger(prefs.getString(DisassemblyPreferenceConstants.START_ADDRESS));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   544
		String endAddressString = prefs.getString(DisassemblyPreferenceConstants.END_ADDRESS);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   545
		if(endAddressString.startsWith("0x")) //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   546
			fEndAddress = new BigInteger(endAddressString.substring(2), 16);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   547
		else
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   548
			fEndAddress = new BigInteger(endAddressString, 16);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   549
		// TLETODO [disassembly[ source only mode
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   550
		fSourceOnlyMode = false; //prefs.getBoolean(DisassemblyPreferenceConstants.USE_SOURCE_ONLY_MODE);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   551
		fShowSource = fSourceOnlyMode || prefs.getBoolean(DisassemblyPreferenceConstants.SHOW_SOURCE);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   552
		fShowDisassembly = !fSourceOnlyMode || !fShowSource;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   553
		fShowOpcodes = prefs.getBoolean(DisassemblyPreferenceConstants.SHOW_FUNCTION_OFFSETS);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   554
		fShowSymbols = prefs.getBoolean(DisassemblyPreferenceConstants.SHOW_SYMBOLS);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   555
		fUpdateBeforeFocus = !prefs.getBoolean(DisassemblyPreferenceConstants.AVOID_READ_BEFORE_PC);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   556
		fPCHistorySizeMax = prefs.getInt(DisassemblyPreferenceConstants.PC_HISTORY_SIZE);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   557
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   558
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   559
	public void logWarning(String message, Throwable error) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   560
		DsfUIPlugin.getDefault().getLog().log(new Status(IStatus.WARNING, DsfUIPlugin.PLUGIN_ID, message, error));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   561
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   562
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   563
	/*
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   564
	 * @see IAdaptable#getAdapter(java.lang.Class)
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   565
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   566
    @Override
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   567
    @SuppressWarnings("unchecked")
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   568
    public Object getAdapter(Class required) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   569
		if (IVerticalRulerInfo.class.equals(required)) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   570
			if (fVerticalRuler != null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   571
				return fVerticalRuler;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   572
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   573
		} else if (IDisassemblyPart.class.equals(required)) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   574
			return this;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   575
		} else if (IFindReplaceTarget.class.equals(required)) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   576
			if (fFindReplaceTarget == null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   577
				fFindReplaceTarget = (fViewer == null ? null : fViewer.getFindReplaceTarget());
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   578
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   579
			return fFindReplaceTarget;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   580
		} else if (ITextOperationTarget.class.equals(required)) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   581
			return (fViewer == null ? null : fViewer.getTextOperationTarget());
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   582
		} else if (Control.class.equals(required)) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   583
			return fViewer != null ? fViewer.getTextWidget() : null;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   584
		} else if (IGotoMarker.class.equals(required)) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   585
			return new IGotoMarker() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   586
				public void gotoMarker(IMarker marker) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   587
					DisassemblyPart.this.gotoMarker(marker);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   588
				}};
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   589
		} else if (IToggleBreakpointsTarget.class.equals(required)) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   590
			return new IToggleBreakpointsTarget() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   591
				public void toggleLineBreakpoints(IWorkbenchPart part, ISelection selection) throws CoreException {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   592
					ITextSelection textSelection = (ITextSelection)selection;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   593
					int line = textSelection.getStartLine();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   594
					IBreakpoint[] bp = getBreakpointsAtLine(line);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   595
					if (bp == null || bp.length == 0) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   596
						insertBreakpoint(line, false);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   597
					} else {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   598
						for (int i = 0; i < bp.length; i++) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   599
							bp[i].delete();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   600
						}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   601
					}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   602
				}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   603
				public boolean canToggleLineBreakpoints(IWorkbenchPart part, ISelection selection) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   604
					return fDebugSessionId != null;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   605
				}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   606
				public void toggleMethodBreakpoints(IWorkbenchPart part, ISelection selection) throws CoreException {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   607
				}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   608
				public boolean canToggleMethodBreakpoints(IWorkbenchPart part, ISelection selection) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   609
					return false;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   610
				}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   611
				public void toggleWatchpoints(IWorkbenchPart part, ISelection selection) throws CoreException {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   612
				}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   613
				public boolean canToggleWatchpoints(IWorkbenchPart part, ISelection selection) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   614
					return false;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   615
				}};
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   616
		} else if (IRunToLineTarget.class.equals(required)) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   617
			return new IRunToLineTarget() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   618
				public void runToLine(IWorkbenchPart part, ISelection selection, ISuspendResume target) throws CoreException {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   619
//					ITextSelection textSelection = (ITextSelection)selection;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   620
//					int line = textSelection.getStartLine();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   621
//					BigInteger address = getAddressOfLine(line);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   622
					// TLETODO [disassembly] run to line
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   623
//					getRunControl().runUntil(...);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   624
				}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   625
				public boolean canRunToLine(IWorkbenchPart part, ISelection selection, ISuspendResume target) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   626
					return fTargetContext != null && isSuspended(fTargetContext) ;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   627
				}};
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   628
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   629
		return super.getAdapter(required);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   630
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   631
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   632
	private void setPreferenceStore(IPreferenceStore store) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   633
		if (fPreferenceStore != null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   634
			fPreferenceStore.removePropertyChangeListener(fPropertyChangeListener);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   635
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   636
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   637
		fPreferenceStore = store;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   638
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   639
		if (fPreferenceStore != null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   640
			fPreferenceStore.addPropertyChangeListener(fPropertyChangeListener);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   641
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   642
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   643
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   644
	/**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   645
	 * Handles a property change event describing a change of the editor's
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   646
	 * preference store and updates the preference related editor properties.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   647
	 * <p>
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   648
	 * Subclasses may extend.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   649
	 * </p>
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   650
	 *
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   651
	 * @param event
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   652
	 *            the property change event
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   653
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   654
	protected void handlePreferenceStoreChanged(PropertyChangeEvent event) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   655
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   656
		if (fViewer == null)
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   657
			return;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   658
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   659
		String property = event.getProperty();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   660
		IPreferenceStore store = getPreferenceStore();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   661
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   662
		if (getFontPropertyPreferenceKey().equals(property)) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   663
			initializeViewerFont(fViewer);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   664
		} else if (property.equals(DisassemblyPreferenceConstants.SHOW_ADDRESS_RULER)) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   665
			fActionToggleAddressColumn.update();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   666
			if (isAddressRulerVisible()) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   667
				showAddressRuler();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   668
			} else {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   669
				hideAddressRuler();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   670
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   671
		} else if (property.equals(DisassemblyPreferenceConstants.ADDRESS_RADIX)) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   672
			if (fAddressRulerColumn != null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   673
				hideAddressRuler();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   674
				showAddressRuler();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   675
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   676
		} else if (property.equals(DisassemblyPreferenceConstants.SHOW_ADDRESS_RADIX)) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   677
			if (fAddressRulerColumn != null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   678
				hideAddressRuler();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   679
				showAddressRuler();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   680
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   681
		} else if (property.equals(DisassemblyPreferenceConstants.SHOW_SOURCE)) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   682
			sourceModeChanged(store.getBoolean(property));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   683
		} else if (property.equals(DisassemblyPreferenceConstants.INSTRUCTION_RADIX)) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   684
			Runnable doit = new Runnable() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   685
				public void run() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   686
					fDocument.invalidateAddressRange(fStartAddress, fEndAddress, true);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   687
					if (!fShowDisassembly) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   688
						fDocument.invalidateDisassemblyWithSource(true);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   689
					}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   690
					fDocument.setMaxOpcodeLength(0);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   691
					fGotoFramePending = true;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   692
				}};
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   693
			doScrollLocked(doit);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   694
		} else if (property.equals(DisassemblyPreferenceConstants.SHOW_SYMBOLS)) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   695
			boolean showSymbols = store.getBoolean(property);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   696
			if (fShowSymbols == showSymbols) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   697
				return;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   698
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   699
			fShowSymbols = showSymbols;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   700
			Runnable doit = new Runnable() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   701
				public void run() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   702
					fDocument.invalidateAddressRange(fStartAddress, fEndAddress, true);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   703
					if (!fShowDisassembly) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   704
						fDocument.invalidateDisassemblyWithSource(true);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   705
					}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   706
					fGotoFramePending = true;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   707
				}};
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   708
			doScrollLocked(doit);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   709
		} else if (property.equals(DisassemblyPreferenceConstants.USE_SOURCE_ONLY_MODE)) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   710
			fSourceOnlyMode = store.getBoolean(property);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   711
			if (fDebugSessionId != null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   712
				disassemblyModeChanged(isDissemblyMixedModeOn());
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   713
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   714
		} else if (property.equals(DisassemblyPreferenceConstants.SHOW_FUNCTION_OFFSETS)) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   715
			fShowOpcodes = store.getBoolean(property);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   716
			fActionToggleFunctionColumn.update();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   717
			if (isOpcodeRulerVisible()) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   718
				showOpcodeRuler();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   719
			} else {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   720
				hideOpcodeRuler();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   721
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   722
		} else if (property.equals(DisassemblyPreferenceConstants.AVOID_READ_BEFORE_PC)) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   723
			fUpdateBeforeFocus = !store.getBoolean(property);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   724
			updateVisibleArea();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   725
		} else if (property.equals(fPCAnnotationColorKey)) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   726
			fPCAnnotationRGB = PreferenceConverter.getColor(store, fPCAnnotationColorKey);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   727
			// redraw
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   728
			for (Iterator<AddressRangePosition> it=fPCHistory.iterator(); it.hasNext();) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   729
				AddressRangePosition pos = it.next();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   730
				fViewer.invalidateTextPresentation(pos.offset, pos.length);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   731
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   732
		} else if (property.equals(DisassemblyPreferenceConstants.PC_HISTORY_SIZE)) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   733
			fPCHistorySizeMax = store.getInt(property);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   734
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   735
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   736
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   737
	/**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   738
	 * This is a callback that will allow us to create the viewer and initialize
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   739
	 * it.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   740
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   741
	@Override
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   742
	public void createPartControl(Composite parent) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   743
		fComposite = parent;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   744
		FillLayout layout = new FillLayout();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   745
		layout.marginHeight = 2;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   746
		parent.setLayout(layout);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   747
		fVerticalRuler = createVerticalRuler();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   748
		int styles = SWT.V_SCROLL | SWT.H_SCROLL | SWT.MULTI | SWT.BORDER | SWT.FULL_SELECTION;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   749
		fViewer = new DisassemblyViewer(parent, fVerticalRuler, getOverviewRuler(), true, styles);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   750
		SourceViewerConfiguration sourceViewerConfig = new DisassemblyViewerConfiguration(this);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   751
		fViewer.addTextPresentationListener(this);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   752
		fViewer.configure(sourceViewerConfig);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   753
		fDecorationSupport = new SourceViewerDecorationSupport(fViewer, getOverviewRuler(), getAnnotationAccess(),
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   754
			getSharedColors());
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   755
		configureSourceViewerDecorationSupport(fDecorationSupport);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   756
		fDecorationSupport.install(getPreferenceStore());
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   757
		if (fPCAnnotationColorKey != null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   758
			fPCAnnotationRGB = PreferenceConverter.getColor(getPreferenceStore(), fPCAnnotationColorKey);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   759
		} else {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   760
			fPCAnnotationRGB = parent.getDisplay().getSystemColor(SWT.COLOR_LIST_SELECTION).getRGB();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   761
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   762
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   763
		initializeViewerFont(fViewer);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   764
		createActions();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   765
		hookRulerContextMenu();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   766
		hookContextMenu();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   767
		contributeToActionBars();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   768
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   769
		fViewer.addSelectionChangedListener(new ISelectionChangedListener() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   770
			public void selectionChanged(SelectionChangedEvent event) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   771
				updateSelectionDependentActions();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   772
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   773
		});
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   774
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   775
		fDocument = createDocument();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   776
		fViewer.setDocument(fDocument, new AnnotationModel());
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   777
		JFaceResources.getFontRegistry().addListener(fPropertyChangeListener);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   778
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   779
		fErrorColor = getSharedColors().getColor(new RGB(96, 0, 0));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   780
		fInstructionColor = getSharedColors().getColor(new RGB(0, 0, 96));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   781
		fSourceColor = getSharedColors().getColor(new RGB(64, 0, 80));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   782
		fLabelColor = getSharedColors().getColor(new RGB(0, 0, 96));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   783
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   784
		if (isAddressRulerVisible()) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   785
			showAddressRuler();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   786
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   787
		if (isOpcodeRulerVisible()) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   788
			showOpcodeRuler();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   789
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   790
		initDragAndDrop();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   791
		PlatformUI.getWorkbench().getHelpSystem().setHelp(fViewer.getControl(), IDisassemblyHelpContextIds.DISASSEMBLY_VIEW);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   792
		updateTitle();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   793
		updateStateDependentActions();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   794
		
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   795
		if (fDebugSessionId != null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   796
			debugContextChanged();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   797
		} else {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   798
			updateDebugContext();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   799
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   800
		DsfSession.addSessionEndedListener(this);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   801
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   802
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   803
	/*
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   804
	 * @see org.eclipse.ui.part.WorkbenchPart#setSite(org.eclipse.ui.IWorkbenchPartSite)
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   805
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   806
	@Override
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   807
	protected void setSite(IWorkbenchPartSite site) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   808
		super.setSite(site);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   809
        site.getPage().addPartListener(fPartListener);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   810
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   811
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   812
	private DisassemblyDocument createDocument() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   813
		DisassemblyDocument doc = new DisassemblyDocument();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   814
		return doc;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   815
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   816
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   817
	/*
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   818
	 * @see org.eclipse.ui.IWorkbenchPart#dispose()
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   819
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   820
	@Override
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   821
	public void dispose() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   822
		IWorkbenchPartSite site = getSite();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   823
		site.setSelectionProvider(null);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   824
		site.getPage().removePartListener(fPartListener);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   825
		if (fHandlerActivations != null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   826
			IHandlerService handlerService = (IHandlerService)site.getService(IHandlerService.class);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   827
			handlerService.deactivateHandlers(fHandlerActivations);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   828
			fHandlerActivations = null;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   829
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   830
		if (fContextActivation != null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   831
			IContextService ctxService = (IContextService)site.getService(IContextService.class);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   832
			ctxService.deactivateContext(fContextActivation);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   833
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   834
		fViewer = null;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   835
		setDebugContext(null);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   836
		DsfSession.removeSessionEndedListener(this);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   837
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   838
		fAnnotationAccess = null;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   839
		fAnnotationPreferences = null;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   840
		fAnnotationRulerColumn = null;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   841
		fComposite = null;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   842
		if (fDecorationSupport != null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   843
			fDecorationSupport.uninstall();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   844
			fDecorationSupport = null;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   845
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   846
		if (fFont != null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   847
			fFont.dispose();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   848
			fFont = null;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   849
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   850
		if (fDropTarget != null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   851
			fDropTarget.dispose();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   852
			fDropTarget = null;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   853
			fDragSource.dispose();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   854
			fDragSource = null;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   855
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   856
		if (fPropertyChangeListener != null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   857
			if (fPreferenceStore != null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   858
				fPreferenceStore.removePropertyChangeListener(fPropertyChangeListener);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   859
				fPreferenceStore = null;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   860
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   861
			fPropertyChangeListener = null;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   862
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   863
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   864
		fDocument.dispose();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   865
		fDocument = null;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   866
		super.dispose();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   867
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   868
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   869
	private void initDragAndDrop() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   870
		if (fDropTarget == null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   871
			Transfer[] dropTypes = new Transfer[] { FileTransfer.getInstance(), TextTransfer.getInstance() };
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   872
			Transfer[] dragTypes = new Transfer[] { TextTransfer.getInstance() };
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   873
			Control dropControl = getSourceViewer().getTextWidget();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   874
			Control dragControl = dropControl;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   875
			int dropOps = DND.DROP_COPY | DND.DROP_DEFAULT;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   876
			int dragOps = DND.DROP_COPY | DND.DROP_DEFAULT;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   877
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   878
			fDropTarget = new DropTarget(dropControl, dropOps);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   879
			fDropTarget.setTransfer(dropTypes);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   880
			fDropTargetAdapter = new DisassemblyDropAdapter(this);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   881
			fDropTarget.addDropListener(fDropTargetAdapter);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   882
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   883
			fDragSource = new DragSource(dragControl, dragOps);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   884
			fDragSource.setTransfer(dragTypes);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   885
			fDragSourceAdapter = new TextViewerDragAdapter(getSourceViewer());
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   886
			fDragSource.addDragListener(fDragSourceAdapter);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   887
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   888
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   889
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   890
	private ISourceViewer getSourceViewer() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   891
		return fViewer;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   892
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   893
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   894
	protected void configureSourceViewerDecorationSupport(SourceViewerDecorationSupport support) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   895
		Iterator<?> e = fAnnotationPreferences.getAnnotationPreferences().iterator();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   896
		while (e.hasNext()) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   897
			AnnotationPreference pref = (AnnotationPreference)e.next();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   898
			support.setAnnotationPreference(pref);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   899
			if (pref.getAnnotationType().equals(fPCAnnotation.getType())) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   900
				fPCAnnotationColorKey = pref.getColorPreferenceKey();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   901
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   902
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   903
		support.setCursorLinePainterPreferenceKeys(CURRENT_LINE, CURRENT_LINE_COLOR);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   904
		support.setSymbolicFontName(getFontPropertyPreferenceKey());
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   905
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   906
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   907
	/**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   908
	 * Returns the symbolic font name for this view as defined in XML.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   909
	 *
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   910
	 * @return a String with the symbolic font name or <code>null</code> if
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   911
	 *         none is defined
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   912
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   913
	private String getSymbolicFontName() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   914
		if (getConfigurationElement() != null)
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   915
			return getConfigurationElement().getAttribute("symbolicFontName"); //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   916
		else
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   917
			return null;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   918
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   919
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   920
	protected final String getFontPropertyPreferenceKey() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   921
		String symbolicFontName = getSymbolicFontName();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   922
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   923
		if (symbolicFontName != null)
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   924
			return symbolicFontName;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   925
		else
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   926
			return JFaceResources.TEXT_FONT;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   927
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   928
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   929
	/**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   930
	 * Initializes the given viewer's font.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   931
	 *
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   932
	 * @param viewer
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   933
	 *            the viewer
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   934
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   935
	private void initializeViewerFont(ISourceViewer viewer) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   936
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   937
		boolean isSharedFont = true;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   938
		Font font = null;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   939
		String symbolicFontName = getSymbolicFontName();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   940
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   941
		if (symbolicFontName != null)
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   942
			font = JFaceResources.getFont(symbolicFontName);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   943
		else if (fPreferenceStore != null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   944
			// Backward compatibility
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   945
			if (fPreferenceStore.contains(JFaceResources.TEXT_FONT)
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   946
				&& !fPreferenceStore.isDefault(JFaceResources.TEXT_FONT)) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   947
				FontData data = PreferenceConverter.getFontData(fPreferenceStore, JFaceResources.TEXT_FONT);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   948
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   949
				if (data != null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   950
					isSharedFont = false;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   951
					font = new Font(viewer.getTextWidget().getDisplay(), data);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   952
				}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   953
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   954
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   955
		if (font == null)
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   956
			font = JFaceResources.getTextFont();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   957
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   958
		setFont(viewer, font);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   959
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   960
		if (fFont != null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   961
			fFont.dispose();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   962
			fFont = null;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   963
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   964
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   965
		if (!isSharedFont)
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   966
			fFont = font;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   967
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   968
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   969
	/**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   970
	 * Sets the font for the given viewer sustaining selection and scroll
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   971
	 * position.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   972
	 *
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   973
	 * @param sourceViewer
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   974
	 *            the source viewer
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   975
	 * @param font
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   976
	 *            the font
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   977
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   978
	private void setFont(ISourceViewer sourceViewer, Font font) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   979
		if (sourceViewer.getDocument() != null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   980
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   981
			Point selection = sourceViewer.getSelectedRange();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   982
			int topIndex = sourceViewer.getTopIndex();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   983
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   984
			StyledText styledText = sourceViewer.getTextWidget();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   985
			Control parent = styledText;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   986
			if (sourceViewer instanceof ITextViewerExtension) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   987
				ITextViewerExtension extension = (ITextViewerExtension) sourceViewer;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   988
				parent = extension.getControl();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   989
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   990
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   991
			parent.setRedraw(false);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   992
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   993
			styledText.setFont(font);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   994
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   995
			if (fVerticalRuler instanceof IVerticalRulerExtension) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   996
				IVerticalRulerExtension e = (IVerticalRulerExtension) fVerticalRuler;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   997
				e.setFont(font);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   998
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   999
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1000
			sourceViewer.setSelectedRange(selection.x, selection.y);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1001
			sourceViewer.setTopIndex(topIndex);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1002
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1003
			if (parent instanceof Composite) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1004
				Composite composite = (Composite) parent;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1005
				composite.layout(true);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1006
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1007
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1008
			parent.setRedraw(true);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1009
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1010
		} else {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1011
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1012
			StyledText styledText = sourceViewer.getTextWidget();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1013
			styledText.setFont(font);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1014
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1015
			if (fVerticalRuler instanceof IVerticalRulerExtension) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1016
				IVerticalRulerExtension e = (IVerticalRulerExtension) fVerticalRuler;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1017
				e.setFont(font);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1018
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1019
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1020
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1021
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1022
	protected IVerticalRuler createVerticalRuler() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1023
		CompositeRuler ruler = createCompositeRuler();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1024
		IPreferenceStore store = getPreferenceStore();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1025
		if (ruler != null && store != null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1026
			for (Iterator<?> iter = ruler.getDecoratorIterator(); iter.hasNext();) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1027
				IVerticalRulerColumn column = (IVerticalRulerColumn) iter.next();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1028
				if (column instanceof AnnotationRulerColumn) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1029
					fAnnotationRulerColumn = (AnnotationRulerColumn) column;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1030
					for (Iterator<?> iter2 = fAnnotationPreferences.getAnnotationPreferences().iterator(); iter2.hasNext();) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1031
						AnnotationPreference preference = (AnnotationPreference) iter2.next();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1032
						String key = preference.getVerticalRulerPreferenceKey();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1033
						boolean showAnnotation = true;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1034
						if (key != null && store.contains(key))
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1035
							showAnnotation = store.getBoolean(key);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1036
						if (showAnnotation)
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1037
							fAnnotationRulerColumn.addAnnotationType(preference.getAnnotationType());
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1038
					}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1039
					fAnnotationRulerColumn.addAnnotationType(Annotation.TYPE_UNKNOWN);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1040
					break;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1041
				}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1042
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1043
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1044
		return ruler;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1045
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1046
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1047
	/**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1048
	 * Returns the vertical ruler.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1049
	 *
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1050
	 * @return the vertical ruler
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1051
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1052
	protected IVerticalRuler getVerticalRuler() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1053
		return fVerticalRuler;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1054
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1055
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1056
	/**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1057
	 * Returns the overview ruler.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1058
	 *
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1059
	 * @return the overview ruler
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1060
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1061
	protected IOverviewRuler getOverviewRuler() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1062
		if (fOverviewRuler == null)
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1063
			fOverviewRuler = createOverviewRuler(getSharedColors());
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1064
		return fOverviewRuler;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1065
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1066
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1067
	protected ISharedTextColors getSharedColors() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1068
		return EditorsUI.getSharedTextColors();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1069
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1070
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1071
	protected IOverviewRuler createOverviewRuler(ISharedTextColors sharedColors) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1072
		IOverviewRuler ruler = new OverviewRuler(getAnnotationAccess(), VERTICAL_RULER_WIDTH, sharedColors);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1073
		Iterator<?> e = fAnnotationPreferences.getAnnotationPreferences().iterator();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1074
		while (e.hasNext()) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1075
			AnnotationPreference preference = (AnnotationPreference) e.next();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1076
			if (preference.contributesToHeader())
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1077
				ruler.addHeaderAnnotationType(preference.getAnnotationType());
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1078
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1079
		return ruler;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1080
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1081
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1082
	/**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1083
	 * Creates a new address ruler column that is appropriately initialized.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1084
	 *
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1085
	 * @return the created line number column
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1086
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1087
	protected IVerticalRulerColumn createAddressRulerColumn() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1088
		fAddressRulerColumn= new AddressRulerColumn();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1089
		initializeRulerColumn(fAddressRulerColumn, DisassemblyPreferenceConstants.ADDRESS_COLOR);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1090
		IPreferenceStore prefs = getPreferenceStore();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1091
		fAddressRulerColumn.setRadix(prefs.getInt(DisassemblyPreferenceConstants.ADDRESS_RADIX));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1092
		fAddressRulerColumn.setShowRadixPrefix(prefs.getBoolean(DisassemblyPreferenceConstants.SHOW_ADDRESS_RADIX));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1093
		return fAddressRulerColumn;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1094
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1095
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1096
	/**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1097
	 * Creates a new ruler column that is appropriately initialized.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1098
	 *
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1099
	 * @return the created line number column
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1100
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1101
	protected IVerticalRulerColumn createOpcodeRulerColumn() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1102
		fOpcodeRulerColumn= new FunctionOffsetRulerColumn();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1103
		initializeRulerColumn(fOpcodeRulerColumn, DisassemblyPreferenceConstants.OPCODE_COLOR);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1104
		return fOpcodeRulerColumn;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1105
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1106
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1107
	/**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1108
	 * Initializes the given address ruler column from the preference store.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1109
	 *
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1110
	 * @param rulerColumn the ruler column to be initialized
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1111
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1112
	protected void initializeRulerColumn(DisassemblyRulerColumn rulerColumn, String colorPrefKey) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1113
		ISharedTextColors sharedColors= getSharedColors();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1114
		IPreferenceStore store= getPreferenceStore();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1115
		if (store != null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1116
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1117
			RGB rgb=  null;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1118
			// foreground color
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1119
			if (store.contains(colorPrefKey)) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1120
				if (store.isDefault(colorPrefKey))
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1121
					rgb= PreferenceConverter.getDefaultColor(store, colorPrefKey);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1122
				else
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1123
					rgb= PreferenceConverter.getColor(store, colorPrefKey);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1124
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1125
			if (rgb == null)
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1126
				rgb= new RGB(0, 0, 0);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1127
			rulerColumn.setForeground(sharedColors.getColor(rgb));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1128
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1129
			rgb= null;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1130
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1131
			rulerColumn.redraw();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1132
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1133
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1134
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1135
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1136
	/**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1137
	 * @return the preference store
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1138
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1139
	private IPreferenceStore getPreferenceStore() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1140
		return fPreferenceStore;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1141
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1142
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1143
	/**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1144
	 * Creates a composite ruler to be used as the vertical ruler by this
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1145
	 * editor. Subclasses may re-implement this method.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1146
	 *
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1147
	 * @return the vertical ruler
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1148
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1149
	protected CompositeRuler createCompositeRuler() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1150
		CompositeRuler ruler = new CompositeRuler();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1151
		ruler.addDecorator(0, new AnnotationRulerColumn(VERTICAL_RULER_WIDTH, getAnnotationAccess()));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1152
		return ruler;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1153
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1154
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1155
	private boolean isAddressRulerVisible() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1156
		return getPreferenceStore().getBoolean(DisassemblyPreferenceConstants.SHOW_ADDRESS_RULER);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1157
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1158
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1159
	/**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1160
	 * Shows the address ruler column.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1161
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1162
	private void showAddressRuler() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1163
		if (fAddressRulerColumn == null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1164
			IVerticalRuler v= getVerticalRuler();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1165
			if (v instanceof CompositeRuler) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1166
				CompositeRuler c= (CompositeRuler) v;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1167
				c.addDecorator(1, createAddressRulerColumn());
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1168
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1169
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1170
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1171
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1172
	/**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1173
	 * Hides the address ruler column.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1174
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1175
	private void hideAddressRuler() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1176
		if (fAddressRulerColumn != null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1177
			IVerticalRuler v= getVerticalRuler();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1178
			if (v instanceof CompositeRuler) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1179
				CompositeRuler c= (CompositeRuler) v;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1180
				c.removeDecorator(fAddressRulerColumn);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1181
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1182
			fAddressRulerColumn = null;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1183
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1184
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1185
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1186
	private boolean isOpcodeRulerVisible() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1187
		return fShowOpcodes;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1188
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1189
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1190
	/**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1191
	 * Shows the opcode ruler column.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1192
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1193
	private void showOpcodeRuler() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1194
		if (fOpcodeRulerColumn == null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1195
			IVerticalRuler v= getVerticalRuler();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1196
			if (v instanceof CompositeRuler) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1197
				CompositeRuler c= (CompositeRuler) v;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1198
				c.addDecorator(2, createOpcodeRulerColumn());
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1199
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1200
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1201
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1202
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1203
	/**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1204
	 * Hides the opcode ruler column.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1205
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1206
	private void hideOpcodeRuler() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1207
		if (fOpcodeRulerColumn != null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1208
			IVerticalRuler v= getVerticalRuler();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1209
			if (v instanceof CompositeRuler) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1210
				CompositeRuler c= (CompositeRuler) v;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1211
				c.removeDecorator(fOpcodeRulerColumn);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1212
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1213
			fOpcodeRulerColumn = null;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1214
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1215
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1216
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1217
	/**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1218
	 * Returns the annotation access.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1219
	 *
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1220
	 * @return the annotation access
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1221
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1222
	protected IAnnotationAccess getAnnotationAccess() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1223
		if (fAnnotationAccess == null)
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1224
			fAnnotationAccess = createAnnotationAccess();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1225
		return fAnnotationAccess;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1226
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1227
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1228
	/**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1229
	 * Creates the annotation access for this editor.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1230
	 *
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1231
	 * @return the created annotation access
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1232
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1233
	protected IAnnotationAccess createAnnotationAccess() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1234
		return new DefaultMarkerAnnotationAccess();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1235
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1236
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1237
	private void hookContextMenu() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1238
		String id = "#DisassemblyPartContext"; //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1239
		MenuManager menuMgr = new MenuManager(id, id);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1240
		menuMgr.setRemoveAllWhenShown(true);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1241
		menuMgr.addMenuListener(new IMenuListener() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1242
			public void menuAboutToShow(IMenuManager manager) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1243
				DisassemblyPart.this.fillContextMenu(manager);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1244
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1245
		});
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1246
		Menu menu = menuMgr.createContextMenu(fViewer.getTextWidget());
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1247
		fViewer.getTextWidget().setMenu(menu);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1248
		getSite().registerContextMenu(id, menuMgr, fViewer);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1249
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1250
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1251
	private void hookRulerContextMenu() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1252
		String id = "#DisassemblyPartRulerContext"; //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1253
		MenuManager menuMgr = new MenuManager(id, id);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1254
		menuMgr.setRemoveAllWhenShown(true);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1255
		menuMgr.addMenuListener(new IMenuListener() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1256
			public void menuAboutToShow(IMenuManager manager) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1257
				DisassemblyPart.this.fillRulerContextMenu(manager);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1258
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1259
		});
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1260
		Menu menu = menuMgr.createContextMenu(fVerticalRuler.getControl());
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1261
		fVerticalRuler.getControl().setMenu(menu);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1262
		getSite().registerContextMenu(id, menuMgr, fViewer);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1263
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1264
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1265
	private void contributeToActionBars() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1266
		IWorkbenchPartSite site = getSite();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1267
		site.setSelectionProvider(fViewer);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1268
		IContextService ctxService = (IContextService)site.getService(IContextService.class);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1269
		fContextActivation = ctxService.activateContext(KEY_BINDING_CONTEXT_DISASSEMBLY);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1270
		contributeToActionBars(getActionBars());
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1271
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1272
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1273
	protected abstract IActionBars getActionBars();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1274
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1275
	protected void contributeToActionBars(IActionBars bars) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1276
		for (Iterator<String> iter = fGlobalActions.keySet().iterator(); iter.hasNext();) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1277
			String key = iter.next();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1278
			IAction action = fGlobalActions.get(key);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1279
			bars.setGlobalActionHandler(key, action);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1280
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1281
		IMenuManager menu = bars.getMenuManager();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1282
		IMenuManager navigateMenu= menu.findMenuUsingPath(IWorkbenchActionConstants.M_NAVIGATE);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1283
		if (navigateMenu != null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1284
			navigateMenu.appendToGroup(IWorkbenchActionConstants.MB_ADDITIONS, fActionGotoPC);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1285
			navigateMenu.appendToGroup(IWorkbenchActionConstants.MB_ADDITIONS, fActionGotoAddress);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1286
			navigateMenu.appendToGroup(IWorkbenchActionConstants.MB_ADDITIONS, fActionGotoSymbol);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1287
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1288
		bars.updateActionBars();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1289
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1290
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1291
	protected void fillContextMenu(IMenuManager manager) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1292
		Point cursorLoc = getSite().getShell().getDisplay().getCursorLocation();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1293
		fViewer.getTextWidget().toControl(cursorLoc);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1294
		fActionToggleSource.update();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1295
		fActionToggleSymbols.update();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1296
		manager.add(new GroupMarker("group.top")); // ICommonMenuConstants.GROUP_TOP //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1297
		manager.add(new Separator("group.breakpoints")); //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1298
		manager.add(new Separator(IWorkbenchActionConstants.GO_TO));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1299
		manager.add(fActionGotoPC);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1300
		manager.add(fActionGotoAddress);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1301
		manager.add(fActionGotoSymbol);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1302
		manager.add(new Separator("group.debug")); //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1303
		manager.add(new Separator(ITextEditorActionConstants.GROUP_EDIT));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1304
		manager.appendToGroup(ITextEditorActionConstants.GROUP_EDIT, fGlobalActions.get(ITextEditorActionConstants.COPY));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1305
		manager.appendToGroup(ITextEditorActionConstants.GROUP_EDIT, fGlobalActions.get(ITextEditorActionConstants.SELECT_ALL));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1306
		manager.add(new Separator(ITextEditorActionConstants.GROUP_SETTINGS));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1307
		manager.add(fActionToggleSource);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1308
		manager.add(fActionToggleSymbols);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1309
		manager.add(fActionOpenPreferences);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1310
		manager.add(new Separator());
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1311
		manager.add(fActionRefreshView);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1312
		// Other plug-ins can contribute their actions here
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1313
		manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1314
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1315
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1316
	protected void fillRulerContextMenu(IMenuManager manager) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1317
		fActionToggleBreakpoint.update();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1318
		fActionToggleBreakpointEnablement.update();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1319
		fActionToggleAddressColumn.update();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1320
		fActionToggleFunctionColumn.update();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1321
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1322
		manager.add(new GroupMarker("group.top")); // ICommonMenuConstants.GROUP_TOP //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1323
		manager.add(new Separator("group.breakpoints")); //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1324
		manager.add(fActionToggleBreakpoint);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1325
		manager.add(fActionToggleBreakpointEnablement);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1326
		manager.add(new GroupMarker("debug")); //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1327
		manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1328
		manager.add(new GroupMarker(ITextEditorActionConstants.GROUP_RESTORE));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1329
		manager.add(new Separator("add")); //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1330
		manager.add(new Separator(ITextEditorActionConstants.GROUP_RULERS));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1331
		manager.add(fActionToggleAddressColumn);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1332
		manager.add(fActionToggleFunctionColumn);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1333
		manager.add(new Separator(ITextEditorActionConstants.GROUP_REST));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1334
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1335
		for (Object listener : fRulerContextMenuListeners.getListeners())
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1336
			((IMenuListener) listener).menuAboutToShow(manager);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1337
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1338
		manager.add(new Separator(ITextEditorActionConstants.GROUP_EDIT));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1339
		manager.appendToGroup(ITextEditorActionConstants.GROUP_EDIT, fGlobalActions.get(ITextEditorActionConstants.COPY));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1340
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1341
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1342
	protected void fillLocalToolBar(IToolBarManager manager) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1343
		manager.add(fActionGotoPC);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1344
		manager.add(fActionGotoAddress);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1345
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1346
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1347
	protected void updateSelectionDependentActions() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1348
		Iterator<Action> iterator= fSelectionActions.iterator();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1349
		while (iterator.hasNext()) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1350
			IUpdate action = (IUpdate)iterator.next();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1351
			action.update();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1352
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1353
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1354
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1355
	protected void updateStateDependentActions() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1356
		Iterator<AbstractDisassemblyAction> iterator= fStateDependentActions.iterator();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1357
		while (iterator.hasNext()) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1358
			IUpdate action = iterator.next();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1359
			action.update();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1360
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1361
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1362
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1363
	protected void createActions() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1364
		Action action;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1365
		action= new TextOperationAction(fViewer, ITextOperationTarget.COPY);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1366
		action.setText(DisassemblyMessages.Disassembly_action_Copy_label);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1367
		action.setImageDescriptor(DisassemblyImageRegistry.getImageDescriptor(DisassemblyImageRegistry.ICON_Copy_enabled));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1368
		action.setDisabledImageDescriptor(DisassemblyImageRegistry.getImageDescriptor(DisassemblyImageRegistry.ICON_Copy_disabled));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1369
		action.setActionDefinitionId(IWorkbenchCommandConstants.EDIT_COPY);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1370
		fGlobalActions.put(ITextEditorActionConstants.COPY, action);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1371
		fSelectionActions.add(action);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1372
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1373
		action= new TextOperationAction(fViewer, ITextOperationTarget.SELECT_ALL);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1374
		action.setText(DisassemblyMessages.Disassembly_action_SelectAll_label);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1375
		action.setActionDefinitionId(IWorkbenchCommandConstants.EDIT_SELECT_ALL);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1376
		fGlobalActions.put(ITextEditorActionConstants.SELECT_ALL, action);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1377
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1378
		action= new TextOperationAction(fViewer, ITextOperationTarget.PRINT);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1379
		action.setActionDefinitionId(IWorkbenchCommandConstants.FILE_PRINT);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1380
		fGlobalActions.put(ITextEditorActionConstants.PRINT, action);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1381
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1382
		fActionGotoPC = new ActionGotoProgramCounter(this);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1383
		fActionGotoPC.setActionDefinitionId(COMMAND_ID_GOTO_PC);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1384
		fStateDependentActions.add(fActionGotoPC);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1385
		registerWithHandlerService(fActionGotoPC);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1386
		
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1387
		fActionGotoAddress = new ActionGotoAddress(this);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1388
		fActionGotoAddress.setActionDefinitionId(COMMAND_ID_GOTO_ADDRESS);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1389
		fStateDependentActions.add(fActionGotoAddress);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1390
		registerWithHandlerService(fActionGotoAddress);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1391
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1392
		fActionGotoSymbol = new ActionGotoSymbol(this);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1393
		fActionGotoSymbol.setActionDefinitionId(COMMAND_ID_GOTO_SYMBOL);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1394
		fStateDependentActions.add(fActionGotoSymbol);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1395
		registerWithHandlerService(fActionGotoSymbol);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1396
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1397
		fActionToggleSource = new ActionToggleSource();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1398
		fStateDependentActions.add(fActionToggleSource);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1399
		fActionToggleBreakpoint = new ActionToggleBreakpoint();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1400
//		fActionToggleBreakpoint.setActionDefinitionId(COMMAND_ID_TOGGLE_BREAKPOINT);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1401
//		registerWithHandlerService(fActionToggleBreakpoint);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1402
		fVerticalRuler.getControl().addMouseListener(new MouseAdapter() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1403
			@Override
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1404
			public void mouseDoubleClick(MouseEvent e) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1405
				fActionToggleBreakpoint.update();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1406
				if (fActionToggleBreakpoint.isEnabled()) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1407
					fActionToggleBreakpoint.run();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1408
				}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1409
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1410
		});
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1411
		fActionToggleBreakpointEnablement = new ActionToggleBreakpointEnablement();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1412
		fActionToggleAddressColumn = new ActionToggleAddressColumn();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1413
		fActionToggleFunctionColumn = new ActionToggleFunctionColumn();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1414
		fActionToggleSymbols = new ActionToggleSymbols();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1415
//		fActionSourceSteppingMode.setActionDefinitionId(COMMAND_ID_TOGGLE_STEPPING_MODE);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1416
//		registerWithHandlerService(fActionSourceSteppingMode);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1417
		fActionRefreshView = new ActionRefreshView();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1418
		fStateDependentActions.add(fActionRefreshView);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1419
		fGlobalActions.put(ActionFactory.REFRESH.getId(), fActionRefreshView);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1420
		fActionOpenPreferences = new ActionOpenPreferences(getSite().getShell());
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1421
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1422
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1423
	/**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1424
	 * Register given action with the handler service for key bindings.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1425
	 * 
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1426
	 * @param action
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1427
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1428
	private void registerWithHandlerService(IAction action) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1429
		if (fHandlerActivations == null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1430
			fHandlerActivations = new ArrayList<IHandlerActivation>(5);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1431
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1432
		IHandlerService handlerService = (IHandlerService)getSite().getService(IHandlerService.class);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1433
		fHandlerActivations.add(handlerService.activateHandler(action.getActionDefinitionId(), new ActionHandler(action)));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1434
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1435
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1436
	private void gotoFrame(IFrameDMContext frame) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1437
		if (fActive) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1438
			gotoFrame(frame.getLevel(), PC_UNKNOWN);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1439
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1440
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1441
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1442
	private void gotoFrame(int frame) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1443
		if (fActive) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1444
			gotoFrame(frame, PC_UNKNOWN);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1445
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1446
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1447
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1448
	/*
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1449
	 * @see org.eclipse.cdt.dsf.debug.internal.ui.disassembly.IDisassemblyPart#gotoProgramCounter()
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1450
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1451
	public final void gotoProgramCounter() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1452
		if (fPCAddress != PC_RUNNING) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1453
			updatePC(fPCAddress);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1454
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1455
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1456
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1457
	/*
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1458
	 * @see org.eclipse.cdt.dsf.debug.internal.ui.disassembly.IDisassemblyPart#gotoAddress(java.math.BigInteger)
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1459
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1460
	public final void gotoAddress(BigInteger address) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1461
		fFocusAddress = address;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1462
		if (fDebugSessionId == null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1463
			return;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1464
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1465
		if (DEBUG) System.out.println("gotoAddress " + getAddressText(address)); //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1466
		if (fGotoAddressPending == PC_UNKNOWN) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1467
			fGotoAddressPending = address;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1468
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1469
		if (fUpdatePending) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1470
			return;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1471
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1472
		AddressRangePosition pos = getPositionOfAddress(address);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1473
		if (pos != null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1474
			if (pos.fValid) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1475
				AddressRangePosition previousPos = /* fUpdateBeforeFocus ? getPositionOfAddress(pos.fAddressOffset-1): */ null;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1476
				if (previousPos == null || previousPos.fValid) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1477
					if (fGotoAddressPending.equals(address)) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1478
						fGotoAddressPending = PC_UNKNOWN;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1479
					}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1480
					gotoPosition(pos, false);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1481
				} else {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1482
					int lines = fBufferZone+3;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1483
					BigInteger endAddress = pos.fAddressOffset;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1484
					BigInteger startAddress = previousPos.fAddressOffset.max(
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1485
							endAddress.subtract(BigInteger.valueOf(lines * fDocument.getMeanSizeOfInstructions())));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1486
					retrieveDisassembly(startAddress, endAddress, lines);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1487
				}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1488
			} else {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1489
				int lines = fBufferZone+3;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1490
				BigInteger endAddress = pos.fAddressOffset.add(pos.fAddressLength).min(
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1491
						address.add(BigInteger.valueOf(lines * fDocument.getMeanSizeOfInstructions())));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1492
				retrieveDisassembly(address, endAddress, lines);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1493
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1494
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1495
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1496
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1497
	/*
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1498
	 * @see org.eclipse.cdt.dsf.debug.internal.ui.disassembly.IDisassemblyPart#gotoSymbol(java.lang.String)
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1499
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1500
	public final void gotoSymbol(final String symbol) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1501
		if (!fActive || fTargetFrameContext == null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1502
			return;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1503
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1504
		final DsfExecutor executor= getSession().getExecutor();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1505
		executor.execute(new DsfRunnable() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1506
			public void run() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1507
				final IExpressions expressions= getService(IExpressions.class);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1508
				if (expressions == null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1509
					return;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1510
				}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1511
				IExpressionDMContext exprDmc= expressions.createExpression(fTargetContext, '&'+symbol);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1512
				final FormattedValueDMContext valueDmc= expressions.getFormattedValueContext(exprDmc, IFormattedValues.HEX_FORMAT);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1513
				expressions.getFormattedExpressionValue(valueDmc, new DataRequestMonitor<FormattedValueDMData>(executor, null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1514
					@Override
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1515
					protected void handleSuccess() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1516
						FormattedValueDMData data= getData();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1517
						final String value= data.getFormattedValue();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1518
						final BigInteger address= decodeAddress(value);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1519
						if (address != null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1520
							asyncExec(new Runnable() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1521
								public void run() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1522
									gotoAddress(address);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1523
								}});
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1524
						}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1525
					}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1526
					@Override
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1527
					protected void handleError() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1528
						asyncExec(new Runnable() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1529
							public void run() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1530
				                ErrorDialog.openError(getSite().getShell(), "Error", null, getStatus()); //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1531
							}});
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1532
					}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1533
				});
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1534
			}});
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1535
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1536
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1537
	private void gotoPosition(Position pos, boolean select) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1538
		if (fViewer == null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1539
			return;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1540
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1541
		setFocusPosition(pos);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1542
		fViewer.setSelectedRange(pos.offset, select ? Math.max(pos.length-1, 0) : 0);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1543
		int revealOffset = pos.offset;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1544
		boolean onTop = false;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1545
		if (/* !fUpdateBeforeFocus && */ pos.offset > 0) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1546
			try {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1547
				AddressRangePosition previousPos = fDocument.getModelPosition(pos.offset - 1);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1548
				if (previousPos instanceof LabelPosition) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1549
					revealOffset = previousPos.offset;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1550
					onTop = true;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1551
				} else if (!previousPos.fValid) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1552
					onTop = true;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1553
				}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1554
			} catch (BadLocationException e) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1555
				// cannot happen
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1556
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1557
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1558
		fViewer.revealOffset(revealOffset, onTop);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1559
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1560
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1561
	private void gotoMarker(final IMarker marker) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1562
		if (marker == null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1563
			return;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1564
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1565
		if (fDebugSessionId == null || fUpdatePending) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1566
			fGotoMarkerPending = marker;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1567
			return;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1568
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1569
		fGotoMarkerPending = null;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1570
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1571
		//TLETODO [disassembly] goto (breakpoint) marker
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1572
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1573
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1574
	/*
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1575
	 * @see org.eclipse.jface.text.IViewportListener#viewportChanged(int)
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1576
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1577
	public void viewportChanged(int verticalOffset) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1578
		if (fDebugSessionId != null && fGotoAddressPending == PC_UNKNOWN && fScrollPos == null && !fUpdatePending && !fRefreshViewPending) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1579
			fUpdatePending = true;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1580
			invokeLater(new Runnable() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1581
				public void run() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1582
					assert fUpdatePending;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1583
					if (fUpdatePending) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1584
						fUpdatePending = false;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1585
						updateVisibleArea();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1586
					}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1587
				}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1588
			});
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1589
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1590
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1591
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1592
	/**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1593
	 * Update lines of currently visible area + one page buffer zone below.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1594
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1595
	private void updateVisibleArea() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1596
		if (!fActive || fUpdatePending || fViewer == null || fDebugSessionId == null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1597
			return;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1598
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1599
		if (fTargetContext == null || !isSuspended(fTargetContext) || fFrameAddress == PC_UNKNOWN) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1600
			return;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1601
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1602
		StyledText styledText = fViewer.getTextWidget();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1603
		Rectangle clientArea = styledText.getClientArea();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1604
		fBufferZone = Math.max(8, clientArea.height / styledText.getLineHeight());
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1605
		int topIndex = fViewer.getTopIndex();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1606
		int bottomIndex = fViewer.getBottomIndex();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1607
		int focusIndex = -1;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1608
		boolean focusVisible = false;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1609
		boolean isScrollingUp = fViewer.isUserTriggeredScrolling() && fViewer.getLastTopPixel() >= styledText.getTopPixel();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1610
		if (fFocusPos != null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1611
			try {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1612
				int focusOffset = fFocusPos.offset;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1613
				focusIndex = fDocument.getLineOfOffset(focusOffset);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1614
				focusVisible = focusIndex >= topIndex && focusIndex <= bottomIndex;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1615
				// workaround for: Clicking the IP annotation in the right ruler has no effect.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1616
				// we deselect the IP location if it is scrolled outside the visible area
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1617
				if (!focusVisible) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1618
					Point selection = fViewer.getSelectedRange();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1619
					if (selection.x == focusOffset && selection.y > 0) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1620
						fViewer.setSelectedRange(selection.x, 0);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1621
					}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1622
				}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1623
			} catch (BadLocationException e) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1624
				setFocusPosition(null);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1625
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1626
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1627
		if (!focusVisible) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1628
			focusIndex = topIndex + fScrollLine;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1629
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1630
		BigInteger focusAddress = getAddressOfLine(focusIndex);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1631
		bottomIndex += 2;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1632
		AddressRangePosition bestPosition = null;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1633
		int bestLine = -1;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1634
		BigInteger bestDistance = null;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1635
		Iterator<AddressRangePosition> it = fDocument.getInvalidAddressRanges().iterator();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1636
		while (it.hasNext()) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1637
			AddressRangePosition p = it.next();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1638
			try {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1639
				int line = fDocument.getLineOfOffset(p.offset);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1640
				if (line >= topIndex && line <= bottomIndex) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1641
					if (p instanceof DisassemblyPosition || p.fAddressLength.compareTo(
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1642
							BigInteger.valueOf(fBufferZone * 2)) <= 0) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1643
						// small areas and known areas are OK to update
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1644
					} else if (!isScrollingUp && !fUpdateBeforeFocus
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1645
							&& p.fAddressOffset.compareTo(focusAddress) < 0) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1646
						continue;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1647
					}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1648
					BigInteger distance = p.fAddressOffset.subtract(focusAddress).abs();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1649
					if (bestDistance == null || distance.compareTo(bestDistance) < 0) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1650
						bestPosition = p;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1651
						bestLine = line;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1652
						bestDistance = distance;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1653
						if (bestDistance.compareTo(BigInteger.valueOf(fBufferZone * 2)) <= 0) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1654
							break;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1655
						}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1656
					}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1657
				}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1658
			} catch (BadLocationException e) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1659
				continue;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1660
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1661
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1662
		if (bestPosition != null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1663
			int lines = fBufferZone+3;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1664
			BigInteger startAddress = bestPosition.fAddressOffset;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1665
			BigInteger endAddress = bestPosition.fAddressOffset.add(bestPosition.fAddressLength);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1666
			BigInteger addressRange = BigInteger.valueOf(lines * fDocument.getMeanSizeOfInstructions());
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1667
			if (bestLine > focusIndex || bestLine == focusIndex && startAddress.compareTo(focusAddress) >= 0) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1668
				// insert at start of range
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1669
				if (endAddress.subtract(startAddress).compareTo(addressRange) < 0) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1670
					// try to increase range to reduce number of requests
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1671
					Iterator<?> iter = fDocument.getModelPositionIterator(endAddress);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1672
					while (iter.hasNext()) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1673
						AddressRangePosition p = (AddressRangePosition)iter.next();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1674
						if (p.fValid) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1675
							endAddress = endAddress.add(p.fAddressLength);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1676
							if (endAddress.subtract(startAddress).compareTo(addressRange) >= 0) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1677
								break;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1678
							}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1679
						} else {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1680
							break;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1681
						}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1682
					}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1683
				}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1684
			} else {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1685
				// insert at end of range
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1686
				startAddress = startAddress.max(endAddress.subtract(addressRange));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1687
				// make sure we get all disassembly lines until endAddress
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1688
				lines = endAddress.subtract(startAddress).intValue();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1689
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1690
			retrieveDisassembly(startAddress, endAddress, lines);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1691
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1692
		scheduleDoPending();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1693
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1694
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1695
	private void asyncExec(Runnable runnable) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1696
		if (fViewer != null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1697
			fViewer.getControl().getDisplay().asyncExec(runnable);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1698
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1699
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1700
	private void invokeLater(Runnable runnable) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1701
		invokeLater(10, runnable);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1702
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1703
	private void invokeLater(int delay, Runnable runnable) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1704
		if (fViewer != null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1705
			fViewer.getControl().getDisplay().timerExec(delay, runnable);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1706
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1707
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1708
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1709
	/**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1710
	 * Insert sourcelines if available.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1711
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1712
	/*default*/ void updateInvalidSource() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1713
		if (fViewer == null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1714
			return;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1715
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1716
		boolean unlock = false;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1717
		try {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1718
			if (fScrollPos == null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1719
				if (fUpdatePending) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1720
					fUpdateSourcePending= true;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1721
					return;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1722
				}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1723
				fUpdateSourcePending= false;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1724
				unlock = true;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1725
				fUpdatePending = true;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1726
				lockScroller();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1727
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1728
			ArrayList<SourcePosition> copy = new ArrayList<SourcePosition>(fDocument.getInvalidSource());
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1729
			Iterator<SourcePosition> it = copy.iterator();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1730
			while (it.hasNext()) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1731
				SourcePosition p = it.next();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1732
				if (!p.fValid) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1733
					insertSource(p);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1734
				} else if (DEBUG && fDocument.getInvalidSource().remove(p)) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1735
					System.err.println("!!! valid source position in invalid source list at "+getAddressText(p.fAddressOffset)); //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1736
				}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1737
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1738
		} finally {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1739
			if (unlock) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1740
				fUpdatePending = false;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1741
				unlockScroller();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1742
				doPending();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1743
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1744
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1745
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1746
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1747
	/**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1748
	 * Show disassembly for given (source) file.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1749
	 * 
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1750
	 * @param file
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1751
	 * @param lines
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1752
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1753
	void retrieveDisassembly(final String file, final int lines, final boolean mixed) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1754
		if (fDebugSessionId == null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1755
			return;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1756
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1757
		if (fUpdatePending) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1758
			invokeLater(new Runnable() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1759
				public void run() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1760
					retrieveDisassembly(file, lines, mixed);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1761
				}});
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1762
			return;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1763
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1764
		if (DEBUG) System.out.println("retrieveDisassembly "+file); //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1765
		String debuggerPath= file;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1766
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1767
		// try reverse lookup
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1768
		final ISourceLookup lookup= getService(ISourceLookup.class);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1769
		final ISourceLookupDMContext ctx= DMContexts.getAncestorOfType(fTargetContext, ISourceLookupDMContext.class);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1770
		final DsfExecutor executor= getSession().getExecutor();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1771
		Query<String> query= new Query<String>() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1772
			@Override
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1773
			protected void execute(final DataRequestMonitor<String> rm) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1774
				final DataRequestMonitor<String> request= new DataRequestMonitor<String>(executor, rm) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1775
					@Override
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1776
					protected void handleSuccess() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1777
						rm.setData(getData());
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1778
						rm.done();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1779
					}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1780
				};
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1781
				lookup.getDebuggerPath(ctx, file, request);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1782
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1783
		};
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1784
		try {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1785
			getSession().getExecutor().execute(query);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1786
			debuggerPath= query.get();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1787
		} catch (InterruptedException exc) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1788
			internalError(exc);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1789
		} catch (ExecutionException exc) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1790
			internalError(exc);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1791
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1792
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1793
		final IDisassemblyDMContext context= DMContexts.getAncestorOfType(fTargetContext, IDisassemblyDMContext.class);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1794
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1795
		final String finalFile= debuggerPath;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1796
		final DataRequestMonitor<IMixedInstruction[]> disassemblyRequest= new DataRequestMonitor<IMixedInstruction[]>(executor, null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1797
			@Override
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1798
			public void handleCompleted() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1799
				final IMixedInstruction[] data= getData();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1800
				if (!isCanceled() && data != null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1801
					asyncExec(new Runnable() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1802
						public void run() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1803
							if (!insertDisassembly(null, data)) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1804
								// retry in non-mixed mode
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1805
								retrieveDisassembly(file, lines, false);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1806
							}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1807
						}});
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1808
				} else {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1809
					final IStatus status= getStatus();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1810
					if (status != null && !status.isOK()) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1811
						asyncExec(new Runnable() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1812
							public void run() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1813
				                ErrorDialog.openError(getSite().getShell(), "Error", null, getStatus()); //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1814
							}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1815
						});
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1816
					}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1817
					fUpdatePending= false;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1818
				}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1819
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1820
		};
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1821
		assert !fUpdatePending;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1822
		fUpdatePending = true;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1823
		executor.execute(new Runnable() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1824
			public void run() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1825
				final IDisassembly disassembly= fServicesTracker.getService(IDisassembly.class);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1826
				if (disassembly == null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1827
					disassemblyRequest.cancel();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1828
					disassemblyRequest.done();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1829
					return;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1830
				}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1831
				disassembly.getMixedInstructions(context, finalFile, 1, lines, disassemblyRequest);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1832
			}});
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1833
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1834
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1835
	private void retrieveDisassembly(BigInteger startAddress, BigInteger endAddress, int lines) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1836
		if (fDebugSessionId == null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1837
			return;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1838
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1839
		if (DEBUG) System.out.println("retrieveDisassembly "+getAddressText(startAddress)+" "+lines+" lines"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1840
		retrieveDisassembly(startAddress, endAddress, lines, true, false);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1841
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1842
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1843
	private void retrieveDisassembly(final BigInteger startAddress, BigInteger endAddress, final int linesHint, boolean mixed, boolean ignoreFile) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1844
		assert !fUpdatePending;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1845
		fUpdatePending = true;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1846
		final int lines= linesHint + 2;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1847
		final BigInteger addressLength= BigInteger.valueOf(lines * 4);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1848
		if (endAddress.subtract(startAddress).compareTo(addressLength) > 0) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1849
			endAddress= startAddress.add(addressLength);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1850
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1851
		boolean insideActiveFrame= startAddress.equals(fFrameAddress);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1852
		String file= null;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1853
		int lineNumber= -1;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1854
		if (!ignoreFile && insideActiveFrame && fTargetFrameData != null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1855
			file= fTargetFrameData.getFile();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1856
			if (file != null && file.trim().length() == 0) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1857
				file= null;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1858
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1859
			lineNumber= fTargetFrameData.getLine();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1860
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1861
		final String finalFile= file;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1862
		final int finalLineNumber= lineNumber;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1863
		final BigInteger finalEndAddress= endAddress;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1864
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1865
		final DsfExecutor executor= getSession().getExecutor();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1866
		final IDisassemblyDMContext context= DMContexts.getAncestorOfType(fTargetContext, IDisassemblyDMContext.class);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1867
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1868
		if (mixed) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1869
			final DataRequestMonitor<IMixedInstruction[]> disassemblyRequest= new DataRequestMonitor<IMixedInstruction[]>(executor, null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1870
				@Override
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1871
				public void handleCompleted() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1872
					final IMixedInstruction[] data= getData();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1873
					if (!isCanceled() && data != null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1874
						asyncExec(new Runnable() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1875
							public void run() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1876
								if (!insertDisassembly(startAddress, data)) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1877
									// retry in non-mixed mode
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1878
									retrieveDisassembly(startAddress, finalEndAddress, linesHint, false, false);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1879
								}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1880
							}});
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1881
					} else {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1882
						final IStatus status= getStatus();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1883
						if (status != null && !status.isOK()) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1884
							if( finalFile != null )	{
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1885
								asyncExec(new Runnable() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1886
									public void run() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1887
										retrieveDisassembly(startAddress, finalEndAddress, linesHint, true, true);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1888
									}});
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1889
							}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1890
							else {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1891
								asyncExec(new Runnable() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1892
									public void run() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1893
										doScrollLocked(new Runnable() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1894
											public void run() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1895
												insertError(startAddress, status.getMessage());
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1896
											}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1897
										});
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1898
									}});
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1899
							}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1900
						}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1901
						fUpdatePending= false;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1902
					}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1903
				}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1904
			};
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1905
			if (file != null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1906
				executor.execute(new Runnable() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1907
					public void run() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1908
						final IDisassembly disassembly= fServicesTracker.getService(IDisassembly.class);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1909
						if (disassembly == null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1910
							disassemblyRequest.cancel();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1911
							disassemblyRequest.done();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1912
							return;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1913
						}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1914
						disassembly.getMixedInstructions(context, finalFile, finalLineNumber, lines*2, disassemblyRequest);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1915
					}});
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1916
			} else {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1917
				executor.execute(new Runnable() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1918
					public void run() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1919
						final IDisassembly disassembly= fServicesTracker.getService(IDisassembly.class);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1920
						if (disassembly == null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1921
							disassemblyRequest.cancel();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1922
							disassemblyRequest.done();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1923
							return;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1924
						}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1925
						disassembly.getMixedInstructions(context, startAddress, finalEndAddress, disassemblyRequest);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1926
					}});
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1927
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1928
		} else {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1929
			final DataRequestMonitor<IInstruction[]> disassemblyRequest= new DataRequestMonitor<IInstruction[]>(executor, null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1930
				@Override
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1931
				public void handleCompleted() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1932
					if (!isCanceled() && getData() != null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1933
						asyncExec(new Runnable() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1934
							public void run() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1935
								insertDisassembly(startAddress, getData());
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1936
							}});
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1937
					} else {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1938
						final IStatus status= getStatus();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1939
						if (status != null && !status.isOK()) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1940
							asyncExec(new Runnable() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1941
								public void run() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1942
									doScrollLocked(new Runnable() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1943
										public void run() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1944
											insertError(startAddress, status.getMessage());
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1945
										}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1946
									});
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1947
								}});
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1948
						}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1949
						fUpdatePending= false;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1950
					}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1951
				}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1952
			};
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1953
			if (file != null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1954
				executor.execute(new Runnable() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1955
					public void run() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1956
						final IDisassembly disassembly= fServicesTracker.getService(IDisassembly.class);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1957
						if (disassembly == null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1958
							disassemblyRequest.cancel();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1959
							disassemblyRequest.done();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1960
							return;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1961
						}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1962
						disassembly.getInstructions(context, finalFile, finalLineNumber, lines, disassemblyRequest);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1963
					}});
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1964
			} else {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1965
				executor.execute(new Runnable() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1966
					public void run() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1967
						final IDisassembly disassembly= fServicesTracker.getService(IDisassembly.class);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1968
						if (disassembly == null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1969
							disassemblyRequest.cancel();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1970
							disassemblyRequest.done();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1971
							return;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1972
						}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1973
						disassembly.getInstructions(context, startAddress, finalEndAddress, disassemblyRequest);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1974
					}});
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1975
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1976
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1977
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1978
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1979
	private void insertError(BigInteger address, String message) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1980
		AddressRangePosition p = null;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1981
		p = getPositionOfAddress(address);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1982
		if (p.fValid) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1983
			return;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1984
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1985
		try {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1986
			fDocument.insertErrorLine(p, address, BigInteger.ONE, message);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1987
		} catch (BadLocationException exc) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1988
			internalError(exc);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1989
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1990
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1991
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1992
	private void insertDisassembly(BigInteger startAddress, IInstruction[] instructions) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1993
		if (fViewer == null || fDebugSessionId == null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1994
			return;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1995
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1996
		if (DEBUG) System.out.println("insertDisassembly "+getAddressText(startAddress)); //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1997
		assert fUpdatePending;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1998
		if (!fUpdatePending) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  1999
			// safe-guard in case something weird is going on
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2000
			return;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2001
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2002
		try {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2003
			lockScroller();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2004
			
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2005
			AddressRangePosition p= null;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2006
			for (int j = 0; j < instructions.length; j++) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2007
				IInstruction instruction = instructions[j];
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2008
				BigInteger address= instruction.getAdress();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2009
				if (startAddress == null || startAddress.compareTo(BigInteger.ZERO) < 0) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2010
					fGotoAddressPending = startAddress = address;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2011
				}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2012
				if (p == null || !p.containsAddress(address)) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2013
					p = getPositionOfAddress(address);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2014
				}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2015
				if (p instanceof ErrorPosition && p.fValid) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2016
					p.fValid = false;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2017
					fDocument.getInvalidAddressRanges().add(p);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2018
				} else if (p == null || p.fValid) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2019
					if (DEBUG) System.out.println("Excess disassembly lines at " + getAddressText(address)); //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2020
					return;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2021
				}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2022
				boolean hasSource= false;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2023
				String compilationPath= null;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2024
				// insert symbol label
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2025
				final String functionName= instruction.getFuntionName();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2026
				if (functionName != null && functionName.length() > 0 && instruction.getOffset() == 0) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2027
					p = fDocument.insertLabel(p, address, functionName, fShowSymbols && (!hasSource || fShowDisassembly));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2028
				}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2029
				// determine instruction byte length
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2030
				BigInteger instrLength= null;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2031
				if (j < instructions.length - 1) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2032
					instrLength= instructions[j+1].getAdress().subtract(instruction.getAdress()).abs();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2033
				} else if (instructions.length == 1) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2034
					if (p.fAddressLength.compareTo(BigInteger.valueOf(8)) <= 0) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2035
						instrLength= p.fAddressLength;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2036
					}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2037
				}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2038
				if (instrLength == null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2039
					// cannot determine length of last instruction
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2040
					break;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2041
				}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2042
				final String opCode;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2043
				// insert function name+offset instead of opcode bytes
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2044
				if (functionName != null && functionName.length() > 0) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2045
					opCode= functionName + '+' + instruction.getOffset();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2046
				} else {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2047
					opCode= ""; //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2048
				}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2049
				p = fDocument.insertDisassemblyLine(p, address, instrLength.intValue(), opCode, instruction.getInstruction(), compilationPath, -1);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2050
				if (p == null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2051
					break;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2052
				}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2053
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2054
			
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2055
		} catch (BadLocationException e) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2056
			// should not happen
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2057
			internalError(e);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2058
		} finally {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2059
			fUpdatePending = false;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2060
			updateInvalidSource();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2061
			unlockScroller();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2062
			doPending();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2063
			updateVisibleArea();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2064
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2065
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2066
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2067
	private boolean insertDisassembly(BigInteger startAddress, IMixedInstruction[] mixedInstructions) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2068
		if (fViewer == null || fDebugSessionId == null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2069
			return true;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2070
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2071
		if (DEBUG) System.out.println("insertDisassembly "+getAddressText(startAddress)); //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2072
		assert fUpdatePending;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2073
		if (!fUpdatePending) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2074
			// safe-guard in case something weird is going on
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2075
			return true;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2076
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2077
		// indicates whether disassembly for the start address was inserted
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2078
		boolean success= false;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2079
		try {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2080
			lockScroller();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2081
			
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2082
			AddressRangePosition p= null;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2083
			for (int i = 0; i < mixedInstructions.length; ++i) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2084
				IMixedInstruction mixedInstruction= mixedInstructions[i];
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2085
				final String file= mixedInstruction.getFileName();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2086
				final int lineNumber= mixedInstruction.getLineNumber() - 1;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2087
				IInstruction[] instructions= mixedInstruction.getInstructions();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2088
				for (int j = 0; j < instructions.length; ++j) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2089
					IInstruction instruction = instructions[j];
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2090
					BigInteger address= instruction.getAdress();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2091
					if (startAddress == null || startAddress.compareTo(BigInteger.ZERO) < 0) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2092
						fGotoAddressPending = startAddress = address;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2093
					}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2094
					if (p == null || !p.containsAddress(address)) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2095
						p = getPositionOfAddress(address);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2096
					}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2097
					if (p instanceof ErrorPosition && p.fValid) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2098
						p.fValid = false;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2099
						fDocument.getInvalidAddressRanges().add(p);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2100
					} else if (p == null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2101
						if (DEBUG) System.out.println("Excess disassembly lines at " + getAddressText(address)); //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2102
						return success;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2103
					} else if (p.fValid) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2104
						if (DEBUG) System.out.println("Excess disassembly lines at " + getAddressText(address)); //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2105
						if (file != null && lineNumber >= 0 || p.fAddressLength == BigInteger.ONE) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2106
							// override probably unaligned disassembly
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2107
							p.fValid = false;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2108
							fDocument.getInvalidAddressRanges().add(p);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2109
						} else {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2110
							return success;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2111
						}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2112
					}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2113
					boolean hasSource= false;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2114
					if (file != null && lineNumber >= 0) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2115
						p = insertSource(p, address, file, lineNumber);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2116
						hasSource = fFile2Storage.get(file) != null;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2117
					}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2118
					// insert symbol label
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2119
					final String functionName= instruction.getFuntionName();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2120
					if (functionName != null && functionName.length() > 0 && instruction.getOffset() == 0) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2121
						p = fDocument.insertLabel(p, address, functionName, fShowSymbols && (!hasSource || fShowDisassembly));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2122
					}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2123
					// determine instruction byte length
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2124
					BigInteger instrLength= null;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2125
					if (j < instructions.length - 1) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2126
						instrLength= instructions[j+1].getAdress().subtract(instruction.getAdress()).abs();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2127
					} else if (i < mixedInstructions.length - 1) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2128
						int nextSrcLineIdx= i+1;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2129
						while (nextSrcLineIdx < mixedInstructions.length) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2130
							IInstruction[] nextInstrs= mixedInstructions[nextSrcLineIdx].getInstructions();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2131
							if (nextInstrs.length > 0) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2132
								instrLength= nextInstrs[0].getAdress().subtract(instruction.getAdress()).abs();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2133
								break;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2134
							}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2135
							++nextSrcLineIdx;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2136
						}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2137
						if (nextSrcLineIdx >= mixedInstructions.length) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2138
							break;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2139
						}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2140
					} else if (instructions.length == 1) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2141
						if (p.fAddressLength.compareTo(BigInteger.valueOf(8)) <= 0) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2142
							instrLength= p.fAddressLength;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2143
						}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2144
					}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2145
					if (instrLength == null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2146
						// cannot determine length of last instruction
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2147
						break;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2148
					}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2149
					final String opCode;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2150
					// insert function name+offset instead of opcode bytes
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2151
					if (functionName != null && functionName.length() > 0) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2152
						opCode= functionName + '+' + instruction.getOffset();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2153
					} else {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2154
						opCode= ""; //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2155
					}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2156
					success= success || address.compareTo(startAddress) == 0;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2157
					p = fDocument.insertDisassemblyLine(p, address, instrLength.intValue(), opCode, instruction.getInstruction(), file, lineNumber);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2158
					if (p == null && success) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2159
						break;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2160
					}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2161
				}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2162
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2163
			
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2164
		} catch (BadLocationException e) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2165
			// should not happen
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2166
			internalError(e);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2167
		} finally {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2168
			fUpdatePending = false;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2169
			if (success) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2170
				updateInvalidSource();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2171
				unlockScroller();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2172
				doPending();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2173
				updateVisibleArea();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2174
			} else {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2175
				unlockScroller();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2176
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2177
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2178
		return success;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2179
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2180
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2181
	private void retrieveFrameAddress(final IExecutionDMContext targetContext, final int frame) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2182
		if (targetContext != null && isSuspended(targetContext)) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2183
			if (fUpdatePending) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2184
				gotoFrame(frame);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2185
				return;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2186
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2187
			if (DEBUG) System.out.println("retrieveFrameAddress "+frame); //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2188
			fUpdatePending = true;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2189
			final DsfExecutor executor= getSession().getExecutor();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2190
			executor.execute(new DsfRunnable() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2191
				public void run() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2192
					retrieveFrameAddressInSessionThread(targetContext, frame);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2193
				}});
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2194
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2195
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2196
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2197
	private void retrieveFrameAddressInSessionThread(final IExecutionDMContext targetContext, final int frame) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2198
		final IStack stack= fServicesTracker.getService(IStack.class);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2199
		final DsfExecutor executor= getSession().getExecutor();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2200
		if (fTargetFrameContext == null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2201
			if (frame == 0) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2202
				stack.getTopFrame(targetContext, new DataRequestMonitor<IFrameDMContext>(executor, null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2203
					@Override
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2204
					protected void handleCompleted() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2205
						fUpdatePending= false;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2206
						fTargetFrameContext= getData();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2207
						if (fTargetFrameContext != null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2208
							retrieveFrameAddressInSessionThread(targetContext, frame);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2209
						}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2210
					}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2211
				});
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2212
			} else {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2213
				// TODO retrieve other stack frame
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2214
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2215
			return;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2216
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2217
		stack.getFrameData(fTargetFrameContext, new DataRequestMonitor<IFrameDMData>(executor, null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2218
			@Override
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2219
			protected void handleCompleted() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2220
				if (!isCanceled()) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2221
					fUpdatePending= false;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2222
					final IFrameDMData frameData= getData();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2223
					fTargetFrameData= frameData;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2224
					final IAddress address= frameData.getAddress();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2225
					final BigInteger addressValue= address.getValue();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2226
					if (DEBUG) System.out.println("retrieveFrameAddress done "+getAddressText(addressValue)); //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2227
					asyncExec(new Runnable() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2228
						public void run() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2229
							if (address.getSize() * 4 > fAddressSize) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2230
								addressSizeChanged(address.getSize() * 4);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2231
							}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2232
							if (frame == 0) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2233
								updatePC(addressValue);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2234
							} else {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2235
								gotoFrame(frame, addressValue);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2236
							}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2237
						}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2238
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2239
					});
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2240
				}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2241
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2242
		});
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2243
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2244
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2245
	private void addressSizeChanged(int addressSize) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2246
		BigInteger oldEndAddress= fEndAddress;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2247
		fEndAddress= BigInteger.ONE.shiftLeft(addressSize);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2248
		int oldAddressSize= fAddressSize;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2249
		fAddressSize= addressSize;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2250
		if (addressSize < oldAddressSize) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2251
			fDocument.deleteDisassemblyRange(fEndAddress, oldEndAddress, true, true);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2252
			List<AddressRangePosition> positions= fDocument.getInvalidAddressRanges();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2253
			List<AddressRangePosition> toRemove= new ArrayList<AddressRangePosition>();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2254
			for (AddressRangePosition position : positions) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2255
				if (position.fAddressOffset.compareTo(fEndAddress) >= 0) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2256
					try {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2257
						fDocument.replace(position, position.length, ""); //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2258
						fDocument.removeModelPosition(position);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2259
						toRemove.add(position);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2260
					} catch (BadLocationException exc) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2261
						internalError(exc);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2262
					}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2263
				} else if (position.containsAddress(fEndAddress)){
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2264
					position.fAddressLength= fEndAddress.subtract(position.fAddressOffset);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2265
				}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2266
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2267
			positions.removeAll(toRemove);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2268
		} else if (addressSize > oldAddressSize) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2269
			fDocument.insertInvalidAddressRange(fDocument.getLength(), 0, oldEndAddress, fEndAddress);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2270
		} else {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2271
			return;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2272
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2273
		if (fAddressRulerColumn != null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2274
			fAddressRulerColumn.setAddressSize(addressSize);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2275
			if (fComposite != null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2276
				fComposite.layout(true);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2277
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2278
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2279
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2280
	
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2281
	private AddressRangePosition getPositionOfAddress(BigInteger address) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2282
		if (address == null || address.compareTo(BigInteger.ZERO) < 0) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2283
			return null;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2284
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2285
		AddressRangePosition pos = fDocument.getPositionOfAddress(address);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2286
		assert !(pos instanceof SourcePosition);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2287
		assert pos != null || address.compareTo(fStartAddress) < 0|| address.compareTo(fEndAddress) >= 0;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2288
		return pos;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2289
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2290
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2291
	private BigInteger getAddressOfLine(int line) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2292
		return fDocument.getAddressOfLine(line);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2293
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2294
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2295
	/**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2296
	 * Passing the focus request to the viewer's control.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2297
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2298
	@Override
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2299
	public void setFocus() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2300
		fViewer.getControl().setFocus();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2301
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2302
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2303
	protected void setActive(boolean active) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2304
		if (DEBUG) System.out.println("setActive("+ active +")"); //$NON-NLS-1$ //$NON-NLS-2$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2305
		fActive = active;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2306
		if (fActive) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2307
			if (fRefreshAll) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2308
				fRefreshAll = false;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2309
				refreshView(0);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2310
			} else {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2311
				doPendingPCUpdates();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2312
				if (fTargetContext != null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2313
					int frame = getActiveStackFrame();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2314
					if (frame < 0 && isSuspended(fTargetContext)) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2315
						frame= 0;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2316
					}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2317
					if (frame != fTargetFrame) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2318
						gotoFrame(frame);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2319
					}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2320
				}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2321
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2322
		} else {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2323
			fGotoAddressPending= fFocusAddress= PC_UNKNOWN;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2324
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2325
		firePropertyChange(PROP_ACTIVE);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2326
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2327
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2328
	private int getActiveStackFrame() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2329
		if (fTargetFrameContext != null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2330
			return fTargetFrameContext.getLevel();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2331
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2332
		return -1;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2333
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2334
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2335
	/**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2336
	 * 
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2337
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2338
	protected void updateDebugContext() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2339
		IAdaptable debugContext= DebugUITools.getDebugContext();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2340
		if (debugContext instanceof IDMVMContext) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2341
			setDebugContext((IDMVMContext)debugContext);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2342
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2343
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2344
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2345
	protected void setDebugContext(IDMVMContext vmContext) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2346
		if (vmContext != null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2347
			IDMContext dmContext= vmContext.getDMContext();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2348
			String sessionId= dmContext.getSessionId();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2349
			if (!sessionId.equals(fDebugSessionId)) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2350
				// switch to different session or initiate session
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2351
				if (DEBUG) System.out.println("DisassemblyPart.setDebugContext() " + sessionId); //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2352
				fTargetContext= null;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2353
				if (dmContext instanceof IFrameDMContext) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2354
					IFrameDMContext frame= (IFrameDMContext) dmContext;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2355
					IExecutionDMContext executionContext= DMContexts.getAncestorOfType(frame, IExecutionDMContext.class);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2356
					if (executionContext != null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2357
						fTargetContext= executionContext;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2358
						fTargetFrameContext= frame;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2359
						fTargetFrame= frame.getLevel();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2360
					}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2361
				}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2362
				if (fTargetContext != null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2363
			        if (fDebugSessionId != null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2364
						if (getSession() != null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2365
							getSession().removeServiceEventListener(this);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2366
						}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2367
			        }
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2368
					fDebugSessionId= sessionId;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2369
					if (fServicesTracker != null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2370
						fServicesTracker.dispose();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2371
					}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2372
			        fServicesTracker = new DsfServicesTracker(DsfUIPlugin.getBundleContext(), sessionId);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2373
			        if (fViewer != null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2374
						debugContextChanged();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2375
					}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2376
				}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2377
			} else if (dmContext instanceof IFrameDMContext) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2378
				// switch to different frame
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2379
				IFrameDMContext frame= (IFrameDMContext) dmContext;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2380
				final IDMContext[] parents= frame.getParents();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2381
				for (IDMContext context : parents) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2382
					if (context instanceof IExecutionDMContext) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2383
						fTargetContext= (IExecutionDMContext) context;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2384
						fTargetFrameContext= frame;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2385
						gotoFrame(frame);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2386
						break;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2387
					}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2388
				}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2389
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2390
		} else if (fDebugSessionId != null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2391
			if (getSession() != null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2392
				getSession().removeServiceEventListener(this);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2393
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2394
			fDebugSessionId= null;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2395
			fTargetContext= null;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2396
			if (fServicesTracker != null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2397
				fServicesTracker.dispose();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2398
				fServicesTracker= null;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2399
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2400
			if (fViewer != null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2401
				debugContextChanged();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2402
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2403
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2404
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2405
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2406
	private void debugContextChanged() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2407
		if (DEBUG) System.out.println("DisassemblyPart.debugContextChanged()"); //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2408
		fRunnableQueue.clear();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2409
		fUpdatePending = false;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2410
		resetViewer();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2411
		if (fDebugSessionId != null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2412
			final DsfSession session= getSession();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2413
			session.addServiceEventListener(this, null);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2414
			updatePC(PC_UNKNOWN);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2415
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2416
        	if (fGotoAddressPending != PC_UNKNOWN) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2417
	        	gotoAddress(fGotoAddressPending);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2418
	        }
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2419
	        if (fGotoMarkerPending != null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2420
	        	gotoMarker(fGotoMarkerPending);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2421
	        }
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2422
			fViewer.addViewportListener(this);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2423
        } else {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2424
			fViewer.removeViewportListener(this);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2425
        	fGotoMarkerPending = null;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2426
//        	invokeLater(new Runnable() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2427
//				public void run() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2428
//					closePart();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2429
//				}});
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2430
        }
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2431
		updateTitle();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2432
		updateStateDependentActions();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2433
		firePropertyChange(PROP_CONNECTED);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2434
		firePropertyChange(PROP_SUSPENDED);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2435
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2436
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2437
	/*
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2438
	 * @see org.eclipse.cdt.dsf.service.DsfSession.SessionEndedListener#sessionEnded(org.eclipse.cdt.dsf.service.DsfSession)
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2439
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2440
	public void sessionEnded(DsfSession endedSsession) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2441
		if (endedSsession.getId().equals(fDebugSessionId)) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2442
			asyncExec(new Runnable() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2443
				public void run() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2444
					setDebugContext(null);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2445
				}});
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2446
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2447
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2448
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2449
	@DsfServiceEventHandler
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2450
	public void handleEvent(IExitedDMEvent event) {
131
6cbf17faf712 Fixed a NPE. Note it's already fixed in CDT head.
l12wang
parents: 37
diff changeset
  2451
		// Note we may get more than one ExitedDMEvent for contexts 
6cbf17faf712 Fixed a NPE. Note it's already fixed in CDT head.
l12wang
parents: 37
diff changeset
  2452
		// (threads, processes, etc.) in this debug session. So check
6cbf17faf712 Fixed a NPE. Note it's already fixed in CDT head.
l12wang
parents: 37
diff changeset
  2453
		// for NPE.
6cbf17faf712 Fixed a NPE. Note it's already fixed in CDT head.
l12wang
parents: 37
diff changeset
  2454
		// This is already fixed in CDT head....01/28/10
6cbf17faf712 Fixed a NPE. Note it's already fixed in CDT head.
l12wang
parents: 37
diff changeset
  2455
		if (fTargetContext == null)
6cbf17faf712 Fixed a NPE. Note it's already fixed in CDT head.
l12wang
parents: 37
diff changeset
  2456
			return;
6cbf17faf712 Fixed a NPE. Note it's already fixed in CDT head.
l12wang
parents: 37
diff changeset
  2457
		
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2458
		final IExecutionDMContext context= event.getDMContext();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2459
		if (context.equals(fTargetContext)
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2460
				|| DMContexts.isAncestorOf(fTargetContext, context)) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2461
			asyncExec(new Runnable() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2462
				public void run() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2463
					setDebugContext(null);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2464
				}});
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2465
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2466
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2467
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2468
	@DsfServiceEventHandler
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2469
	public void handleEvent(ISuspendedDMEvent event) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2470
		final IExecutionDMContext context= event.getDMContext();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2471
		if (context.equals(fTargetContext)
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2472
				|| DMContexts.isAncestorOf(fTargetContext, context)) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2473
			asyncExec(new Runnable() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2474
				public void run() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2475
					updatePC(PC_UNKNOWN);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2476
					firePropertyChange(PROP_SUSPENDED);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2477
				}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2478
			});
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2479
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2480
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2481
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2482
	@DsfServiceEventHandler
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2483
	public void handleEvent(IResumedDMEvent event) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2484
		final IExecutionDMContext context= event.getDMContext();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2485
		if (context.equals(fTargetContext)
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2486
				|| DMContexts.isAncestorOf(fTargetContext, context)) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2487
			asyncExec(new Runnable() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2488
				public void run() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2489
					updatePC(PC_RUNNING);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2490
					firePropertyChange(PROP_SUSPENDED);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2491
				}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2492
			});
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2493
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2494
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2495
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2496
	private void attachBreakpointsAnnotationModel() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2497
		IAnnotationModel annotationModel = fViewer.getAnnotationModel();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2498
		if (annotationModel instanceof IAnnotationModelExtension) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2499
			IAnnotationModelExtension ame= (IAnnotationModelExtension) annotationModel;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2500
			ame.addAnnotationModel(BREAKPOINT_ANNOTATIONS, new BreakpointsAnnotationModel());
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2501
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2502
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2503
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2504
	private void refreshView(int delay) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2505
		if (fViewer == null || fRefreshViewPending || fRefreshAll) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2506
			return;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2507
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2508
		fRunnableQueue.clear();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2509
		fRefreshViewPending = true;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2510
		final long refreshViewScheduled = System.currentTimeMillis() + delay;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2511
		final Runnable refresh = new Runnable() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2512
			public void run() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2513
				fRefreshViewPending = false;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2514
				long now = System.currentTimeMillis();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2515
				if (now >= refreshViewScheduled) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2516
					if (DEBUG) System.err.println("*** refreshing view ***"); //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2517
					fFocusAddress = PC_UNKNOWN;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2518
					int targetFrame= fTargetFrame;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2519
					resetViewer();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2520
					if (fScrollPos != null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2521
						fScrollPos.isDeleted = true;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2522
					}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2523
					gotoFrame(targetFrame);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2524
				} else {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2525
					refreshView((int)(refreshViewScheduled - now));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2526
				}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2527
			}};
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2528
		if (delay > 0) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2529
			invokeLater(delay, new Runnable() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2530
				public void run() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2531
					doScrollLocked(refresh);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2532
				}});
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2533
		} else {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2534
			doScrollLocked(refresh);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2535
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2536
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2537
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2538
	private void resetViewer() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2539
		// clear all state and cache
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2540
		fPCAnnotationUpdatePending = false;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2541
		fGotoFramePending = false;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2542
		fPCAddress = fFrameAddress = PC_RUNNING;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2543
		fTargetFrame = -1;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2544
		fGotoAddressPending = fFocusAddress;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2545
		fFocusAddress = PC_UNKNOWN;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2546
		setFocusPosition(null);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2547
		fPCHistory.clear();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2548
		fPendingPCUpdates.clear();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2549
		fFile2Storage.clear();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2550
		DisassemblyDocument doc= fDocument;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2551
		fDocument = createDocument();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2552
		fViewer.setDocument(fDocument, new AnnotationModel());
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2553
		doc.dispose();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2554
        if (fDebugSessionId != null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2555
            attachBreakpointsAnnotationModel();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2556
			fDocument.insertInvalidAddressRange(0, 0, fStartAddress, fEndAddress);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2557
        }
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2558
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2559
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2560
    private AddressRangePosition getPCPosition(BigInteger address) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2561
		if (address.compareTo(BigInteger.ZERO) < 0) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2562
			// invalid address
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2563
			return null;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2564
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2565
		AddressRangePosition pos = getPositionOfAddress(address);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2566
		if (pos == null || !pos.fValid) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2567
			// invalid disassembly line
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2568
			return null;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2569
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2570
		if (pos.length > 0) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2571
			// valid disassembly line
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2572
			return pos;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2573
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2574
		// hidden disassembly
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2575
		if (!(pos instanceof DisassemblyPosition)) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2576
			return pos;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2577
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2578
		String srcFile = ((DisassemblyPosition)pos).getFile();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2579
		if (srcFile == null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2580
			return pos;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2581
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2582
		SourceFileInfo fi = fDocument.getSourceInfo(srcFile);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2583
		if (fi == null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2584
			return pos;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2585
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2586
		if (fi.fSource == null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2587
			if (fi.fError != null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2588
				// could not read source
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2589
				return pos;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2590
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2591
			return null;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2592
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2593
//		if (!fi.fValid) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2594
//			// need line info first
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2595
//			return null;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2596
//		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2597
		// determine stmt line of source range
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2598
		try {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2599
			int stmtLine = ((DisassemblyPosition)pos).getLine();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2600
			if (stmtLine < 0) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2601
				return pos;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2602
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2603
			BigInteger stmtAddress = fi.fLine2Addr[stmtLine];
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2604
			if (stmtAddress.compareTo(BigInteger.ZERO) < 0) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2605
				return pos;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2606
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2607
			SourcePosition srcPos = fDocument.getSourcePosition(stmtAddress);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2608
			if (srcPos == null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2609
				return pos;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2610
			} else if (!srcPos.fValid) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2611
				return null;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2612
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2613
			assert stmtLine >= srcPos.fLine;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2614
			int baseOffset = fi.fSource.getLineOffset(srcPos.fLine);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2615
			IRegion stmtLineRegion = fi.fSource.getLineInformation(stmtLine);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2616
			int lineOffset = stmtLineRegion.getOffset();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2617
			int offset = srcPos.offset + lineOffset - baseOffset;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2618
			int length = stmtLineRegion.getLength() + 1;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2619
			if (offset >= srcPos.offset && offset < srcPos.offset + srcPos.length) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2620
				return new AddressRangePosition(offset, length, address, BigInteger.ZERO);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2621
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2622
		} catch (BadLocationException e) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2623
			internalError(e);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2624
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2625
		return pos;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2626
    }
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2627
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2628
    /**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2629
	 * Update the annotation indicating the given address.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2630
	 * @return a position which denotes the documents position
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2631
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2632
	private AddressRangePosition updateAddressAnnotation(Annotation annotation, BigInteger address) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2633
		IAnnotationModel annotationModel = fViewer.getAnnotationModel();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2634
		annotationModel.removeAnnotation(annotation);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2635
		AddressRangePosition pos = getPCPosition(address);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2636
		if (pos != null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2637
			annotationModel.addAnnotation(annotation, new Position(pos.offset, Math.max(0, pos.length-1)));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2638
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2639
		return pos;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2640
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2641
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2642
	public IBreakpoint[] getBreakpointsAtLine(int line) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2643
		BreakpointsAnnotationModel bpModel= null;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2644
		IAnnotationModel am= fViewer.getAnnotationModel();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2645
		if (am instanceof IAnnotationModelExtension) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2646
			IAnnotationModelExtension ame= (IAnnotationModelExtension) am;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2647
			bpModel= (BreakpointsAnnotationModel) ame.getAnnotationModel(BREAKPOINT_ANNOTATIONS);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2648
			if (bpModel != null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2649
				IRegion lineRegion;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2650
				try {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2651
					lineRegion= fDocument.getLineInformation(line);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2652
				} catch (BadLocationException exc) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2653
					return null;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2654
				}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2655
				int offset= lineRegion.getOffset();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2656
				int length= lineRegion.getLength();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2657
				@SuppressWarnings("unchecked")
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2658
				Iterator<SimpleMarkerAnnotation> it= bpModel.getAnnotationIterator(offset, length, true, true);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2659
				List<IBreakpoint> bpList= new ArrayList<IBreakpoint>(5);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2660
				final IBreakpointManager bpMgr= DebugPlugin.getDefault().getBreakpointManager();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2661
				while (it.hasNext()) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2662
					final SimpleMarkerAnnotation annotation= it.next();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2663
					IBreakpoint bp= bpMgr.getBreakpoint(annotation.getMarker());
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2664
					if (bp != null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2665
						bpList.add(bp);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2666
					}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2667
				}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2668
				if (bpList.size() > 0) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2669
					return bpList.toArray(new IBreakpoint[bpList.size()]);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2670
				}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2671
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2672
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2673
		return null;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2674
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2675
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2676
	private void gotoFrame(int frame, BigInteger address) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2677
		if (DEBUG) System.out.println("gotoFrame " + frame + " " + getAddressText(address)); //$NON-NLS-1$ //$NON-NLS-2$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2678
		fTargetFrame = frame;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2679
		fFrameAddress = address;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2680
		if (fTargetFrame == -1) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2681
			fTargetFrame = getActiveStackFrame();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2682
			if (fTargetFrame < 0 && isSuspended(fTargetContext)) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2683
				fTargetFrame= 0;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2684
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2685
			if (fTargetFrame == -1) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2686
				fGotoFramePending = false;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2687
				return;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2688
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2689
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2690
		fGotoFramePending = true;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2691
		if (frame == 0) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2692
			fPCAddress = fFrameAddress;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2693
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2694
		if (fFrameAddress.compareTo(PC_UNKNOWN) == 0) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2695
			if (!fUpdatePending) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2696
				fGotoFramePending = false;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2697
				retrieveFrameAddress(fTargetContext, fTargetFrame);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2698
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2699
			return;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2700
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2701
		AddressRangePosition pcPos = updatePCAnnotation();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2702
		if (pcPos == null && fFrameAddress.compareTo(BigInteger.ZERO) >= 0) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2703
			pcPos = getPCPosition(fFrameAddress);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2704
			if (pcPos == null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2705
				gotoAddress(fFrameAddress);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2706
				return;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2707
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2708
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2709
		if (pcPos != null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2710
			if (frame == 0) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2711
				addToPCHistory(pcPos);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2712
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2713
			fGotoFramePending = false;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2714
			if (fGotoAddressPending == fFrameAddress) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2715
				fGotoAddressPending = PC_UNKNOWN;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2716
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2717
//			if (DEBUG) System.out.println("pc updated "+getAddressText(address)); //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2718
			gotoPosition(pcPos, false);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2719
			updateVisibleArea();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2720
		} else {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2721
			// give up
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2722
			fGotoFramePending = false;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2723
			fGotoAddressPending = PC_UNKNOWN;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2724
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2725
		doPendingPCUpdates();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2726
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2727
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2728
	/*
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2729
	 * @see org.eclipse.cdt.dsf.debug.internal.ui.disassembly.IDisassemblyPart#isActive()
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2730
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2731
	public final boolean isActive() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2732
		return fActive;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2733
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2734
	
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2735
	/*
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2736
	 * @see org.eclipse.cdt.dsf.debug.internal.ui.disassembly.IDisassemblyPart#isConnected()
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2737
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2738
	public final boolean isConnected() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2739
		return fDebugSessionId != null && fTargetContext != null;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2740
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2741
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2742
	/*
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2743
	 * @see org.eclipse.cdt.dsf.debug.internal.ui.disassembly.IDisassemblyPart#isSuspended()
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2744
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2745
	public final boolean isSuspended() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2746
		return isConnected() && isSuspended(fTargetContext);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2747
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2748
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2749
	/*
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2750
	 * @see org.eclipse.cdt.dsf.debug.internal.ui.disassembly.IDisassemblyPart#getTextViewer()
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2751
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2752
	public final ISourceViewer getTextViewer() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2753
		return fViewer;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2754
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2755
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2756
	/*
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2757
	 * @see org.eclipse.cdt.dsf.debug.internal.ui.disassembly.IDisassemblyPart#addRulerContextMenuListener(org.eclipse.jface.action.IMenuListener)
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2758
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2759
	public final void addRulerContextMenuListener(IMenuListener listener) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2760
		fRulerContextMenuListeners.add(listener);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2761
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2762
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2763
	/*
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2764
	 * @see org.eclipse.cdt.dsf.debug.internal.ui.disassembly.IDisassemblyPart#removeRulerContextMenuListener(org.eclipse.jface.action.IMenuListener)
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2765
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2766
	public final void removeRulerContextMenuListener(IMenuListener listener) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2767
		fRulerContextMenuListeners.remove(listener);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2768
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2769
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2770
	private boolean isSuspended(final IExecutionDMContext targetContext) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2771
		DsfSession session = getSession();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2772
		if (session == null || !session.isActive()) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2773
			return false;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2774
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2775
		if (session.getExecutor().isInExecutorThread()) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2776
			return getRunControl().isSuspended(targetContext);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2777
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2778
		Query<Boolean> query = new Query<Boolean>() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2779
			@Override
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2780
			protected void execute(DataRequestMonitor<Boolean> rm) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2781
				try {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2782
					rm.setData(getRunControl().isSuspended(targetContext));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2783
				} finally {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2784
					rm.done();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2785
				}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2786
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2787
		};
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2788
		session.getExecutor().execute(query);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2789
		try {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2790
			return query.get();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2791
		} catch (InterruptedException exc) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2792
		} catch (ExecutionException exc) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2793
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2794
		return false;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2795
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2796
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2797
	private IRunControl getRunControl() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2798
		return getService(IRunControl.class);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2799
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2800
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2801
	/*default*/ DsfSession getSession() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2802
		return DsfSession.getSession(fDebugSessionId);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2803
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2804
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2805
	/*default*/ <V> V getService(Class<V> serviceClass) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2806
		if (fServicesTracker != null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2807
			return fServicesTracker.getService(serviceClass);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2808
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2809
		return null;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2810
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2811
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2812
	/*default*/ IFrameDMContext getTargetFrameContext() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2813
		return fTargetFrameContext;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2814
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2815
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2816
	/**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2817
	 * Schedule the retrieval of a module time stamp for the given address.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2818
	 * Should return a <code>Long</code> object in case the value was computed,
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2819
	 * another object to be waited on if the retrieval is in progress, <code>null</code>
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2820
	 * if no time stamp could be retrieved.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2821
	 * 
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2822
	 * @param address
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2823
	 * @return Long, Object or <code>null</code>
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2824
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2825
	synchronized Object retrieveModuleTimestamp(BigInteger address) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2826
		// TLETODO [disassembly] retrieve and cache module time stamp
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2827
		return null;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2828
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2829
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2830
	private void setFocusPosition(Position pcPos) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2831
		if (fFocusPos != null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2832
			fDocument.removePosition(fFocusPos);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2833
			fFocusPos = null;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2834
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2835
		if (pcPos != null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2836
			fFocusPos = new Position(pcPos.offset, pcPos.length);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2837
			try {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2838
				fDocument.addPosition(fFocusPos);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2839
			} catch (BadLocationException e) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2840
				internalError(e);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2841
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2842
		} else {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2843
			fFocusAddress = PC_UNKNOWN;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2844
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2845
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2846
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2847
	private void doPendingPCUpdates() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2848
		if (fPendingPCUpdates.isEmpty()) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2849
			return;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2850
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2851
		BigInteger pc;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2852
		do {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2853
			pc = fPendingPCUpdates.remove(0);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2854
			if (pc.compareTo(BigInteger.ZERO) >= 0) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2855
				break;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2856
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2857
		} while (!fPendingPCUpdates.isEmpty());
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2858
		gotoFrame(0, pc);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2859
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2860
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2861
	private void addToPCHistory(AddressRangePosition pcPos) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2862
		if (DEBUG) System.out.println("addToPCHistory "+getAddressText(pcPos.fAddressOffset)); //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2863
		if (fPCHistorySizeMax <= 1) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2864
			return;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2865
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2866
		AddressRangePosition first = null;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2867
		if (fPCHistory.size() > 0) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2868
			first = fPCHistory.getFirst();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2869
			if (first.fAddressOffset == pcPos.fAddressOffset) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2870
				if (first.offset != pcPos.offset || first.length != pcPos.length) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2871
					fPCHistory.removeFirst();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2872
					fViewer.invalidateTextPresentation(first.offset, first.length);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2873
				} else {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2874
					return;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2875
				}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2876
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2877
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2878
		// clone and add
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2879
		pcPos = new AddressRangePosition(pcPos.offset, pcPos.length, pcPos.fAddressOffset, BigInteger.ZERO);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2880
		fPCHistory.addFirst(pcPos);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2881
		try {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2882
			fDocument.addPosition(pcPos);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2883
		} catch (BadLocationException e) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2884
			internalError(e);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2885
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2886
		// limit to max size
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2887
		if (fPCHistory.size() > fPCHistorySizeMax) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2888
			AddressRangePosition last = fPCHistory.removeLast();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2889
			fDocument.removePosition(last);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2890
			fViewer.invalidateTextPresentation(last.offset, last.length);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2891
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2892
		// redraw
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2893
		for (Iterator<AddressRangePosition> it=fPCHistory.iterator(); it.hasNext();) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2894
			AddressRangePosition pos = it.next();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2895
			fViewer.invalidateTextPresentation(pos.offset, pos.length);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2896
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2897
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2898
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2899
	/**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2900
	 * Update current pc. If a pc update is currently under way, adds this
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2901
	 * address to a list of pending pc updates.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2902
	 *
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2903
	 * @param pc  Current pc address. -1 means retrieve pc from top frame, -2
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2904
	 *            means target resumed
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2905
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2906
	private void updatePC(BigInteger pc) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2907
		if (!fPendingPCUpdates.isEmpty()) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2908
			BigInteger last = fPendingPCUpdates.get(fPendingPCUpdates.size()-1);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2909
			if (last.compareTo(BigInteger.ZERO) < 0) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2910
				fPendingPCUpdates.remove(fPendingPCUpdates.size()-1);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2911
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2912
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2913
		fPendingPCUpdates.add(pc);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2914
		if (fPendingPCUpdates.size() > fPCHistorySizeMax) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2915
			if (!fActive) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2916
				// if not active, we can savely remove
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2917
				// the pc updates before the history range
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2918
				fPendingPCUpdates.remove(0);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2919
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2920
			// we ignore the current goto frame request
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2921
			// and continue with the pending updates
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2922
			fGotoFramePending = false;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2923
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2924
		if (fActive) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2925
			if (fGotoFramePending) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2926
				if (!fUpdatePending) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2927
					gotoFrame(0, fFrameAddress);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2928
				}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2929
			} else {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2930
				doPendingPCUpdates();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2931
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2932
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2933
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2934
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2935
	private AddressRangePosition updatePCAnnotation() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2936
		if (fUpdatePending) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2937
			fPCAnnotationUpdatePending = true;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2938
			return null;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2939
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2940
		AddressRangePosition pos;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2941
		if (fTargetFrame == 0) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2942
			// clear secondary
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2943
			updateAddressAnnotation(fSecondaryPCAnnotation, PC_UNKNOWN);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2944
			// set primary
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2945
			pos = updateAddressAnnotation(fPCAnnotation, fPCAddress);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2946
		} else {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2947
			// clear primary
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2948
			updateAddressAnnotation(fPCAnnotation, PC_UNKNOWN);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2949
			// set secondary
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2950
			pos = updateAddressAnnotation(fSecondaryPCAnnotation, fFrameAddress);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2951
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2952
		fPCAnnotationUpdatePending = pos == null && fFrameAddress.compareTo(BigInteger.ZERO) >= 0;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2953
		return pos;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2954
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2955
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2956
	private void scheduleDoPending() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2957
		if (!fUpdatePending && !fDoPendingPosted) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2958
			fDoPendingPosted = true;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2959
			invokeLater(new Runnable() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2960
				public void run() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2961
					doPending();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2962
					fDoPendingPosted = false;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2963
				}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2964
			});
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2965
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2966
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2967
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2968
	private void doPending() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2969
		if (fViewer == null || fDocument == null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2970
			return;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2971
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2972
		if (fUpdateSourcePending) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2973
			updateInvalidSource();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2974
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2975
		boolean sourceValid= fDocument.getInvalidSource().isEmpty();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2976
		if (sourceValid || fShowDisassembly) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2977
			if (fGotoFramePending) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2978
				gotoFrame(fTargetFrame, fFrameAddress);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2979
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2980
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2981
		if (sourceValid) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2982
			if (fGotoAddressPending != PC_UNKNOWN) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2983
				gotoAddress(fGotoAddressPending);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2984
			} else if (fGotoMarkerPending != null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2985
				gotoMarker(fGotoMarkerPending);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2986
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2987
			if (fPCAnnotationUpdatePending && !fGotoFramePending) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2988
				updatePCAnnotation();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2989
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2990
			if (fUpdateTitlePending) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2991
				updateTitle();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2992
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2993
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2994
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2995
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2996
	/**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2997
	 * Safely run given runnable in a state when no update is pending.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2998
	 * Delays execution by 10 ms if update is currently pending.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  2999
	 * @param doit
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3000
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3001
	private void doScrollLocked(final Runnable doit) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3002
		if (fViewer == null || fDebugSessionId == null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3003
			// disposed
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3004
			return;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3005
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3006
		if (!fActive) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3007
			// refresh all when becoming active again
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3008
			fRefreshViewPending= false;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3009
			fRefreshAll = true;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3010
			return;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3011
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3012
		if (doit != null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3013
			fRunnableQueue.add(doit);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3014
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3015
		if (fUpdatePending) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3016
			if (fRunnableQueue.size() == 1) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3017
				Runnable doitlater = new Runnable() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3018
					public void run() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3019
						doScrollLocked(null);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3020
					}};
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3021
				invokeLater(doitlater);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3022
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3023
		} else {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3024
			fUpdatePending = true;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3025
			lockScroller();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3026
			try {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3027
				ArrayList<Runnable> copy = new ArrayList<Runnable>(fRunnableQueue);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3028
				fRunnableQueue.clear();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3029
				for (Iterator<Runnable> iter = copy.iterator(); iter.hasNext();) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3030
					Runnable doitnow = iter.next();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3031
					try {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3032
						doitnow.run();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3033
					} catch(Exception e) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3034
						internalError(e);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3035
					}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3036
				}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3037
			} finally {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3038
				fUpdatePending = false;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3039
				unlockScroller();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3040
				doPending();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3041
				updateVisibleArea();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3042
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3043
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3044
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3045
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3046
	private void lockScroller() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3047
		assert fScrollPos == null;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3048
		if (isOpcodeRulerVisible()) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3049
			fRedrawControl = fViewer.getControl();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3050
		} else {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3051
			fRedrawControl = fViewer.getTextWidget();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3052
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3053
		fRedrawControl.setRedraw(false);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3054
		try {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3055
			int topOffset = fViewer.getTopIndexStartOffset();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3056
			int topIndex = fViewer.getTopIndex();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3057
			int bottomIndex = fViewer.getBottomIndex();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3058
			int bottomOffset = fViewer.getBottomIndexEndOffset();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3059
			int focusLine;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3060
			int focusOffset;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3061
			if (fFocusPos != null && fFocusPos.isDeleted) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3062
				fFocusPos = null;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3063
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3064
			if (fFocusPos != null && fFocusPos.offset >= topOffset && fFocusPos.offset <= bottomOffset) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3065
				focusOffset = fFocusPos.offset;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3066
				focusLine = fDocument.getLineOfOffset(focusOffset);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3067
			} else {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3068
				focusLine = Math.max(0, (topIndex + bottomIndex) / 2);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3069
				focusOffset = fDocument.getLineOffset(focusLine);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3070
				AddressRangePosition pos = fDocument.getDisassemblyPosition(focusOffset);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3071
				if (pos != null && !pos.fValid) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3072
					// don't lock position of invalid range
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3073
					focusOffset = pos.offset+pos.length;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3074
					focusLine = fDocument.getLineOfOffset(focusOffset);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3075
				}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3076
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3077
			fScrollPos = new Position(focusOffset);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3078
			fScrollLine = focusLine - topIndex;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3079
			fDocument.addPosition(fScrollPos);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3080
		} catch (BadLocationException e) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3081
			// should not happen
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3082
			internalError(e);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3083
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3084
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3085
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3086
	private void unlockScroller() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3087
		try {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3088
			if (fScrollPos == null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3089
				return;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3090
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3091
			if (fScrollPos.isDeleted) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3092
				fScrollPos.isDeleted = false;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3093
				if (fScrollPos.offset >= fDocument.getLength()) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3094
					fScrollPos.offset = 0;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3095
					fScrollLine = 0;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3096
				}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3097
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3098
			if (fFocusPos != null && (fFocusPos.isDeleted || fFocusPos.length == 0)) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3099
				if (fFocusAddress.compareTo(BigInteger.ZERO) >= 0) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3100
					fGotoAddressPending = fFocusAddress;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3101
					setFocusPosition(getPositionOfAddress(fFocusAddress));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3102
				}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3103
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3104
			int topLine = fDocument.getLineOfOffset(fScrollPos.offset) - fScrollLine;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3105
			// limit text size
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3106
			int lineCount = fDocument.getNumberOfLines();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3107
			if (lineCount > fgHighWaterMark*fBufferZone) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3108
				int startLine = Math.max(0, topLine-fgLowWaterMark/2*fBufferZone);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3109
				int endLine = Math.min(lineCount-1, topLine+fgLowWaterMark/2*fBufferZone);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3110
				fDocument.deleteLineRange(endLine, lineCount-1);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3111
				fDocument.deleteLineRange(0, startLine);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3112
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3113
			int lineHeight = fViewer.getTextWidget().getLineHeight();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3114
			int topPixel = topLine * lineHeight;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3115
			if (Math.abs(fViewer.getTextWidget().getTopPixel() - topPixel) >= lineHeight) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3116
				fViewer.setTopIndex(topLine);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3117
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3118
		} catch (BadLocationException e) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3119
			// should not happen
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3120
			internalError(e);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3121
		} finally {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3122
			if (fScrollPos != null && fDocument != null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3123
				fDocument.removePosition(fScrollPos);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3124
				fScrollPos = null;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3125
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3126
			if (fViewer != null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3127
				fRedrawControl.setRedraw(true);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3128
				getVerticalRuler().update();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3129
				getOverviewRuler().update();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3130
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3131
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3132
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3133
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3134
    private void insertSource(SourcePosition pos) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3135
    	if (!fShowSource) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3136
    		fDocument.insertSource(pos, "", pos.fLine, true); //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3137
    		return;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3138
    	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3139
    	SourceFileInfo fi = pos.fFileInfo;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3140
    	BigInteger address = pos.fAddressOffset;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3141
    	int lineNr = pos.fLine;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3142
		if (fi.fError != null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3143
			// handled below
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3144
		} else if (fi.fValid) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3145
//			assert fi.fLinesNode.isValid();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3146
			Addr2Line a2l = fi.fAddr2Line[Addr2Line.hash(address, fi.fAddr2Line.length)];
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3147
			while (a2l != null && !a2l.addr.equals(address))
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3148
				a2l = a2l.next;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3149
			if (a2l != null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3150
				int first = a2l.first;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3151
				int line;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3152
				for (line = first; line <= a2l.last; ++line) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3153
					if (!fi.fLine2Addr[line].equals(address)) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3154
						if (line > first) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3155
							String source = fi.getLines(first, line-1);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3156
							pos = fDocument.insertSource(pos, source, first, false);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3157
						}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3158
						first = line+1;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3159
					}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3160
				}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3161
				if (line > first) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3162
					String source = fi.getLines(first, line-1);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3163
					fDocument.insertSource(pos, source, first, true);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3164
					if (source.length() == 0) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3165
						fDocument.removeSourcePosition(pos);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3166
					}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3167
				} else if (first > a2l.first) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3168
					fDocument.insertSource(pos, "", first, true); //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3169
					fDocument.removeSourcePosition(pos);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3170
				}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3171
			} else {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3172
				// no source at all
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3173
				fDocument.insertSource(pos, "", lineNr, true); //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3174
				fDocument.removeSourcePosition(pos);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3175
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3176
		} else if (fi.fLinesNode == null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3177
			// TLETODO [disassembly] asynchronous line info
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3178
			if (fi.fSource != null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3179
				fi.fError= new Error();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3180
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3181
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3182
		if (fi.fError != null && !pos.fValid) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3183
			if (fi.fSource != null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3184
				if (fi.fSource != null && lineNr >= 0 && lineNr < fi.fSource.getNumberOfLines()) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3185
					fi.fStartAddress = fi.fStartAddress.min(pos.fAddressOffset);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3186
					fi.fEndAddress = fi.fEndAddress.max(pos.fAddressOffset.add(pos.fAddressLength));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3187
					if (fi.fLine2Addr[lineNr] == null || fi.fLine2Addr[lineNr].compareTo(BigInteger.ZERO) < 0) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3188
						fi.fLine2Addr[lineNr] = pos.fAddressOffset;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3189
						String sourceLine = fi.getLine(lineNr);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3190
						fDocument.insertSource(pos, sourceLine, lineNr, true);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3191
					} else if (fi.fLine2Addr[lineNr].compareTo(pos.fAddressOffset) > 0) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3192
						SourcePosition oldPos = fDocument.getSourcePosition(fi.fLine2Addr[lineNr]);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3193
						if (oldPos != null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3194
							try {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3195
								fDocument.replace(oldPos, oldPos.length, null);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3196
							} catch (BadLocationException e) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3197
								internalError(e);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3198
							}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3199
							fDocument.removeSourcePosition(oldPos);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3200
						}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3201
						fi.fLine2Addr[lineNr] = pos.fAddressOffset;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3202
						String sourceLine = fi.getLine(lineNr);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3203
						fDocument.insertSource(pos, sourceLine, lineNr, true);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3204
					} else if (fi.fLine2Addr[lineNr].equals(pos.fAddressOffset)) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3205
						String sourceLine = fi.getLine(lineNr);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3206
						fDocument.insertSource(pos, sourceLine, lineNr, true);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3207
					} else {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3208
						fDocument.insertSource(pos, "", lineNr, true); //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3209
						fDocument.removeSourcePosition(pos);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3210
					}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3211
				}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3212
			} else {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3213
				// no source at all
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3214
				fDocument.insertSource(pos, "", lineNr, true); //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3215
				fDocument.removeSourcePosition(pos);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3216
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3217
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3218
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3219
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3220
    private void updateTitle() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3221
        if (fDebugSessionId == null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3222
        	String descr = DisassemblyMessages.Disassembly_message_notConnected;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3223
        	String title = getConfigurationElement().getAttribute("name"); //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3224
        	setPartName(title);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3225
        	setContentDescription(descr);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3226
        	setTitleToolTip(title);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3227
        } else {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3228
        	// TLETODO Proper content description
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3229
        	setContentDescription(""); //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3230
        }
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3231
    }
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3232
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3233
    private boolean isDissemblyMixedModeOn() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3234
    	// TLETODO [disassembly] mixed mode on/off
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3235
        return true;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3236
    }
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3237
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3238
	/**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3239
	 * Close this part
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3240
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3241
	protected abstract void closePart();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3242
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3243
	/*
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3244
	 * @see org.eclipse.jface.text.ITextPresentationListener#applyTextPresentation(org.eclipse.jface.text.TextPresentation)
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3245
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3246
	@SuppressWarnings("unchecked")
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3247
    public void applyTextPresentation(TextPresentation textPresentation) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3248
		IRegion coverage = textPresentation.getExtent();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3249
		if (coverage == null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3250
			coverage= new Region(0, fDocument.getLength());
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3251
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3252
		int startOffset = coverage.getOffset();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3253
		int length = coverage.getLength();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3254
		int endOffset = startOffset + length;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3255
		Iterator<Position> it;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3256
		try {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3257
			// make sure we start with first overlapping position
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3258
			AddressRangePosition pos = fDocument.getModelPosition(startOffset);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3259
			assert pos != null;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3260
			if (pos == null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3261
				return;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3262
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3263
			it = fDocument.getPositionIterator(DisassemblyDocument.CATEGORY_MODEL, pos.offset);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3264
		} catch (BadPositionCategoryException e) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3265
			return;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3266
		} catch (BadLocationException e) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3267
			return;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3268
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3269
		ArrayList<StyleRange> styleRanges = new ArrayList<StyleRange>();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3270
		while(it.hasNext()) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3271
			AddressRangePosition pos = (AddressRangePosition)it.next();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3272
			if (pos.offset >= endOffset) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3273
				break;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3274
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3275
			if (pos.offset+pos.length <= startOffset) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3276
				continue;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3277
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3278
			if (pos.fValid && pos.length > 0) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3279
				if (pos instanceof DisassemblyPosition) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3280
					DisassemblyPosition disPos = (DisassemblyPosition)pos;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3281
					styleRanges.add(new StyleRange(pos.offset, disPos.length, fInstructionColor, null, SWT.NULL));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3282
				} else if (pos instanceof ErrorPosition) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3283
					styleRanges.add(new StyleRange(pos.offset, pos.length, fErrorColor, null, SWT.NULL));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3284
				} else if (pos instanceof LabelPosition) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3285
					styleRanges.add(new StyleRange(pos.offset, pos.length, fLabelColor, null, SWT.BOLD));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3286
				} else if (pos instanceof SourcePosition) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3287
					SourcePosition srcPos = (SourcePosition)pos;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3288
					TextPresentation presentation = null;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3289
					if (srcPos.fFileInfo.fSource != null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3290
						 presentation = srcPos.fFileInfo.getPresentation(srcPos.fFileInfo.getRegion(srcPos.fLine, pos.length));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3291
					}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3292
					if (presentation != null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3293
						// clip result window to coverage
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3294
						int start = Math.max(startOffset, srcPos.offset);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3295
						int end = Math.min(endOffset, srcPos.offset + srcPos.length);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3296
						int srcOffset = srcPos.fFileInfo.getLineOffset(srcPos.fLine);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3297
						int clipOffset = start - srcPos.offset;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3298
						presentation.setResultWindow(new Region(srcOffset + clipOffset, end-start));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3299
						for (Iterator<StyleRange> iter = presentation.getNonDefaultStyleRangeIterator(); iter.hasNext();) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3300
							StyleRange styleRange = iter.next();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3301
							styleRange.start += srcPos.offset + clipOffset;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3302
							styleRanges.add(styleRange);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3303
						}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3304
					} else {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3305
						styleRanges.add(new StyleRange(pos.offset, pos.length, fSourceColor, null, SWT.NULL));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3306
					}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3307
				}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3308
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3309
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3310
		if (styleRanges.size() > 0) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3311
			for (Iterator<StyleRange> iter = styleRanges.iterator(); iter.hasNext();) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3312
				textPresentation.addStyleRange(iter.next());
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3313
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3314
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3315
		// update pc history trail
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3316
		if (fPCHistory.size() > 1) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3317
			HSL hsv = new HSL(fPCAnnotationRGB);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3318
			double luminanceStep = (1-hsv.luminance)/(fPCHistorySizeMax+1);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3319
			hsv.luminance = 1 - luminanceStep * (fPCHistorySizeMax - fPCHistory.size());
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3320
			for (ListIterator<AddressRangePosition> listIt = fPCHistory.listIterator(fPCHistory.size()); listIt.hasPrevious();) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3321
				AddressRangePosition pcPos = listIt.previous();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3322
				hsv.luminance -= luminanceStep;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3323
				if (pcPos.isDeleted) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3324
					listIt.remove();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3325
					continue;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3326
				}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3327
				if (!pcPos.fValid) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3328
					continue;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3329
				}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3330
				if (pcPos.overlapsWith(startOffset, length)) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3331
					RGB rgb = hsv.toRGB();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3332
					Color pcColor = getSharedColors().getColor(rgb);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3333
					Color textColor = null;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3334
					// experimental: if color is dark, use white (background) as text color
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3335
//					Color textColor = hsv.luminance < 0.7 ? fViewer.getTextWidget().getBackground() : null;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3336
					textPresentation.mergeStyleRange(new StyleRange(pcPos.offset, pcPos.length, textColor, pcColor));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3337
				}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3338
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3339
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3340
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3341
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3342
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3343
    private IBreakpoint insertBreakpoint(int line, boolean edit) throws CoreException {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3344
    	SourcePosition srcPos = null;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3345
		try {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3346
			int lineOffset = fDocument.getLineOffset(line);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3347
			srcPos = fDocument.getSourcePosition(lineOffset);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3348
		} catch (BadLocationException e) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3349
			// should not happen, but its safe to ignore anyway
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3350
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3351
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3352
    	IResource resource;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3353
    	ICBreakpoint bp;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3354
    	
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3355
		if (srcPos != null && srcPos.length > 0) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3356
            SourceFileInfo srcInfo = srcPos.fFileInfo;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3357
            String filePath = null;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3358
            resource = (IResource)srcInfo.fFile.getAdapter(IResource.class);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3359
            if (resource != null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3360
            	final IPath location= resource.getLocation();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3361
            	if (location == null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3362
            		return null;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3363
            	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3364
				filePath = location.toOSString();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3365
            } else {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3366
    		    resource = ResourcesPlugin.getWorkspace().getRoot();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3367
            	filePath = srcInfo.fFile.getFullPath().toOSString();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3368
            }
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3369
            BigInteger address = srcPos.fAddressOffset;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3370
            AddressRangePosition pos = fDocument.getDisassemblyPosition(address);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3371
            int srcLine = -1;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3372
            if (pos instanceof DisassemblyPosition) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3373
            	srcLine = ((DisassemblyPosition)pos).getLine();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3374
            }
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3375
            bp= CDIDebugModel.createLineBreakpoint(filePath, resource, ICBreakpointType.REGULAR, srcLine + 1, true, 0, "", true); //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3376
    	} else {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3377
    		resource = ResourcesPlugin.getWorkspace().getRoot();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3378
    		BigInteger address = getAddressOfLine(line);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3379
    		bp= CDIDebugModel.createAddressBreakpoint(null, null, resource, ICBreakpointType.REGULAR, new Addr64(address), true, 0, "", true); //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3380
    	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3381
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3382
    	return bp;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3383
    }
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3384
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3385
	private AddressRangePosition insertSource(AddressRangePosition pos, BigInteger address, final String file, int lineNr) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3386
		Object sourceElement = null;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3387
		if (fFile2Storage.containsKey(file)) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3388
			sourceElement = fFile2Storage.get(file);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3389
		} else {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3390
			final ISourceLookupDMContext ctx= DMContexts.getAncestorOfType(fTargetContext, ISourceLookupDMContext.class);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3391
			final DsfExecutor executor= getSession().getExecutor();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3392
			Query<Object> query= new Query<Object>() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3393
				@Override
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3394
				protected void execute(final DataRequestMonitor<Object> rm) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3395
					final DataRequestMonitor<Object> request= new DataRequestMonitor<Object>(executor, rm) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3396
						@Override
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3397
						protected void handleSuccess() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3398
							rm.setData(getData());
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3399
							rm.done();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3400
						}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3401
					};
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3402
					final ISourceLookup lookup= getService(ISourceLookup.class);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3403
					lookup.getSource(ctx, file, request);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3404
				}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3405
			};
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3406
			try {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3407
				getSession().getExecutor().execute(query);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3408
				sourceElement= query.get();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3409
			} catch (InterruptedException exc) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3410
				internalError(exc);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3411
			} catch (ExecutionException exc) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3412
				internalError(exc);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3413
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3414
			if (sourceElement instanceof File) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3415
				sourceElement = new LocalFileStorage((File)sourceElement);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3416
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3417
			if (sourceElement instanceof IStorage) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3418
				fFile2Storage.put(file, sourceElement);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3419
			} else {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3420
				fFile2Storage.put(file, null);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3421
				logWarning(DisassemblyMessages.Disassembly_log_error_locateFile+file, null);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3422
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3423
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3424
		if (sourceElement instanceof IStorage) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3425
			SourceFileInfo fi = fDocument.getSourceInfo((IStorage)sourceElement);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3426
			if (fi == null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3427
				IStorage storage = (IStorage)sourceElement;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3428
				Display display = getSite().getShell().getDisplay();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3429
				Runnable done = new SourceColorerJob(display, storage, this);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3430
				fi = fDocument.createSourceInfo(file, storage, done);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3431
				EditionFinderJob editionJob = null;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3432
				if (storage instanceof IFile) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3433
					editionJob = new EditionFinderJob(fi, address, this);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3434
					editionJob.schedule();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3435
				}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3436
				fi.fReadingJob.schedule();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3437
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3438
			pos = fDocument.insertInvalidSource(pos, address, fi, lineNr);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3439
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3440
		return pos;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3441
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3442
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3443
	private void disassemblyModeChanged(boolean isDisassemblyOn) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3444
		if (fShowDisassembly == isDisassemblyOn) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3445
			return;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3446
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3447
		if (fShowDisassembly && !fSourceOnlyMode) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3448
			// if not in source-only mode, do not update if disassembly mode is disabled
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3449
			return;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3450
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3451
		fShowDisassembly = isDisassemblyOn;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3452
		if (!fShowDisassembly) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3453
			sourceModeChanged(true);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3454
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3455
		fActionToggleSource.update();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3456
		Runnable doit = new Runnable() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3457
			public void run() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3458
				fDocument.invalidateDisassemblyWithSource(!fShowDisassembly);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3459
				fGotoFramePending = true;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3460
			}};
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3461
		doScrollLocked(doit);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3462
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3463
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3464
	/**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3465
	 * Turn on/off source mode.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3466
	 * @param isSourceModeOn
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3467
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3468
	private void sourceModeChanged(boolean isSourceModeOn) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3469
		if (fShowSource == isSourceModeOn) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3470
			return;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3471
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3472
		fShowSource = isSourceModeOn;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3473
		fActionToggleSource.update();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3474
		fDocument.invalidateSource();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3475
		if (!fShowSource && !fShowDisassembly) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3476
			disassemblyModeChanged(true);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3477
		} else {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3478
			fPCAnnotationUpdatePending = true;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3479
			updateInvalidSource();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3480
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3481
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3482
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3483
	public static BigInteger decodeAddress(String string) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3484
		if (string.startsWith("0x")) { //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3485
			return new BigInteger(string.substring(2), 16);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3486
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3487
		return new BigInteger(string);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3488
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3489
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3490
	private static String getAddressText(BigInteger address) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3491
		if (address == null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3492
			return "<null>"; //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3493
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3494
		if (address.compareTo(BigInteger.ZERO) < 0) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3495
			return address.toString();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3496
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3497
		String hex = address.toString(16);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3498
		return "0x" + "0000000000000000".substring(hex.length() + (address.bitLength() <= 32 ? 8 : 0)) + hex; //$NON-NLS-1$ //$NON-NLS-2$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3499
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3500
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3501
	static void internalError(Throwable e) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3502
		if (DEBUG) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3503
			System.err.println("Disassembly: Internal error"); //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3504
			e.printStackTrace();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3505
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3506
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3507
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
  3508
}