Ejemplo n.º 1
0
 private void updateAnnotations(IWorkbenchWindow window, TCFNode node, Set<TCFAnnotation> set) {
   if (disposed) return;
   assert Thread.currentThread() == display.getThread();
   WorkbenchWindowInfo win_info = windows.get(window);
   if (win_info == null) return;
   Map<IEditorInput, IEditorPart> editors = new HashMap<IEditorInput, IEditorPart>();
   Map<IViewPart, ITCFDisassemblyPart> views = new HashMap<IViewPart, ITCFDisassemblyPart>();
   IWorkbenchPage page = window.getActivePage();
   if (page != null) {
     for (IEditorReference ref : page.getEditorReferences()) {
       IEditorPart editor = ref.getEditor(false);
       if (editor == null) continue;
       editors.put(editor.getEditorInput(), editor);
     }
     for (IViewReference ref : page.getViewReferences()) {
       IViewPart view = ref.getView(false);
       if (view == null) continue;
       ITCFDisassemblyPart disasm =
           (ITCFDisassemblyPart) view.getAdapter(ITCFDisassemblyPart.class);
       if (disasm != null) views.put(view, disasm);
     }
   }
   boolean flush_all =
       node == null
           || !views.keySet().equals(win_info.views.keySet())
           || !editors.equals(win_info.editors)
           || changed_launch_cfgs.contains(node.launch);
   win_info.views.clear();
   win_info.views.putAll(views);
   win_info.editors.clear();
   win_info.editors.putAll(editors);
   Iterator<TCFAnnotation> i = win_info.annotations.iterator();
   while (i.hasNext()) {
     TCFAnnotation a = i.next();
     if (!flush_all && set != null && set.remove(a)) continue;
     a.dispose();
     i.remove();
   }
   if (set != null) win_info.annotations.addAll(set);
   ISourcePresentation presentation = TCFModelPresentation.getDefault();
   // Disassembly views
   for (TCFAnnotation a : win_info.annotations) {
     if (a.addr == null) continue;
     for (ITCFDisassemblyPart disasm : views.values()) {
       IAnnotationModel ann_model = disasm.getAnnotationModel();
       if (ann_model == null) continue;
       if (a.models.contains(ann_model)) {
         ann_model.removeAnnotation(a);
         a.models.remove(ann_model);
       }
       Position p = disasm.getAddressPosition(a.addr);
       if (p == null) continue;
       if (a.breakpoint != null && hidePlantingAnnotation(ann_model, a.breakpoint, p)) continue;
       ann_model.addAnnotation(a, p);
       a.models.add(ann_model);
     }
   }
   // Disassembly editor
   for (TCFAnnotation a : win_info.annotations) {
     if (a.addr == null) continue;
     IEditorPart editor = editors.get(TCFModel.DisassemblyEditorInput.INSTANCE);
     if (editor == null) continue;
     ITCFDisassemblyPart disasm =
         (ITCFDisassemblyPart) editor.getAdapter(ITCFDisassemblyPart.class);
     if (disasm == null) continue;
     IAnnotationModel ann_model = disasm.getAnnotationModel();
     if (ann_model == null) continue;
     if (a.models.contains(ann_model)) {
       ann_model.removeAnnotation(a);
       a.models.remove(ann_model);
     }
     Position p = disasm.getAddressPosition(a.addr);
     if (p == null) continue;
     if (a.breakpoint != null && hidePlantingAnnotation(ann_model, a.breakpoint, p)) continue;
     ann_model.addAnnotation(a, p);
     a.models.add(ann_model);
   }
   // Source editors
   if (set == null) return;
   for (TCFAnnotation a : set) {
     if (a.area == null) continue;
     Object source_element = TCFSourceLookupDirector.lookup(node.launch, a.ctx, a.area);
     if (source_element == null) continue;
     IEditorInput editor_input = presentation.getEditorInput(source_element);
     IEditorPart editor = editors.get(editor_input);
     if (!(editor instanceof ITextEditor)) continue;
     IDocumentProvider doc_provider = ((ITextEditor) editor).getDocumentProvider();
     IAnnotationModel ann_model = doc_provider.getAnnotationModel(editor_input);
     if (ann_model == null) continue;
     IRegion region = null;
     try {
       doc_provider.connect(editor_input);
     } catch (CoreException e) {
     }
     try {
       IDocument document = doc_provider.getDocument(editor_input);
       if (document != null) region = document.getLineInformation(a.area.start_line - 1);
     } catch (BadLocationException e) {
     } finally {
       doc_provider.disconnect(editor_input);
     }
     if (region == null) continue;
     Position p = new Position(region.getOffset(), region.getLength());
     if (a.breakpoint != null && hidePlantingAnnotation(ann_model, a.breakpoint, p)) continue;
     ann_model.addAnnotation(a, p);
     a.models.add(ann_model);
   }
 }
