diff --git a/src/org/ntlab/traceDebugger/BreakPointView.java b/src/org/ntlab/traceDebugger/BreakPointView.java index 7ab2c9c..239bad6 100644 --- a/src/org/ntlab/traceDebugger/BreakPointView.java +++ b/src/org/ntlab/traceDebugger/BreakPointView.java @@ -88,8 +88,6 @@ MethodExecution methodExecution = tbp.getMethodExecutions().iterator().next(); int highlightLineNo = tbp.getLineNo(); JavaEditorOperator.openSrcFileOfMethodExecution(methodExecution, highlightLineNo); -// IMarker marker = DebuggingController.getInstance().createCurrentLineMarker(methodExecution, highlightLineNo); -// JavaEditorOperator.markAndOpenJavaFile(marker); } } }); @@ -149,7 +147,6 @@ @Override public void run() { debuggingController.debugAction(); - updateImages(true); } }; debugAction.setText("Debug"); @@ -161,7 +158,6 @@ @Override public void run() { debuggingController.terminateAction(); - updateImages(false); } }; terminateAction.setText("Terminate"); diff --git a/src/org/ntlab/traceDebugger/DebuggingController.java b/src/org/ntlab/traceDebugger/DebuggingController.java index 5c8dbcc..382972a 100644 --- a/src/org/ntlab/traceDebugger/DebuggingController.java +++ b/src/org/ntlab/traceDebugger/DebuggingController.java @@ -144,10 +144,13 @@ return false; } terminateAction(); - traceBreakPoints.reset(); debuggingTp = traceBreakPoints.getFirstTracePoint(); - if (debuggingTp == null) return false; + if (debuggingTp == null) { + MessageDialog.openInformation(null, "Error", "An available breakpoint was not found"); + return false; + } refresh(null, debuggingTp, false); + ((BreakPointView)TraceDebuggerPlugin.getActiveView(BreakPointView.ID)).updateImages(true); isRunning = true; return true; } @@ -342,9 +345,9 @@ public boolean backResumeAction() { if (!isRunning) return false; - if (debuggingTp == null) return false; - long currentTime = debuggingTp.getStatement().getTimeStamp(); + if (debuggingTp == null) return false; TracePoint previousTp = debuggingTp; + long currentTime = debuggingTp.getStatement().getTimeStamp(); debuggingTp = traceBreakPoints.getPreviousTracePoint(currentTime); if (debuggingTp == null) { terminateAction(); diff --git a/src/org/ntlab/traceDebugger/TraceBreakPoint.java b/src/org/ntlab/traceDebugger/TraceBreakPoint.java index 00b4ddb..3638620 100644 --- a/src/org/ntlab/traceDebugger/TraceBreakPoint.java +++ b/src/org/ntlab/traceDebugger/TraceBreakPoint.java @@ -33,6 +33,7 @@ for (Statement statement : me.getStatements()) { if (statement.getLineNo() == lineNo) { tracePoints.add(me.getTracePoint(order)); + break; } order++; } diff --git a/src/org/ntlab/traceDebugger/TraceBreakPoints.java b/src/org/ntlab/traceDebugger/TraceBreakPoints.java index b85135f..8aac53a 100644 --- a/src/org/ntlab/traceDebugger/TraceBreakPoints.java +++ b/src/org/ntlab/traceDebugger/TraceBreakPoints.java @@ -6,11 +6,10 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; -import java.util.LinkedList; import java.util.List; -import java.util.ListIterator; import java.util.Map; +import org.ntlab.traceAnalysisPlatform.tracer.trace.MethodExecution; import org.ntlab.traceAnalysisPlatform.tracer.trace.MethodInvocation; import org.ntlab.traceAnalysisPlatform.tracer.trace.Statement; import org.ntlab.traceAnalysisPlatform.tracer.trace.Trace; @@ -19,10 +18,8 @@ public class TraceBreakPoints { private Trace trace; private Map> traceBreakPoints = new HashMap<>(); - private List histories = new LinkedList<>(); - private ListIterator historyIt = histories.listIterator(); - private TracePoint curHistPoint; - private int curIdx = -1; + private List histories = new ArrayList<>(); + private TracePoint lastReferencePoint; public TraceBreakPoints(Trace trace) { this.trace = trace; @@ -101,62 +98,34 @@ return null; } - private void addHistories(TraceBreakPoint tbp) { - ListIterator it = histories.listIterator(); - Iterator tbpIt = tbp.getTracePoints().iterator(); - if (!(tbpIt.hasNext())) return; - TracePoint addedTp = tbpIt.next(); - int idx = 0; - while (it.hasNext()) { - TracePoint tp = it.next(); - if (getTime(addedTp) < getTime(tp)) { - it.previous(); - it.add(addedTp); - if (idx <= curIdx) { - curIdx++; + private void addHistories(TraceBreakPoint tbp) { + for (TracePoint tp : tbp.getTracePoints()) { + histories.add(tp); + } + Collections.sort(histories, new Comparator() { + @Override + public int compare(TracePoint o1, TracePoint o2) { + long o1Time = getTime(o1); + long o2Time = getTime(o2); + return (o1Time < o2Time) ? -1 : 1; + } + private long getTime(TracePoint tp) { + Statement statement = tp.getStatement(); + if (statement instanceof MethodInvocation) { + return ((MethodInvocation)statement).getCalledMethodExecution().getEntryTime(); } - addedTp = null; - if (!(tbpIt.hasNext())) break; - addedTp = tbpIt.next(); + return statement.getTimeStamp(); } - idx++; - } - if (addedTp != null) { - it.add(addedTp); - while (tbpIt.hasNext()) { - it.add(tbpIt.next()); - } - } - historyIt = histories.listIterator(curIdx + 1); // ���Ɏ擾����C���f�b�N�X�ɍ��킹���C�e���[�^���Ď擾 + }); confirm(); } private void removeHistories(TraceBreakPoint tbp) { - ListIterator it = histories.listIterator(); - Iterator tbpIt = tbp.getTracePoints().iterator(); - if (!(tbpIt.hasNext())) return; - TracePoint removedTp = tbpIt.next(); - int idx = 0; + List removedPoints = tbp.getTracePoints(); + Iterator it = histories.iterator(); while (it.hasNext()) { TracePoint tp = it.next(); - if (tp.equals(removedTp)) { - it.remove(); - if (tp.equals(curHistPoint)) { - curHistPoint = null; // ���݈ʒu�ɑΉ�����u���[�N�|�C���g���폜���ꂽ�ꍇ�͌��݈ʒu���Ȃ��ɂ��� - curIdx = -1; - } else if (-1 < curIdx && idx <= curIdx) { - curIdx--; - } - if (!(tbpIt.hasNext())) break; - removedTp = tbpIt.next(); - } else { - idx++; - } - } - if (curHistPoint == null) { - historyIt = null; - } else { - historyIt = histories.listIterator(curIdx + 1); // ���Ɏ擾����C���f�b�N�X�ɍ��킹���C�e���[�^���Ď擾 + if (removedPoints.contains(tp)) it.remove(); } confirm(); } @@ -166,87 +135,33 @@ } public TracePoint getNextTracePoint(long time) { - long curHistTime; - if (curHistPoint == null) { - curHistTime = 0L; - curIdx = -1; - historyIt = histories.listIterator(); - } else { - curHistTime = getTime(curHistPoint); - } - if (curHistTime <= time) { - while (historyIt.hasNext()) { - TracePoint tp = historyIt.next(); - if (tp.equals(curHistPoint)) continue; - curHistPoint = tp; - curIdx++; - if (!checkAvailable(curHistPoint)) continue; - curHistTime = getTime(curHistPoint); - if (curHistTime > time) { - confirm(); - return curHistPoint; - } + for (TracePoint tp : histories) { + if (!(checkAvailable(tp))) continue; + if (getTime(tp) > time) { + lastReferencePoint = tp; + confirm(); + return tp.duplicate(); } - } else { - while (historyIt.hasPrevious()) { - TracePoint tp = historyIt.previous(); - if (tp.equals(curHistPoint)) continue; - curIdx--; - if (!checkAvailable(tp)) continue; - curHistTime = getTime(tp); - if (curHistTime <= time) { - confirm(); - return curHistPoint; - } - curHistPoint = tp; - } - confirm(); - return curHistPoint; } + lastReferencePoint = null; confirm(); return null; } public TracePoint getPreviousTracePoint(long time) { - long curHistTime; - if (curHistPoint == null) { - curHistTime = Long.MAX_VALUE; - curIdx = histories.size(); - historyIt = histories.listIterator(histories.size()); - } else { - curHistTime = getTime(curHistPoint); - } - if (curHistTime >= time) { - while (historyIt.hasPrevious()) { - TracePoint tp = historyIt.previous(); - if (tp.equals(curHistPoint)) continue; - curHistPoint = tp; - curIdx--; - if (!checkAvailable(curHistPoint)) continue; - curHistTime = getTime(curHistPoint); - if (curHistTime < time) { - confirm(); - return curHistPoint; - } + TracePoint tmp = null; + for (TracePoint tp : histories) { + if (!(checkAvailable(tp))) continue; + if (getTime(tp) >= time) { + lastReferencePoint = tmp; + confirm(); + return (tmp != null) ? tmp.duplicate() : null; } - } else { - while (historyIt.hasNext()) { - TracePoint tp = historyIt.next(); - if (tp.equals(curHistPoint)) continue; - curIdx++; - if (!checkAvailable(tp)) continue; - curHistTime = getTime(tp); - if (curHistTime >= time) { - confirm(); - return curHistPoint; - } - curHistPoint = tp; - } - confirm(); - return curHistPoint; + tmp = tp; } + lastReferencePoint = tmp; confirm(); - return null; + return (tmp != null) ? tmp.duplicate() : null; } private TraceBreakPoint getTraceBreakPoint(TracePoint tp) { @@ -260,19 +175,9 @@ TraceBreakPoint tbp = getTraceBreakPoint(tp); return (tbp != null) ? tbp.isAvailable() : false; } - - public void reset() { - curIdx = -1; - historyIt = histories.listIterator(); - curHistPoint = null; - } public void clear() { traceBreakPoints.clear(); - histories.clear(); - curIdx = -1; - historyIt = null; - curHistPoint = null; } private long getTime(TracePoint tp) { @@ -282,23 +187,23 @@ } return statement.getTimeStamp(); } - + private void confirm() { System.out.println(); - if (curHistPoint == null) { + if (lastReferencePoint == null) { System.out.println("cur: " + "Not Exist"); } else { - System.out.println("cur: " + getTime(curHistPoint)); + System.out.println("cur: " + getTime(lastReferencePoint)); } - int idx = 0; for (TracePoint tp : histories) { String signature = tp.getMethodExecution().getSignature(); int lineNo = tp.getStatement().getLineNo(); long time = getTime(tp); - String idxStr = (idx == curIdx) ? "����������" : ""; - System.out.println(time + " " + signature + " line: " + lineNo + " " + idxStr); - idx++; + StringBuilder msg = new StringBuilder(); + msg.append(time + " " + signature + " line: " + lineNo); + if (tp.equals(lastReferencePoint)) msg.append(" ����������"); + System.out.println(msg); } System.out.println(); - } + } }