@Override public Object getSourceElement(IStackFrame stackFrame) { final Object res; if (stackFrame instanceof DSLStackFrameAdapter) { final DSLStackFrameAdapter eStackFrame = (DSLStackFrameAdapter) stackFrame; final EObject instruction = eStackFrame.getCurrentInstruction(); if (instruction instanceof Step) { res = ((Step) instruction).getMseoccurrence().getMse(); } else if (instruction != null) { res = instruction; } else { res = eStackFrame.getContext(); } } else { res = null; } return res; }
/** * {@inheritDoc} * * @see org.eclipse.debug.core.model.ISourceLocator#getSourceElement(org.eclipse.debug.core.model.IStackFrame) */ public Object getSourceElement(IStackFrame stackFrame) { final Object res; if (stackFrame instanceof DSLStackFrameAdapter) { final DSLStackFrameAdapter eStackFrame = (DSLStackFrameAdapter)stackFrame; final EObject instruction = eStackFrame.getCurrentInstruction(); if (instruction != null) { res = instruction; } else { res = eStackFrame.getContext(); } } else { res = null; } return res; }
@Override public String getInstructionPointerText(IEditorPart editorPart, IStackFrame frame) { // AnnotationPreference preference = EditorsUI.getAnnotationPreferenceLookup().getAnnotationPreference(INSTRUCTION_POINTER_ANNOTATION_TYPE); // String text = preference.getPreferenceLabel(); String text = "Instruction Pointer"; if (frame instanceof BfStackFrame) { try { int location = ((BfStackFrame) frame).getCharStart(); text = text + " [" + location + "]"; } catch (DebugException ex) { DbgActivator.getDefault().logError("Instruction Pointer location could not be revealed", ex); } } return text; }
@Override public Object getSourceElement(IStackFrame stackFrame) { final Object res; if (stackFrame instanceof DSLStackFrameAdapter) { final DSLStackFrameAdapter eStackFrame = (DSLStackFrameAdapter) stackFrame; final EObject instruction = eStackFrame.getCurrentInstruction(); if (instruction instanceof Step) { res = getFirstTarget((Step) instruction); } else if (instruction != null) { res = instruction; } else { res = eStackFrame.getContext(); } } else { res = null; } return res; }
@Override public void selectLine(final IJiveDebugTarget target, final IJiveEvent event) { // new line, remove current annotations removeAnnotations((IJavaDebugTarget) target); // situations in which we cannot synchronize if (event == null || event.line() == event.model().valueFactory().createUnavailableLine()) { return; } // set up the mock objects for the lookup final IStackFrame stackFrame = createStackFrame(target, event); final ISourceLookupResult result = DebugUITools.lookupSource(stackFrame, target.getLaunch() .getSourceLocator()); // synchronize the source final IWorkbench workbench = PlatformUI.getWorkbench(); DebugUITools.displaySource(result, workbench.getActiveWorkbenchWindow().getActivePage()); }
public CaughtException(String currentFrameId, String excType, String msg, StoppedStack threadNstack) { this.currentFrameId = currentFrameId; this.excType = StringEscapeUtils.unescapeXml(excType); this.msg = StringEscapeUtils.unescapeXml(msg); this.threadNstack = threadNstack; IStackFrame[] stack = threadNstack.stack; for (IStackFrame iStackFrame : stack) { if (iStackFrame instanceof PyStackFrame) { PyStackFrame f = (PyStackFrame) iStackFrame; if (currentFrameId.equals(f.getId())) { f.setCurrentStackFrame(); break; } } } }
@Override public Object execute(ExecutionEvent event) throws ExecutionException { ISelection selection = HandlerUtil.getCurrentSelection(event); if (selection instanceof StructuredSelection) { StructuredSelection structuredSelection = (StructuredSelection) selection; Object elem = structuredSelection.getFirstElement(); if (elem instanceof IAdaptable) { IAdaptable iAdaptable = (IAdaptable) elem; elem = iAdaptable.getAdapter(IStackFrame.class); } if (elem instanceof PyStackFrame) { try { PyStackFrame pyStackFrame = (PyStackFrame) elem; IPath path = pyStackFrame.getPath(); int lineNumber = pyStackFrame.getLineNumber(); PyExceptionBreakPointManager.getInstance().ignoreCaughtExceptionsWhenThrownFrom .addIgnoreThrownExceptionIn(path.toFile(), lineNumber); } catch (DebugException e) { Log.log(e); } } } return null; }
/** * Returns the current stack frame context, or <code>null</code> if none. * * @return the current stack frame context, or <code>null</code> if none */ public static IJavaStackFrame getStackFrame() { IAdaptable adaptable = DebugUITools.getDebugContext(); if (adaptable != null) { Object x = adaptable.getAdapter(IJavaStackFrame.class); if (x != null) return (IJavaStackFrame)x; } try { for (ILaunch launch: DebugPlugin.getDefault().getLaunchManager().getLaunches()) { for (IThread thread: launch.getDebugTarget().getThreads()) { IStackFrame[] frames = thread.getStackFrames(); if (frames.length > 0) return (IJavaStackFrame)frames[0]; } } } catch (DebugException e) { throw new RuntimeException(e); } return null; }
/** * Initializes {@link DSLEclipseDebugIntegration#SUPPORTED_TYPES}. * * @return the {@link Set} of * {@link org.eclipse.emf.common.notify.AdapterFactory#isFactoryForType(Object) supported * types}. */ private static Set<Object> initSupportedTypes() { final Set<Object> res = new HashSet<Object>(); res.add(IThread.class); res.add(IDebugTarget.class); res.add(IStackFrame.class); res.add(IVariable.class); res.add(IBreakpoint.class); return res; }
/** * Gets an {@link IStackFrame} form a {@link StackFrame}. * * @param frame * the {@link StackFrame} * @return the {@link IStackFrame} */ public DSLStackFrameAdapter getStackFrame(StackFrame frame) { synchronized(frame) { final DSLStackFrameAdapter res = (DSLStackFrameAdapter)adapt(frame, IStackFrame.class); if (res == null) { throw new IllegalStateException("can't addapt StackFrame to IStackFrame."); } return res; } }
/** * {@inheritDoc} * * @see org.eclipse.debug.core.model.IThread#getStackFrames() */ public IStackFrame[] getStackFrames() throws DebugException { List<IStackFrame> res = new ArrayList<IStackFrame>(); if (isSuspended()) { StackFrame currentFrame = getHost().getTopStackFrame(); while (currentFrame != null) { res.add(factory.getStackFrame(currentFrame)); currentFrame = currentFrame.getParentFrame(); } } return res.toArray(new IStackFrame[res.size()]); }
/** * {@inheritDoc} * * @see org.eclipse.debug.core.model.IThread#getTopStackFrame() */ public IStackFrame getTopStackFrame() throws DebugException { final IStackFrame res; if (getHost().getTopStackFrame() != null) { res = factory.getStackFrame(getHost().getTopStackFrame()); } else { res = null; } return res; }
@Override public boolean addAnnotations(IEditorPart editorPart, IStackFrame frame) { if (frame instanceof DSLStackFrameAdapter) { changeCurrentStackFrame(frame); if (editorPart instanceof DialectEditor) { final EObject instruction = ((DSLStackFrameAdapter)frame).getCurrentInstruction(); SiriusEditorUtils.showInstruction((DialectEditor)editorPart, instruction); } else { super.addAnnotations(editorPart, frame); } } return true; }
/** * Changes the current {@link IStackFrame}. * * @param frame * the selected {@link IStackFrame} */ protected void changeCurrentStackFrame(IStackFrame frame) { final IDebugTarget debugTarget = frame.getDebugTarget(); for (IDSLCurrentInstructionListener listener : ((DSLDebugTargetAdapter)debugTarget) .getCurrentInstructionListeners()) { listener.setCurrentFrame(frame.getModelIdentifier(), ((DSLStackFrameAdapter)frame).getHost()); } }
/** * {@inheritDoc} * * @see org.eclipse.debug.ui.IDebugEditorPresentation#addAnnotations(org.eclipse.ui.IEditorPart, * org.eclipse.debug.core.model.IStackFrame) */ public boolean addAnnotations(IEditorPart editorPart, IStackFrame frame) { if (frame instanceof DSLStackFrameAdapter) { final EObject instruction = ((DSLStackFrameAdapter)frame).getCurrentInstruction(); final URI instructionUri = EcoreUtil.getURI(instruction); EMFEditorUtils.selectInstruction(editorPart, instructionUri); } return true; }
@Override public IStackFrame getTopStackFrame() throws DebugException { if (frames == null) { calculateFrames(); } return frames.get(0); }
@Override public IStackFrame[] getStackFrames() throws DebugException { if (frames == null) { calculateFrames(); } return frames.toArray(new IStackFrame[frames.size()]); }
private JDIStackFrame createStackFrame(JDIThread thread, int depth) { try { IStackFrame[] jdiStackFrames = thread.getStackFrames(); return jdiStackFrames.length > depth ? (JDIStackFrame) jdiStackFrames[depth] : null; } catch (DebugException e) { return null; } }
private static String getUnitFromTopStackFrame(IJavaThread thread) throws CoreException { if (!thread.hasStackFrames()) { return null; } IStackFrame top = thread.getTopStackFrame(); if (top.getVariables().length > 0) { for (IVariable var : top.getVariables()) { try { IValue value = var.getValue(); if (value instanceof IJavaValue) { IJavaObject javaValue = (IJavaObject) value; IJavaDebugTarget debugTarget = thread.getDebugTarget().getAdapter(IJavaDebugTarget.class); IJavaValue arg = debugTarget.newValue("Fully Qualified Name"); // the signature (2nd argument) can be retrieved with javap. Unit extends soot.tagkit.Host for the tag support // -> javap -cp soot-trunk.jar -s soot.tagkit.Host // the signature is in the output under "descriptor" IJavaType type = javaValue.getJavaType(); if (isTagHost(type)) { // check, if this is a unit, which contains Tags IJavaValue fqnTag = javaValue.sendMessage("getTag", "(Ljava/lang/String;)Lsoot/tagkit/Tag;", new IJavaValue[] { arg }, thread, false); IJavaValue tagValue = ((IJavaObject) fqnTag).sendMessage("getValue", "()[B", new IJavaValue[0], thread, false); IJavaArray byteArray = (IJavaArray) tagValue; byte[] b = new byte[byteArray.getLength()]; for (int i = 0; i < b.length; i++) { IJavaPrimitiveValue byteValue = (IJavaPrimitiveValue) byteArray.getValue(i); b[i] = byteValue.getByteValue(); } String currentUnitFqn = new String(b); return currentUnitFqn; } } } catch (Exception e) { logger.error("Couldn't retrieve variable " + var.getName() + " from top stack frame", e); } } } return null; }
private boolean isSubStack(IStackFrame[] stackFrames) { if(stackFrames.length > callStack.size()) return false; for(int i = 0; i < stackFrames.length; i++) if(stackFrames[i] != callStack.get(i).getStackFrame()) return false; return true; }
private boolean isStackIncrement(IStackFrame[] stackFrames) { if(stackFrames.length < callStack.size()) return false; for(int i = 0; i < callStack.size(); i++) if(stackFrames[i] != callStack.get(i).getStackFrame()) return false; return true; }
public StackFrameModel getFrame(IStackFrame exceptionFrame) { for(StackFrameModel s : callStack) if(s.getStackFrame() == exceptionFrame) return s; assert false; return null; }
@Override public IStackFrame getTopStackFrame() throws DebugException { if (stackFrames.length > 0) { return stackFrames[0]; } return null; }
@Override public Object getSourceElement(IStackFrame stackFrame) { if (stackFrame instanceof MontoStackFrame) { MontoStackFrame montoStackFrame = (MontoStackFrame) stackFrame; Source source = montoStackFrame.getStackFrame().getSource(); IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(source.getPhysicalName())); return file; } else { System.out.println("Unexpected stackframe class found in MontoSourceLocator: " + stackFrame.getClass().getName()); return null; } }
@Override public boolean addAnnotations(IEditorPart editorPart, IStackFrame frame) { /* * The color of the default annotation can be set with * "Window->Preferences->General->Editors->Text Editors->Annotations" * at Debug Call Stack. */ if (editorPart instanceof BfEditor) { @SuppressWarnings("unused") BfEditor editor = (BfEditor) editorPart; } return false; }
@Override public String getInstructionPointerAnnotationType(IEditorPart editorPart, IStackFrame frame) { // if (editorPart instanceof BfEditor) { // BfEditor editor = (BfEditor) editorPart; // editor.get // } /* * Because of bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=459664 * this annotation MUST define an own IAnnotationImageProvider. */ return INSTRUCTION_POINTER_ANNOTATION_TYPE; }
@Override public IStackFrame[] getStackFrames() throws DebugException { if (this.stackFrame != null) { return new IStackFrame[] {this.stackFrame}; } else { return new IStackFrame[] {}; } }
public IStackFrame getTopStackFrame() throws DebugException { // Do not return frames[0] if it's a fake 'exception throwing' frame. StackFrameBase[] frames = getStackFrames(); if (frames.length == 0) { return null; } if (frames[0].isRegularFrame()) { return frames[0]; } if (frames.length == 1) { return null; } return frames[1]; }
@Override public boolean addAnnotations(IEditorPart editorPart, IStackFrame frame) { if (frame instanceof DSLStackFrameAdapter) { changeCurrentStackFrame(frame); if (editorPart instanceof DialectEditor) { EObject instruction = ((DSLStackFrameAdapter) frame) .getCurrentInstruction(); if (instruction instanceof Step) { final List<MSE> tickedEvents = StepHelper.collectAllMSEs((Step) instruction); showEvents(tickedEvents); final Set<EObject> callers = new LinkedHashSet<EObject>(); for (MSE event : tickedEvents) { if (event.getCaller() != null) { callers.add(event.getCaller()); } } SiriusEditorUtils.showInstructions((DialectEditor) editorPart, new ArrayList<EObject>(callers)); } else { SiriusEditorUtils.showInstruction((DialectEditor) editorPart, instruction); } } else { super.addAnnotations(editorPart, frame); } } return true; }
@Override protected void stepToFrame(final IStackFrame frame) throws DebugException { synchronized (this) { if (!canStepReturn()) { return; } } final JDTStepHandler handler = new StepToFrameHandler(frame); handler.step(); }
private IStackFrame createStackFrame(final IJiveDebugTarget target, final IJiveEvent event) { try { final IThread thread = new MockThread(target, event); return thread.getTopStackFrame(); } catch (final DebugException e) { throw new IllegalStateException("This should never occur since a mock object is returned."); } }