Ejemplo n.º 2
0
  private void updateAnnotations(final IWorkbenchWindow window, final TCFNode node) {
    if (disposed) return;
    assert Thread.currentThread() == display.getThread();
    final WorkbenchWindowInfo win_info = windows.get(window);
    if (win_info == null) return;
    ITCFAnnotationProvider provider = TCFAnnotationProvider.getAnnotationProvider(node);
    if (win_info.provider != provider) {
      if (win_info.provider != null) win_info.provider.updateAnnotations(window, null);
      win_info.provider = provider;
    }
    if (win_info.provider != null) {
      if (win_info.annotations.size() > 0) {
        for (TCFAnnotation a : win_info.annotations) a.dispose();
        win_info.annotations.clear();
      }
      win_info.update_node = node;
      win_info.update_task = null;
      win_info.provider.updateAnnotations(window, node);
      return;
    }
    if (win_info.update_node == node && win_info.update_task != null && !win_info.update_task.done)
      return;
    win_info.update_node = node;
    win_info.update_task =
        new UpdateTask() {
          public void run() {
            if (win_info.update_task != this) {
              /* Selection has changed and another update has started - abort this */
              return;
            }
            if (node == null) {
              /* No selection - no annotations */
              done(null);
              return;
            }
            if (node.isDisposed()) {
              /* Selected node disposed - no annotations */
              done(null);
              return;
            }
            TCFNodeExecContext thread = null;
            TCFNodeExecContext memory = null;
            TCFNodeStackFrame frame = null;
            TCFNodeStackFrame last_top_frame = null;
            String bp_group = null;
            boolean suspended = false;
            if (node instanceof TCFNodeStackFrame) {
              thread = (TCFNodeExecContext) node.parent;
              frame = (TCFNodeStackFrame) node;
              // Make sure frame.getFrameNo() is valid
              TCFChildrenStackTrace trace = thread.getStackTrace();
              if (!trace.validate(this)) return;
            } else if (node instanceof TCFNodeExecContext) {
              thread = (TCFNodeExecContext) node;
              // Make sure frame.getTopFrame() is valid
              TCFChildrenStackTrace trace = thread.getStackTrace();
              if (!trace.validate(this)) return;
              frame = trace.getTopFrame();
            }
            if (thread != null) {
              TCFDataCache<IRunControl.RunControlContext> rc_ctx_cache = thread.getRunContext();
              if (!rc_ctx_cache.validate(this)) return;
              IRunControl.RunControlContext rc_ctx_data = rc_ctx_cache.getData();
              if (rc_ctx_data != null) bp_group = rc_ctx_data.getBPGroup();
              TCFDataCache<TCFNodeExecContext> mem_cache = thread.getMemoryNode();
              if (!mem_cache.validate(this)) return;
              memory = mem_cache.getData();
              if (bp_group == null
                  && memory != null
                  && rc_ctx_data != null
                  && rc_ctx_data.hasState()) bp_group = memory.id;
              last_top_frame = thread.getLastTopFrame();
              TCFDataCache<TCFContextState> state_cache = thread.getState();
              if (!state_cache.validate(this)) return;
              suspended = state_cache.getData() != null && state_cache.getData().is_suspended;
            }
            Set<TCFAnnotation> set = new LinkedHashSet<TCFAnnotation>();
            if (memory != null) {
              TCFLaunch launch = node.launch;
              TCFBreakpointsStatus bs = launch.getBreakpointsStatus();
              if (bs != null) {
                for (String id : bs.getStatusIDs()) {
                  Map<String, Object> map = bs.getStatus(id);
                  if (map == null) continue;
                  String error = (String) map.get(IBreakpoints.STATUS_ERROR);
                  if (error != null)
                    addBreakpointErrorAnnotation(set, launch, memory.id, id, error);
                  Object[] arr = toObjectArray(map.get(IBreakpoints.STATUS_INSTANCES));
                  if (arr == null) continue;
                  for (Object o : arr) {
                    Map<String, Object> m = toObjectMap(o);
                    String ctx_id = (String) m.get(IBreakpoints.INSTANCE_CONTEXT);
                    if (ctx_id == null) continue;
                    if (!ctx_id.equals(node.id) && !ctx_id.equals(bp_group)) continue;
                    error = (String) m.get(IBreakpoints.INSTANCE_ERROR);
                    BigInteger addr =
                        JSON.toBigInteger((Number) m.get(IBreakpoints.INSTANCE_ADDRESS));
                    ILineNumbers.CodeArea area = null;
                    ILineNumbers.CodeArea org_area = getBreakpointCodeArea(launch, id);
                    if (addr != null) {
                      TCFDataCache<TCFSourceRef> line_cache = memory.getLineInfo(addr);
                      if (line_cache != null) {
                        if (!line_cache.validate(this)) return;
                        TCFSourceRef line_data = line_cache.getData();
                        if (line_data != null) area = line_data.area;
                      }
                    }
                    if (area == null) area = org_area;
                    String bp_name = "Breakpoint";
                    IBreakpoint bp = TCFBreakpointsModel.getBreakpointsModel().getBreakpoint(id);
                    if (bp != null)
                      bp_name =
                          bp.getMarker().getAttribute(TCFBreakpointsModel.ATTR_MESSAGE, bp_name);
                    if (error != null) {
                      String location = "";
                      if (addr != null) location = " at 0x" + addr.toString(16);
                      if (org_area == null) org_area = area;
                      TCFAnnotation a =
                          new TCFAnnotation(
                              memory.id,
                              id,
                              addr,
                              org_area,
                              ImageCache.IMG_BREAKPOINT_ERROR,
                              bp_name + " failed to plant" + location + ": " + error,
                              TYPE_BP_INSTANCE);
                      set.add(a);
                    } else if (area != null && addr != null) {
                      String location =
                          " planted at 0x" + addr.toString(16) + ", line " + area.start_line;
                      TCFAnnotation a =
                          new TCFAnnotation(
                              memory.id,
                              id,
                              addr,
                              area,
                              ImageCache.IMG_BREAKPOINT_INSTALLED,
                              bp_name + location,
                              TYPE_BP_INSTANCE);
                      a.breakpoint = bp;
                      set.add(a);
                      if (isLineAdjusted(area, org_area)) {
                        TCFAnnotation b =
                            new TCFAnnotation(
                                memory.id,
                                id,
                                null,
                                org_area,
                                ImageCache.IMG_BREAKPOINT_WARNING,
                                "Breakpoint location is adjusted: " + location,
                                TYPE_BP_INSTANCE);
                        set.add(b);
                      }
                    }
                    error = (String) m.get(IBreakpoints.INSTANCE_CONDITION_ERROR);
                    if (error != null) {
                      TCFAnnotation a =
                          new TCFAnnotation(
                              memory.id,
                              id,
                              addr,
                              org_area,
                              ImageCache.IMG_BREAKPOINT_ERROR,
                              bp_name + " failed to evaluate condition: " + error,
                              TYPE_BP_INSTANCE);
                      set.add(a);
                    }
                  }
                }
              }
            }
            if (suspended && frame != null && frame.getFrameNo() >= 0) {
              TCFDataCache<TCFSourceRef> line_cache = frame.getLineInfo();
              if (!line_cache.validate(this)) return;
              TCFSourceRef line_data = line_cache.getData();
              if (line_data != null && line_data.area != null) {
                TCFAnnotation a = null;
                String addr_str = "";
                TCFDataCache<BigInteger> addr_cache = frame.getAddress();
                if (!addr_cache.validate(this)) return;
                BigInteger addr_data = addr_cache.getData();
                if (addr_data != null) addr_str += ", IP: 0x" + addr_data.toString(16);
                TCFDataCache<IStackTrace.StackTraceContext> frame_cache =
                    frame.getStackTraceContext();
                if (!frame_cache.validate(this)) return;
                IStackTrace.StackTraceContext frame_data = frame_cache.getData();
                if (frame_data != null) {
                  BigInteger i = JSON.toBigInteger(frame_data.getFrameAddress());
                  if (i != null) addr_str += ", FP: 0x" + i.toString(16);
                }
                addr_str += ", line: " + line_data.area.start_line;
                if (frame.getFrameNo() == 0) {
                  a =
                      new TCFAnnotation(
                          line_data.context_id,
                          null,
                          null,
                          line_data.area,
                          ImageCache.IMG_INSTRUCTION_POINTER_TOP,
                          "Current Instruction Pointer" + addr_str,
                          TYPE_TOP_FRAME);
                } else {
                  a =
                      new TCFAnnotation(
                          line_data.context_id,
                          null,
                          null,
                          line_data.area,
                          ImageCache.IMG_INSTRUCTION_POINTER,
                          "Call Stack Frame" + addr_str,
                          TYPE_STACK_FRAME);
                }
                set.add(a);
              }
            }
            if (!suspended && last_top_frame != null) {
              TCFDataCache<TCFSourceRef> line_cache = last_top_frame.getLineInfo();
              if (!line_cache.validate(this)) return;
              TCFSourceRef line_data = line_cache.getData();
              if (line_data != null && line_data.area != null) {
                TCFAnnotation a =
                    new TCFAnnotation(
                        line_data.context_id,
                        null,
                        null,
                        line_data.area,
                        ImageCache.IMG_INSTRUCTION_POINTER,
                        "Last Instruction Pointer position",
                        TYPE_STACK_FRAME);
                set.add(a);
              }
            }
            done(set);
          }

          private void done(final Set<TCFAnnotation> res) {
            done = true;
            final Runnable update_task = this;
            displayExec(
                new Runnable() {
                  public void run() {
                    if (update_task != win_info.update_task) return;
                    assert win_info.update_node == node;
                    win_info.update_task = null;
                    try {
                      ResourcesPlugin.getWorkspace()
                          .run(
                              new IWorkspaceRunnable() {
                                public void run(IProgressMonitor monitor) throws CoreException {
                                  updateAnnotations(window, node, res);
                                }
                              },
                              null);
                    } catch (Exception e) {
                      Activator.log(e);
                    }
                  }
                });
          }
        };
    Protocol.invokeLater(win_info.update_task);
  }
Ejemplo n.º 3
0
 void dispose() {
   for (TCFAnnotation a : annotations) a.dispose();
   annotations.clear();
 }