@Override public String toString() { return toString(true); }
private static StringBuilder getNodeState(ExecutionNode node, ExecutionGraph graph) { MethodState state = node.getContext().getMethodState(); String op = node.toString().replaceAll(DOT, "?").replace("\"", "\\\""); String stateStr = state.toString().replaceAll(DOT, "?").replace("\"", "\\\"").trim(); int nodeIndex = graph.getNodeIndex(node); StringBuilder sb = new StringBuilder(); sb.append("\"@").append(node.getAddress()).append('.').append(nodeIndex).append(" :: "); sb.append(op).append('\n').append(stateStr).append('"'); return sb; } }
public String toString(boolean onlyPeekCachedRegisters) { StringBuilder sb = new StringBuilder(); if (mState != null) { sb.append(method.getSignature()).append(" State: ").append(mState.toString(onlyPeekCachedRegisters)); } if (sb.length() > 0) { sb.append('\n'); } Set<VirtualType> initializedClasses = getInitializedClasses(); if (initializedClasses.size() < 4) { // Too many will trash the heap for (VirtualType virtualClass : initializedClasses) { ClassState cState = classToStatus.get(virtualClass).getClassState(); sb.append("Class state: ").append(virtualClass).append(' ').append(cState); } } return sb.toString(); }
private static ExecutionNode buildNode(int address, String nodeString, String stateString) { ExecutionNode node = mock(ExecutionNode.class); when(node.getAddress()).thenReturn(address); when(node.toString()).thenReturn(nodeString); MethodState state = mock(MethodState.class); when(state.toString()).thenReturn(stateString); ExecutionContext context = mock(ExecutionContext.class); when(context.getMethodState()).thenReturn(state); when(node.getContext()).thenReturn(context); return node; }
@Test public void hasExpectedToString() { ExecutionGraph graph = VMTester.execute(CLASS_NAME, "simpleLoop()V"); ExecutionNode node = graph.getRoot(); MethodState state = node.getContext().getMethodState(); String expected = "params: 0, locals: 2\nv0: type=I, value=0"; assertEquals(expected, state.toString()); } }