diff --git a/src/org/ntlab/traceDebugger/DebuggingController.java b/src/org/ntlab/traceDebugger/DebuggingController.java index 7b8c78a..f6b696f 100644 --- a/src/org/ntlab/traceDebugger/DebuggingController.java +++ b/src/org/ntlab/traceDebugger/DebuggingController.java @@ -1,6 +1,8 @@ package org.ntlab.traceDebugger; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; import org.eclipse.core.filebuffers.FileBuffers; import org.eclipse.core.filebuffers.ITextFileBuffer; @@ -37,7 +39,7 @@ private static final DebuggingController theInstance = new DebuggingController(); private TracePoint debuggingTp; private TraceBreakPoint selectedTraceBreakPoint; - private IMarker currentLineMarker; + private List currentLineMarkers = new ArrayList<>(); private LoadingTraceFileStatus loadingTraceFileStatus = LoadingTraceFileStatus.NOT_YET; private boolean isRunning = false; public static final String CURRENT_MARKER_ID = "org.ntlab.traceDebugger.currentMarker"; @@ -227,15 +229,32 @@ return true; } +// public void terminateAction() { +// debuggingTp = null; +// if (currentLineMarker != null) { +// try { +// currentLineMarker.delete(); +// } catch (CoreException e) { +// e.printStackTrace(); +// } +// } +// ((CallStackView)TraceDebuggerPlugin.getActiveView(CallStackView.ID)).reset(); +// ((VariableView)TraceDebuggerPlugin.getActiveView(VariableView.ID)).reset(); +// ((BreakPointView)TraceDebuggerPlugin.getActiveView(BreakPointView.ID)).updateImagesForDebug(false); +// isRunning = false; +// } + public void terminateAction() { debuggingTp = null; - if (currentLineMarker != null) { - try { - currentLineMarker.delete(); - } catch (CoreException e) { - e.printStackTrace(); - } - } + if (!(currentLineMarkers.isEmpty())) { + for (IMarker currentLineMarker : currentLineMarkers) { + try { + currentLineMarker.delete(); + } catch (CoreException e) { + e.printStackTrace(); + } + } + } ((CallStackView)TraceDebuggerPlugin.getActiveView(CallStackView.ID)).reset(); ((VariableView)TraceDebuggerPlugin.getActiveView(VariableView.ID)).reset(); ((BreakPointView)TraceDebuggerPlugin.getActiveView(BreakPointView.ID)).updateImagesForDebug(false); @@ -453,10 +472,9 @@ } private void refresh(TracePoint from, TracePoint to, boolean isReturned, boolean canDifferentialUpdateVariables) { - MethodExecution me = to.getMethodExecution(); - int lineNo = to.getStatement().getLineNo(); - IMarker marker = createCurrentLineMarker(me, lineNo); - JavaEditorOperator.markAndOpenJavaFile(marker); + List markers = createCurrentLineMarkers(to); + if (!(markers.isEmpty())) JavaEditorOperator.markAndOpenJavaFile(markers.get(0)); + CallStackView callStackView = ((CallStackView)TraceDebuggerPlugin.getActiveView(CallStackView.ID)); callStackView.updateByTracePoint(to); VariableView variableView = ((VariableView)TraceDebuggerPlugin.getActiveView(VariableView.ID)); @@ -487,32 +505,49 @@ variableView.markAndExpandVariablesByDeltaMarkers(deltaMarkerManager.getMarkers()); } - public IMarker createCurrentLineMarker(MethodExecution methodExecution, int highlightLineNo) { - IFile file = JavaElementFinder.findIFile(methodExecution); - try { - if (currentLineMarker != null) currentLineMarker.delete(); - currentLineMarker = file.createMarker(CURRENT_MARKER_ID); - Map attributes = new HashMap<>(); - attributes.put(IMarker.TRANSIENT, true); - attributes.put(IMarker.LINE_NUMBER, highlightLineNo); - - IPath path = file.getFullPath(); - ITextFileBufferManager manager = FileBuffers.getTextFileBufferManager(); - manager.connect(path, LocationKind.IFILE, null); - ITextFileBuffer buffer = manager.getTextFileBuffer(path, LocationKind.IFILE); - IDocument document = buffer.getDocument(); + public List createCurrentLineMarkers(TracePoint tp) { + deleteCurrentLineMarkers(); + while (tp != null) { try { - IRegion region = document.getLineInformation(highlightLineNo - 1); - attributes.put(IMarker.CHAR_START, region.getOffset()); - attributes.put(IMarker.CHAR_END, region.getOffset() + region.getLength()); - } catch (BadLocationException e) { + MethodExecution methodExecution = tp.getMethodExecution(); + int highlightLineNo = tp.getStatement().getLineNo(); + IFile file = JavaElementFinder.findIFile(methodExecution); + IMarker currentLineMarker = file.createMarker(CURRENT_MARKER_ID); + currentLineMarkers.add(currentLineMarker); + Map attributes = new HashMap<>(); + attributes.put(IMarker.TRANSIENT, true); + attributes.put(IMarker.LINE_NUMBER, highlightLineNo); + + IPath path = file.getFullPath(); + ITextFileBufferManager manager = FileBuffers.getTextFileBufferManager(); + manager.connect(path, LocationKind.IFILE, null); + ITextFileBuffer buffer = manager.getTextFileBuffer(path, LocationKind.IFILE); + IDocument document = buffer.getDocument(); + try { + IRegion region = document.getLineInformation(highlightLineNo - 1); + attributes.put(IMarker.CHAR_START, region.getOffset()); + attributes.put(IMarker.CHAR_END, region.getOffset() + region.getLength()); + } catch (BadLocationException e) { + e.printStackTrace(); + } + currentLineMarker.setAttributes(attributes); + } catch (CoreException e) { e.printStackTrace(); } - currentLineMarker.setAttributes(attributes); - } catch (CoreException e) { - e.printStackTrace(); + tp = tp.getMethodExecution().getCallerTracePoint(); } - return currentLineMarker; + return currentLineMarkers; + } + + private void deleteCurrentLineMarkers() { + for (IMarker currentLineMarker : currentLineMarkers) { + try { + currentLineMarker.delete(); + } catch (CoreException e) { + e.printStackTrace(); + } + } + currentLineMarkers.clear(); } private TracePoint getTracePointSelectedOnCallStack() {