diff --git a/org.ntlab.reverseDebugger/src/org/ntlab/debuggingControl/DebuggingControlAction.java b/org.ntlab.reverseDebugger/src/org/ntlab/debuggingControl/DebuggingControlAction.java index cc7f4cf..5db785d 100644 --- a/org.ntlab.reverseDebugger/src/org/ntlab/debuggingControl/DebuggingControlAction.java +++ b/org.ntlab.reverseDebugger/src/org/ntlab/debuggingControl/DebuggingControlAction.java @@ -7,6 +7,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Scanner; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IWorkspaceRoot; @@ -149,18 +150,102 @@ methodName = "getId"; Value threadIdValue = callInstanceMethod(vm, thread, methodName, thread); StringReference threadId = vm.mirrorOf(String.valueOf(((LongValue)threadIdValue).value())); - System.out.print("threadId = " + threadId); // �擾����ThreadId�̊m�F�p + System.out.println("threadId = " + threadId); // �擾����ThreadId�̊m�F�p // threadId�ɑΉ�����ThreadInstance���擾 className = "TraceJSON"; - methodName = "getThreadInstanceForDebuggingControl"; + methodName = "getThreadInstance"; Value threadInstance = callStaticMethod(vm, thread, packageName, className, methodName, threadId); // threadInstance�̌Ăяo���X�^�b�N��̃��\�b�h�ɂ‚��Ă̊e��f�[�^���擾���ĕ\������ // printStackData(vm, thread, threadInstance); // threadInstance�̃��\�b�h�Ăяo���؂̑S���\�b�h�ɂ‚��Ă̊e��f�[�^���擾���ĕ\������ - printCallTreeDataFromRoot(vm, thread, threadInstance); +// printCallTreeDataFromRoot(vm, thread, threadInstance); + + // �I�����C����͒���traceCollector��TraceJSON#getObjectFlow()���Ăяo�����̃R�[�h + printObjectFlow(vm, thread, threadInstance); + } + + /** + * �I�����C����͒���traceCollector��TraceJSON#getObjectFlow()���Ăяo�����̃R�[�h + * @param vm + * @param thread + * @param threadInstance + */ + private void printObjectFlow(VirtualMachine vm, ThreadReference thread, Value threadInstance) throws InvalidTypeException, + ClassNotLoadedException, InvocationException, IncompatibleThreadStateException { + // ThreadInstance������curMethodExecution��, ����statement���X�g���擾 + String methodName = "getCurrentMethodExecution"; + Value methodExecution = callInstanceMethod(vm, thread, methodName, (ObjectReference)threadInstance); + Scanner scanner = new Scanner(System.in); + methodName = "getStatements"; + Value statements = callInstanceMethod(vm, thread, methodName, (ObjectReference)methodExecution); + methodName = "size"; + int statementsSize = ((IntegerValue)callInstanceMethod(vm, thread, methodName, (ObjectReference)statements)).value(); + + // �f�o�b�K�Ŏ~�߂Ă���n�_�ɊY�����郁�\�b�h���s����, �X�^�[�g�ƂȂ���̃G�C���A�X�̃��X�g���擾���ĕ\������ + String packageName = "org.ntlab.traceCollector.tracer.trace"; + String className = "TraceJSON"; + methodName = "findAllStartAlias"; + Value startAliasList = callStaticMethod(vm, thread, packageName, className, methodName, methodExecution); + methodName = "size"; + int startAliasListSize = ((IntegerValue)callInstanceMethod(vm, thread, methodName, (ObjectReference)startAliasList)).value(); + System.out.println("-----------------------------------------------------"); + for (int i = 0; i < startAliasListSize; i++) { + methodName = "get"; + Value startAlias = callInstanceMethod(vm, thread, methodName, (ObjectReference)startAliasList, vm.mirrorOf(i)); + StringBuilder sb = new StringBuilder(String.format("%2d%s", i, ": ")); + methodName = "getObjectId"; + sb.append(String.format("%12s", ((StringReference)callInstanceMethod(vm, thread, methodName, (ObjectReference)startAlias)).value() + " ")); + methodName = "getLineNo"; + sb.append(String.format("%4s", ((IntegerValue)callInstanceMethod(vm, thread, methodName, (ObjectReference)startAlias)).value() + " ")); + methodName = "getStatementType"; + sb.append(String.format("%-16s", ((StringReference)callInstanceMethod(vm, thread, methodName, (ObjectReference)startAlias)).value())); + sb.append(" -> "); + methodName = "getStatementSignature"; + sb.append(String.format("%-30s", ((StringReference)callInstanceMethod(vm, thread, methodName, (ObjectReference)startAlias)).value() + " ")); + methodName = "getOccurrenceExp"; + sb.append(String.format("%3d%s", ((IntegerValue)callInstanceMethod(vm, thread, methodName, (ObjectReference)startAlias)).value(), " ")); + methodName = "getClassName"; + sb.append(String.format("%-20s", ((StringReference)callInstanceMethod(vm, thread, methodName, (ObjectReference)startAlias)).value() + " ")); + System.out.println(sb); + } + System.out.println("-----------------------------------------------------"); + + // �I�������G�C���A�X���N�_�ɃI�u�W�F�N�g�t���[���Ăяo���Č��ʂ����X�g�Ŏ󂯎�� + System.out.print("(input)aliasNo? -> "); + int aliasNo = scanner.nextInt(); + methodName = "get"; + Value startAlias = callInstanceMethod(vm, thread, methodName, (ObjectReference)startAliasList, vm.mirrorOf(aliasNo)); + methodName = "toString"; + Value str = callInstanceMethod(vm, thread, methodName, (ObjectReference)startAlias); + printValue("", "", str, true); + methodName = "getObjectFlow"; + Value aliasLists = callStaticMethod(vm, thread, packageName, className, methodName, startAlias); + System.out.println(); + + // �擾�������X�g�̒��g�����[�v�ʼn񂵂Ȃ���m�F��, �‚��łɓ��Y�\�[�X�t�@�C����Ώ�Eclipse�ŊJ�����Ă݂� + methodName = "size"; + int aliasListsSize = ((IntegerValue)callInstanceMethod(vm, thread, methodName, (ObjectReference)aliasLists)).value(); + for (int i = 0; i < aliasListsSize; i++) { + System.out.println("---------------------------------------------"); + System.out.println("���X�g" + i); + methodName = "get"; + Value aliasList = callInstanceMethod(vm, thread, methodName,(ObjectReference)aliasLists, vm.mirrorOf(i)); + methodName = "size"; + int aliasListSize = ((IntegerValue)callInstanceMethod(vm, thread, methodName, (ObjectReference)aliasList)).value(); + for (int j = 0; j < aliasListSize; j++) { + methodName = "get"; + Value alias = callInstanceMethod(vm, thread, methodName, (ObjectReference)aliasList, vm.mirrorOf(j)); + methodName = "toString"; + Value str2 = callInstanceMethod(vm, thread, methodName, (ObjectReference)alias); + printValue("", "", str2, true); + methodName = "getMethodExecution"; + Value aliasMethodExecution = callInstanceMethod(vm ,thread, methodName, (ObjectReference)alias); + openSrcFileOfMethodExecution(vm, thread, aliasMethodExecution); + } + } } /** @@ -229,17 +314,17 @@ return; } String methodName = "size"; - final int METHOD_EXECUTION_SIZE = ((IntegerValue)callInstanceMethod(vm, thread, methodName, (ObjectReference)methodExecutions)).value(); - if (METHOD_EXECUTION_SIZE == 0) { + final int METHOD_EXECUTIONS_SIZE = ((IntegerValue)callInstanceMethod(vm, thread, methodName, (ObjectReference)methodExecutions)).value(); + if (METHOD_EXECUTIONS_SIZE == 0) { return; } final String DEEP_SPACE_INDENT = indent.replace("-", " ") + " "; // ���\�b�h�V�O�l�`���ȊO�ł̕\���p - for (int i = 0; i < METHOD_EXECUTION_SIZE; i++) { + for (int i = 0; i < METHOD_EXECUTIONS_SIZE; i++) { IntegerValue index = vm.mirrorOf(i); methodName = "get"; Value methodExecution = callInstanceMethod(vm, thread, methodName, (ObjectReference)methodExecutions, index); - Value lineNo = (parent != null) ? getMethodExecutionLineNo(vm, thread, parent, methodExecution) : vm.mirrorOf(0); + Value lineNo = (parent != null) ? getMethodExecutionLineNo(vm, thread, parent, methodExecution) : vm.mirrorOf(0); // �f�[�^�̎擾�ƕ\���֘A Value methodSignature = getMethodExecutionSignature(vm, thread, methodExecution); @@ -333,7 +418,7 @@ System.out.print(indent + fieldName); // ���̃t�B�[���h�ɂ‚��Ă̍ŐV�̍X�V�����擾(FieldUpdate) - methodName = "getRecentlyFieldUpdateForDebuggingControl"; + methodName = "getRecentlyFieldUpdate"; ObjectReference fieldUpdate = (ObjectReference)callStaticMethod(vm, thread, packageName, className, methodName, thisObjId, vm.mirrorOf(fieldName), thread); if (fieldUpdate == null) { System.out.println(" id = null����!" + " type = null����!"); @@ -402,7 +487,7 @@ for (int i = 0;; i++){ // ���̔z��v�f�ɂ‚��Ă̍ŐV�̍X�V�����擾(ArrayUpdate) - methodName = "getRecentlyArrayUpdateForDebuggingControl"; + methodName = "getRecentlyArrayUpdate"; IntegerValue index = vm.mirrorOf(i); ObjectReference arrayUpdate = (ObjectReference)callStaticMethod(vm, thread, packageName, className, methodName, arrayObjId, index, thread); if (arrayUpdate == null) { @@ -568,7 +653,6 @@ IEditorPart editor = JavaUI.openInEditor(type); if (!type.isLocal() && !type.isMember()) { JavaUI.revealInEditor(editor, (IJavaElement)method); - System.out.println("JavaUI.revealInEditor() ���Ăяo������!"); } } } catch (PartInitException | JavaModelException e) { @@ -602,13 +686,12 @@ private boolean checkMethodSignature(IType type, IMethod method, String methodSignature) { String fqcn = type.getFullyQualifiedName(); try { - String jdiMethodSignature = (method.isConstructor()) ? (fqcn + "(") : (fqcn + "." + method.getElementName() + "("); - System.out.println(jdiMethodSignature); - if (methodSignature.contains(jdiMethodSignature)) { + StringBuilder jdtMethodSignature = new StringBuilder(); + jdtMethodSignature.append((method.isConstructor()) ? (fqcn + "(") : (fqcn + "." + method.getElementName() + "(")); + if (methodSignature.contains(jdtMethodSignature)) { // ������v���Ă����ꍇ�Ɍ���A�������X�g����������ł���v���邩�ǂ����𔻒� (�I�[�o�[���[�h�ɂ��딻��������) - jdiMethodSignature += String.join(",", parseFQCNParameters(type, method)) + ")"; // �S�����̃V�O�l�`�������S���薼�ɕϊ�����,�ŋ�؂��������� - System.out.println(jdiMethodSignature); - return methodSignature.contains(jdiMethodSignature); + jdtMethodSignature.append(String.join(",", parseFQCNParameters(type, method)) + ")"); // �S�����̃V�O�l�`�������S����N���X���ɕϊ�����,�ŋ�؂��������� + return methodSignature.contains(jdtMethodSignature); } } catch (JavaModelException e) { e.printStackTrace(); @@ -617,11 +700,10 @@ } /** - * IMethod����擾�ł���S�����̃V�O�l�`�������S���薼�ɒu�������Ċi�[�������X�g��Ԃ� + * IMethod����擾�ł���S�����̃V�O�l�`�������S����N���X���ɒu�������Ċi�[�������X�g��Ԃ� * @param type * @param method * @return - * @throws JavaModelException */ private List parseFQCNParameters(IType type, IMethod method) throws JavaModelException { List parameters = new ArrayList<>(); @@ -638,7 +720,11 @@ } String[][] resolveType = type.resolveType(readableTypeSplit[0]); // �p�b�P�[�W���ƃN���X���̑g�ݍ��킹���擾 if (resolveType != null) { - readableTypeSplit[0] = (resolveType[0][0] + "." + resolveType[0][1]); // ���S���薼 + if (resolveType[0][0].isEmpty()) { + readableTypeSplit[0] = (resolveType[0][1]); // �f�t�H���g�p�b�P�[�W�̏ꍇ�̓p�b�P�[�W����.�͓���Ȃ� + } else { + readableTypeSplit[0] = (resolveType[0][0] + "." + resolveType[0][1]); // ���S����N���X�� + } } parameters.add(readableTypeSplit[0] + readableTypeSplit[1]); } @@ -649,7 +735,7 @@ * �p�b�P�[�W���ƃN���X���ƃ��\�b�h���ƈ������w�肵�Ă��̃N���X���\�b�h���Ăяo�� * @param vm * @param thread - * @param packageName �Ăт����������\�b�h������N���X�̃p�b�P�[�W�� (�N���X���ƌq���Ŋ��S���薼�ɂ��邽�߁A������ . ���‚���) + * @param packageName �Ăт����������\�b�h������N���X�̃p�b�P�[�W�� * @param className �Ăяo���������\�b�h������N���X�� * @param methodName �Ăяo���������\�b�h�� (static) * @param args �Ăяo���������\�b�h�ɓn������(Value �̃N���X�^�ʼn•ϒ�)