diff --git a/src/org/ntlab/traceDebugger/BreakPointView.java b/src/org/ntlab/traceDebugger/BreakPointView.java index 84e1d25..3be8f6a 100644 --- a/src/org/ntlab/traceDebugger/BreakPointView.java +++ b/src/org/ntlab/traceDebugger/BreakPointView.java @@ -41,10 +41,7 @@ protected IAction stepReturnAction; protected IAction stepNextAction; protected IAction resumeAction; -// private IAction stepBackIntoAction; -// private IAction stepBackOverAction; -// private IAction stepBackReturnAction; -// private IAction backResumeAction; + private IAction importBreakpointAction; protected Shell shell; protected DebuggingController debuggingController = DebuggingController.getInstance(); public static final String ID = "org.ntlab.traceDebugger.breakPointView"; @@ -143,6 +140,15 @@ changeAvailableAction.setText("Change available of selected trace breakpoint"); changeAvailableAction.setToolTipText("Change available of selected trace breakpoint"); + importBreakpointAction = new Action() { + @Override + public void run() { + debuggingController.impoerBreakpointAction(); + } + }; + importBreakpointAction.setText("Import breakpoints"); + importBreakpointAction.setToolTipText("Copy breakpoint from Eclipse"); + debugAction = new Action() { @Override public void run() { @@ -217,47 +223,12 @@ resumeAction.setToolTipText("Resume"); ImageDescriptor image = DebugUITools.getImageDescriptor(IInternalDebugUIConstants.IMG_DLCL_RESUME); resumeAction.setImageDescriptor(image); - -// stepBackIntoAction = new Action() { -// @Override -// public void run() { -// debuggingController.stepBackIntoAction(); -// } -// }; -// stepBackIntoAction.setText("Step Back Into"); -// stepBackIntoAction.setToolTipText("Step Back Into"); -// -// stepBackOverAction = new Action() { -// @Override -// public void run() { -// debuggingController.stepBackOverAction(); -// } -// }; -// stepBackOverAction.setText("Step Back Over"); -// stepBackOverAction.setToolTipText("Step Back Over"); -// -// stepBackReturnAction = new Action() { -// @Override -// public void run() { -// debuggingController.stepBackReturnAction(); -// } -// }; -// stepBackReturnAction.setText("Step Back Return"); -// stepBackReturnAction.setToolTipText("Step Back Return"); -// -// backResumeAction = new Action() { -// @Override -// public void run() { -// debuggingController.backResumeAction(); -// } -// }; -// backResumeAction.setText("Back Resume"); -// backResumeAction.setToolTipText("Back Resume"); } protected void createToolBar() { IToolBarManager mgr = getViewSite().getActionBars().getToolBarManager(); mgr.add(fileOpenAction); + mgr.add(importBreakpointAction); mgr.add(debugAction); mgr.add(terminateAction); mgr.add(resumeAction); @@ -265,15 +236,12 @@ mgr.add(stepOverAction); mgr.add(stepReturnAction); mgr.add(stepNextAction); -// mgr.add(stepBackIntoAction); -// mgr.add(stepBackOverAction); -// mgr.add(stepBackReturnAction); -// mgr.add(backResumeAction); } protected void createMenuBar() { IMenuManager mgr = getViewSite().getActionBars().getMenuManager(); mgr.add(fileOpenAction); + mgr.add(importBreakpointAction); mgr.add(debugAction); mgr.add(terminateAction); mgr.add(resumeAction); @@ -281,10 +249,6 @@ mgr.add(stepOverAction); mgr.add(stepReturnAction); mgr.add(stepNextAction); -// mgr.add(stepBackIntoAction); -// mgr.add(stepBackOverAction); -// mgr.add(stepBackReturnAction); -// mgr.add(backResumeAction); } private void createPopupMenu() { diff --git a/src/org/ntlab/traceDebugger/DebuggingController.java b/src/org/ntlab/traceDebugger/DebuggingController.java index 934a258..ba0e2a8 100644 --- a/src/org/ntlab/traceDebugger/DebuggingController.java +++ b/src/org/ntlab/traceDebugger/DebuggingController.java @@ -89,24 +89,13 @@ MessageDialog.openInformation(null, "Error", "Trace file was not found"); return false; } -// InputDialog inputDialog = new InputDialog(null, "method signature dialog", "Input method signature", "E.setC(C)", null); -// InputDialog inputDialog = new InputDialog(null, "method signature dialog", "Input method signature", "D.setC(_arraySample.C)", null); -// InputDialog inputDialog = new InputDialog(null, "method signature dialog", "Input method signature", "Company.pay(Money,Person)", null); -// InputDialog inputDialog = new InputDialog(null, "method signature dialog", "Input method signature", "P.setM(worstCase.M)", null); -// InputDialog inputDialog = new InputDialog(null, "method signature dialog", "Input method signature", "DefaultDrawingView.addToSelection(Figure)", null); -// InputDialog inputDialog = new InputDialog(null, "method signature dialog", "Input method signature", "SelectionManager.addFig(Fig)", null); -// InputDialog inputDialog = new InputDialog(null, "method signature dialog", "Input method signature", "SelectionManager.makeSelectionFor(Fig)", null); - InputDialog inputDialog = new InputDialog(null, "method signature dialog", "Input method signature", "ActionRemoveFromDiagram.actionPerformed(ActionEvent)", null); + InputDialog inputDialog = new InputDialog(null, "method signature dialog", "Input method signature", "", null); if (inputDialog.open() != InputDialog.OK) return false; String methodSignature = inputDialog.getValue(); inputDialog = new InputDialog(null, "line No dialog", "Input line no", "", null); if (inputDialog.open() != InputDialog.OK) return false; int lineNo = Integer.parseInt(inputDialog.getValue()); - long currentTime = 0L; - if (debuggingTp != null) { - currentTime = debuggingTp.getStatement().getTimeStamp(); - } - boolean isSuccess = traceBreakPoints.addTraceBreakPoint(methodSignature, lineNo, currentTime); + boolean isSuccess = traceBreakPoints.addTraceBreakPoint(methodSignature, lineNo); if (!isSuccess) { MessageDialog.openInformation(null, "Error", "This trace point does not exist in the trace."); return false; @@ -114,6 +103,16 @@ ((BreakPointView)TraceDebuggerPlugin.getActiveView(BreakPointView.ID)).updateTraceBreakPoints(traceBreakPoints); return true; } + + public boolean impoerBreakpointAction() { + if (TraceDebuggerPlugin.getAnalyzer() == null) { + MessageDialog.openInformation(null, "Error", "Trace file was not found"); + return false; + } + traceBreakPoints.importBreakpointFromEclipse(); + ((BreakPointView)TraceDebuggerPlugin.getActiveView(BreakPointView.ID)).updateTraceBreakPoints(traceBreakPoints); + return true; + } public boolean removeTraceBreakPointAction() { if (selectedTraceBreakPoint == null) return false; diff --git a/src/org/ntlab/traceDebugger/TraceBreakPoint.java b/src/org/ntlab/traceDebugger/TraceBreakPoint.java index 3638620..fa46658 100644 --- a/src/org/ntlab/traceDebugger/TraceBreakPoint.java +++ b/src/org/ntlab/traceDebugger/TraceBreakPoint.java @@ -13,14 +13,24 @@ public class TraceBreakPoint { private List tracePoints = new ArrayList<>(); private String methodSignature; + private String readableSignature; private int lineNo; private List methodExecutions = new ArrayList<>(); private boolean isAvailable = false; - - public TraceBreakPoint(String methodSignature, int lineNo, long currentTime) { + + private TraceBreakPoint(String methodSignature, int lineNo, boolean isAvailable, String readableSignature) { this.methodSignature = methodSignature; this.lineNo = lineNo; - isAvailable = initTracePoints(methodSignature, lineNo); + this.isAvailable = isAvailable; + this.readableSignature = readableSignature; + } + + public static TraceBreakPoint createNewTraceBreakPoint(String methodSignature, int lineNo, boolean isAvailable, String readableSignature) + throws IllegalArgumentException { + TraceBreakPoint newTraceBreakPoint = new TraceBreakPoint(methodSignature, lineNo, isAvailable, readableSignature); + boolean isValid = newTraceBreakPoint.initTracePoints(methodSignature, lineNo); + if (!isValid) throw new IllegalArgumentException(); + return newTraceBreakPoint; } private boolean initTracePoints(String methodSignature, int lineNo) { @@ -62,29 +72,30 @@ } public String getReadableSignature() { - MethodExecution methodExecution = methodExecutions.iterator().next(); - String signature = methodExecution.getSignature(); - String objectType = methodExecution.getThisClassName(); - objectType = objectType.substring(objectType.lastIndexOf(".") + 1); - boolean isConstructor = methodExecution.isConstructor(); - String declaringType = Trace.getDeclaringType(signature, isConstructor); - declaringType = declaringType.substring(declaringType.lastIndexOf(".") + 1); - String methodName = Trace.getMethodName(signature); - String args = "("; - String delimiter = ""; - String[] argArray = signature.split("\\(")[1].split(","); - for (String arg : argArray) { - args += (delimiter + arg.substring(arg.lastIndexOf(".") + 1)); - delimiter = ", "; - } - - StringBuilder sb = new StringBuilder(); - sb.append(objectType); - if (!declaringType.equals(objectType)) { - sb.append("(" + declaringType + ")"); - } - sb.append("." + methodName + args); - return sb.toString(); + return readableSignature; +// MethodExecution methodExecution = methodExecutions.iterator().next(); +// String signature = methodExecution.getSignature(); +// String objectType = methodExecution.getThisClassName(); +// objectType = objectType.substring(objectType.lastIndexOf(".") + 1); +// boolean isConstructor = methodExecution.isConstructor(); +// String declaringType = Trace.getDeclaringType(signature, isConstructor); +// declaringType = declaringType.substring(declaringType.lastIndexOf(".") + 1); +// String methodName = Trace.getMethodName(signature); +// String args = "("; +// String delimiter = ""; +// String[] argArray = signature.split("\\(")[1].split(","); +// for (String arg : argArray) { +// args += (delimiter + arg.substring(arg.lastIndexOf(".") + 1)); +// delimiter = ", "; +// } +// +// StringBuilder sb = new StringBuilder(); +// sb.append(objectType); +// if (!declaringType.equals(objectType)) { +// sb.append("(" + declaringType + ")"); +// } +// sb.append("." + methodName + args); +// return sb.toString(); } public int getLineNo() { diff --git a/src/org/ntlab/traceDebugger/TraceBreakPoints.java b/src/org/ntlab/traceDebugger/TraceBreakPoints.java index 8aac53a..a3d2203 100644 --- a/src/org/ntlab/traceDebugger/TraceBreakPoints.java +++ b/src/org/ntlab/traceDebugger/TraceBreakPoints.java @@ -9,6 +9,10 @@ import java.util.List; import java.util.Map; +import org.eclipse.core.resources.IMarker; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.debug.core.DebugPlugin; +import org.eclipse.debug.core.model.IBreakpoint; import org.ntlab.traceAnalysisPlatform.tracer.trace.MethodExecution; import org.ntlab.traceAnalysisPlatform.tracer.trace.MethodInvocation; import org.ntlab.traceAnalysisPlatform.tracer.trace.Statement; @@ -42,7 +46,12 @@ return list; } - public boolean addTraceBreakPoint(String inputSignature, int lineNo, long currentTime) { + public boolean addTraceBreakPoint(String inputSignature, int lineNo) { + boolean isSuccess = addTraceBreakPoint(inputSignature, lineNo, true); + return isSuccess; + } + + public boolean addTraceBreakPoint(String inputSignature, int lineNo, boolean isAvailable) { String methodSignature = findMethodSignaureOnTrace(inputSignature); if (methodSignature == null) return false; Map innerMap = traceBreakPoints.get(methodSignature); @@ -50,15 +59,14 @@ innerMap = new HashMap<>(); traceBreakPoints.put(methodSignature, innerMap); } - TraceBreakPoint tbp = new TraceBreakPoint(methodSignature, lineNo, currentTime); - if (!tbp.isAvailable()) return false; - innerMap.put(lineNo, tbp); - addHistories(tbp); - return true; - } - - public boolean addTraceBreakPoint(String methodSignature, int lineNo) { - return addTraceBreakPoint(methodSignature, lineNo, 0L); + try { + TraceBreakPoint tbp = TraceBreakPoint.createNewTraceBreakPoint(methodSignature, lineNo, isAvailable, inputSignature); + innerMap.put(lineNo, tbp); + addHistories(tbp); + return true; + } catch (IllegalArgumentException e) { + return false; + } } private void removeTraceBreakPoint(String methodSignature, int lineNo) { @@ -75,6 +83,32 @@ removeTraceBreakPoint(methodSignature, lineNo); } + public void importBreakpointFromEclipse() { + IBreakpoint[] breakpoints = DebugPlugin.getDefault().getBreakpointManager().getBreakpoints(); + for (IBreakpoint breakpoint : breakpoints) { + try { + IMarker breakpointMarker = breakpoint.getMarker(); + Map attributes = breakpointMarker.getAttributes(); + String type = (String)attributes.get("org.eclipse.jdt.debug.core.typeName"); + type = type.substring(type.lastIndexOf(".") + 1); + int lineNo = (int)attributes.get(IMarker.LINE_NUMBER); + boolean available = (boolean)attributes.get(IBreakpoint.ENABLED); + String message = (String)attributes.get(IMarker.MESSAGE); + String methodName = message.substring(message.indexOf("-") + 2); + methodName = methodName.replace(" ", ""); + String signature; + if (methodName.startsWith(type + "(")) { + signature = methodName; // �R���X�g���N�^���̏ꍇ + } else { + signature = type + "." + methodName; + } + addTraceBreakPoint(signature, lineNo, available); + } catch (CoreException e) { + e.printStackTrace(); + } + } + } + private String findMethodSignaureOnTrace(String inputSignature) { HashSet methodSignatures = trace.getAllMethodSignatures(); for (String signature : methodSignatures) {